• 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++ unique active player

alcapone

Member
Joined
Jan 13, 2021
Messages
247
Reaction score
19
"This attribute is supposed to return the number of unique active players on a server. So returned XML looks like:
<players online="344" unique="144" max="1500" peak="1501"/>"


Xin is asking that if they have this 'unique' tag anyone would have any idea how to create it or an example

bump

bump
 
Solution

updated protocolstatus block:
C++:
// Compliance to otservlist.org regulations
// Dont count players with idletime over 15 minutes, count max 4 players per IP, count unique IPs
// https://otland.net/threads/very-important-rules-change-on-otservlist-org.247531/
// https://otland.net/threads/very-important-rules-change-on-otservlist-org.247531/post-2492577
// No official statement for unique IP count ???
uint32_t real = 0;
uint32_t ips = 0;
std::map<uint32_t, uint32_t> listIP;
for (const auto& it : g_game.getPlayers()) {
    if (it.second->idleTime <= 900000 && it.second->getIP() != 0) {
        auto ip = listIP.find(it.second->getIP())...
Xinn is asking for this?
Where did you get this information?

My guess is that he wants you to modify the status protocol response to contain a count of unique IP addresses.
But if this is an otservlist regulation, it should be public information.
 
Xinn is asking for this?
Where did you get this information?

My guess is that he wants you to modify the status protocol response to contain a count of unique IP addresses.
But if this is an otservlist regulation, it should be public information.
some servers were banned for not having this information when contacting the answer I got was this "This attribute is supposed to return the number of unique active players on a server. So returned XML looks like: <players online="344" unique="144" max="1500" peak="1501"/>"

I asked for more information who knows some more unanswered example code.

xin.png
 
Last edited:

updated protocolstatus block:
C++:
// Compliance to otservlist.org regulations
// Dont count players with idletime over 15 minutes, count max 4 players per IP, count unique IPs
// https://otland.net/threads/very-important-rules-change-on-otservlist-org.247531/
// https://otland.net/threads/very-important-rules-change-on-otservlist-org.247531/post-2492577
// No official statement for unique IP count ???
uint32_t real = 0;
uint32_t ips = 0;
std::map<uint32_t, uint32_t> listIP;
for (const auto& it : g_game.getPlayers()) {
    if (it.second->idleTime <= 900000 && it.second->getIP() != 0) {
        auto ip = listIP.find(it.second->getIP());
        if (ip != listIP.end()) {
            listIP[it.second->getIP()]++;
            if (listIP[it.second->getIP()] < 5) {
                real++;
            }
        }
        else {
            listIP[it.second->getIP()] = 1;
            real++;
            ips++;
        }
    }
}
players.append_attribute("online") = std::to_string(real).c_str();
players.append_attribute("unique") = std::to_string(ips).c_str();
 
Last edited:
Solution

updated protocolstatus block:
C++:
// Compliance to otservlist.org regulations
// Dont count players with idletime over 15 minutes, count max 4 players per IP, count unique IPs
// https://otland.net/threads/very-important-rules-change-on-otservlist-org.247531/
// https://otland.net/threads/very-important-rules-change-on-otservlist-org.247531/post-2492577
// No official statement for unique IP count ???
uint32_t real = 0;
uint32_t ips = 0;
std::map<uint32_t, uint32_t> listIP;
for (const auto& it : g_game.getPlayers()) {
    if (it.second->idleTime < 960000 && it.second->getIP() != 0) {
        auto ip = listIP.find(it.second->getIP());
        if (ip != listIP.end()) {
            listIP[it.second->getIP()]++;
            if (listIP[it.second->getIP()] < 5) {
                real++;
            }
        }
        else {
            listIP[it.second->getIP()] = 1;
            real++;
            ips++;
        }
    }
}
players.append_attribute("online") = std::to_string(real).c_str();
players.append_attribute("unique") = std::to_string(ips).c_str();
I added and sent to him
 

updated protocolstatus block:
C++:
// Compliance to otservlist.org regulations
// Dont count players with idletime over 15 minutes, count max 4 players per IP, count unique IPs
// https://otland.net/threads/very-important-rules-change-on-otservlist-org.247531/
// https://otland.net/threads/very-important-rules-change-on-otservlist-org.247531/post-2492577
// No official statement for unique IP count ???
uint32_t real = 0;
uint32_t ips = 0;
std::map<uint32_t, uint32_t> listIP;
for (const auto& it : g_game.getPlayers()) {
    if (it.second->idleTime < 960000 && it.second->getIP() != 0) {
        auto ip = listIP.find(it.second->getIP());
        if (ip != listIP.end()) {
            listIP[it.second->getIP()]++;
            if (listIP[it.second->getIP()] < 5) {
                real++;
            }
        }
        else {
            listIP[it.second->getIP()] = 1;
            real++;
            ips++;
        }
    }
}
players.append_attribute("online") = std::to_string(real).c_str();
players.append_attribute("unique") = std::to_string(ips).c_str();
Is this the only thing we need to add? Or should we also edit something in the player.h file? Thanks!

EDIT: Tried it out, ofc we need to move the:
"int32_t idleTime = 0;" to the public part of the player.h file!
 
Last edited:
Is this the only thing we need to add? Or should we also edit something in the player.h file? Thanks!

EDIT: Tried it out, ofc we need to move the:
"int32_t idleTime = 0;" to the public part of the player.h file!
it will depend on what he invents, the cool thing is to enter ots sites that are on the list and have 2,000 online and on the list 10 and nothing is done
 

updated protocolstatus block:
C++:
// Compliance to otservlist.org regulations
// Dont count players with idletime over 15 minutes, count max 4 players per IP, count unique IPs
// https://otland.net/threads/very-important-rules-change-on-otservlist-org.247531/
// https://otland.net/threads/very-important-rules-change-on-otservlist-org.247531/post-2492577
// No official statement for unique IP count ???
uint32_t real = 0;
uint32_t ips = 0;
std::map<uint32_t, uint32_t> listIP;
for (const auto& it : g_game.getPlayers()) {
    if (it.second->idleTime < 960000 && it.second->getIP() != 0) {
        auto ip = listIP.find(it.second->getIP());
        if (ip != listIP.end()) {
            listIP[it.second->getIP()]++;
            if (listIP[it.second->getIP()] < 5) {
                real++;
            }
        }
        else {
            listIP[it.second->getIP()] = 1;
            real++;
            ips++;
        }
    }
}
players.append_attribute("online") = std::to_string(real).c_str();
players.append_attribute("unique") = std::to_string(ips).c_str();

Hey @Znote thanks for sharing this :)
I applied the changes

1658476970615.png

And protocolstatus.cpp

1658477039745.png

But it still doesn't allow me to connect 4 multi-clients. Any idea of what was done wrong? :)
Thanks in advance! Regards :)
 
