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 \/
TALKACTION TO PRINT TEST \/
!ping prints
SOURCE BASE \/
source code edited base: Fir3element/3777 (https://github.com/Fir3element/3777)
SOURCES EDITS \/
luascript.cpp (https://pastebin.com/1RAxBrpx)
lines 2089-2098
lines 7390-7450
luascript.h ([C++] luascript.h - Pastebin.com (https://pastebin.com/JtdnJS8a))
lines 347-352
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