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

Compiling Help to add this func on my sources

dawnking

Member
Joined
Jun 23, 2016
Messages
176
Reaction score
22
I tried to add this funcs in my sources:
https://otland.net/threads/getotsystime-getplayerping-cid-doplayersendping-cid.121182/

I think i made something worng
Like guys ask to suport here... Everything i change i put inside
Code:
// getOtsysTime() + getPlayerPing(cid) + doPlayerSendPing(cid)

// end

Errors when compile
Code:
In file included from luascript.h:33:0,
  from luascript.cpp:18:
luascript.cpp: In member function ‘virtual void LuaInterface::registerFunctions()’:
luascript.cpp:2091:47: error: ‘LuaScriptInterface’ has not been declared
  lua_register(m_luaState, "doPlayerSendPing", LuaScriptInterface::luadoPlayerSendPing);
  ^
/usr/include/lua5.1/lua.h:260:53: note: in definition of macro ‘lua_pushcfunction’
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
  ^
luascript.cpp:2091:2: note: in expansion of macro ‘lua_register’
  lua_register(m_luaState, "doPlayerSendPing", LuaScriptInterface::luadoPlayerSendPing);
  ^
luascript.cpp:2093:48: error: ‘LuaScriptInterface’ has not been declared
  lua_register(m_luaState, "getPlayerLastPing", LuaScriptInterface::luagetPlayerLastPing);
  ^
/usr/include/lua5.1/lua.h:260:53: note: in definition of macro ‘lua_pushcfunction’
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
  ^
luascript.cpp:2093:2: note: in expansion of macro ‘lua_register’
  lua_register(m_luaState, "getPlayerLastPing", LuaScriptInterface::luagetPlayerLastPing);
  ^
luascript.cpp:2095:48: error: ‘LuaScriptInterface’ has not been declared
  lua_register(m_luaState, "getPlayerLastPong", LuaScriptInterface::luagetPlayerLastPong);
  ^
/usr/include/lua5.1/lua.h:260:53: note: in definition of macro ‘lua_pushcfunction’
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
  ^
luascript.cpp:2095:2: note: in expansion of macro ‘lua_register’
  lua_register(m_luaState, "getPlayerLastPong", LuaScriptInterface::luagetPlayerLastPong);
  ^
luascript.cpp:2097:43: error: ‘LuaScriptInterface’ has not been declared
  lua_register(m_luaState, "getOtsysTime", LuaScriptInterface::luagetOtsysTime);
  ^
/usr/include/lua5.1/lua.h:260:53: note: in definition of macro ‘lua_pushcfunction’
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
  ^
luascript.cpp:2097:2: note: in expansion of macro ‘lua_register’
  lua_register(m_luaState, "getOtsysTime", LuaScriptInterface::luagetOtsysTime);
  ^
luascript.cpp: At global scope:
luascript.cpp:10929:9: error: ‘LuaScriptInterface’ has not been declared
int32_t LuaScriptInterface::luadoPlayerSendPing(lua_State* L)
  ^
luascript.cpp: In function ‘int32_t luadoPlayerSendPing(lua_State*)’:
luascript.cpp:10932:33: error: ‘getEnv’ was not declared in this scope
  ScriptEnviroment* env = getEnv();
  ^
luascript.cpp:10933:50: error: ‘popNumber’ was not declared in this scope
  Player* player = env->getPlayerByUID(popNumber(L));
  ^
In file included from luascript.cpp:26:0:
player.h:1196:11: error: ‘int64_t Player::lastPing’ is private
  int64_t lastPing;
  ^
luascript.cpp:10940:13: error: within this context
  player->lastPing = timeNow;
  ^
In file included from luascript.cpp:26:0:
player.h:1216:17: error: ‘ProtocolGame* Player::client’ is private
  ProtocolGame* client;
  ^
luascript.cpp:10941:13: error: within this context
  if(player->client)
  ^
In file included from luascript.cpp:26:0:
player.h:1216:17: error: ‘ProtocolGame* Player::client’ is private
  ProtocolGame* client;
  ^
luascript.cpp:10943:13: error: within this context
  player->client->sendPing();
  ^
In file included from player.h:33:0,
  from luascript.cpp:26:
protocolgame.h:205:8: error: ‘void ProtocolGame::sendPing()’ is private
  void sendPing();
  ^
luascript.cpp:10943:30: error: within this context
  player->client->sendPing();
  ^
luascript.cpp: At global scope:
luascript.cpp:10952:9: error: ‘LuaScriptInterface’ has not been declared
int32_t LuaScriptInterface::luagetOtsysTime(lua_State* L)
  ^
