mirror of https://github.com/OpenTTD/OpenTTD
(svn r22308) -Fix [FS#4574]: waiting on a server could kick the client, or rather the client would kick itself due to an unexpected packet
parent
6ce83c0aaa
commit
d1a50a01b4
|
@ -719,17 +719,14 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_WELCOME)
|
||||||
|
|
||||||
DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_WAIT)
|
DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_WAIT)
|
||||||
{
|
{
|
||||||
if (this->status != STATUS_AUTHORIZED) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
/* We set the internal wait state when requesting the map. */
|
||||||
this->status = STATUS_MAP_WAIT;
|
if (this->status != STATUS_MAP_WAIT) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
|
||||||
|
|
||||||
|
/* But... only now we set the join status to waiting, instead of requesting. */
|
||||||
_network_join_status = NETWORK_JOIN_STATUS_WAITING;
|
_network_join_status = NETWORK_JOIN_STATUS_WAITING;
|
||||||
_network_join_waiting = p->Recv_uint8();
|
_network_join_waiting = p->Recv_uint8();
|
||||||
SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0);
|
SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0);
|
||||||
|
|
||||||
/* We are put on hold for receiving the map.. we need GUI for this ;) */
|
|
||||||
DEBUG(net, 1, "The server is currently busy sending the map to someone else, please wait..." );
|
|
||||||
DEBUG(net, 1, "There are %d clients in front of you", _network_join_waiting);
|
|
||||||
|
|
||||||
return NETWORK_RECV_STATUS_OKAY;
|
return NETWORK_RECV_STATUS_OKAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -539,9 +539,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
|
||||||
if (this->status == STATUS_MAP) {
|
if (this->status == STATUS_MAP) {
|
||||||
if (this->savegame_mutex != NULL) this->savegame_mutex->BeginCritical();
|
if (this->savegame_mutex != NULL) this->savegame_mutex->BeginCritical();
|
||||||
|
|
||||||
|
bool last_packet = false;
|
||||||
|
|
||||||
for (uint i = 0; i < sent_packets && this->savegame_packets != NULL; i++) {
|
for (uint i = 0; i < sent_packets && this->savegame_packets != NULL; i++) {
|
||||||
Packet *p = this->savegame_packets;
|
Packet *p = this->savegame_packets;
|
||||||
bool last_packet = p->buffer[2] == PACKET_SERVER_MAP_DONE;
|
last_packet = p->buffer[2] == PACKET_SERVER_MAP_DONE;
|
||||||
|
|
||||||
/* Remove the packet from the savegame queue and put it in the real queue. */
|
/* Remove the packet from the savegame queue and put it in the real queue. */
|
||||||
this->savegame_packets = p->next;
|
this->savegame_packets = p->next;
|
||||||
|
@ -549,7 +551,16 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
|
||||||
this->NetworkTCPSocketHandler::SendPacket(p);
|
this->NetworkTCPSocketHandler::SendPacket(p);
|
||||||
|
|
||||||
if (last_packet) {
|
if (last_packet) {
|
||||||
/* Done reading! */
|
/* There is no more data, so break the for */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->savegame_mutex != NULL) this->savegame_mutex->EndCritical();
|
||||||
|
|
||||||
|
if (last_packet) {
|
||||||
|
/* Done reading, make sure saving is done as well */
|
||||||
|
WaitTillSaved();
|
||||||
|
|
||||||
/* Set the status to DONE_MAP, no we will wait for the client
|
/* Set the status to DONE_MAP, no we will wait for the client
|
||||||
* to send it is ready (maybe that happens like never ;)) */
|
* to send it is ready (maybe that happens like never ;)) */
|
||||||
|
@ -573,13 +584,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendMap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* There is no more data, so break the for */
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (this->savegame_mutex != NULL) this->savegame_mutex->EndCritical();
|
|
||||||
|
|
||||||
switch (this->SendPackets()) {
|
switch (this->SendPackets()) {
|
||||||
case SPS_CLOSED:
|
case SPS_CLOSED:
|
||||||
|
|
Loading…
Reference in New Issue