From d0b54bbeeed0a841083312d30cc69c97e6671035 Mon Sep 17 00:00:00 2001 From: DarthArgus Date: Mon, 26 Sep 2016 16:41:26 +0000 Subject: [PATCH] better efficiency --- external/3rd/library/udplibrary/UdpLibrary.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/external/3rd/library/udplibrary/UdpLibrary.cpp b/external/3rd/library/udplibrary/UdpLibrary.cpp index 1299073a..b2ff3c91 100755 --- a/external/3rd/library/udplibrary/UdpLibrary.cpp +++ b/external/3rd/library/udplibrary/UdpLibrary.cpp @@ -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)