luascript.cpp:10958:9: error: ‘LuaScriptInterface’ has not been declared
int32_t LuaScriptInterface::luagetPlayerLastPing(lua_State* L)
  ^
luascript.cpp: In function ‘int32_t luagetPlayerLastPing(lua_State*)’:
luascript.cpp:10961:33: error: ‘getEnv’ was not declared in this scope
  ScriptEnviroment* env = getEnv();
  ^
luascript.cpp:10962:50: error: ‘popNumber’ was not declared in this scope
  Player* player = env->getPlayerByUID(popNumber(L));
  ^
In file included from luascript.cpp:18:0:
luascript.cpp:10965:46: error: ‘getError’ was not declared in this scope
  errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  ^
luascript.h:221:40: note: in definition of macro ‘errorEx’
#define errorEx(a) error(__FUNCTION__, a)
  ^
luascript.h:221:41: error: ‘error’ was not declared in this scope
#define errorEx(a) error(__FUNCTION__, a)
  ^
luascript.cpp:10965:3: note: in expansion of macro ‘errorEx’
  errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  ^
luascript.h:221:41: note: suggested alternatives:
#define errorEx(a) error(__FUNCTION__, a)
  ^
luascript.cpp:10965:3: note: in expansion of macro ‘errorEx’
  errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  ^
In file included from /usr/include/boost/asio/detail/impl/posix_mutex.ipp:24:0,
  from /usr/include/boost/asio/detail/posix_mutex.hpp:73,
  from /usr/include/boost/asio/detail/mutex.hpp:25,
  from /usr/include/boost/asio/detail/service_registry.hpp:20,
  from /usr/include/boost/asio/impl/io_service.hpp:19,
  from /usr/include/boost/asio/io_service.hpp:767,
  from /usr/include/boost/asio/basic_io_object.hpp:19,
  from /usr/include/boost/asio/basic_socket.hpp:20,
  from /usr/include/boost/asio/basic_datagram_socket.hpp:20,
  from /usr/include/boost/asio.hpp:21,
  from otsystem.h:33,
  from luascript.h:20,
  from luascript.cpp:18:
