better efficiency

This commit is contained in:
DarthArgus
2016-09-26 16:41:26 +00:00
parent 51e0119460
commit d0b54bbeee
+12 -5
View File
@@ -1007,16 +1007,23 @@ void UdpManager::ProcessRawPacket(const PacketHistoryEntry *e)
{
if (mParams.maxConnectionsPerIP > 0)
{
UdpConnection *alreadyExists;
int clientConnections = 0;
for (int i = 1; i != 65535; i++)
// and instead of counting up as previously
// we can count down from the top, as i think UDP (or SWG at least) usually uses higher outgoing ports?
// of course a flooder will use any port so that doesn't matter...
for (int i = 65535; i >= 1; --i)
{
alreadyExists = AddressGetConnection(e->mIp, i);
if (alreadyExists != nullptr)
if (AddressGetConnection(e->mIp, i) != nullptr)
{
clientConnections++;
}
// no need to keep looping/counting if and when we reach the limit
// of course we'll still count all the way
if (clientConnections >= mParams.maxConnectionsPerIP)
{
break;
}
}
if (clientConnections >= mParams.maxConnectionsPerIP)