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

Ping System (OTHire)

well yes sometimes i get disconnected and also my players so dont know whats going on maybe any bad configuration when adding this? but ofcourse it is working very good tho :D
4uswfl.png
 
my final recommendation is don't use it i been testing it and some times you get disconnected without any rason or atleast it is happening to me... i was looking this post Ping is not working [OThire 0.0.3 - 7.72] · Issue #979 · edubart/otclient and i wanted to implement but don't get it i dont know where or in wich part of game.h i have to register this getNewPing(const std::string& ip)
 
I am not really into OTHire but as far as I can see in the changes, there's not pongBack therefore the ping system proceeds to kick you. I'd suggest to take a look how the pong is being received.

Code:
if (noPongTime >= 60000) {
        if(canLogout()){
            if (client) {
                client->logout(true);
            } else {
                g_game.removeCreature(this, true);
            }
        }
 
I am not really into OTHire but as far as I can see in the changes, there's not pongBack therefore the ping system proceeds to kick you. I'd suggest to take a look how the pong is being received.

Code:
if (noPongTime >= 60000) {
        if(canLogout()){
            if (client) {
                client->logout(true);
            } else {
                g_game.removeCreature(this, true);
            }
        }
othire already comes with a ping system but it is different from the tfs or otclient ones
Code:
    if(OTSYS_TIME() - last_pong >= 60000){
        if(canLogout()){
            if(client){
                client->logout(true);
            }
            else{
                g_game.removeCreature(this, true);
            }
        }
    }
should i change that line of Nopong with this one?
 
Edit... after changing that i just notice the ping went down a little bit so the problem of disconnect still there i will keep looking on that lines about NoPong@Westwol
2ujrpc7.png
 
Last edited:
my final recommendation is don't use it i been testing it and some times you get disconnected without any rason or atleast it is happening to me... i was looking this post Ping is not working [OThire 0.0.3 - 7.72] · Issue #979 · edubart/otclient and i wanted to implement but don't get it i dont know where or in wich part of game.h i have to register this getNewPing(const std::string& ip)
Add to game.h somewhere beside protected.
Code:
int getNewPing(const std::string& ip)
 
Add to game.h somewhere beside protected.
Code:
int getNewPing(const std::string& ip)
Thank you i'm compiling right now but @ruth i still have to put this in modules/game_things/things.lua
?
Code:
g_game.enableFeature(GameClientPing)

EDIT
i compile it everything fine but the ping doesnt show up :/ should i add something more somewhere else? i have to put the ip of the vps where it says ip? because i tried to put the ip but i cant compile :O
 
Last edited:
Thank you i'm compiling right now but @ruth i still have to put this in modules/game_things/things.lua
?
Code:
g_game.enableFeature(GameClientPing)

EDIT
i compile it everything fine but the ping doesnt show up :/ should i add something more somewhere else? i have to put the ip of the vps where it says ip? because i tried to put the ip but i cant compile :O

Usage print(g_game.getNewPing("Server IP"))
 
Last edited:
The part above this message "Now we start with otclient sources we need to add some codes here too... Thanks to @ruth or Anastacia from github for this code of otclient" is not needed. As i said before this ping system is only client side.
 
The part above this message "Now we start with otclient sources we need to add some codes here too... Thanks to @ruth or Anastacia from github for this code of otclient" is not needed. As i said before this ping system is only client side.
true i just tested it by adding this to things.lua
Code:
g_game.enableFeature(GameClientPing)
and worked
 
here you go guys the code is working and tested by me i make the tutorial easy for you guys so follow it and you wont have any problems

Player.h around line 900
Code:
    void sendPing();
    void sendPingBack() const {
        if (client) {
            client->sendPingBack();
        }
    }

Protocolgame.h look for this
Code:
void parseReceivePing(NetworkMessage& msg);
and add this below
Code:
    void parseReceivePingBack(NetworkMessage& msg);

Protocolgame.h around line 192
Code:
    void sendPing();
    void sendPingBack();

Game.h around line 505
Code:
    bool playerReceivePing(uint32_t playerId);
    bool playerReceivePingBack(uint32_t playerId);

Protocolgame.cpp around line 516
Code:
        case 0x1D:
            addGameTask(&Game::playerReceivePingBack, player->getID());
            break;

Protocolgame.cpp around line 553
Code:
        case 0x1D: // keep alive / ping response
            parseReceivePingBack(msg);
            break;

Protocolgame.cpp around line 1090
Code:
void ProtocolGame::parseReceivePingBack(NetworkMessage& msg)
{
  addGameTask(&Game::playerReceivePingBack, player->getID());
}

Protocolgame.cpp around line 1905
Code:
void ProtocolGame::sendPing()
{
    NetworkMessage_ptr msg = getOutputBuffer();
    if(msg){
        TRACK_MESSAGE(msg);
        msg->AddByte(0x1E);
    }
}

void ProtocolGame::sendPingBack()
{
    NetworkMessage_ptr msg = getOutputBuffer();
    if(msg){
        TRACK_MESSAGE(msg);
        msg->AddByte(0x1D);
    }
}

Game.cpp around line 2250
Code:
bool Game::playerReceivePing(uint32_t playerId)
{
    Player* player = getPlayerByID(playerId);
    if(!player || player->isRemoved())
        return false;

    player->receivePing();
    return true;
}

bool Game::playerReceivePingBack(uint32_t playerId)
{
    Player* player = getPlayerByID(playerId);
    if(!player || player->isRemoved())
        return false;

    player->sendPingBack();
    return true;
}

Otclient/modules/game_things/things.lua
Code:
g_game.enableFeature(GameClientPing)

Otclient/modules/game_interface/interface.lua
Code:
function onGameStart()
  show()
  g_game.setPingDelay(4000)
end

In case you want the ping system only in the client side only you can edit this files in otclient sources... Thanks to @ruth or Anastacia from github for this code of otclient

add this to Luafunctions.cpp
Code:
g_lua.bindSingletonFunction("g_game", "getNewPing", &Game::getNewPing, &g_game);

in game.cpp after this
Code:
#include <framework/platform/platformwindow.h>
we add this
Code:
#include <winsock2.h>
#include <iphlpapi.h>
#include <icmpapi.h>
#include <stdio.h>
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
int Game::getNewPing(const std::string& ip)
{
    HANDLE hIcmpFile;
    unsigned long ipaddr = inet_addr(ip.c_str());
    DWORD dwRetVal = 0;
    char SendData[32] = "Data Buffer";
    LPVOID ReplyBuffer = NULL;
    DWORD ReplySize = 0;
    // Validate the parameters
    if (ipaddr == INADDR_NONE) {
        return 0;
    }
    hIcmpFile = IcmpCreateFile();
    if (hIcmpFile == INVALID_HANDLE_VALUE) {
        g_logger.info(stdext::format("\tUnable to open handle.\n"));
        g_logger.info(stdext::format("IcmpCreatefile returned error: %ld\n", GetLastError()));
        return 0;
    }
    ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData);
    ReplyBuffer = (VOID*)malloc(ReplySize);
    if (ReplyBuffer == NULL) {
        g_logger.info(stdext::format("\tUnable to allocate memory\n"));
        return 0;
    }
    dwRetVal = IcmpSendEcho(hIcmpFile, ipaddr, SendData, sizeof(SendData),
        NULL, ReplyBuffer, ReplySize, 5000);
    if (dwRetVal != 0) {
        PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
        struct in_addr ReplyAddr;
        ReplyAddr.S_un.S_addr = pEchoReply->Address;
        return pEchoReply->RoundTripTime;
    }
    else {
        g_logger.info(stdext::format("\tCall to IcmpSendEcho failed.\n"));
        g_logger.info(stdext::format("\tIcmpSendEcho returned error: %ld\n", GetLastError()));
        return 0;
    }
    return 0;
}

in game.h we should add this somewhere before Protected
Code:
int getNewPing(const std::string& ip);


Otclient/modules/game_things/things.lua
Code:
print(g_game.getNewPing("YOUR_NUMERIC_IP"))

Otclient/modules/game_interface/interface.lua
Code:
function onGameStart()
  show()
  g_game.setPingDelay(4000)
end


I DONT HAVE THIS #include <framework/platform/platformwindow.h> IN GAME.CPP OTC :/ ARE YOU SURE that's where we should put the code its there? could you tell me the lines please?
PD: SOLVED
Code:
#include <framework/core/application.h>
#include "luavaluecasts.h"
#include "protocolgame.h"
#include "protocolcodes.h"
//ping related
#include <winsock2.h>
#include <iphlpapi.h>
#include <icmpapi.h>
#include <stdio.h>
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")

int Game::getNewPing(const std::string& ip)
{
    HANDLE hIcmpFile;
    unsigned long ipaddr = inet_addr(ip.c_str());
    DWORD dwRetVal = 0;
    char SendData[32] = "Data Buffer";
    LPVOID ReplyBuffer = NULL;
    DWORD ReplySize = 0;

    // Validate the parameters

    if (ipaddr == INADDR_NONE) {
        return 0;
    }

    hIcmpFile = IcmpCreateFile();
    if (hIcmpFile == INVALID_HANDLE_VALUE) {
        g_logger.info(stdext::format("\tUnable to open handle.\n"));
        g_logger.info(stdext::format("IcmpCreatefile returned error: %ld\n", GetLastError()));
        return 0;
    }

    ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData);
    ReplyBuffer = (VOID*)malloc(ReplySize);
    if (ReplyBuffer == NULL) {
        g_logger.info(stdext::format("\tUnable to allocate memory\n"));
        return 0;
    }

    dwRetVal = IcmpSendEcho(hIcmpFile, ipaddr, SendData, sizeof(SendData),
        NULL, ReplyBuffer, ReplySize, 5000);
    if (dwRetVal != 0) {
        PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
        struct in_addr ReplyAddr;
        ReplyAddr.S_un.S_addr = pEchoReply->Address;
        return pEchoReply->RoundTripTime;
    }
    else {
        g_logger.info(stdext::format("\tCall to IcmpSendEcho failed.\n"));
        g_logger.info(stdext::format("\tIcmpSendEcho returned error: %ld\n", GetLastError()));
        return 0;
    }
    return 0;
}

