# tcp_game.cpp

Go to the documentation of this file.

    00001 /* $Id: tcp_game.cpp 18809 2010-01-15 16:41:15Z 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   this->client_id = INVALID_CLIENT_ID;
    00046   this->status = STATUS_INACTIVE;
    00047 }
    00048
    00057 NetworkRecvStatus NetworkClientSocket::CloseConnection(bool error)
    00058 {
    00059   /* Clients drop back to the main menu */
    00060   if (!_network_server && _networking) {
    00061     _switch_mode = SM_MENU;
    00062     _networking = false;
    00063     extern StringID _switch_mode_errorstr;
    00064     _switch_mode_errorstr = STR_NETWORK_ERROR_LOSTCONNECTION;
    00065
    00066     return NETWORK_RECV_STATUS_CONN_LOST;
    00067   }
    00068
    00069   NetworkCloseClient(this, error);
    00070   return NETWORK_RECV_STATUS_OKAY;
    00071 }
    00072
    00073 #endif /* ENABLE_NETWORK */