• 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!

TFS 0.X DDOS players protection

warriorfrog

Active Member
Joined
Jul 29, 2015
Messages
334
Reaction score
35
I'm trying to add ping functions to 0.4 source codes by using @Mock base to use this test script made by @M0ustafa it should protect players when server got in ddos, it should kick everybody while server is on DDOS attack...

But i just make some small changes to put it to run, idk if it is working i need someone else with code experience to tell me if it is working
Is anyone can help?

GLOBALEVENT TO KICK PLAYERS WHEN SERVER IS ON DDOS \/

Code:
<globalevent name="ddos_mock" interval="6000" event="script" value="ddos.lua"/>

Code:
---Script by mock the bear
local ping_timeout_ = 2000  -- Equals 2 seconds of non response
local active_anti_ddos = true;
local ping_to_execute_anti_ddos = 0.75 --[[is ping timeout * self.
If helf of this server ping if near this value
the server will auto kick]]

local pingbase = 0;
local pingN = 0;
local block = false;
local player_o = 0;
function onThink(interval, lastExecution) -- MTB
    pingbase = 0;
    pingN = 0;
    block = false;
    local pls = getPlayersOnline()
    player_o = #pls
    for i,cid in pairs(pls) do
        ping.getPing(cid,29894,function(cid,_,ping_,i)
        if active_anti_ddos then
            pingbase = pingbase+ping_
            pingN = pingN+1
            if (math.floor(player_o/2) > 5) and math.floor(player_o/2) <= pingN then
                if pingbase/pingN > ping_timeout_*ping_to_execute_anti_ddos then
                    broadcastMessage("DDoS attack maby detected! KICKING EVEBODY!", 25)
                    block = true;
                    for a,cid in pairs(getPlayersOnline()) do
                        doRemoveCreature(cid)
                    end
                    doSaveServer()
                end
            end
        end
        if ping_ > ping_timeout_ and not block and (isPlayerPzLocked(cid) == false) then
            doRemoveCreature(cid)
        end
        if i == pls then
            print('Ping avarage: '..pingbase/pingN..' ms/player.')
        end
        end,i)
    end
    return true
end

TALKACTION TO PRINT TEST \/

!ping prints
Code:
function onSay(cid, words, param, channel)
    print("doPlayerSendPing: ", doPlayerSendPing(cid))
    print("getPlayerLastPing: ", getPlayerLastPing(cid))
    print("getPlayerLastPong: ", getPlayerLastPong(cid))
    print("getOtsysTime: ", getOtsysTime(cid))
    return true
end

Code:
doPlayerSendPing:

getPlayerLastPing:
1586826102309
getPlayerLastPong:
1586826098349
getOtsysTime:
1586826102309

SOURCE BASE \/
source code edited base: Fir3element/3777 (https://github.com/Fir3element/3777)

SOURCES EDITS \/

luascript.cpp (https://pastebin.com/1RAxBrpx)

lines 2089-2098
Code:
    // ping 1
    //doPlayerSendPing(cid)
    lua_register(m_luaState, "doPlayerSendPing", LuaInterface::luaDoPlayerSendPing);
    //getPlayerLastPing(cid)
    lua_register(m_luaState, "getPlayerLastPing", LuaInterface::luaGetPlayerLastPing);
    //getPlayerLastPong(cid)
    lua_register(m_luaState, "getPlayerLastPong", LuaInterface::luaGetPlayerLastPong);
    //getOtsysTime(cid)
    lua_register(m_luaState, "getOtsysTime", LuaInterface::luaGetOtsysTime);
    // /ping 1

lines 7390-7450
Code:
// ping 2
// Adaptado by Yan Liima(Night for tibiaking.com)
int32_t LuaInterface::luaDoPlayerSendPing(lua_State* L)
{
    //doPlayerSendPing(cid)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getPlayerByUID(popNumber(L));
    if(!player)
    {
        lua_pushboolean(L, false);
        return 1;
    }
    int64_t timeNow = OTSYS_TIME();
    player->lastPing = timeNow;
    if(player->client)
    {
            void sendPing();
            lua_pushboolean(L, true);
    }else{
          lua_pushboolean(L, false);       
          }
    lua_pushboolean(L, true);

    return 1;
}
int32_t LuaInterface::luaGetOtsysTime(lua_State* L)
{
    //getOtsysTime()
    lua_pushnumber(L, OTSYS_TIME());
    return 1;
}
int32_t LuaInterface::luaGetPlayerLastPing(lua_State* L)
{
    //getPlayerLastPing(cid)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getPlayerByUID(popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
         lua_pushboolean(L, false);
        return 1;
    }
    int64_t timeNow = OTSYS_TIME();
    lua_pushnumber(L, player->lastPing);
    return 1;
}
int32_t LuaInterface::luaGetPlayerLastPong(lua_State* L)
{
    //getPlayerLastPong(cid)
    ScriptEnviroment* env = getEnv();
    Player* player = env->getPlayerByUID(popNumber(L));
    if(!player)
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
         lua_pushboolean(L, false);
        return 1;
    }
    lua_pushnumber(L, player->lastPong);
    return 1;
}
// /ping 2

