tcp_game.cpp

Go to the documentation of this file.
00001 /* $Id: tcp_game.cpp 19072 2010-02-09 23:49:19Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00014 #ifdef ENABLE_NETWORK
00015 
00016 #include "../../stdafx.h"
00017 
00018 #include "../network.h"
00019 #include "../network_internal.h"
00020 #include "../../core/pool_func.hpp"
00021 
00022 #include "table/strings.h"
00023 
00025 assert_compile(MAX_CLIENT_SLOTS > MAX_CLIENTS);
00026 assert_compile(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENT_SLOTS);
00027 
00028 NetworkClientSocketPool _networkclientsocket_pool("NetworkClientSocket");
00029 INSTANTIATE_POOL_METHODS(NetworkClientSocket)
00030 
00031 NetworkClientSocket::NetworkClientSocket(ClientID client_id)
00032 {
00033   this->client_id         = client_id;
00034   this->status            = STATUS_INACTIVE;
00035 }
00036 
00037 NetworkClientSocket::~NetworkClientSocket()
00038 {
00039   while (this->command_queue != NULL) {
00040     CommandPacket *p = this->command_queue->next;
00041     free(this->command_queue);
00042     this->command_queue = p;
00043   }
00044 
00045   if (_redirect_console_to_client == this->client_id) _redirect_console_to_client = INVALID_CLIENT_ID;
00046   this->client_id = INVALID_CLIENT_ID;
00047   this->status = STATUS_INACTIVE;
00048 }
00049 
00058 NetworkRecvStatus NetworkClientSocket::CloseConnection(bool error)
00059 {
00060   /* Clients drop back to the main menu */
00061   if (!_network_server && _networking) {
00062     _switch_mode = SM_MENU;
00063     _networking = false;
00064     extern StringID _switch_mode_errorstr;
00065     _switch_mode_errorstr = STR_NETWORK_ERROR_LOSTCONNECTION;
00066 
00067     return NETWORK_RECV_STATUS_CONN_LOST;
00068   }
00069 
00070   return NetworkCloseClient(this, error ? NETWORK_RECV_STATUS_SERVER_ERROR : NETWORK_RECV_STATUS_CONN_LOST);
00071 }
00072 
00073 #endif /* ENABLE_NETWORK */

Generated on Mon Aug 30 19:36:55 2010 for OpenTTD by  doxygen 1.6.1