# tcp_game.cpp

Go to the documentation of this file.

    00001 /* $Id$ */
    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_internal.h"
    00019 #include "../../core/pool_func.hpp"
    00020
    00021 #include "table/strings.h"
    00022
    00024 assert_compile(MAX_CLIENT_SLOTS > MAX_CLIENTS);
    00025 assert_compile(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENT_SLOTS);
    00026
    00027 NetworkClientSocketPool _networkclientsocket_pool("NetworkClientSocket");
    00028 INSTANTIATE_POOL_METHODS(NetworkClientSocket)
    00029
    00030 NetworkClientSocket::NetworkClientSocket(ClientID client_id)
    00031 {
    00032   this->client_id         = client_id;
    00033   this->status            = STATUS_INACTIVE;
    00034 }
    00035
    00036 NetworkClientSocket::~NetworkClientSocket()
    00037 {
    00038   while (this->command_queue != NULL) {
    00039     CommandPacket *p = this->command_queue->next;
    00040     free(this->command_queue);
    00041     this->command_queue = p;
    00042   }
    00043
    00044   this->client_id = INVALID_CLIENT_ID;
    00045   this->status = STATUS_INACTIVE;
    00046 }
    00047
    00056 NetworkRecvStatus NetworkClientSocket::CloseConnection(bool error)
    00057 {
    00058   /* Clients drop back to the main menu */
    00059   if (!_network_server && _networking) {
    00060     _switch_mode = SM_MENU;
    00061     _networking = false;
    00062     extern StringID _switch_mode_errorstr;
    00063     _switch_mode_errorstr = STR_NETWORK_ERROR_LOSTCONNECTION;
    00064
    00065     return NETWORK_RECV_STATUS_CONN_LOST;
    00066   }
    00067
    00068   NetworkCloseClient(this, error);
    00069   return NETWORK_RECV_STATUS_OKAY;
    00070 }
    00071
    00072 #endif /* ENABLE_NETWORK */