Hello i have an otclient compiled with ping system but i cant get it work in OTHire, i tryed the ping system with tibianic client sources and it Works perfectly so what is the problem between othire and otclient?
g_game.enableFeature(GameClientPing)
well i just wanted to make my client look like more helpful but its alright man thank you right, i Will use my client like it is without the ping systemTibianic DLL sources use ICMP to check ping which is different than client-server ping-pong. ICMP will not show you the extra latency caused by cpu usage of client/server but rather the minimal ping you can have to the server.
thanks @ruth i have one personal question how i can pack or compress the otclient? i have been looking in Google any program similar to molebox but i cant add the folder Modules i just can add the libs i really want to compress it like you do with yours i mean if it is posible ofcourseYou can try this one:
Ping is not working [OThire 0.0.3 - 7.72] · Issue #979 · edubart/otclient
It's ICMP system like tibanic .dll but in otclient (just client side).
did u fix the ping issue?thanks @ruth i have one personal question how i can pack or compress the otclient? i have been looking in Google any program similar to molebox but i cant add the folder Modules i just can add the libs i really want to compress it like you do with yours i mean if it is posible ofcourse
no i didnt try the fix that @ruth post here but u can try it maybe? i didnt have time for compile the otcdid u fix the ping issue?
if you did. can u share the fix please?
OTClient\modules\game_things\things.lua
g_game.enableFeature(GameClientPing)
YurOTS its based in tfs? because i did try to add that last week to othire but without successfull and othire is based in OTServ as i knowI have implemented a ping system from TFS to YurOTS today.
It works perfectly.
All you have to do is copy, paste & adapt the code to your engine.
otland/forgottenserver
otland/forgottenserver
And then go to
and in function load() addCode:OTClient\modules\game_things\things.lua
Code:g_game.enableFeature(GameClientPing)
And that's it
you'll have to edit the code you cant copy paste everything i'll try to add it after i finish to add new creature events to OTH and mods handler folder to OTH srcYurOTS its based in tfs? because i did try to add that last week to othire but without successfull and othire is based in OTServ as i know
YurOTS is not based on TFS. YurOTS is based on CVS from 2005-12-28. It is the oldest still used engine.YurOTS its based in tfs? because i did try to add that last week to othire but without successfull and othire is based in OTServ as i know
void sendPing();
void sendPingBack() const {
if (client) {
client->sendPingBack();
}
}
void parseReceivePing(NetworkMessage& msg);
void parseReceivePingBack(NetworkMessage& msg);
void sendPing();
void sendPingBack();
bool playerReceivePing(uint32_t playerId);
bool playerReceivePingBack(uint32_t playerId);
case 0x1D:
addGameTask(&Game::playerReceivePingBack, player->getID());
break;
case 0x1D: // keep alive / ping response
parseReceivePingBack(msg);
break;
void ProtocolGame::parseReceivePingBack(NetworkMessage& msg)
{
addGameTask(&Game::playerReceivePingBack, player->getID());
}
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);
}
}
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;
}
g_game.enableFeature(GameClientPing)
function onGameStart()
show()
g_game.setPingDelay(4000)
end
g_lua.bindSingletonFunction("g_game", "getNewPing", &Game::getNewPing, &g_game);
#include <framework/platform/platformwindow.h>
#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;
}
int getNewPing(const std::string& ip);
print(g_game.getNewPing("YOUR_NUMERIC_IP"))
function onGameStart()
show()
g_game.setPingDelay(4000)
end
thank you so much @Olddies :O i dont see the best answer option i wish give it to youhere 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(); } }
Player.h add or replace around line 985
Code:void receivePing() { lastPong = OTSYS_TIME(); }
Player.h around line 1108
Code:int64_t lastPing; int64_t lastPong;
Protocolgame.h look for this
and add this belowCode:void parseReceivePing(NetworkMessage& msg);
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; }
Player.cpp look for this and remove it
Code:lastping = OTSYS_TIME(); lastpong = OTSYS_TIME();
Player.cpp add after this
add thisCode:Player::Player(const std::string& _name, ProtocolGame* p) :
Code:Creature(), lastPing(OTSYS_TIME()), lastPong(lastPing)
Player.cpp after this
add thisCode:void Player::sendStats() { if(client){ client->sendStats(); } }
Code:void Player::sendPing() { int64_t timeNow = OTSYS_TIME(); bool hasLostConnection = false; if ((timeNow - lastPing) >= 5000){ lastPing = timeNow; if (client) { client->sendPing(); } else { hasLostConnection = true; } } int64_t noPongTime = timeNow - lastPong; if ((hasLostConnection || noPongTime >= 7000) && attackedCreature && attackedCreature->getPlayer()) { setAttackedCreature(nullptr); } if (noPongTime >= 60000) { if(canLogout()){ if (client) { client->logout(true); } else { g_game.removeCreature(this, true); } } } }
Otclient/modules/game_things/things.lua
Code:g_game.enableFeature(GameClientPing)
if you have any issue with it post here i will try to help when i can