• 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++ [TFS 0.4] Save CountOfCharacters per IP

mameca123

www.TheHeroesOfTime.com
Joined
Nov 19, 2008
Messages
37
Reaction score
8
Hello,

I'd like to know an easier way to create - on the server opening moment - a list where the index is each player IP address and the list[IP] returns the number of characters online (no EXIT) using such IP address.

The idea is to create an ANTI-MC system on protocolgame.cpp.

Nowadays, I am running an non-optimized check. For every login, I check the player's IP and I loop through every player online to get their address. If IP address is equal to the login-character's IP address, I increment a count variable. If >= 4, I send a message window to the player saying that he has already 4 characters online, and refuse the login. This was done in lua via creaturescripts before but it was way less optimized. But I'd like to optimize it more (as my idea above).

How it is done nowadays:
1669315953086.png
 
This work ?
Works on OTX 2:

C++:
        player->lastIP = player->getIP();
        
        /* Count 4 players per IP */
        uint32_t player_with_ip = 0;
        for (AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)    {
            if (it->second->getIP () !=0) {
                if (it->second->getIP() == player->lastIP) {
                    player_with_ip++;
                }
            }
        }
        if (player_with_ip >= 4) {
            disconnectClient (0x14, "You can only login 4 characters per IP, and you reached the limit.");
            return false;
        }
 
Works on OTX 2:

C++:
        player->lastIP = player->getIP();
       
        /* Count 4 players per IP */
        uint32_t player_with_ip = 0;
        for (AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)    {
            if (it->second->getIP () !=0) {
                if (it->second->getIP() == player->lastIP) {
                    player_with_ip++;
                }
            }
        }
        if (player_with_ip >= 4) {
            disconnectClient (0x14, "You can only login 4 characters per IP, and you reached the limit.");
            return false;
        }
Not work... :(

C++:
[CC] objects/protocolgame.o
protocolgame.cpp: In member function ‘void ProtocolGame::login(const string&, uint32_t, const string&, OperatingSystem_t, uint16_t, bool)’:
protocolgame.cpp:319:20: error: return-statement with a value, in function returning ‘void’ [-fpermissive]
  319 |             return false;
      |                    ^~~~~
make: *** [Makefile:74: objects/protocolgame.o] Error 1
 
Paste it here
C++:
PlayerVector temp = g_game.getPlayersByIP(player->getIP());
if ((int32_t)temp.size() >= 4)
{
    disconnectClient(0x14, "You can only login 4 characters per IP, and you reached the limit.");
    return;
}
 
Can you adapt this to TFS 1.5?
C++:
int32_t ipsCounter = 0;
for (const auto& it : g_game.getPlayers())
{
    if (player->getIP() == it.second->getIP() && ++ipsCounter >= 4)
    {
        disconnectClient("You can only login 4 characters per IP, and you reached the limit.");
        return;
    }
}
 
C++:
int32_t ipsCounter = 0;
for (const auto& it : g_game.getPlayers())
{
    if (player->getIP() == it.second->getIP() && ++ipsCounter >= 4)
    {
        disconnectClient("You can only login 4 characters per IP, and you reached the limit.");
        return;
    }
}
I added and compiled with no errors, everything is fine. However, when I logged in with 4 characters and tried to enter the fifth one, the message appeared saying 'You can only login with 4 characters per IP and you consume the limit'. However, I was still able to log in normally. Is there any way to prevent me from entering more characters?
 
EDIT POST: Perfect! Now it's resolved. It was only necessary to locate the part of the code where it says "player->incrementReferenceCounter(); player->setID();" and add the code below it. Working fine now!
 
Last edited:
Yes 🧐
 
Yes 🧐
Meant 1.5 jeje
 
C++:
int32_t ipsCounter = 0;
for (const auto& it : g_game.getPlayers())
{
    if (player->getIP() == it.second->getIP() && ++ipsCounter >= 4)
    {
        disconnectClient("You can only login 4 characters per IP, and you reached the limit.");
        return;
    }
}
I have a question: this code you made is working fine so far, right? But what if someone uses a program like VPN to bypass IP and create multiple accounts... what can we do about it?
 
this code you made is working fine so far, right?
Now that you mention it, not completely.
You can replace it.second->getIP() with it.second->lastIP

That will prevent players to bypass the check by X logout [ip address turning into "0.0.0.0"]

But what if someone uses a program like VPN to bypass IP and create multiple accounts... what can we do about it?
Nothing 😝
 
Back
Top