Hey @Znote thanks for sharing this :)
I applied the changes

View attachment 69435

And protocolstatus.cpp

View attachment 69436

But it still doesn't allow me to connect 4 multi-clients. Any idea of what was done wrong? :)
Thanks in advance! Regards :)

This only affects count reporting, if you can not connect more than 4 MC, check your network filtering rules. Etc a firewall or iptables that block more than 4 concurrent connections per IP.
 
This only affects count reporting, if you can not connect more than 4 MC, check your network filtering rules. Etc a firewall or iptables that block more than 4 concurrent connections per IP.
That was a really quick answer! Thanks :D Where should I start looking for it? I basically need to have 4 mc connections, this is something really requested from the people that plays my server, if you can guide me with it I'll appreciate it a lot :) I use TFS 1.5 downgraded by Nekiro (8.60). Also using a VPS as host provider.
 
@Znote I made this modification to old code can this make the engine vulnerable if i call g_game functon on status.cpp?

C++:
int32_t Game::getRealIps()
{
    uint32_t ips = 0;
    std::map<uint32_t, uint32_t> listIP;
    for(AutoList<Player>::listiterator it = Player::listPlayer.list.begin(); it != Player::listPlayer.list.end(); ++it)
    {
        if(it->second->isRemoved())
        {
            continue;
        }
       
        if (it->second->getIdleTime() <= 900000 && it->second->getIP() != 0)
        {
            auto ip = listIP.find(it->second->getIP());
            if (ip == listIP.end())
            {
                listIP[it->second->getIP()] = 1;
                ips++;
            }
        }
    }
    return ips;
}
 

updated protocolstatus block:
C++:
// Compliance to otservlist.org regulations
// Dont count players with idletime over 15 minutes, count max 4 players per IP, count unique IPs
// https://otland.net/threads/very-important-rules-change-on-otservlist-org.247531/
// https://otland.net/threads/very-important-rules-change-on-otservlist-org.247531/post-2492577
// No official statement for unique IP count ???
uint32_t real = 0;
uint32_t ips = 0;
std::map<uint32_t, uint32_t> listIP;
for (const auto& it : g_game.getPlayers()) {
    if (it.second->idleTime < 960000 && it.second->getIP() != 0) {
        auto ip = listIP.find(it.second->getIP());
        if (ip != listIP.end()) {
            listIP[it.second->getIP()]++;
            if (listIP[it.second->getIP()] < 5) {
                real++;
            }
        }
        else {
            listIP[it.second->getIP()] = 1;
            real++;
            ips++;
        }
    }
}
players.append_attribute("online") = std::to_string(real).c_str();
players.append_attribute("unique") = std::to_string(ips).c_str();
Hello,

Can you help me adapt this script to the OTX2 -0.7 codename Lord Zedd?

Attached is my status.cpp
 

Attachments

Last edited:
status.cpp
game.cpp

Next time create your own thread

Hello friend, thank you very much, but it did not work.

The error follows.

Can you help please?

Lua:
tportugal@oldtibia:/srv/shared/Source$ make -j$(nproc)
make  all-am
make[1]: Entering directory '/srv/shared/Source'
  CXX      actions.o
  CXX      baseevents.o
  CXX      chat.o
  CXX      combat.o
  CXX      beds.o
  CXX      condition.o
  CXX      configmanager.o
  CXX      connection.o
  CXX      container.o
  CXX      creature.o
  CXX      creatureevent.o
  CXX      cylinder.o
  CXX      database.o
  CXX      databasemanager.o
  CXX      databasemysql.o
  CXX      depot.o
  CXX      dispatcher.o
  CXX      exception.o
  CXX      fileloader.o
  CXX      game.o
  CXX      globalevent.o
  CXX      group.o
  CXX      gui.o
  CXX      house.o
  CXX      housetile.o
game.cpp:6037:38: error: no ‘uint32_t Game::getPlayersWithMcLimit()’ member function declared in class ‘Game’
 uint32_t Game::getPlayersWithMcLimit()
                                      ^
game.cpp:6064:39: error: no ‘uint32_t Game::getUniquePlayersOnline()’ member function declared in class ‘Game’
 uint32_t Game::getUniquePlayersOnline()
                                       ^
  CXX      inputbox.o
  CXX      ioban.o
  CXX      ioguild.o
Makefile:552: recipe for target 'game.o' failed
make[1]: *** [game.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/srv/shared/Source'
Makefile:409: recipe for target 'all' failed
make: *** [all] Error 2
 
Back
Top