/usr/include/boost/asio/error.hpp:66:17: note:  ‘boost::asio::error’
namespace error {
  ^
In file included from /usr/include/boost/asio.hpp:82:0,
  from otsystem.h:33,
  from luascript.h:20,
  from luascript.cpp:18:
/usr/include/boost/asio/placeholders.hpp:55:22: note:  ‘boost::asio::placeholders::error’
inline boost::arg<1> error()
  ^
In file included from luascript.cpp:26:0:
player.h:1196:11: error: ‘int64_t Player::lastPing’ is private
  int64_t lastPing;
  ^
luascript.cpp:10970:28: error: within this context
  lua_pushnumber(L, player->lastPing);
  ^
luascript.cpp:10969:10: warning: unused variable ‘timeNow’ [-Wunused-variable]
  int64_t timeNow = OTSYS_TIME();
  ^
luascript.cpp: At global scope:
luascript.cpp:10973:9: error: ‘LuaScriptInterface’ has not been declared
int32_t LuaScriptInterface::luagetPlayerLastPong(lua_State* L)
  ^
luascript.cpp: In function ‘int32_t luagetPlayerLastPong(lua_State*)’:
luascript.cpp:10976:33: error: ‘getEnv’ was not declared in this scope
  ScriptEnviroment* env = getEnv();
  ^
luascript.cpp:10977:50: error: ‘popNumber’ was not declared in this scope
  Player* player = env->getPlayerByUID(popNumber(L));
  ^
In file included from luascript.cpp:18:0:
luascript.cpp:10980:46: error: ‘getError’ was not declared in this scope
  errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  ^
luascript.h:221:40: note: in definition of macro ‘errorEx’
#define errorEx(a) error(__FUNCTION__, a)
  ^
luascript.h:221:41: error: ‘error’ was not declared in this scope
#define errorEx(a) error(__FUNCTION__, a)
  ^
luascript.cpp:10980:3: note: in expansion of macro ‘errorEx’
  errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  ^
luascript.h:221:41: note: suggested alternatives:
#define errorEx(a) error(__FUNCTION__, a)
  ^
luascript.cpp:10980:3: note: in expansion of macro ‘errorEx’
  errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  ^
In file included from /usr/include/boost/asio/detail/impl/posix_mutex.ipp:24:0,
  from /usr/include/boost/asio/detail/posix_mutex.hpp:73,
  from /usr/include/boost/asio/detail/mutex.hpp:25,
  from /usr/include/boost/asio/detail/service_registry.hpp:20,
  from /usr/include/boost/asio/impl/io_service.hpp:19,
  from /usr/include/boost/asio/io_service.hpp:767,
  from /usr/include/boost/asio/basic_io_object.hpp:19,
  from /usr/include/boost/asio/basic_socket.hpp:20,
  from /usr/include/boost/asio/basic_datagram_socket.hpp:20,
  from /usr/include/boost/asio.hpp:21,
  from otsystem.h:33,
  from luascript.h:20,
  from luascript.cpp:18:
/usr/include/boost/asio/error.hpp:66:17: note:  ‘boost::asio::error’
namespace error {
  ^
In file included from /usr/include/boost/asio.hpp:82:0,
  from otsystem.h:33,
  from luascript.h:20,
  from luascript.cpp:18:
/usr/include/boost/asio/placeholders.hpp:55:22: note:  ‘boost::asio::placeholders::error’
inline boost::arg<1> error()
  ^
In file included from luascript.cpp:26:0:
player.h:1195:11: error: ‘int64_t Player::lastPong’ is private
  int64_t lastPong;
  ^
luascript.cpp:10984:28: error: within this context
  lua_pushnumber(L, player->lastPong);
  ^
mv -f .deps/items.Tpo .deps/items.Po
g++ -DHAVE_CONFIG_H -I.  -I/usr/include/libxml2  -I/usr/include/lua5.1  -O2 -fomit-frame-pointer -D__USE_MYSQL__  -D__ENABLE_SERVER_DIAGNOSTIC__ -D__ROOT_PERMISSION__ -D_THREAD_SAFE -D_REENTRANT -Wall -Wextra -Wno-strict-aliasing -Wno-unused-parameter -Wno-array-bounds -pthread -pipe -MT manager.o -MD -MP -MF .deps/manager.Tpo -c -o manager.o manager.cpp
Makefile:546: recipe for target 'luascript.o' failed
make[1]: *** [luascript.o] Error 1
make[1]: ** Esperando que outros processos terminem.
mv -f .deps/mailbox.Tpo .deps/mailbox.Po
mv -f .deps/manager.Tpo .deps/manager.Po
make[1]: Leaving directory '/home/pedro/Documentos/otserver/3777/src'
Makefile:403: recipe for target 'all' failed
make: *** [all] Error 2
pedro@pedro-DC8CU41:~/Documentos/otserver/3777/src$

This is my luascript.cpp
http://hastebin.com/imohaqewim.cpp

This is my luascript.h
http://hastebin.com/ameyiyomiz.cpp

I'm using 0.4
 
Last edited:
I got the same problem:
Code:
<globalevent name="ddosprotect" interval="1000" event="script" value="antiddos.lua"/>

Code:
function onThink(interval, lastExecution)
   local averageServerPing = 0
   local playerCount = 0

   for _, cid in ipairs(getPlayersOnline()) do
    averageServerPing = (playerGetLastPing(cid) + averageServerPing)
    print(playerGetLastPing)
    playerCount =_
   end

