diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-01-26 14:15:34 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-01-26 14:45:25 +0300 |
commit | 5d43f16fea7f97f3302b89d64c165b7c5b5222dc (patch) | |
tree | 386d26ecf76fc1e44b1319ce1f1595b48d6c5c45 | |
parent | 85d58aef208ae7c1f0ef5d449e17a1410a6eb04d (diff) | |
download | manaplus-5d43f16fea7f97f3302b89d64c165b7c5b5222dc.tar.gz manaplus-5d43f16fea7f97f3302b89d64c165b7c5b5222dc.tar.bz2 manaplus-5d43f16fea7f97f3302b89d64c165b7c5b5222dc.tar.xz manaplus-5d43f16fea7f97f3302b89d64c165b7c5b5222dc.zip |
Fix show ping time if timer overflowed and still no response from server.
-rw-r--r-- | src/gui/debugwindow.cpp | 12 | ||||
-rw-r--r-- | src/localplayer.cpp | 30 | ||||
-rw-r--r-- | src/localplayer.h | 2 |
3 files changed, 23 insertions, 21 deletions
diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 39ee07767..1a957345a 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -412,16 +412,8 @@ NetDebugTab::NetDebugTab(const Widget2 *const widget) : void NetDebugTab::logic() { - if (player_node && player_node->getPingTime() != 0) - { - mPingLabel->setCaption(strprintf(_("Ping: %s ms"), - toString(static_cast<int>(player_node->getPingTime())).c_str())); - } - else - { - mPingLabel->setCaption(strprintf(_("Ping: %s ms"), "?")); - } - + mPingLabel->setCaption(strprintf(_("Ping: %s ms"), + player_node->getPingTime().c_str())); mInPackets1Label->setCaption(strprintf(_("In: %d bytes/s"), PacketCounters::getInBytes())); mOutPackets1Label->setCaption(strprintf(_("Out: %d bytes/s"), diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 619150ef9..a4104ce03 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -73,7 +73,8 @@ #include "debug.h" -const short awayLimitTimer = 60; +static const short awayLimitTimer = 60; +static const int MAX_TICK_VALUE = 10000; typedef std::map<int, Guild*>::const_iterator GuildMapCIter; @@ -3452,24 +3453,32 @@ void LocalPlayer::pingRequest() Net::getBeingHandler()->requestNameById(getId()); } -int LocalPlayer::getPingTime() const +std::string LocalPlayer::getPingTime() const { int time = 0; + std::string str; if (!mWaitPing) { - time = mPingTime; + if (!mPingTime) + str = "?"; + else + str = toString(mPingTime); } else { time = tick_time; if (time > mPingSendTick) - { time -= mPingSendTick; - if (time <= mPingTime) - time = mPingTime; - } + else + time += MAX_TICK_VALUE - mPingSendTick; + if (time <= mPingTime) + time = mPingTime; + if (mPingTime != time) + str = strprintf("%d (%d)", mPingTime, time); + else + str = toString(time); } - return time; + return str; } void LocalPlayer::pingResponse() @@ -3477,14 +3486,15 @@ void LocalPlayer::pingResponse() if (mWaitPing == true && mPingSendTick > 0) { mWaitPing = false; - if (tick_time < mPingSendTick) + const int time = tick_time; + if (time < mPingSendTick) { mPingSendTick = 0; mPingTime = 0; } else { - mPingTime = (tick_time - mPingSendTick) * 10; + mPingTime = (time - mPingSendTick) * 10; } } } diff --git a/src/localplayer.h b/src/localplayer.h index ce615b2e6..600c8aef4 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -286,7 +286,7 @@ class LocalPlayer final : public Being, int getDisableGameModifiers() const A_WARN_UNUSED { return mDisableGameModifiers; } - int getPingTime() const A_WARN_UNUSED; + std::string getPingTime() const A_WARN_UNUSED; void tryPingRequest(); |