View Single Post
  #11  
Old 09-23-2008, 05:18 AM
Derision
Developer
 
Join Date: Feb 2004
Location: UK
Posts: 1,540
Default

I tried reorganising the code to work as you originally intended. This is totally untested.

Note that in the case where a connection is removed, I have put a continue; statement which will go back to the top of the while loop, as I don't believe you want to advance the iterator if you've just deleted an element.

Code:
void ClientList::GetCLEIP(int32 iIP) {

        ClientListEntry* countCLEIPs = 0;
        LinkedListIterator<ClientListEntry*> iterator(clientlist);

        int IPInstances = 0;
        iterator.Reset();

        while(iterator.MoreElements()) {

                countCLEIPs = iterator.GetData();

                // If the IP matches, and the connection admin status is below the exempt status,
                // or exempt status is less than 0 (no-one is exempt)

                if ((countCLEIPs->GetIP() == iIP) &&
                    ((countCLEIPs->Admin() < (RuleI(World, ExemptMaxClientsStatus))) ||
                     (RuleI(World, ExemptMaxClientsStatus) < 0))) {

                        // Increment the occurences of this IP address

                        IPInstances++;

                        // If the number of connections exceeds the lower limit

                        if (IPInstances > (RuleI(World, MaxClientsPerIP))){

                                // If the Admin status of the connection is not eligible for the higher limit,
                                // or there is no higher limit (AddMaxClientStatus<0)

                                if ((countCLEIPs->Admin() < (RuleI(World, AddMaxClientsStatus)) ||
                                    (RuleI(World, AddMaxClientsStatus) < 0))) {

                                        // Remove the connection

                                        countCLEIPs->SetOnline(CLE_Status_Offline);
                                        iterator.RemoveCurrent();
                                        continue;

                                }
                                // else they are eligible for the higher limit, but if they exceed that

                                else if (IPInstances > RuleI(World, AddMaxClientsPerIP)) {

                                        // Remove the connection

                                        countCLEIPs->SetOnline(CLE_Status_Offline);
                                        iterator.RemoveCurrent();
                                        continue;

                                }
                        }
                }
                iterator.Advance();
        }
}
Reply With Quote