   averageServerPing = (averageServerPing / playerCount)
   print(averageServerPing)
   if averageServerPing > 2000 then
    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


In localhost, show me it on console:
Code:
-nan
-nan
[16:11:23.997] Infernality has logged in.

1470078683805
> Broadcasted message: "DDos attack! Everyone will be kicked".
[16:11:25.761] Infernality has logged out.
-nan
-nan
 
the problem with your code is that lastPing is a value of OTSYS_TIME in time of server sent a ping, and lastPong is time of server received from client a ping, not the ping itself.

I'm sorry, i don't understand
Code:
int32_t LuaInterface::luaPlayerGetLastPing(lua_State* L) {
   ScriptEnviroment* env = getEnv();
   Player* player = env->getPlayerByUID(popNumber(L));
   if (player) {
     lua_pushnumber(L, player->lastPing);
   } else {
     errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
     lua_pushnil(L);
   }
   return 1;
}

int32_t LuaInterface::luaPlayerGetLastPong(lua_State* L) {
   ScriptEnviroment* env = getEnv();
   Player* player = env->getPlayerByUID(popNumber(L));
   if (player) {
     lua_pushnumber(L, player->lastPong);
   } else {
     errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
     lua_pushnil(L);
   }
   return 1;
}
 
I'm sorry, i don't understand
look, getLastPing is not player ping, its the last time server sent a ping to client (OS time) not player ping, and getlastpong is last time server received a ping (OS time also) so if you a result of a ping what you do? its basic math dude come on.
 
look, getLastPing is not player ping, its the last time server sent a ping to client (OS time) not player ping, and getlastpong is last time server received a ping (OS time also) so if you a result of a ping what you do? its basic math dude come on.

what is OS time?
 
look, getLastPing is not player ping, its the last time server sent a ping to client (OS time) not player ping, and getlastpong is last time server received a ping (OS time also) so if you a result of a ping what you do? its basic math dude come on.

You have sure it's not a player info?
Code:
int32_t LuaInterface::luaPlayerGetLastPing(lua_State* L) {
ScriptEnviroment* env = getEnv();
Player* player = env->getPlayerByUID(popNumber(L));
if (player) {
lua_pushnumber(L, player->lastPing);
} else {
errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
lua_pushnil(L);
}
return 1;
}
 
lua_pushnumber(L, player->lastPing);
it is, i never said that isnt, it just doesnt do what you think, it codes is something like this

Code:
int64_t timeNow = OTSYS_TIME();
bool hasLostConnection = false;
if ((timeNow - lastPing) >= 5000) {
lastPing = timeNow;
}
which means each 5 seconds lastPing (data that are been sending to lua) will be filled with timeNow not with connection ms or something,
averageServerPing = (playerGetLastPing(cid) + averageServerPing)
so this code in lua has a logic problem, and same goes to lastPong. (lastPong is saved time now when server receive a ping, lastping is time now when server sent to client)
 
it is, i never said that isnt, it just doesnt do what you think, it codes is something like this

Code:
int64_t timeNow = OTSYS_TIME();
bool hasLostConnection = false;
if ((timeNow - lastPing) >= 5000) {
lastPing = timeNow;
}
which means each 5 seconds lastPing (data that are been sending to lua) will be filled with timeNow not with connection ms or something,

so this code in lua has a logic problem, and same goes to lastPong. (lastPong is saved time now when server receive a ping, lastping is time now when server sent to client)

I'm sorry, i'm not tryng to say something u didn't say, i just try to understand, i'm the noob here...

So you mean this 2 function:
Code:
int32_t LuaInterface::luaPlayerGetLastPing(lua_State* L) {
  ScriptEnviroment* env = getEnv();
  Player* player = env->getPlayerByUID(popNumber(L));
  if (player) {
  lua_pushnumber(L, player->lastPing);
  } else {
  errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  lua_pushnil(L);
  }
  return 1;
}

int32_t LuaInterface::luaPlayerGetLastPong(lua_State* L) {
  ScriptEnviroment* env = getEnv();
  Player* player = env->getPlayerByUID(popNumber(L));
  if (player) {
  lua_pushnumber(L, player->lastPong);
  } else {
  errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  lua_pushnil(L);
  }
  return 1;
}

luaPlayerGetLastPing - show the hour player send ping
luaPlayerGetLastPong - show the time ping was recived from the server

For exemple
luaPlayerGetLastPing 7:00 AM
luaPlayerGetLastPong 7:01 AM

So my ping is 60000 ms

So the problem is in the LUA script:
Code:
function onThink(interval, lastExecution)
  local averageServerPing = 0
  local playerCount = 0

  for _, cid in ipairs(getPlayersOnline()) do
  averageServerPing = (playerGetLastPing(cid) + averageServerPing)
  print(playerGetLastPing)
  playerCount =_
  end

  averageServerPing = (averageServerPing / playerCount)
  print(averageServerPing)
  if averageServerPing > 2000 then
  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

And what it do? \/
Code:
int32_t LuaInterface::luaPlayerSendPing(lua_State* L) {
  ScriptEnviroment* env = getEnv();
  Player* player = env->getPlayerByUID(popNumber(L));
  if (player) {
  ProtocolGame* client;
  client->sendPing();
  lua_pushboolean(L, true);
  } else {
  errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
  lua_pushnil(L);
  }
  return 1;
}

I just tryng to understand to take a way to fix this script... It is a necessary script.
 
its not about beeing noob or something, as i said before its basic math, playerPing = player:getLastPong() - player:getLastPing().

You mean this?
Code:
function onThink(interval, lastExecution)
   local averageServerPing = 0
   local playerCount = 0

   for _, cid in ipairs(getPlayersOnline()) do
     local playerPing = player:getLastPong() - player:getLastPing()
    averageServerPing = (playerPing + averageServerPing)
    print(playerPing)
    playerCount =_
   end

   averageServerPing = (averageServerPing / playerCount)
   print(averageServerPing)
   if averageServerPing > 2000 then
    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
 
You mean this?
Code:
function onThink(interval, lastExecution)
   local averageServerPing = 0
   local playerCount = 0

   for _, cid in ipairs(getPlayersOnline()) do
     local playerPing = player:getLastPong() - player:getLastPing()
    averageServerPing = (playerPing + averageServerPing)
    print(playerPing)
    playerCount =_
   end

   averageServerPing = (averageServerPing / playerCount)
   print(averageServerPing)
   if averageServerPing > 2000 then
    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
 
Back
Top