1
/* $Id: tcp_game.cpp 15903 2009-03-30 23:15:05Z rubidium $ */
4
* @file tcp_game.cpp Basic functions to receive and send TCP packets for game purposes.
9
#include "../../stdafx.h"
10
#include "../../openttd.h"
11
#include "../../variables.h"
13
#include "../network_internal.h"
17
#include "table/strings.h"
18
#include "../../oldpool_func.h"
20
/** Make very sure the preconditions given in network_type.h are actually followed */
21
assert_compile(MAX_CLIENT_SLOTS == (MAX_CLIENT_SLOTS >> NCI_BITS_PER_POOL_BLOCK) << NCI_BITS_PER_POOL_BLOCK);
22
assert_compile(MAX_CLIENT_SLOTS > MAX_CLIENTS);
24
typedef ClientIndex NetworkClientSocketID;
25
DEFINE_OLD_POOL_GENERIC(NetworkClientSocket, NetworkClientSocket);
27
NetworkClientSocket::NetworkClientSocket(ClientID client_id)
29
this->client_id = client_id;
30
this->status = STATUS_INACTIVE;
33
NetworkClientSocket::~NetworkClientSocket()
35
while (this->command_queue != NULL) {
36
CommandPacket *p = this->command_queue->next;
37
free(this->command_queue);
38
this->command_queue = p;
41
this->client_id = INVALID_CLIENT_ID;
42
this->status = STATUS_INACTIVE;
46
* Functions to help NetworkRecv_Packet/NetworkSend_Packet a bit
47
* A socket can make errors. When that happens this handles what to do.
48
* For clients: close connection and drop back to main-menu
49
* For servers: close connection and that is it
50
* @return the new status
51
* TODO: needs to be splitted when using client and server socket packets
53
NetworkRecvStatus NetworkClientSocket::CloseConnection()
55
/* Clients drop back to the main menu */
56
if (!_network_server && _networking) {
57
_switch_mode = SM_MENU;
59
extern StringID _switch_mode_errorstr;
60
_switch_mode_errorstr = STR_NETWORK_ERR_LOSTCONNECTION;
62
return NETWORK_RECV_STATUS_CONN_LOST;
65
NetworkCloseClient(this);
66
return NETWORK_RECV_STATUS_OKAY;
69
#endif /* ENABLE_NETWORK */