luascript.h ([C++] luascript.h - Pastebin.com (https://pastebin.com/JtdnJS8a))
lines 347-352
Code:
        // Ping
        static int32_t luaDoPlayerSendPing(lua_State* L);
        static int32_t luaGetPlayerLastPing(lua_State* L);
        static int32_t luaGetPlayerLastPong(lua_State* L);
        static int32_t luaGetOtsysTime(lua_State* L);
        // /Ping
 
2. Spamming / Double post: You may not repeat the same message multiple times. It is seen as spamming. This also applies if you for example "bump" a thread.
bump

bump

bump
 
there is a warning on compile:
Code:
luascript.cpp: In static member function ‘static int32_t LuaInterface::luaGetPlayerLastPing(lua_State*)’:
luascript.cpp:7495:13: warning: unused variable ‘timeNow’ [-Wunused-variable]
     int64_t timeNow = OTSYS_TIME();
             ^~~~~~~
g++ manager.cpp

is it the problem?
 
Is this a real DDOS (IP layer attack), or something internal to OT?

If it's a real one, why do the checking in-game? It might be easier to look for a network-centric tool instead.
If something exists, it would be independent of the OT version, which would be nice.
 
Is this a real DDOS (IP layer attack), or something internal to OT?

If it's a real one, why do the checking in-game? It might be easier to look for a network-centric tool instead.
If something exists, it would be independent of the OT version, which would be nice.

i just trying to get player/players ping on LUA so i can create some features to help lagged players with many ways
 
based on this
Code:
doPlayerSendPing:

getPlayerLastPing:
1586826102309
getPlayerLastPong:
1586826098349
getOtsysTime:
1586826102309

It appears to be working as intended, no?

doPlayerSendPing - sends a ping to the player.

getPlayerLastPing - shows the time of the last "doPlayerSendPing"

getPlayerLastPong - shows the time of when the players last 'pong' was received (ping sends out, pong is return)

getOtsysTime - shows the current time.

--
So in your test script, you're sending the ping, but not waiting for the pong.. which is why the value is lower.

A better test would be
Lua:
local function pingPongCheck(cid)
    if not isPlayer(cid) then
        return true
    end
    print("getOtsysTime: ", getOtsysTime(cid))
    print("getPlayerLastPing: ", getPlayerLastPing(cid))
    print("getPlayerLastPong: ", getPlayerLastPong(cid))
    print("difference: ", (getPlayerLastPong(cid) - getPlayerLastPing(cid)))
    print("Positive value of difference means pong was received. (and the difference is how long it took to receive their response)\nNegative value means it hasn't been received. (have not received a response for 2 seconds)")
end

function onSay(cid, words, param, channel)
    doPlayerSendPing(cid)
    addEvent(pingPongCheck, 2000, cid)
    return true
end
 
based on this
Code:
doPlayerSendPing:

getPlayerLastPing:
1586826102309
getPlayerLastPong:
1586826098349
getOtsysTime:
1586826102309

It appears to be working as intended, no?

doPlayerSendPing - sends a ping to the player.

getPlayerLastPing - shows the time of the last "doPlayerSendPing"

getPlayerLastPong - shows the time of when the players last 'pong' was received (ping sends out, pong is return)

getOtsysTime - shows the current time.

--
So in your test script, you're sending the ping, but not waiting for the pong.. which is why the value is lower.

A better test would be
Lua:
local function pingPongCheck(cid)
    if not isPlayer(cid) then
        return true
    end
    print("getOtsysTime: ", getOtsysTime(cid))
    print("getPlayerLastPing: ", getPlayerLastPing(cid))
    print("getPlayerLastPong: ", getPlayerLastPong(cid))
    print("difference: ", (getPlayerLastPong(cid) - getPlayerLastPing(cid)))
    print("Positive value of difference means pong was received. (and the difference is how long it took to receive their response)\nNegative value means it hasn't been received. (have not received a response for 2 seconds)")
end

function onSay(cid, words, param, channel)
    doPlayerSendPing(cid)
    addEvent(pingPongCheck, 2000, cid)
    return true
end

it still showing strange numbers:
Code:
getOtsysTime: 
1611416355747
getPlayerLastPing: 
1611416353747
getPlayerLastPong: 
1611416351525
difference: 
-2222
Positive value of difference means pong was received. (and the difference is how long it took to receive their response)
Negative value means it hasn't been received. (have not received a response for 2 seconds)
 
these numbers are timestamps

Lua:
local delay = 50
if getPlayerLastPing() + delay < os.time() then
  -- do something if 50 seconds passed from the last ping
end
 
Last edited:
Solution
these numbers are timestamps

Lua:
local delay = 50
if getPlayerLastPing() + delay < os.time() then
  -- do something if 50 seconds passed from the last ping
end

Anyway, I doubt the usefulness of such a solution, if you kick your players based on them not receiving pings, players will be able to kick themselves from the game by just xlogging.

@Xikini @4Nathu4
so everything was always working and i was being dumb?
 
i've create this 2 scripts based on u guys told me about this functions

globalevents:
Code:
    <!-- PLAYERS LAGGED / DDOS PROTECT -->
    <!-- if player is lagged AND is not under atk AND is not atking = KICK the player -->
    <globalevent name="lagprotect_pve" interval="900" event="script" value="lagprotect_pve.lua"/>
    <!-- if players online avarage ping is high = KICK everyone (this check latter cause players could ddos server in wars) -->
    <globalevent name="lagprotect_pvp" interval="900" event="script" value="lagprotect_pvp.lua"/>

lagprotect_pve.lua
Code:
function imBeingAttacked(cid)
    for tid, _ in ipairs(getOnlinePlayers()) do -- Loop through all online players
        if(getCreatureTarget(tid) == cid) then
            return true
        end
    end
    return false
end

function myTargetIsPlayer(cid)
    local myTarget = getCreatureTarget(cid)
    if(isPlayer(myTarget)) then
        return true
    else
        return false
    end
end

function onThink(interval, lastExecution)
    local MAX_DELAY_SECS_RESPONSE = 2
    for tid, _ in ipairs(getOnlinePlayers()) do -- Loop through all online players
        if getPlayerLastPing(tid) + MAX_DELAY_SECS_RESPONSE < os.time() then
            if imBeingAttacked(cid) == false and myTargetIsPlayer(cid) == false then
                doRemoveCreature(cid)
            end
        end
    end
end


lagprotect_pvp.lua
Code:
function onThink(interval, lastExecution)
    local MAX_DELAY_SECS_RESPONSE = 2
    local average_server_ping = 0
    local players_online = 0
    -- loop all players to get ping avarage and players online
    for _, cid in ipairs(getPlayersOnline()) do
        average_server_ping = playerGetLastPing(cid) + average_server_ping
        players_online = players_online + 1
    end
    average_server_ping = (average_server_ping / players_online)
    -- check if server avarage ping is higher then limit
    if average_server_ping + MAX_DELAY_SECS_RESPONSE < os.time() then
        -- if it is higher, kick everyone
        doBroadcastMessage("DDos attack! Everyone will be kicked")
        for _, cid in ipairs(getPlayersOnline()) do
          addEvent(function(cid)
                doRemoveCreature(cid)
          end, 1000, cid)
        end
    end
    return TRUE
end

i can't test, my server is just local for now
idk if it is working
and idk if it is good (i'm not good scripter)
can u tell me this 2 questions i have?


---

edit:

this errors is because i'm in localhost?

Code:
[17:40:56.284] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_pve
[17:40:57.186] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_pve
[17:40:58.087] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_pve
[17:40:58.989] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_pve
[17:40:59.891] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_pve
[17:41:00.793] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_pve
[17:41:01.704] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_pve
[17:41:02.585] Frog Knight has logged in.

[17:41:02.636] [Error - GlobalEvent Interface] 
[17:41:02.636] data/globalevents/scripts/lagprotect_pve.lua:onThink
[17:41:02.636] Description: 
[17:41:02.636] (luaGetPlayerLastPing) Player not found

[17:41:02.636] [Error - GlobalEvent Interface] 
[17:41:02.636] data/globalevents/scripts/lagprotect_pve.lua:onThink
[17:41:02.636] Description: 
[17:41:02.636] data/globalevents/scripts/lagprotect_pve.lua:22: attempt to perform arithmetic on a boolean value
[17:41:02.636] stack traceback:
[17:41:02.636]     data/globalevents/scripts/lagprotect_pve.lua:22: in function <data/globalevents/scripts/lagprotect_pve.lua:19>
[17:41:02.636] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_pve

[17:41:02.636] [Error - GlobalEvent Interface] 
[17:41:02.636] data/globalevents/scripts/lagprotect_pvp.lua:onThink
[17:41:02.636] Description: 
[17:41:02.636] data/globalevents/scripts/lagprotect_pvp.lua:7: attempt to call global 'playerGetLastPing' (a nil value)
[17:41:02.636] stack traceback:
[17:41:02.636]     data/globalevents/scripts/lagprotect_pvp.lua:7: in function <data/globalevents/scripts/lagprotect_pvp.lua:1>
[17:41:02.636] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_pvp

[17:41:03.538] [Error - GlobalEvent Interface] 
[17:41:03.538] data/globalevents/scripts/lagprotect_pve.lua:onThink
[17:41:03.538] Description: 
[17:41:03.538] (luaGetPlayerLastPing) Player not found

[17:41:03.538] [Error - GlobalEvent Interface] 
[17:41:03.538] data/globalevents/scripts/lagprotect_pve.lua:onThink
[17:41:03.538] Description: 
[17:41:03.538] data/globalevents/scripts/lagprotect_pve.lua:22: attempt to perform arithmetic on a boolean value
[17:41:03.538] stack traceback:
[17:41:03.538]     data/globalevents/scripts/lagprotect_pve.lua:22: in function <data/globalevents/scripts/lagprotect_pve.lua:19>
[17:41:03.538] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_pve
 
Last edited:
I'm trying to use this ping function to protect players lagged and server lagged with this script: TFS 0.X - Skills/ML/LVL loss LUA (https://otland.net/threads/skills-ml-lvl-loss-lua.273522/#post-2648266)

I tried:
Code:
    <!-- PLAYERS LAGGED / DDOS PROTECT -->
    <!-- if player is lagged AND is not under atk AND is not atking -->
    <!-- SET STORAGE to do not lose anything in death_loss_lua.lua -->
    <globalevent name="lagprotect_player" interval="5000" event="script" value="lagprotect_player.lua"/>
    <!-- if players online avarage ping is high -->
    <!-- SET STORAGE to do not lose anything in death_loss_lua.lua -->
    <globalevent name="lagprotect_server" interval="5200" event="script" value="lagprotect_server.lua"/>

lagprotect_player.lua
Code:
function imBeingAttacked(cid)
    for tid, _ in ipairs(getOnlinePlayers()) do -- Loop through all online players
        if(getCreatureTarget(tid) == cid) then
            return true
        end
    end
    return false
end

function myTargetIsPlayer(cid)
    local myTarget = getCreatureTarget(cid)
    if(isPlayer(myTarget)) then
        return true
    else
        return false
    end
end

function onThink(interval, lastExecution)
    local MAX_DELAY_SECS_RESPONSE = 2
    for tid, _ in ipairs(getOnlinePlayers()) do -- Loop through all online players
        if isPlayer(tid) then
            if getPlayerLastPing(tid) + MAX_DELAY_SECS_RESPONSE < os.time() then
                if imBeingAttacked(tid) == false and myTargetIsPlayer(tid) == false then
                      doPlayerSendTextMessage(tid,TALKTYPE_BROADCAST, "[LAG PROTECT] Your connection is lagged! Your exp,skills,items are protected.")
                      setPlayerStorageValue(tid, 7, 1)
                      addEvent(function(tid)
                        setPlayerStorageValue(tid, 7, -1)
                      end, 5000, tid)
                end
            end
        end
    end
end

lagprotect_server.lua
Code:
function onThink(interval, lastExecution)
    local MAX_DELAY_SECS_RESPONSE = 2
    local average_server_ping = 0
    local players_online = 0
    -- loop all players to get ping avarage and players online
    for _, cid in ipairs(getPlayersOnline()) do
        average_server_ping = playerGetLastPing(cid) + average_server_ping
        players_online = players_online + 1
    end
    average_server_ping = (average_server_ping / players_online)
    -- check if server avarage ping is higher then limit
    if average_server_ping + MAX_DELAY_SECS_RESPONSE < os.time() then
        -- if it is higher, kick everyone
        doBroadcastMessage("[DDOS PROTECT] Server is under attack or lagged! Your exp,skills,items are protected.")
        for _, cid in ipairs(getPlayersOnline()) do
            if isPlayer(tid) then
              setPlayerStorageValue(cid, 7, 1)
              addEvent(function(cid)
                setPlayerStorageValue(cid, 7, -1)
              end, 5200, cid)
            end
        end
    end
    return TRUE
end

but i got some problems:
1- when there is no players online:
Code:
[6:54:42.664] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player
[6:54:47.811] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player

2- when i login on some char:
Code:
[6:55:17.927] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player

[6:55:19.232] [Error - GlobalEvent Interface] 
[6:55:19.232] data/globalevents/scripts/lagprotect_server.lua:onThink
[6:55:19.232] Description: 
[6:55:19.232] data/globalevents/scripts/lagprotect_server.lua:7: attempt to call global 'playerGetLastPing' (a nil value)
[6:55:19.232] stack traceback:
[6:55:19.232]     data/globalevents/scripts/lagprotect_server.lua:7: in function <data/globalevents/scripts/lagprotect_server.lua:1>
[6:55:19.232] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_server
[6:55:22.944] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player

[6:55:24.450] [Error - GlobalEvent Interface] 
[6:55:24.450] data/globalevents/scripts/lagprotect_server.lua:onThink
[6:55:24.450] Description: 
[6:55:24.450] data/globalevents/scripts/lagprotect_server.lua:7: attempt to call global 'playerGetLastPing' (a nil value)
[6:55:24.450] stack traceback:
[6:55:24.450]     data/globalevents/scripts/lagprotect_server.lua:7: in function <data/globalevents/scripts/lagprotect_server.lua:1>
[6:55:24.450] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_server
 
I'm trying to use this ping function to protect players lagged and server lagged with this script: TFS 0.X - Skills/ML/LVL loss LUA (https://otland.net/threads/skills-ml-lvl-loss-lua.273522/#post-2648266)

I tried:
Code:
    <!-- PLAYERS LAGGED / DDOS PROTECT -->
    <!-- if player is lagged AND is not under atk AND is not atking -->
    <!-- SET STORAGE to do not lose anything in death_loss_lua.lua -->
    <globalevent name="lagprotect_player" interval="5000" event="script" value="lagprotect_player.lua"/>
    <!-- if players online avarage ping is high -->
    <!-- SET STORAGE to do not lose anything in death_loss_lua.lua -->
    <globalevent name="lagprotect_server" interval="5200" event="script" value="lagprotect_server.lua"/>

lagprotect_player.lua
Code:
function imBeingAttacked(cid)
    for tid, _ in ipairs(getOnlinePlayers()) do -- Loop through all online players
        if(getCreatureTarget(tid) == cid) then
            return true
        end
    end
    return false
end

function myTargetIsPlayer(cid)
    local myTarget = getCreatureTarget(cid)
    if(isPlayer(myTarget)) then
        return true
    else
        return false
    end
end

function onThink(interval, lastExecution)
    local MAX_DELAY_SECS_RESPONSE = 2
    for tid, _ in ipairs(getOnlinePlayers()) do -- Loop through all online players
        if isPlayer(tid) then
            if getPlayerLastPing(tid) + MAX_DELAY_SECS_RESPONSE < os.time() then
                if imBeingAttacked(tid) == false and myTargetIsPlayer(tid) == false then
                      doPlayerSendTextMessage(tid,TALKTYPE_BROADCAST, "[LAG PROTECT] Your connection is lagged! Your exp,skills,items are protected.")
                      setPlayerStorageValue(tid, 7, 1)
                      addEvent(function(tid)
                        setPlayerStorageValue(tid, 7, -1)
                      end, 5000, tid)
                end
            end
        end
    end
end

lagprotect_server.lua
Code:
function onThink(interval, lastExecution)
    local MAX_DELAY_SECS_RESPONSE = 2
    local average_server_ping = 0
    local players_online = 0
    -- loop all players to get ping avarage and players online
    for _, cid in ipairs(getPlayersOnline()) do
        average_server_ping = playerGetLastPing(cid) + average_server_ping
        players_online = players_online + 1
    end
    average_server_ping = (average_server_ping / players_online)
    -- check if server avarage ping is higher then limit
    if average_server_ping + MAX_DELAY_SECS_RESPONSE < os.time() then
        -- if it is higher, kick everyone
        doBroadcastMessage("[DDOS PROTECT] Server is under attack or lagged! Your exp,skills,items are protected.")
        for _, cid in ipairs(getPlayersOnline()) do
            if isPlayer(tid) then
              setPlayerStorageValue(cid, 7, 1)
              addEvent(function(cid)
                setPlayerStorageValue(cid, 7, -1)
              end, 5200, cid)
            end
        end
    end
    return TRUE
end

but i got some problems:
1- when there is no players online:
Code:
[6:54:42.664] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player
[6:54:47.811] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player

2- when i login on some char:
Code:
[6:55:17.927] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player

[6:55:19.232] [Error - GlobalEvent Interface]
[6:55:19.232] data/globalevents/scripts/lagprotect_server.lua:onThink
[6:55:19.232] Description:
[6:55:19.232] data/globalevents/scripts/lagprotect_server.lua:7: attempt to call global 'playerGetLastPing' (a nil value)
[6:55:19.232] stack traceback:
[6:55:19.232]     data/globalevents/scripts/lagprotect_server.lua:7: in function <data/globalevents/scripts/lagprotect_server.lua:1>
[6:55:19.232] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_server
[6:55:22.944] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player

[6:55:24.450] [Error - GlobalEvent Interface]
[6:55:24.450] data/globalevents/scripts/lagprotect_server.lua:onThink
[6:55:24.450] Description:
[6:55:24.450] data/globalevents/scripts/lagprotect_server.lua:7: attempt to call global 'playerGetLastPing' (a nil value)
[6:55:24.450] stack traceback:
[6:55:24.450]     data/globalevents/scripts/lagprotect_server.lua:7: in function <data/globalevents/scripts/lagprotect_server.lua:1>
[6:55:24.450] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_server

bump
 
I'm trying to use this ping function to protect players lagged and server lagged with this script: TFS 0.X - Skills/ML/LVL loss LUA (https://otland.net/threads/skills-ml-lvl-loss-lua.273522/#post-2648266)

I tried:
Code:
    <!-- PLAYERS LAGGED / DDOS PROTECT -->
    <!-- if player is lagged AND is not under atk AND is not atking -->
    <!-- SET STORAGE to do not lose anything in death_loss_lua.lua -->
    <globalevent name="lagprotect_player" interval="5000" event="script" value="lagprotect_player.lua"/>
    <!-- if players online avarage ping is high -->
    <!-- SET STORAGE to do not lose anything in death_loss_lua.lua -->
    <globalevent name="lagprotect_server" interval="5200" event="script" value="lagprotect_server.lua"/>

lagprotect_player.lua
Code:
function imBeingAttacked(cid)
    for tid, _ in ipairs(getOnlinePlayers()) do -- Loop through all online players
        if(getCreatureTarget(tid) == cid) then
            return true
        end
    end
    return false
end

function myTargetIsPlayer(cid)
    local myTarget = getCreatureTarget(cid)
    if(isPlayer(myTarget)) then
        return true
    else
        return false
    end
end

function onThink(interval, lastExecution)
    local MAX_DELAY_SECS_RESPONSE = 2
    for tid, _ in ipairs(getOnlinePlayers()) do -- Loop through all online players
        if isPlayer(tid) then
            if getPlayerLastPing(tid) + MAX_DELAY_SECS_RESPONSE < os.time() then
                if imBeingAttacked(tid) == false and myTargetIsPlayer(tid) == false then
                      doPlayerSendTextMessage(tid,TALKTYPE_BROADCAST, "[LAG PROTECT] Your connection is lagged! Your exp,skills,items are protected.")
                      setPlayerStorageValue(tid, 7, 1)
                      addEvent(function(tid)
                        setPlayerStorageValue(tid, 7, -1)
                      end, 5000, tid)
                end
            end
        end
    end
end

lagprotect_server.lua
Code:
function onThink(interval, lastExecution)
    local MAX_DELAY_SECS_RESPONSE = 2
    local average_server_ping = 0
    local players_online = 0
    -- loop all players to get ping avarage and players online
    for _, cid in ipairs(getPlayersOnline()) do
        average_server_ping = playerGetLastPing(cid) + average_server_ping
        players_online = players_online + 1
    end
    average_server_ping = (average_server_ping / players_online)
    -- check if server avarage ping is higher then limit
    if average_server_ping + MAX_DELAY_SECS_RESPONSE < os.time() then
        -- if it is higher, kick everyone
        doBroadcastMessage("[DDOS PROTECT] Server is under attack or lagged! Your exp,skills,items are protected.")
        for _, cid in ipairs(getPlayersOnline()) do
            if isPlayer(tid) then
              setPlayerStorageValue(cid, 7, 1)
              addEvent(function(cid)
                setPlayerStorageValue(cid, 7, -1)
              end, 5200, cid)
            end
        end
    end
    return TRUE
end

but i got some problems:
1- when there is no players online:
Code:
[6:54:42.664] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player
[6:54:47.811] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player

2- when i login on some char:
Code:
[6:55:17.927] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player

[6:55:19.232] [Error - GlobalEvent Interface]
[6:55:19.232] data/globalevents/scripts/lagprotect_server.lua:onThink
[6:55:19.232] Description:
[6:55:19.232] data/globalevents/scripts/lagprotect_server.lua:7: attempt to call global 'playerGetLastPing' (a nil value)
[6:55:19.232] stack traceback:
[6:55:19.232]     data/globalevents/scripts/lagprotect_server.lua:7: in function <data/globalevents/scripts/lagprotect_server.lua:1>
[6:55:19.232] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_server
[6:55:22.944] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player

[6:55:24.450] [Error - GlobalEvent Interface]
[6:55:24.450] data/globalevents/scripts/lagprotect_server.lua:onThink
[6:55:24.450] Description:
[6:55:24.450] data/globalevents/scripts/lagprotect_server.lua:7: attempt to call global 'playerGetLastPing' (a nil value)
[6:55:24.450] stack traceback:
[6:55:24.450]     data/globalevents/scripts/lagprotect_server.lua:7: in function <data/globalevents/scripts/lagprotect_server.lua:1>
[6:55:24.450] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_server

bump
 
I'm trying to use this ping function to protect players lagged and server lagged with this script: TFS 0.X - Skills/ML/LVL loss LUA (https://otland.net/threads/skills-ml-lvl-loss-lua.273522/#post-2648266)

I tried:
Code:
    <!-- PLAYERS LAGGED / DDOS PROTECT -->
    <!-- if player is lagged AND is not under atk AND is not atking -->
    <!-- SET STORAGE to do not lose anything in death_loss_lua.lua -->
    <globalevent name="lagprotect_player" interval="5000" event="script" value="lagprotect_player.lua"/>
    <!-- if players online avarage ping is high -->
    <!-- SET STORAGE to do not lose anything in death_loss_lua.lua -->
    <globalevent name="lagprotect_server" interval="5200" event="script" value="lagprotect_server.lua"/>

lagprotect_player.lua
Code:
function imBeingAttacked(cid)
    for tid, _ in ipairs(getOnlinePlayers()) do -- Loop through all online players
        if(getCreatureTarget(tid) == cid) then
            return true
        end
    end
    return false
end

function myTargetIsPlayer(cid)
    local myTarget = getCreatureTarget(cid)
    if(isPlayer(myTarget)) then
        return true
    else
        return false
    end
end

function onThink(interval, lastExecution)
    local MAX_DELAY_SECS_RESPONSE = 2
    for tid, _ in ipairs(getOnlinePlayers()) do -- Loop through all online players
        if isPlayer(tid) then
            if getPlayerLastPing(tid) + MAX_DELAY_SECS_RESPONSE < os.time() then
                if imBeingAttacked(tid) == false and myTargetIsPlayer(tid) == false then
                      doPlayerSendTextMessage(tid,TALKTYPE_BROADCAST, "[LAG PROTECT] Your connection is lagged! Your exp,skills,items are protected.")
                      setPlayerStorageValue(tid, 7, 1)
                      addEvent(function(tid)
                        setPlayerStorageValue(tid, 7, -1)
                      end, 5000, tid)
                end
            end
        end
    end
end

lagprotect_server.lua
Code:
function onThink(interval, lastExecution)
    local MAX_DELAY_SECS_RESPONSE = 2
    local average_server_ping = 0
    local players_online = 0
    -- loop all players to get ping avarage and players online
    for _, cid in ipairs(getPlayersOnline()) do
        average_server_ping = playerGetLastPing(cid) + average_server_ping
        players_online = players_online + 1
    end
    average_server_ping = (average_server_ping / players_online)
    -- check if server avarage ping is higher then limit
    if average_server_ping + MAX_DELAY_SECS_RESPONSE < os.time() then
        -- if it is higher, kick everyone
        doBroadcastMessage("[DDOS PROTECT] Server is under attack or lagged! Your exp,skills,items are protected.")
        for _, cid in ipairs(getPlayersOnline()) do
            if isPlayer(tid) then
              setPlayerStorageValue(cid, 7, 1)
              addEvent(function(cid)
                setPlayerStorageValue(cid, 7, -1)
              end, 5200, cid)
            end
        end
    end
    return TRUE
end

but i got some problems:
1- when there is no players online:
Code:
[6:54:42.664] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player
[6:54:47.811] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player

2- when i login on some char:
Code:
[6:55:17.927] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player

[6:55:19.232] [Error - GlobalEvent Interface]
[6:55:19.232] data/globalevents/scripts/lagprotect_server.lua:onThink
[6:55:19.232] Description:
[6:55:19.232] data/globalevents/scripts/lagprotect_server.lua:7: attempt to call global 'playerGetLastPing' (a nil value)
[6:55:19.232] stack traceback:
[6:55:19.232]     data/globalevents/scripts/lagprotect_server.lua:7: in function <data/globalevents/scripts/lagprotect_server.lua:1>
[6:55:19.232] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_server
[6:55:22.944] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_player

[6:55:24.450] [Error - GlobalEvent Interface]
[6:55:24.450] data/globalevents/scripts/lagprotect_server.lua:onThink
[6:55:24.450] Description:
[6:55:24.450] data/globalevents/scripts/lagprotect_server.lua:7: attempt to call global 'playerGetLastPing' (a nil value)
[6:55:24.450] stack traceback:
[6:55:24.450]     data/globalevents/scripts/lagprotect_server.lua:7: in function <data/globalevents/scripts/lagprotect_server.lua:1>
[6:55:24.450] [Error - GlobalEvents::think] Couldn't execute event: lagprotect_server

bump
 
Back
Top