Hi,
Anti MC scripts everywhere but there is one problem.
If someone gives a quick exit and logs in, the onLogin function won't see it and can still have more characters logged in than allowed.
Can you remedy this ?
Ideally the Admin account type and one IP address should be allowed to Max MC.
local multiclient_limit = 3
local countGMTowardsLimit = false
-- END OF CONFIG
GLOBAL_PLAYER_IPS = GLOBAL_PLAYER_IPS or {
-- [ip_string] = {{playerId}, {playerId}}
}
local...
local AccPorIp = 3 -- Allowed connections
function onLogin(player)
local mc = 0
for _, verificar in ipairs(Game.getPlayers()) do
if player:getIp() == verificar:getIp() then
mc = mc + 1
if mc > AccPorIp then return false end
end
end
return true
end
thats totally wrong code.LUA:local AccPorIp = 3 -- Allowed connections function onLogin(player) local mc = 0 for _, verificar in ipairs(Game.getPlayers()) do if player:getIp() == verificar:getIp() then mc = mc + 1 if mc > AccPorIp then return false end end end return true end
Elaborate pipsqueakthats totally wrong code.
So what? Can you play with the character that is exited? No, stop overthinking simple stuff.it should be done in protocol, not in onLogin, because if you exit with pz or infight your character stay in game, and when someone login on logged in character it does not proc onLogin func from lua so you can just bypass it easly
You can play character that exited using other IP than detected inSo what? Can you play with the character that is exited? No, stop overthinking simple stuff.
onLogin
event.onLogin
event won't be executed, so it won't limit number of characters logged from given IP.onThink
event to check number of players per IP and kick them, if there are too many logged from same IP - as Xikini's script does.ProtocolGame
ex. ProtocolGame::connect
to check MC for every connection, not just for every onLogin
event.iptables -A INPUT -p tcp --syn --dport 7172 -m connlimit --connlimit-above 2 --connlimit-mask 32 -j REJECT --reject-with tcp-reset
Can you adapt this to TFS 1.5?
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;
}
}
It should not hit CPU usage hard. Loop over players online is super fast, even with 2000 online. Only problem can be access to IP and conversion to comparable format.Does Roddet's C++ implementation have performance issues by looping through all online players on each login
std::map<IP, count_of_connections>
is faster, but code may be a bit complicated.uint32_t
. getIP()
in Connection
called some socket
function to get IP from it, IDK what it did inside, maybe it called some system function to obtain IP of socket (slow), but maybe it already had socket IP in OTS RAM and just had to copy it (fast).getIP()
returns boost::asio::ip::address
structure (with IPv4 or IPv6 inside), but socket.remote_endpoint()
is called only once and cached in remoteAddress
variable, so there is cache already.uint32_t
IP format and they already added internal cache in getIP()
function, to call socket.remote_endpoint
only once - when getIP()
is called first time. Only CPU wasting part of getIP()
is locking std::scoped_lock lock(connectionLock);
, even when we only read cached variable.getIP()
, but not cachedConnection
classConnection
class, may waste some CPU on connectionLock
for every call to getIP()