• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ Otservlist ban, c++ code to count online.

DukeeH

Active Member
Joined
Dec 6, 2010
Messages
550
Solutions
3
Reaction score
39
Hello everyone.

I just got banned from otservlist, and I have this code to follow both rules (not count xlogged and count 4 per ip).
After contacting them by mail and showing the code, he still tells me that i'm counting 5 per ip.

I know that I can just change that 5 to 4, but for me, if it's < 5 it's counting 4.
I want to know if it's really counting 5 from someone that understands it.


C++:
uint32_t Game::getPlayersWithMcLimit()
{

    std::map<uint32_t, uint32_t> ips;
    uint32_t count = 0;

    for (AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)
    {
        if (!it->second->isRemoved() && it->second->getIdleTime() < 960000)
        {
            uint32_t ip = it->second->getIP();


            if (ips.find(ip) == ips.end())
            {
                ips[ip] = 1;
                count++;
            }
            else if (ips[ip] < 5)
            {
                ips[ip]++;
                count++;
            }
        }
    }
    return count;
}

Thanks for your time.
 
Solution
I understood it wrong, so i just change to 4 and it'll be right?

edit.
I'm sorry for being stubborn, but all the codes I see, are coded like this, are they all wrong or mine is diferrent?
* I added comments in the code

I'll use this one for example, by Gunz post:

Lua:
uint32_t real = 0;

std::map<uint32_t, uint32_t> listIP;

for (const auto& it : g_game.getPlayers()) {
   if (it.second->getIP() !=...
Hello everyone.

I just got banned from otservlist, and I have this code to follow both rules (not count xlogged and count 4 per ip).
After contacting them by mail and showing the code, he still tells me that i'm counting 5 per ip.

I know that I can just change that 5 to 4, but for me, if it's < 5 it's counting 4.
I want to know if it's really counting 5 from someone that understands it.


C++:
uint32_t Game::getPlayersWithMcLimit()
{

    std::map<uint32_t, uint32_t> ips;
    uint32_t count = 0;

    for (AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)
    {
        if (!it->second->isRemoved() && it->second->getIdleTime() < 960000)
        {
            uint32_t ip = it->second->getIP();


            if (ips.find(ip) == ips.end())
            {
                ips[ip] = 1;
                count++;
            }
            else if (ips[ip] < 5)
            {
                ips[ip]++;
                count++;
            }
        }
    }
    return count;
}

Thanks for your time.

Yes it's added up to 5.

If ips[ip] is still less than 5 when it reaches that point in the loop (aka it's 4), it will add to the table (now it's 5).
The next time it comes around it's no longer less than 5, because it is 5.
 
Yes it's added up to 5.

If ips[ip] is still less than 5 when it reaches that point in the loop (aka it's 4), it will add to the table (now it's 5).
The next time it comes around it's no longer less than 5, because it is 5.
I understood it wrong, so i just change to 4 and it'll be right?

edit.
I'm sorry for being stubborn, but all the codes I see, are coded like this, are they all wrong or mine is diferrent?
 
Last edited:
I understood it wrong, so i just change to 4 and it'll be right?

edit.
I'm sorry for being stubborn, but all the codes I see, are coded like this, are they all wrong or mine is diferrent?
* I added comments in the code

I'll use this one for example, by Gunz post:

Lua:
uint32_t real = 0;

std::map<uint32_t, uint32_t> listIP;

for (const auto& it : g_game.getPlayers()) {
   if (it.second->getIP() != 0) {
      auto ip = listIP.find(it.second->getIP());
      if (ip != listIP.end()) {
         listIP[it.second->getIP()]++; -- Updates count first
         if (listIP[it.second->getIP()] < 5) { -- make sure count is less than 5
            real++; -- if it is less than 5, he updates the total real count
         }
      } else {
         listIP[it.second->getIP()] = 1;
         real++;
      }
   }
}
players.append_attribute("online") = std::to_string(real).c_str();

Now your code:
Lua:
uint32_t Game::getPlayersWithMcLimit()
{

    std::map<uint32_t, uint32_t> ips;
    uint32_t count = 0;

    for (AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)
    {
        if (!it->second->isRemoved() && it->second->getIdleTime() < 960000)
        {
            uint32_t ip = it->second->getIP();


            if (ips.find(ip) == ips.end())
            {
                ips[ip] = 1;
                count++;
            }
            else if (ips[ip] < 5) -- checks if it's less than 5 before updating count
            {
                ips[ip]++;  -- updates count
                count++; -- now updates real count as well, even though ips[ip] could now be 5
            }
        }
    }
    return count;
}


So to fix your code, the simplest thing would be to change 5 to 4. Or you can restructure your code to be more similar to the other posts.
 
Solution
Back
Top