mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
(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
This commit is contained in:
parent
cdfc0ec4a3
commit
ce91f6b45e
@ -266,7 +266,7 @@ protected:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Notification that another client is currently receiving the map:
|
* 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);
|
DECLARE_GAME_RECEIVE_COMMAND(PACKET_SERVER_WAIT);
|
||||||
|
|
||||||
|
@ -490,9 +490,10 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendWait()
|
|||||||
NetworkClientSocket *new_cs;
|
NetworkClientSocket *new_cs;
|
||||||
Packet *p;
|
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) {
|
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);
|
p = new Packet(PACKET_SERVER_WAIT);
|
||||||
@ -561,24 +562,28 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
|
|||||||
* to send it is ready (maybe that happens like never ;)) */
|
* to send it is ready (maybe that happens like never ;)) */
|
||||||
this->status = STATUS_DONE_MAP;
|
this->status = STATUS_DONE_MAP;
|
||||||
|
|
||||||
|
/* Find the best candidate for joining, i.e. the first joiner. */
|
||||||
NetworkClientSocket *new_cs;
|
NetworkClientSocket *new_cs;
|
||||||
bool new_map_client = false;
|
NetworkClientSocket *best = NULL;
|
||||||
/* Check if there is a client waiting for receiving the map
|
|
||||||
* and start sending him the map */
|
|
||||||
FOR_ALL_CLIENT_SOCKETS(new_cs) {
|
FOR_ALL_CLIENT_SOCKETS(new_cs) {
|
||||||
if (new_cs->status == STATUS_MAP_WAIT) {
|
if (new_cs->status == STATUS_MAP_WAIT) {
|
||||||
/* Check if we already have a new client to send the map to */
|
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)) {
|
||||||
if (!new_map_client) {
|
best = new_cs;
|
||||||
/* 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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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()) {
|
switch (this->SendPackets()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user