mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-08 23:19:40 +00:00
(svn r16601) -Fix [FS#2880]: try 2... hopefully better this time
This commit is contained in:
parent
83f8d52a67
commit
9b156c1bd4
@ -50,9 +50,10 @@ public:
|
||||
/**
|
||||
* Close the current connection; for TCP this will be mostly equivalent
|
||||
* to Close(), but for UDP it just means the packet has to be dropped.
|
||||
* @param error Whether we quit under an error condition or not.
|
||||
* @return new status of the connection.
|
||||
*/
|
||||
virtual NetworkRecvStatus CloseConnection() { this->has_quit = true; return NETWORK_RECV_STATUS_OKAY; }
|
||||
virtual NetworkRecvStatus CloseConnection(bool error = true) { this->has_quit = true; return NETWORK_RECV_STATUS_OKAY; }
|
||||
|
||||
/**
|
||||
* Whether the current client connected to the socket has quit.
|
||||
|
@ -27,10 +27,10 @@ NetworkTCPSocketHandler::~NetworkTCPSocketHandler()
|
||||
this->sock = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
NetworkRecvStatus NetworkTCPSocketHandler::CloseConnection()
|
||||
NetworkRecvStatus NetworkTCPSocketHandler::CloseConnection(bool error)
|
||||
{
|
||||
this->writable = false;
|
||||
NetworkSocketHandler::CloseConnection();
|
||||
NetworkSocketHandler::CloseConnection(error);
|
||||
|
||||
/* Free all pending and partially received packets */
|
||||
while (this->packet_queue != NULL) {
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
*/
|
||||
bool IsConnected() const { return this->sock != INVALID_SOCKET; }
|
||||
|
||||
virtual NetworkRecvStatus CloseConnection();
|
||||
virtual NetworkRecvStatus CloseConnection(bool error = true);
|
||||
void Send_Packet(Packet *packet);
|
||||
bool Send_Packets();
|
||||
bool IsPacketQueueEmpty();
|
||||
|
@ -50,7 +50,7 @@ NetworkClientSocket::~NetworkClientSocket()
|
||||
* @return the new status
|
||||
* TODO: needs to be splitted when using client and server socket packets
|
||||
*/
|
||||
NetworkRecvStatus NetworkClientSocket::CloseConnection()
|
||||
NetworkRecvStatus NetworkClientSocket::CloseConnection(bool error)
|
||||
{
|
||||
/* Clients drop back to the main menu */
|
||||
if (!_network_server && _networking) {
|
||||
@ -62,7 +62,7 @@ NetworkRecvStatus NetworkClientSocket::CloseConnection()
|
||||
return NETWORK_RECV_STATUS_CONN_LOST;
|
||||
}
|
||||
|
||||
NetworkCloseClient(this);
|
||||
NetworkCloseClient(this, error);
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ public:
|
||||
|
||||
CommandPacket *command_queue; ///< The command-queue awaiting delivery
|
||||
|
||||
NetworkRecvStatus CloseConnection();
|
||||
NetworkRecvStatus CloseConnection(bool error = true);
|
||||
|
||||
NetworkClientSocket(ClientID client_id = INVALID_CLIENT_ID);
|
||||
~NetworkClientSocket();
|
||||
|
@ -62,9 +62,9 @@ void NetworkUDPSocketHandler::Close()
|
||||
this->sockets.Clear();
|
||||
}
|
||||
|
||||
NetworkRecvStatus NetworkUDPSocketHandler::CloseConnection()
|
||||
NetworkRecvStatus NetworkUDPSocketHandler::CloseConnection(bool error)
|
||||
{
|
||||
NetworkSocketHandler::CloseConnection();
|
||||
NetworkSocketHandler::CloseConnection(error);
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ protected:
|
||||
/** The opened sockets. */
|
||||
SocketList sockets;
|
||||
|
||||
NetworkRecvStatus CloseConnection();
|
||||
NetworkRecvStatus CloseConnection(bool error = true);
|
||||
|
||||
/* Declare all possible packets here. If it can be received by the
|
||||
* a specific handler, it has to be implemented. */
|
||||
|
@ -278,7 +278,7 @@ static void NetworkClientError(NetworkRecvStatus res, NetworkClientSocket *cs)
|
||||
/* We just want to close the connection.. */
|
||||
if (res == NETWORK_RECV_STATUS_CLOSE_QUERY) {
|
||||
cs->NetworkSocketHandler::CloseConnection();
|
||||
NetworkCloseClient(cs);
|
||||
NetworkCloseClient(cs, true);
|
||||
_networking = false;
|
||||
|
||||
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
|
||||
@ -291,6 +291,7 @@ static void NetworkClientError(NetworkRecvStatus res, NetworkClientSocket *cs)
|
||||
case NETWORK_RECV_STATUS_NEWGRF_MISMATCH: errorno = NETWORK_ERROR_NEWGRF_MISMATCH; break;
|
||||
default: errorno = NETWORK_ERROR_GENERAL; break;
|
||||
}
|
||||
|
||||
/* This means we fucked up and the server closed the connection */
|
||||
if (res != NETWORK_RECV_STATUS_SERVER_ERROR && res != NETWORK_RECV_STATUS_SERVER_FULL &&
|
||||
res != NETWORK_RECV_STATUS_SERVER_BANNED) {
|
||||
@ -298,7 +299,7 @@ static void NetworkClientError(NetworkRecvStatus res, NetworkClientSocket *cs)
|
||||
}
|
||||
|
||||
_switch_mode = SM_MENU;
|
||||
NetworkCloseClient(cs);
|
||||
NetworkCloseClient(cs, true);
|
||||
_networking = false;
|
||||
}
|
||||
|
||||
@ -437,7 +438,7 @@ static NetworkClientSocket *NetworkAllocClient(SOCKET s)
|
||||
}
|
||||
|
||||
/* Close a connection */
|
||||
void NetworkCloseClient(NetworkClientSocket *cs)
|
||||
void NetworkCloseClient(NetworkClientSocket *cs, bool error)
|
||||
{
|
||||
/*
|
||||
* Sending a message just before leaving the game calls cs->Send_Packets.
|
||||
@ -448,9 +449,7 @@ void NetworkCloseClient(NetworkClientSocket *cs)
|
||||
*/
|
||||
if (cs->sock == INVALID_SOCKET) return;
|
||||
|
||||
DEBUG(net, 1, "Closed client connection %d", cs->client_id);
|
||||
|
||||
if (!cs->HasClientQuit() && _network_server && cs->status > STATUS_INACTIVE) {
|
||||
if (error && !cs->HasClientQuit() && _network_server && cs->status > STATUS_INACTIVE) {
|
||||
/* We did not receive a leave message from this client... */
|
||||
char client_name[NETWORK_CLIENT_NAME_LENGTH];
|
||||
NetworkClientSocket *new_cs;
|
||||
@ -467,6 +466,8 @@ void NetworkCloseClient(NetworkClientSocket *cs)
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG(net, 1, "Closed client connection %d", cs->client_id);
|
||||
|
||||
/* When the client was PRE_ACTIVE, the server was in pause mode, so unpause */
|
||||
if (cs->status == STATUS_PRE_ACTIVE && (_pause_mode & PM_PAUSED_JOIN)) {
|
||||
DoCommandP(0, PM_PAUSED_JOIN, 0, CMD_PAUSE);
|
||||
@ -579,7 +580,7 @@ static void NetworkClose()
|
||||
SEND_COMMAND(PACKET_CLIENT_QUIT)();
|
||||
cs->Send_Packets();
|
||||
}
|
||||
NetworkCloseClient(cs);
|
||||
NetworkCloseClient(cs, false);
|
||||
}
|
||||
|
||||
if (_network_server) {
|
||||
|
@ -148,7 +148,7 @@ void NetworkExecuteLocalCommandQueue();
|
||||
void NetworkFreeLocalCommandQueue();
|
||||
|
||||
/* from network.c */
|
||||
void NetworkCloseClient(NetworkClientSocket *cs);
|
||||
void NetworkCloseClient(NetworkClientSocket *cs, bool error);
|
||||
void NetworkTextMessage(NetworkAction action, ConsoleColour colour, bool self_send, const char *name, const char *str = "", int64 data = 0);
|
||||
void NetworkGetClientName(char *clientname, size_t size, const NetworkClientSocket *cs);
|
||||
uint NetworkCalculateLag(const NetworkClientSocket *cs);
|
||||
|
@ -167,13 +167,13 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkClientSocket *cs, Netw
|
||||
DEBUG(net, 1, "Client %d made an error and has been disconnected. Reason: '%s'", cs->client_id, str);
|
||||
}
|
||||
|
||||
cs->CloseConnection();
|
||||
cs->CloseConnection(false);
|
||||
|
||||
/* Make sure the data get's there before we close the connection */
|
||||
cs->Send_Packets();
|
||||
|
||||
/* The client made a mistake, so drop his connection now! */
|
||||
NetworkCloseClient(cs);
|
||||
NetworkCloseClient(cs, false);
|
||||
}
|
||||
|
||||
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHECK_NEWGRFS)(NetworkClientSocket *cs)
|
||||
@ -963,7 +963,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ERROR)
|
||||
}
|
||||
}
|
||||
|
||||
cs->CloseConnection();
|
||||
cs->CloseConnection(false);
|
||||
}
|
||||
|
||||
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT)
|
||||
@ -989,13 +989,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_QUIT)
|
||||
}
|
||||
}
|
||||
|
||||
/* First tell we already closed the connection...
|
||||
* ... then start the generic code to close the actual connection.
|
||||
* This to make sure the 'connection lost' message is only shown
|
||||
* when the connection got really lost and not when the client
|
||||
* told us it was going to disconnect. */
|
||||
cs->NetworkSocketHandler::CloseConnection();
|
||||
cs->CloseConnection();
|
||||
cs->CloseConnection(false);
|
||||
}
|
||||
|
||||
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ACK)
|
||||
@ -1610,7 +1604,7 @@ void NetworkServer_Tick(bool send_frame)
|
||||
/* 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);
|
||||
NetworkCloseClient(cs);
|
||||
NetworkCloseClient(cs, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1626,13 +1620,13 @@ void NetworkServer_Tick(bool send_frame)
|
||||
int lag = NetworkCalculateLag(cs);
|
||||
if (lag > _settings_client.network.max_join_time) {
|
||||
IConsolePrintF(CC_ERROR,"Client #%d is dropped because it took longer than %d ticks for him to join", cs->client_id, _settings_client.network.max_join_time);
|
||||
NetworkCloseClient(cs);
|
||||
NetworkCloseClient(cs, true);
|
||||
}
|
||||
} else if (cs->status == STATUS_INACTIVE) {
|
||||
int lag = NetworkCalculateLag(cs);
|
||||
if (lag > 4 * DAY_TICKS) {
|
||||
IConsolePrintF(CC_ERROR,"Client #%d is dropped because it took longer than %d ticks to start the joining process", cs->client_id, 4 * DAY_TICKS);
|
||||
NetworkCloseClient(cs);
|
||||
NetworkCloseClient(cs, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user