tcp_game.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
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
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