TO SOLVED MINOR COMPILATION ERRORS I DID THIS
_WINSOCK_DEPRECATED_NO_WARNINGS symbol to my project settings via "Project"->"Properties"->"Configuration properties"->"C/C++"->"Preprocessor"->"Preprocessor
 
Last edited:
I DONT HAVE THIS #include <framework/platform/platformwindow.h> IN GAME.CPP OTC :/ ARE YOU SURE that's where we should put the code its there? could you tell me the lines please?
shouldnt be that hard to understand it is in the top of the file... but if u dont have it just search for this
Code:
Game g_game;
then add it before that code
 
shouldnt be that hard to understand it is in the top of the file... but if u dont have it just search for this
Code:
Game g_game;
then add it before that code
Wasn't hard to understand but i were suffering some compilation errors
above i posted the solution
 
I followed tutorial OTClient Ping client side

but when i enable ping at optio nit doesnt appear
no errors on terminal
things.lua
Code:
--1first line
print(g_game.getNewPing("127.0.0.1"))
filename =  nil
loaded = false

gameinterface.lua
Code:
function onGameStart()
  show()
  g_game.setPingDelay(4000)
end
any idea why?
 
I followed tutorial OTClient Ping client side

but when i enable ping at optio nit doesnt appear
no errors on terminal
things.lua
Code:
--1first line
print(g_game.getNewPing("127.0.0.1"))
filename =  nil
loaded = false

gameinterface.lua
Code:
function onGameStart()
  show()
  g_game.setPingDelay(4000)
end
any idea why?
look for this in things.lua
Code:
g_game.setProtocolVersion(0)
then add the code below
Code:
print(g_game.getNewPing("127.0.0.1"))
 
Code:
    disconnect(g_game, { onClientVersionChange = load })
    g_game.setClientVersion(0)
    g_game.setProtocolVersion(0)
    print(g_game.getNewPing("127.0.0.1"))
    connect(g_game, { onClientVersionChange = load })
  end
end

the ping still wont appear :/
 
Code:
    disconnect(g_game, { onClientVersionChange = load })
    g_game.setClientVersion(0)
    g_game.setProtocolVersion(0)
    print(g_game.getNewPing("127.0.0.1"))
    connect(g_game, { onClientVersionChange = load })
  end
end

the ping still wont appear :/
did you compile the otc sources with the req modifications? also make sure the ping is enabled in the otclient
 
Back
Top