mirror of
https://github.com/edubart/otclient.git
synced 2025-12-02 16:06:51 +01:00
Platform fixes and rework ping
This commit is contained in:
@@ -47,6 +47,7 @@ Game::Game()
|
||||
m_serverBeat = 50;
|
||||
m_seq = 0;
|
||||
m_ping = -1;
|
||||
m_pingDelay = 1000;
|
||||
m_canReportBugs = false;
|
||||
m_fightMode = Otc::FightBalanced;
|
||||
m_chaseMode = Otc::DontChase;
|
||||
@@ -79,6 +80,8 @@ void Game::resetGameStates()
|
||||
m_followingCreature = nullptr;
|
||||
m_attackingCreature = nullptr;
|
||||
m_localPlayer = nullptr;
|
||||
m_pingSent = 0;
|
||||
m_pingReceived = 0;
|
||||
|
||||
for(auto& it : m_containers) {
|
||||
const ContainerPtr& container = it.second;
|
||||
@@ -176,14 +179,9 @@ void Game::processGameStart()
|
||||
disableBotCall();
|
||||
|
||||
if(g_game.getFeature(Otc::GameClientPing) || g_game.getFeature(Otc::GameExtendedClientPing)) {
|
||||
m_protocolGame->sendPing();
|
||||
m_pingEvent = g_dispatcher.cycleEvent([this] {
|
||||
if(m_protocolGame && m_protocolGame->isConnected()) {
|
||||
enableBotCall();
|
||||
m_protocolGame->sendPing();
|
||||
disableBotCall();
|
||||
}
|
||||
}, 2000);
|
||||
m_pingEvent = g_dispatcher.scheduleEvent([this] {
|
||||
g_game.ping();
|
||||
}, m_pingDelay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,10 +222,20 @@ void Game::processPing()
|
||||
disableBotCall();
|
||||
}
|
||||
|
||||
void Game::processPingBack(int elapsed)
|
||||
void Game::processPingBack()
|
||||
{
|
||||
m_ping = elapsed;
|
||||
g_lua.callGlobalField("g_game", "onPingBack", elapsed);
|
||||
m_pingReceived++;
|
||||
|
||||
if(m_pingReceived == m_pingSent)
|
||||
m_ping = m_pingTimer.elapsed_millis();
|
||||
else
|
||||
g_logger.error("got an invalid ping from server");
|
||||
|
||||
g_lua.callGlobalField("g_game", "onPingBack", m_ping);
|
||||
|
||||
m_pingEvent = g_dispatcher.scheduleEvent([this] {
|
||||
g_game.ping();
|
||||
}, m_pingDelay);
|
||||
}
|
||||
|
||||
void Game::processTextMessage(Otc::MessageMode mode, const std::string& text)
|
||||
@@ -1252,9 +1260,14 @@ void Game::ping()
|
||||
if(!m_protocolGame || !m_protocolGame->isConnected())
|
||||
return;
|
||||
|
||||
if(m_pingReceived != m_pingSent)
|
||||
return;
|
||||
|
||||
m_denyBotCall = false;
|
||||
m_protocolGame->sendPing();
|
||||
m_denyBotCall = true;
|
||||
m_pingSent++;
|
||||
m_pingTimer.restart();
|
||||
}
|
||||
|
||||
void Game::changeMapAwareRange(int xrange, int yrange)
|
||||
|
||||
@@ -54,7 +54,7 @@ protected:
|
||||
void processConnectionError(const boost::system::error_code& error);
|
||||
void processDisconnect();
|
||||
void processPing();
|
||||
void processPingBack(int elapsed);
|
||||
void processPingBack();
|
||||
|
||||
void processUpdateNeeded(const std::string& signature);
|
||||
void processLoginError(const std::string& error);
|
||||
@@ -252,6 +252,7 @@ public:
|
||||
|
||||
//void reportRuleViolation2();
|
||||
void ping();
|
||||
void setPingDelay(int delay) { m_pingDelay = delay; }
|
||||
|
||||
// otclient only
|
||||
void changeMapAwareRange(int xrange, int yrange);
|
||||
@@ -280,7 +281,7 @@ public:
|
||||
bool isAttacking() { return !!m_attackingCreature; }
|
||||
bool isFollowing() { return !!m_followingCreature; }
|
||||
|
||||
int getPing() { return m_ping; }
|
||||
int getPing() { return m_ping >= 0 ? std::max(m_ping, m_pingTimer.elapsed_millis()) : -1; }
|
||||
ContainerPtr getContainer(int index) { return m_containers[index]; }
|
||||
std::map<int, ContainerPtr> getContainers() { return m_containers; }
|
||||
std::map<int, Vip> getVips() { return m_vips; }
|
||||
@@ -320,8 +321,12 @@ private:
|
||||
bool m_denyBotCall;
|
||||
bool m_dead;
|
||||
int m_serverBeat;
|
||||
int m_ping;
|
||||
ticks_t m_ping;
|
||||
uint m_pingSent;
|
||||
uint m_pingReceived;
|
||||
stdext::timer m_pingTimer;
|
||||
uint m_seq;
|
||||
int m_pingDelay;
|
||||
Otc::FightModes m_fightMode;
|
||||
Otc::ChaseModes m_chaseMode;
|
||||
Otc::Direction m_lastWalkDir;
|
||||
|
||||
@@ -77,7 +77,7 @@ bool LocalPlayer::canWalk(Otc::Direction direction)
|
||||
return false;
|
||||
|
||||
// prewalk has a timeout, because for some reason that I don't know yet the server sometimes doesn't answer the prewalk
|
||||
bool prewalkTimeouted = m_walking && m_preWalking && m_walkTimer.ticksElapsed() >= getStepDuration() + PREWALK_TIMEOUT;
|
||||
bool prewalkTimeouted = m_walking && m_preWalking && m_walkTimer.ticksElapsed() >= getStepDuration() + 5*PREWALK_TIMEOUT;
|
||||
|
||||
// avoid doing more walks than wanted when receiving a lot of walks from server
|
||||
if(!m_lastPrewalkDone && m_preWalking && !prewalkTimeouted)
|
||||
@@ -127,8 +127,9 @@ void LocalPlayer::preWalk(Otc::Direction direction)
|
||||
Position newPos = m_position.translatedToDirection(direction);
|
||||
|
||||
// avoid reanimating prewalks
|
||||
if(m_preWalking && m_lastPrewalkDestination == newPos)
|
||||
if(m_preWalking && m_lastPrewalkDestination == newPos) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_waitingWalkPong = false;
|
||||
if(m_walkPingTimer.ticksElapsed() > getStepDuration() && m_idleTimer.ticksElapsed() > getStepDuration()*2) {
|
||||
@@ -157,6 +158,7 @@ void LocalPlayer::cancelWalk(Otc::Direction direction)
|
||||
m_waitingWalkPong = false;
|
||||
m_walkPingTimer.restart();
|
||||
m_idleTimer.restart();
|
||||
lockWalk();
|
||||
|
||||
if(m_autoWalkDestination.isValid()) {
|
||||
g_game.stop();
|
||||
|
||||
@@ -219,6 +219,7 @@ void Client::registerLuaFunctions()
|
||||
g_lua.bindSingletonFunction("g_game", "mount", &Game::mount, &g_game);
|
||||
g_lua.bindSingletonFunction("g_game", "requestItemInfo", &Game::requestItemInfo, &g_game);
|
||||
g_lua.bindSingletonFunction("g_game", "ping", &Game::ping, &g_game);
|
||||
g_lua.bindSingletonFunction("g_game", "setPingDelay", &Game::setPingDelay, &g_game);
|
||||
g_lua.bindSingletonFunction("g_game", "changeMapAwareRange", &Game::changeMapAwareRange, &g_game);
|
||||
g_lua.bindSingletonFunction("g_game", "canPerformGameAction", &Game::canPerformGameAction, &g_game);
|
||||
g_lua.bindSingletonFunction("g_game", "canReportBugs", &Game::canReportBugs, &g_game);
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
#include <framework/core/eventdispatcher.h>
|
||||
#include <framework/core/application.h>
|
||||
#include <framework/core/resourcemanager.h>
|
||||
#include <boost/concept_check.hpp>
|
||||
|
||||
|
||||
enum {
|
||||
|
||||
@@ -235,7 +235,6 @@ private:
|
||||
std::string m_accountName;
|
||||
std::string m_accountPassword;
|
||||
std::string m_characterName;
|
||||
stdext::timer m_pingTimer;
|
||||
LocalPlayerPtr m_localPlayer;
|
||||
};
|
||||
|
||||
|
||||
@@ -430,7 +430,7 @@ void ProtocolGame::parsePing(const InputMessagePtr& msg)
|
||||
|
||||
void ProtocolGame::parsePingBack(const InputMessagePtr& msg)
|
||||
{
|
||||
g_game.processPingBack(m_pingTimer.elapsed_millis());
|
||||
g_game.processPingBack();
|
||||
}
|
||||
|
||||
void ProtocolGame::parseChallenge(const InputMessagePtr& msg)
|
||||
|
||||
@@ -129,7 +129,6 @@ void ProtocolGame::sendPing()
|
||||
msg->addU8(Proto::ClientPing);
|
||||
Protocol::send(msg);
|
||||
}
|
||||
m_pingTimer.restart();
|
||||
}
|
||||
|
||||
void ProtocolGame::sendPingBack()
|
||||
|
||||
Reference in New Issue
Block a user