summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-04-22 16:07:47 +0000
committerrubidium <rubidium@openttd.org>2011-04-22 16:07:47 +0000
commitce91f6b45ea207ae7d1d0983bb02ea061e28dad0 (patch)
treec72936d0581b7dc765f89c3cfb0ddb467b5c8398 /src
parentcdfc0ec4a3cb1fc9e23cc74c405e56c736fe3272 (diff)
downloadopenttd-ce91f6b45ea207ae7d1d0983bb02ea061e28dad0.tar.xz
(svn r22370) -Codechange/fix: keep better accounting of the order in which clients joined:
* Clients can't be starved from joining the game * Clients will see the amount of clients actually waiting in front of them, instead of the amount of waiting clients in total
Diffstat (limited to 'src')
-rw-r--r--src/network/core/tcp_game.h2
-rw-r--r--src/network/network_server.cpp33
2 files changed, 20 insertions, 15 deletions
diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h
index fc15e7ba8..decbe00c5 100644
--- a/src/network/core/tcp_game.h
+++ b/src/network/core/tcp_game.h
@@ -266,7 +266,7 @@ protected:
/**
* Notification that another client is currently receiving the map:
- * uint8 Number of clients awaiting the map.
+ * uint8 Number of clients waiting in front of you.
*/
DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_WAIT);
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index c2db408fa..9ceaa73a3 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -490,9 +490,10 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendWait()
NetworkClientSocket *new_cs;
Packet *p;
- /* Count how many clients are waiting in the queue */
+ /* Count how many clients are waiting in the queue, in front of you! */
FOR_ALL_CLIENT_SOCKETS(new_cs) {
- if (new_cs->status == STATUS_MAP_WAIT) waiting++;
+ if (new_cs->status != STATUS_MAP_WAIT) continue;
+ if (new_cs->GetInfo()->join_date < this->GetInfo()->join_date || (new_cs->GetInfo()->join_date == this->GetInfo()->join_date && new_cs->client_id < this->client_id)) waiting++;
}
p = new Packet(PACKET_SERVER_WAIT);
@@ -561,24 +562,28 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
* to send it is ready (maybe that happens like never ;)) */
this->status = STATUS_DONE_MAP;
+ /* Find the best candidate for joining, i.e. the first joiner. */
NetworkClientSocket *new_cs;
- bool new_map_client = false;
- /* Check if there is a client waiting for receiving the map
- * and start sending him the map */
+ NetworkClientSocket *best = NULL;
FOR_ALL_CLIENT_SOCKETS(new_cs) {
if (new_cs->status == STATUS_MAP_WAIT) {
- /* Check if we already have a new client to send the map to */
- if (!new_map_client) {
- /* If not, this client will get the map */
- new_cs->status = STATUS_AUTHORIZED;
- new_map_client = true;
- new_cs->SendMap();
- } else {
- /* Else, send the other clients how many clients are in front of them */
- new_cs->SendWait();
+ if (best == NULL || best->GetInfo()->join_date > new_cs->GetInfo()->join_date || (best->GetInfo()->join_date == new_cs->GetInfo()->join_date && best->client_id > new_cs->client_id)) {
+ best = new_cs;
}
}
}
+
+ /* Is there someone else to join? */
+ if (best != NULL) {
+ /* Let the first start joining. */
+ best->status = STATUS_AUTHORIZED;
+ best->SendMap();
+
+ /* And update the rest. */
+ FOR_ALL_CLIENT_SOCKETS(new_cs) {
+ if (new_cs->status == STATUS_MAP_WAIT) new_cs->SendWait();
+ }
+ }
}
switch (this->SendPackets()) {