tcp_game.cpp
Go to the documentation of this file.00001
00002
00007 #ifdef ENABLE_NETWORK
00008
00009 #include "../../stdafx.h"
00010 #include "../../openttd.h"
00011 #include "../../variables.h"
00012
00013 #include "../network_internal.h"
00014 #include "packet.h"
00015 #include "tcp_game.h"
00016
00017 #include "table/strings.h"
00018 #include "../../oldpool_func.h"
00019
00021 assert_compile(MAX_CLIENT_SLOTS == (MAX_CLIENT_SLOTS >> NCI_BITS_PER_POOL_BLOCK) << NCI_BITS_PER_POOL_BLOCK);
00022 assert_compile(MAX_CLIENT_SLOTS > MAX_CLIENTS);
00023
00024 typedef ClientIndex NetworkClientSocketID;
00025 DEFINE_OLD_POOL_GENERIC(NetworkClientSocket, NetworkClientSocket);
00026
00027 NetworkClientSocket::NetworkClientSocket(ClientID client_id)
00028 {
00029 this->client_id = client_id;
00030 this->status = STATUS_INACTIVE;
00031 }
00032
00033 NetworkClientSocket::~NetworkClientSocket()
00034 {
00035 while (this->command_queue != NULL) {
00036 CommandPacket *p = this->command_queue->next;
00037 free(this->command_queue);
00038 this->command_queue = p;
00039 }
00040
00041 this->client_id = INVALID_CLIENT_ID;
00042 this->status = STATUS_INACTIVE;
00043 }
00044
00053 NetworkRecvStatus NetworkClientSocket::CloseConnection()
00054 {
00055
00056 if (!_network_server && _networking) {
00057 _switch_mode = SM_MENU;
00058 _networking = false;
00059 extern StringID _switch_mode_errorstr;
00060 _switch_mode_errorstr = STR_NETWORK_ERR_LOSTCONNECTION;
00061
00062 return NETWORK_RECV_STATUS_CONN_LOST;
00063 }
00064
00065 NetworkCloseClient(this);
00066 return NETWORK_RECV_STATUS_OKAY;
00067 }
00068
00069 #endif