summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-11-19 12:33:19 +0000
committerrubidium <rubidium@openttd.org>2010-11-19 12:33:19 +0000
commit6d09f4a3cbb0ebf40b568026f47220f01449857c (patch)
tree0ca0e51a2c1bcb9970f4118ef0e979574fc295bc /src
parent611a9f200785885a29447f4fd138220283a8dcd0 (diff)
downloadopenttd-6d09f4a3cbb0ebf40b568026f47220f01449857c.tar.xz
(svn r21254) -Change: show a different "lag" message when a client is lagging because of connection trouble or lagging because the client is just slow
Diffstat (limited to 'src')
-rw-r--r--src/network/core/tcp_game.cpp3
-rw-r--r--src/network/core/tcp_game.h1
-rw-r--r--src/network/network_server.cpp17
3 files changed, 17 insertions, 4 deletions
diff --git a/src/network/core/tcp_game.cpp b/src/network/core/tcp_game.cpp
index 4f4baeb6b..3cf1a468b 100644
--- a/src/network/core/tcp_game.cpp
+++ b/src/network/core/tcp_game.cpp
@@ -30,6 +30,7 @@ NetworkGameSocketHandler::NetworkGameSocketHandler(SOCKET s)
this->sock = s;
this->last_frame = _frame_counter;
this->last_frame_server = _frame_counter;
+ this->last_packet = _realtime_tick;
}
/**
@@ -70,6 +71,8 @@ NetworkRecvStatus NetworkGameSocketHandler::HandlePacket(Packet *p)
{
PacketGameType type = (PacketGameType)p->Recv_uint8();
+ this->last_packet = _realtime_tick;
+
switch (this->HasClientQuit() ? PACKET_END : type) {
GAME_COMMAND(PACKET_SERVER_FULL)
GAME_COMMAND(PACKET_SERVER_BANNED)
diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h
index a2e0226be..b4a6999cd 100644
--- a/src/network/core/tcp_game.h
+++ b/src/network/core/tcp_game.h
@@ -473,6 +473,7 @@ public:
uint32 last_frame; ///< Last frame we have executed
uint32 last_frame_server; ///< Last frame the server has executed
CommandQueue incoming_queue; ///< The command-queue awaiting handling
+ uint last_packet; ///< Time we received the last frame.
NetworkRecvStatus CloseConnection(bool error = true);
virtual NetworkRecvStatus CloseConnection(NetworkRecvStatus status) = 0;
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 513758811..42de4cd2f 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -1522,14 +1522,23 @@ void NetworkServer_Tick(bool send_frame)
if (lag > 3) {
/* Client did still not report in after 4 game-day, drop him
* (that is, the 3 of above, + 1 before any lag is counted) */
- IConsolePrintF(CC_ERROR,"Client #%d is dropped because the client did not respond for more than 4 game-days", cs->client_id);
+ IConsolePrintF(CC_ERROR, cs->last_packet + 3 * DAY_TICKS * MILLISECONDS_PER_TICK > _realtime_tick ?
+ /* A packet was received in the last three game days, so the client is likely lagging behind. */
+ "Client #%d is dropped because the client's game state is more than 4 game-days behind" :
+ /* No packet was received in the last three game days; sounds like a lost connection. */
+ "Client #%d is dropped because the client did not respond for more than 4 game-days",
+ cs->client_id);
cs->CloseConnection(NETWORK_RECV_STATUS_SERVER_ERROR);
continue;
}
- /* Report once per time we detect the lag */
- if (cs->lag_test == 0) {
- IConsolePrintF(CC_WARNING,"[%d] Client #%d is slow, try increasing *net_frame_freq to a higher value!", _frame_counter, cs->client_id);
+ /* Report once per time we detect the lag, and only when we
+ * received a packet in the last 2000 milliseconds. If we
+ * did not receive a packet, then the client is not just
+ * slow, but the connection is likely severed. Mentioning
+ * frame_freq is not useful in this case. */
+ if (cs->lag_test == 0 && cs->last_packet + DAY_TICKS * MILLISECONDS_PER_TICK > _realtime_tick) {
+ IConsolePrintF(CC_WARNING,"[%d] Client #%d is slow, try increasing [network.]frame_freq to a higher value!", _frame_counter, cs->client_id);
cs->lag_test = 1;
}
} else {