Class for handling the server side of the game connection. More...
#include <network_server.h>
Public Types | |
enum | ClientStatus { STATUS_INACTIVE, STATUS_NEWGRFS_CHECK, STATUS_AUTH_GAME, STATUS_AUTH_COMPANY, STATUS_AUTHORIZED, STATUS_MAP_WAIT, STATUS_MAP, STATUS_DONE_MAP, STATUS_PRE_ACTIVE, STATUS_ACTIVE, STATUS_END } |
Status of a client. More... | |
Public Member Functions | |
ServerNetworkGameSocketHandler (SOCKET s) | |
Create a new socket for the server side of the game connection. | |
~ServerNetworkGameSocketHandler () | |
Clear everything related to this client. | |
virtual Packet * | ReceivePacket () |
Receives a packet for the given client. | |
virtual void | SendPacket (Packet *packet) |
This function puts the packet in the send-queue and it is send as soon as possible. | |
NetworkRecvStatus | CloseConnection (NetworkRecvStatus status) |
Close the network connection due to the given status. | |
void | GetClientName (char *client_name, size_t size) const |
Get the name of the client, if the user did not send it yet, Client #<no> is used. | |
NetworkRecvStatus | SendMap () |
This sends the map to the client. | |
NetworkRecvStatus | SendErrorQuit (ClientID client_id, NetworkErrorCode errorno) |
Tell the client another client quit with an error. | |
NetworkRecvStatus | SendQuit (ClientID client_id) |
Tell the client another client quit. | |
NetworkRecvStatus | SendShutdown () |
Tell the client we're shutting down. | |
NetworkRecvStatus | SendNewGame () |
Tell the client we're starting a new game. | |
NetworkRecvStatus | SendRConResult (uint16 colour, const char *command) |
Send the result of a console action. | |
NetworkRecvStatus | SendMove (ClientID client_id, CompanyID company_id) |
Tell that a client moved to another company. | |
NetworkRecvStatus | SendClientInfo (NetworkClientInfo *ci) |
Send the client information about a client. | |
NetworkRecvStatus | SendError (NetworkErrorCode error) |
Send an error to the client, and close its connection. | |
NetworkRecvStatus | SendChat (NetworkAction action, ClientID client_id, bool self_send, const char *msg, int64 data) |
Send a chat message. | |
NetworkRecvStatus | SendJoin (ClientID client_id) |
Tell that a client joined. | |
NetworkRecvStatus | SendFrame () |
Tell the client that they may run to a particular frame. | |
NetworkRecvStatus | SendSync () |
Request the client to sync. | |
NetworkRecvStatus | SendCommand (const CommandPacket *cp) |
Send a command to the client to execute. | |
NetworkRecvStatus | SendCompanyUpdate () |
Send an update about the company password states. | |
NetworkRecvStatus | SendConfigUpdate () |
Send an update about the max company/spectator counts. | |
const char * | GetClientIP () |
Get the IP address/hostname of the connected client. | |
Static Public Member Functions | |
static void | Send () |
Send the packets for the server sockets. | |
static void | AcceptConnection (SOCKET s, const NetworkAddress &address) |
Handle the acception of a connection to the server. | |
static bool | AllowConnection () |
Whether an connection is allowed or not at this moment. | |
static const char * | GetName () |
Get the name used by the listener. | |
static ServerNetworkGameSocketHandler * | GetByClientID (ClientID client_id) |
Return the client state given it's client-identifier. | |
Data Fields | |
byte | lag_test |
Byte used for lag-testing the client. | |
byte | last_token |
The last random token we did send to verify the client is listening. | |
uint32 | last_token_frame |
The last frame we received the right token. | |
ClientStatus | status |
Status of this client. | |
CommandQueue | outgoing_queue |
The command-queue awaiting delivery. | |
int | receive_limit |
Amount of bytes that we can receive at this moment. | |
Packet * | savegame_packets |
Packet queue of the savegame; send these "slowly" to the client. | |
struct PacketWriter * | savegame |
Writer used to write the savegame. | |
ThreadMutex * | savegame_mutex |
Mutex for making threaded saving safe. | |
NetworkAddress | client_address |
IP-address of the client (so he can be banned). | |
Protected Member Functions | |
virtual NetworkRecvStatus | Receive_CLIENT_JOIN (Packet *p) |
Try to join the server: string OpenTTD revision (norev000 if no revision). | |
virtual NetworkRecvStatus | Receive_CLIENT_COMPANY_INFO (Packet *p) |
Request company information (in detail). | |
virtual NetworkRecvStatus | Receive_CLIENT_GAME_PASSWORD (Packet *p) |
Send a password to the server to authorize: uint8 Password type (see NetworkPasswordType). | |
virtual NetworkRecvStatus | Receive_CLIENT_COMPANY_PASSWORD (Packet *p) |
Send a password to the server to authorize uint8 Password type (see NetworkPasswordType). | |
virtual NetworkRecvStatus | Receive_CLIENT_GETMAP (Packet *p) |
Request the map from the server. | |
virtual NetworkRecvStatus | Receive_CLIENT_MAP_OK (Packet *p) |
Tell the server that we are done receiving/loading the map. | |
virtual NetworkRecvStatus | Receive_CLIENT_ACK (Packet *p) |
Tell the server we are done with this frame: uint32 Current frame counter of the client. | |
virtual NetworkRecvStatus | Receive_CLIENT_COMMAND (Packet *p) |
The client has done a command and wants us to handle it. | |
virtual NetworkRecvStatus | Receive_CLIENT_CHAT (Packet *p) |
Sends a chat-packet to the server: uint8 ID of the action (see NetworkAction). | |
virtual NetworkRecvStatus | Receive_CLIENT_SET_PASSWORD (Packet *p) |
Set the password for the clients current company: string The password. | |
virtual NetworkRecvStatus | Receive_CLIENT_SET_NAME (Packet *p) |
Gives the client a new name: string New name of the client. | |
virtual NetworkRecvStatus | Receive_CLIENT_QUIT (Packet *p) |
The client is quiting the game. | |
virtual NetworkRecvStatus | Receive_CLIENT_ERROR (Packet *p) |
The client made an error and is quiting the game. | |
virtual NetworkRecvStatus | Receive_CLIENT_RCON (Packet *p) |
Send an RCon command to the server: string RCon password. | |
virtual NetworkRecvStatus | Receive_CLIENT_NEWGRFS_CHECKED (Packet *p) |
Tell the server that we have the required GRFs. | |
virtual NetworkRecvStatus | Receive_CLIENT_MOVE (Packet *p) |
Request the server to move this client into another company: uint8 ID of the company the client wants to join. | |
NetworkRecvStatus | SendCompanyInfo () |
Send the client information about the companies. | |
NetworkRecvStatus | SendNewGRFCheck () |
Send the check for the NewGRFs. | |
NetworkRecvStatus | SendWelcome () |
Send the client a welcome message with some basic information. | |
NetworkRecvStatus | SendWait () |
Tell the client that its put in a waiting queue. | |
NetworkRecvStatus | SendNeedGamePassword () |
Request the game password. | |
NetworkRecvStatus | SendNeedCompanyPassword () |
Request the company password. |
Class for handling the server side of the game connection.
Definition at line 29 of file network_server.h.
Status of a client.
Definition at line 57 of file network_server.h.
ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler | ( | SOCKET | s | ) |
Create a new socket for the server side of the game connection.
s | The socket to connect with. |
Definition at line 156 of file network_server.cpp.
References _network_client_id, _settings_client, NetworkSettings::bytes_per_frame_burst, NetworkGameSocketHandler::client_id, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::MAX_SIZE, ClientSettings::network, receive_limit, status, and STATUS_INACTIVE.
Referenced by AcceptConnection().
void ServerNetworkGameSocketHandler::AcceptConnection | ( | SOCKET | s, | |
const NetworkAddress & | address | |||
) | [static] |
Handle the acception of a connection to the server.
s | The socket of the new connection. | |
address | The address of the peer. |
Definition at line 487 of file network.cpp.
References client_address, ServerNetworkGameSocketHandler(), and SetWindowDirty().
bool ServerNetworkGameSocketHandler::AllowConnection | ( | ) | [static] |
Whether an connection is allowed or not at this moment.
Definition at line 268 of file network_server.cpp.
References _network_clients_connected, _network_game_info, _settings_client, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_networkclientsocket_pool >::CanAllocateItem(), NetworkServerGameInfo::clients_on, NetworkSettings::max_clients, MAX_CLIENTS, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::MAX_SIZE, and ClientSettings::network.
NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection | ( | NetworkRecvStatus | status | ) | [virtual] |
Close the network connection due to the given status.
status | The reason the connection got closed. |
Implements NetworkGameSocketHandler.
Definition at line 216 of file network_server.cpp.
References _network_clients_connected, _network_game_info, CC_DEFAULT, NetworkGameSocketHandler::client_id, NetworkServerGameInfo::clients_on, DEBUG, DeleteWindowById(), FOR_ALL_CLIENT_SOCKETS, GetClientName(), NetworkGameSocketHandler::GetInfo(), NetworkSocketHandler::HasClientQuit(), NETWORK_CLIENT_NAME_LENGTH, NETWORK_RECV_STATUS_CONN_LOST, NETWORK_RECV_STATUS_OKAY, NetworkAdminClientError(), NetworkTCPSocketHandler::SendPackets(), SetWindowDirty(), NetworkTCPSocketHandler::sock, and STATUS_AUTHORIZED.
Referenced by Receive_CLIENT_ERROR(), Receive_CLIENT_QUIT(), SendError(), SendNeedCompanyPassword(), SendNeedGamePassword(), and SendWelcome().
ServerNetworkGameSocketHandler * ServerNetworkGameSocketHandler::GetByClientID | ( | ClientID | client_id | ) | [static] |
Return the client state given it's client-identifier.
client_id | the ClientID to search for |
Definition at line 129 of file network.cpp.
References FOR_ALL_CLIENT_SOCKETS.
Referenced by SendCompanyInfo().
const char * ServerNetworkGameSocketHandler::GetClientIP | ( | ) |
Get the IP address/hostname of the connected client.
Definition at line 1893 of file network_server.cpp.
References client_address, and NetworkAddress::GetHostname().
void ServerNetworkGameSocketHandler::GetClientName | ( | char * | client_name, | |
size_t | size | |||
) | const |
Get the name of the client, if the user did not send it yet, Client #<no> is used.
client_name | The variable to write the name to. | |
size | The amount of bytes we can write. |
Definition at line 2072 of file network_server.cpp.
References NetworkGameSocketHandler::client_id, NetworkClientInfo::client_name, NetworkGameSocketHandler::GetInfo(), StrEmpty(), and ttd_strlcpy().
Referenced by CloseConnection(), Receive_CLIENT_ERROR(), Receive_CLIENT_MAP_OK(), Receive_CLIENT_QUIT(), and SendError().
static const char* ServerNetworkGameSocketHandler::GetName | ( | ) | [inline, static] |
Get the name used by the listener.
Definition at line 117 of file network_server.h.
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ACK | ( | Packet * | p | ) | [protected, virtual] |
Tell the server we are done with this frame: uint32 Current frame counter of the client.
uint8 The random token that the server sent in the PACKET_SERVER_FRAME packet.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1181 of file network_server.cpp.
References _frame_counter, DAY_TICKS, IConsoleCmdExec(), NetworkGameSocketHandler::last_frame, NetworkGameSocketHandler::last_frame_server, last_token, last_token_frame, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), Packet::Recv_uint8(), SendError(), status, STATUS_ACTIVE, STATUS_AUTHORIZED, and STATUS_PRE_ACTIVE.
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT | ( | Packet * | p | ) | [protected, virtual] |
Sends a chat-packet to the server: uint8 ID of the action (see NetworkAction).
uint8 ID of the destination type (see DestType). uint32 ID of the client or company (destination of the chat). string Message (max NETWORK_CHAT_LENGTH). uint64 data (used e.g. for 'give money' actions).
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1349 of file network_server.cpp.
References CC_ERROR, NetworkClientInfo::client_id, NetworkGameSocketHandler::client_id, NetworkClientInfo::client_playas, NetworkGameSocketHandler::GetInfo(), IConsolePrintF(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), NETWORK_CHAT_LENGTH, NETWORK_RECV_STATUS_OKAY, NetworkServerSendChat(), Packet::Recv_string(), Packet::Recv_uint32(), Packet::Recv_uint64(), Packet::Recv_uint8(), SendError(), status, and STATUS_AUTHORIZED.
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND | ( | Packet * | p | ) | [protected, virtual] |
The client has done a command and wants us to handle it.
p | the packet in which the command was sent |
Only CMD_COMPANY_CTRL is always allowed, for the rest, playas needs to match the company in the packet. If it doesn't, the client has done something pretty naughty (or a bug), and will be kicked
Reimplemented from NetworkGameSocketHandler.
Definition at line 1056 of file network_server.cpp.
References _settings_client, CommandQueue::Append(), CC_ERROR, NetworkGameSocketHandler::client_id, NetworkClientInfo::client_id, CLIENT_ID_SERVER, NetworkClientInfo::client_playas, CommandContainer::cmd, CMD_CLIENT_ID, CMD_COMPANY_CTRL, CMD_SERVER, CMD_SPECTATOR, CommandPacket::company, COMPANY_NEW_COMPANY, COMPANY_SPECTATOR, CommandQueue::Count(), DESTTYPE_CLIENT, GetCommandFlags(), NetworkGameSocketHandler::GetInfo(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetNumItems(), NetworkSocketHandler::HasClientQuit(), IConsolePrintF(), NetworkGameSocketHandler::incoming_queue, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), NetworkSettings::max_commands_in_queue, NetworkSettings::max_companies, ClientSettings::network, NETWORK_RECV_STATUS_CONN_LOST, NETWORK_RECV_STATUS_OKAY, NetworkServerSendChat(), CommandContainer::p1, CommandContainer::p2, NetworkGameSocketHandler::ReceiveCommand(), and SendError().
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMPANY_INFO | ( | Packet * | p | ) | [protected, virtual] |
Request company information (in detail).
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 819 of file network_server.cpp.
References SendCompanyInfo().
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWORD | ( | Packet * | p | ) | [protected, virtual] |
Send a password to the server to authorize uint8 Password type (see NetworkPasswordType).
string The password.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 945 of file network_server.cpp.
References _network_company_states, NetworkClientInfo::client_playas, NetworkGameSocketHandler::GetInfo(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), NETWORK_PASSWORD_LENGTH, Packet::Recv_string(), SendError(), SendWelcome(), status, STATUS_AUTH_COMPANY, and StrEmpty().
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR | ( | Packet * | p | ) | [protected, virtual] |
The client made an error and is quiting the game.
uint8 Error of the code caused (see NetworkErrorCode).
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1120 of file network_server.cpp.
References CC_DEFAULT, NetworkGameSocketHandler::client_id, CloseConnection(), DEBUG, FOR_ALL_CLIENT_SOCKETS, GetClientName(), GetNetworkErrorMsg(), NetworkSocketHandler::HasClientQuit(), lastof, NETWORK_CLIENT_NAME_LENGTH, NETWORK_RECV_STATUS_CONN_LOST, NetworkAdminClientError(), Packet::Recv_uint8(), and STATUS_AUTHORIZED.
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD | ( | Packet * | p | ) | [protected, virtual] |
Send a password to the server to authorize: uint8 Password type (see NetworkPasswordType).
string The password.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 920 of file network_server.cpp.
References _network_company_states, _settings_client, NetworkClientInfo::client_playas, NetworkGameSocketHandler::GetInfo(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), ClientSettings::network, NETWORK_PASSWORD_LENGTH, NetworkCompanyState::password, Packet::Recv_string(), SendError(), SendNeedCompanyPassword(), SendWelcome(), NetworkSettings::server_password, status, STATUS_AUTH_GAME, and StrEmpty().
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_GETMAP | ( | Packet * | p | ) | [protected, virtual] |
Request the map from the server.
uint32 NewGRF version (release versions of OpenTTD only).
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 967 of file network_server.cpp.
References FOR_ALL_CLIENT_SOCKETS, HasBit(), NetworkSocketHandler::HasClientQuit(), Packet::Recv_uint32(), SendError(), SendMap(), SendWait(), Packet::size, status, STATUS_MAP, and STATUS_MAP_WAIT.
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN | ( | Packet * | p | ) | [protected, virtual] |
Try to join the server: string OpenTTD revision (norev000 if no revision).
string Name of the client (max NETWORK_NAME_LENGTH). uint8 ID of the company to play as (1..MAX_COMPANIES). uint8 ID of the clients Language.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 845 of file network_server.cpp.
References _date, _date_fract, _grfconfig, _network_company_states, _settings_client, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_networkclientinfo_pool >::CanAllocateItem(), NetworkGameSocketHandler::client_id, NetworkClientInfo::client_lang, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, COMPANY_NEW_COMPANY, COMPANY_SPECTATOR, DEBUG, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetNumItems(), NetworkSocketHandler::HasClientQuit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, IsNetworkCompatibleVersion(), Company::IsValidHumanID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), NetworkClientInfo::join_date, lastof, NetworkSettings::max_companies, NetworkSettings::max_spectators, NetworkCompanyState::months_empty, ClientSettings::network, NETWORK_CLIENT_NAME_LENGTH, NETWORK_RECV_STATUS_CONN_LOST, NETWORK_REVISION_LENGTH, NetworkFindName(), Receive_CLIENT_NEWGRFS_CHECKED(), Packet::Recv_string(), Packet::Recv_uint8(), SendError(), SendNewGRFCheck(), NetworkGameSocketHandler::SetInfo(), status, STATUS_INACTIVE, STATUS_NEWGRFS_CHECK, strecpy(), and StrEmpty().
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MAP_OK | ( | Packet * | p | ) | [protected, virtual] |
Tell the server that we are done receiving/loading the map.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1009 of file network_server.cpp.
References _frame_counter, CC_DEFAULT, NetworkGameSocketHandler::client_id, FOR_ALL_CLIENT_SOCKETS, GetClientName(), NetworkGameSocketHandler::GetInfo(), NetworkSocketHandler::HasClientQuit(), NetworkGameSocketHandler::last_frame, NetworkGameSocketHandler::last_frame_server, NETWORK_CLIENT_NAME_LENGTH, NetworkAdminClientInfo(), NetworkHandleCommandQueue(), SendCompanyUpdate(), SendConfigUpdate(), SendError(), SendFrame(), SendSync(), status, STATUS_AUTHORIZED, STATUS_DONE_MAP, and STATUS_PRE_ACTIVE.
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MOVE | ( | Packet * | p | ) | [protected, virtual] |
Request the server to move this client into another company: uint8 ID of the company the client wants to join.
string Password, if the company is password protected.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1449 of file network_server.cpp.
References _network_company_states, NetworkGameSocketHandler::client_id, COMPANY_SPECTATOR, DEBUG, Company::IsValidHumanID(), NETWORK_PASSWORD_LENGTH, NETWORK_RECV_STATUS_OKAY, NetworkServerDoMove(), Packet::Recv_string(), Packet::Recv_uint8(), SendError(), status, STATUS_ACTIVE, and StrEmpty().
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED | ( | Packet * | p | ) | [protected, virtual] |
Tell the server that we have the required GRFs.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 824 of file network_server.cpp.
References _network_company_states, _settings_client, NetworkClientInfo::client_playas, NetworkGameSocketHandler::GetInfo(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), ClientSettings::network, NetworkCompanyState::password, SendError(), SendNeedCompanyPassword(), SendNeedGamePassword(), SendWelcome(), NetworkSettings::server_password, status, STATUS_NEWGRFS_CHECK, and StrEmpty().
Referenced by Receive_CLIENT_JOIN().
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_QUIT | ( | Packet * | p | ) | [protected, virtual] |
The client is quiting the game.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1154 of file network_server.cpp.
References CC_DEFAULT, NetworkGameSocketHandler::client_id, CloseConnection(), FOR_ALL_CLIENT_SOCKETS, GetClientName(), NetworkSocketHandler::HasClientQuit(), NETWORK_CLIENT_NAME_LENGTH, NETWORK_RECV_STATUS_CONN_LOST, NetworkAdminClientQuit(), and STATUS_AUTHORIZED.
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_RCON | ( | Packet * | p | ) | [protected, virtual] |
Send an RCon command to the server: string RCon password.
string Command to be executed.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1424 of file network_server.cpp.
References _redirect_console_to_client, _settings_client, NetworkGameSocketHandler::client_id, DEBUG, IConsoleCmdExec(), INVALID_CLIENT_ID, ClientSettings::network, NETWORK_PASSWORD_LENGTH, NETWORK_RCONCOMMAND_LENGTH, NETWORK_RECV_STATUS_OKAY, NetworkSettings::rcon_password, Packet::Recv_string(), SendError(), status, STATUS_ACTIVE, and StrEmpty().
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME | ( | Packet * | p | ) | [protected, virtual] |
Gives the client a new name: string New name of the client.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1398 of file network_server.cpp.
References CC_DEFAULT, NetworkClientInfo::client_id, NetworkClientInfo::client_name, NetworkGameSocketHandler::GetInfo(), NetworkSocketHandler::HasClientQuit(), lastof, NETWORK_CLIENT_NAME_LENGTH, NETWORK_RECV_STATUS_CONN_LOST, NETWORK_RECV_STATUS_OKAY, NetworkFindName(), NetworkUpdateClientInfo(), Packet::Recv_string(), SendError(), status, STATUS_ACTIVE, and strecpy().
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_SET_PASSWORD | ( | Packet * | p | ) | [protected, virtual] |
Set the password for the clients current company: string The password.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1381 of file network_server.cpp.
References NetworkClientInfo::client_playas, NetworkGameSocketHandler::GetInfo(), NETWORK_PASSWORD_LENGTH, NETWORK_RECV_STATUS_OKAY, NetworkServerSetCompanyPassword(), Packet::Recv_string(), SendError(), status, and STATUS_ACTIVE.
Packet * ServerNetworkGameSocketHandler::ReceivePacket | ( | ) | [virtual] |
Receives a packet for the given client.
Reimplemented from NetworkTCPSocketHandler.
Definition at line 196 of file network_server.cpp.
References receive_limit, and Packet::size.
void ServerNetworkGameSocketHandler::Send | ( | ) | [static] |
Send the packets for the server sockets.
Definition at line 281 of file network_server.cpp.
References FOR_ALL_CLIENT_SOCKETS, SPS_CLOSED, and STATUS_MAP.
NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat | ( | NetworkAction | action, | |
ClientID | client_id, | |||
bool | self_send, | |||
const char * | msg, | |||
int64 | data | |||
) |
Send a chat message.
action | The action associated with the message. | |
client_id | The origin of the chat message. | |
self_send | Whether we did send the message. | |
msg | The actual message. | |
data | Arbitrary extra data. |
Definition at line 703 of file network_server.cpp.
References NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_CHAT, Packet::Send_bool(), Packet::Send_string(), Packet::Send_uint32(), Packet::Send_uint64(), Packet::Send_uint8(), and SendPacket().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendClientInfo | ( | NetworkClientInfo * | ci | ) |
Send the client information about a client.
ci | The client to send information about. |
Definition at line 305 of file network_server.cpp.
References NetworkClientInfo::client_id, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, INVALID_CLIENT_ID, NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_CLIENT_INFO, Packet::Send_string(), Packet::Send_uint32(), Packet::Send_uint8(), and SendPacket().
Referenced by SendWelcome().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendCommand | ( | const CommandPacket * | cp | ) |
Send a command to the client to execute.
cp | The command to send. |
Definition at line 683 of file network_server.cpp.
References CommandPacket::frame, CommandPacket::my_cmd, NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_COMMAND, Packet::Send_bool(), Packet::Send_uint32(), and SendPacket().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo | ( | ) | [protected] |
Send the client information about the companies.
Definition at line 319 of file network_server.cpp.
References CLIENT_ID_SERVER, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, FOR_ALL_CLIENT_SOCKETS, GetByClientID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), lastof, MAX_COMPANIES, NETWORK_CLIENT_NAME_LENGTH, NETWORK_CLIENTS_LENGTH, NETWORK_COMPANY_INFO_VERSION, NETWORK_RECV_STATUS_OKAY, NetworkPopulateCompanyStats(), PACKET_SERVER_COMPANY_INFO, Packet::Send_bool(), Packet::Send_string(), Packet::Send_uint8(), SendPacket(), strecat(), strecpy(), and StrEmpty().
Referenced by Receive_CLIENT_COMPANY_INFO().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyUpdate | ( | ) |
Send an update about the company password states.
Definition at line 794 of file network_server.cpp.
References _network_company_passworded, NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_COMPANY_UPDATE, Packet::Send_uint16(), and SendPacket().
Referenced by Receive_CLIENT_MAP_OK().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendConfigUpdate | ( | ) |
Send an update about the max company/spectator counts.
Definition at line 804 of file network_server.cpp.
References _settings_client, NetworkSettings::max_companies, NetworkSettings::max_spectators, ClientSettings::network, NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_CONFIG_UPDATE, Packet::Send_uint8(), and SendPacket().
Referenced by Receive_CLIENT_MAP_OK().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendError | ( | NetworkErrorCode | error | ) |
Send an error to the client, and close its connection.
error | The error to disconnect for. |
Definition at line 385 of file network_server.cpp.
References CC_DEFAULT, NetworkGameSocketHandler::client_id, CloseConnection(), DEBUG, FOR_ALL_CLIENT_SOCKETS, GetClientName(), GetNetworkErrorMsg(), lastof, NETWORK_CLIENT_NAME_LENGTH, NETWORK_RECV_STATUS_SERVER_ERROR, NetworkAdminClientError(), PACKET_SERVER_ERROR, Packet::Send_uint8(), SendPacket(), status, and STATUS_AUTHORIZED.
Referenced by Receive_CLIENT_ACK(), Receive_CLIENT_CHAT(), Receive_CLIENT_COMMAND(), Receive_CLIENT_COMPANY_PASSWORD(), Receive_CLIENT_GAME_PASSWORD(), Receive_CLIENT_GETMAP(), Receive_CLIENT_JOIN(), Receive_CLIENT_MAP_OK(), Receive_CLIENT_MOVE(), Receive_CLIENT_NEWGRFS_CHECKED(), Receive_CLIENT_RCON(), Receive_CLIENT_SET_NAME(), Receive_CLIENT_SET_PASSWORD(), and SendMap().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendErrorQuit | ( | ClientID | client_id, | |
NetworkErrorCode | errorno | |||
) |
Tell the client another client quit with an error.
client_id | The client that quit. | |
errorno | The reason the client quit. |
Definition at line 722 of file network_server.cpp.
References NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_ERROR_QUIT, Packet::Send_uint32(), Packet::Send_uint8(), and SendPacket().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendFrame | ( | ) |
Tell the client that they may run to a particular frame.
Definition at line 643 of file network_server.cpp.
References _frame_counter, _frame_counter_max, _sync_seed_1, last_token, NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_FRAME, Packet::Send_uint32(), Packet::Send_uint8(), and SendPacket().
Referenced by Receive_CLIENT_MAP_OK().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendJoin | ( | ClientID | client_id | ) |
Tell that a client joined.
client_id | The client that joined. |
Definition at line 632 of file network_server.cpp.
References NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_JOIN, Packet::Send_uint32(), and SendPacket().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendMove | ( | ClientID | client_id, | |
CompanyID | company_id | |||
) |
Tell that a client moved to another company.
client_id | The client that moved. | |
company_id | The company the client moved to. |
Definition at line 783 of file network_server.cpp.
References NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_MOVE, Packet::Send_uint32(), Packet::Send_uint8(), and SendPacket().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedCompanyPassword | ( | ) | [protected] |
Request the company password.
Definition at line 461 of file network_server.cpp.
References _settings_client, _settings_game, CloseConnection(), GameSettings::game_creation, GameCreationSettings::generation_seed, ClientSettings::network, NetworkSettings::network_id, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_NEED_COMPANY_PASSWORD, Packet::Send_string(), Packet::Send_uint32(), SendPacket(), status, and STATUS_AUTH_COMPANY.
Referenced by Receive_CLIENT_GAME_PASSWORD(), and Receive_CLIENT_NEWGRFS_CHECKED().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedGamePassword | ( | ) | [protected] |
Request the game password.
Definition at line 448 of file network_server.cpp.
References CloseConnection(), NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_NEED_GAME_PASSWORD, SendPacket(), status, and STATUS_AUTH_GAME.
Referenced by Receive_CLIENT_NEWGRFS_CHECKED().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGame | ( | ) |
Tell the client we're starting a new game.
Definition at line 756 of file network_server.cpp.
References NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_NEWGAME, and SendPacket().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGRFCheck | ( | ) | [protected] |
Send the check for the NewGRFs.
Definition at line 428 of file network_server.cpp.
References _grfconfig, GRFConfig::flags, GCF_STATIC, HasBit(), GRFConfig::ident, NETWORK_RECV_STATUS_OKAY, GRFConfig::next, PACKET_SERVER_CHECK_NEWGRFS, Packet::Send_uint8(), NetworkSocketHandler::SendGRFIdentifier(), and SendPacket().
Referenced by Receive_CLIENT_JOIN().
void ServerNetworkGameSocketHandler::SendPacket | ( | Packet * | packet | ) | [virtual] |
This function puts the packet in the send-queue and it is send as soon as possible.
This is the next tick, or maybe one tick later if the OS-network-buffer is full)
packet | the packet to send |
Reimplemented from NetworkTCPSocketHandler.
Definition at line 209 of file network_server.cpp.
References ThreadMutex::BeginCritical(), ThreadMutex::EndCritical(), and savegame_mutex.
Referenced by SendChat(), SendClientInfo(), SendCommand(), SendCompanyInfo(), SendCompanyUpdate(), SendConfigUpdate(), SendError(), SendErrorQuit(), SendFrame(), SendJoin(), SendMap(), SendMove(), SendNeedCompanyPassword(), SendNeedGamePassword(), SendNewGame(), SendNewGRFCheck(), SendQuit(), SendRConResult(), SendShutdown(), SendSync(), SendWait(), and SendWelcome().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendQuit | ( | ClientID | client_id | ) |
Tell the client another client quit.
client_id | The client that quit. |
Definition at line 737 of file network_server.cpp.
References NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_QUIT, Packet::Send_uint32(), and SendPacket().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendRConResult | ( | uint16 | colour, | |
const char * | command | |||
) |
Send the result of a console action.
colour | The colour of the result. | |
command | The command that was executed. |
Definition at line 768 of file network_server.cpp.
References NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_RCON, Packet::Send_string(), Packet::Send_uint16(), and SendPacket().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendShutdown | ( | ) |
Tell the client we're shutting down.
Definition at line 748 of file network_server.cpp.
References NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_SHUTDOWN, and SendPacket().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendSync | ( | ) |
Request the client to sync.
Definition at line 666 of file network_server.cpp.
References _frame_counter, _sync_seed_1, NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_SYNC, Packet::Send_uint32(), and SendPacket().
Referenced by Receive_CLIENT_MAP_OK().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendWait | ( | ) | [protected] |
Tell the client that its put in a waiting queue.
Definition at line 504 of file network_server.cpp.
References NetworkGameSocketHandler::client_id, FOR_ALL_CLIENT_SOCKETS, NetworkGameSocketHandler::GetInfo(), NetworkClientInfo::join_date, NETWORK_RECV_STATUS_OKAY, PACKET_SERVER_WAIT, Packet::Send_uint8(), SendPacket(), and STATUS_MAP_WAIT.
Referenced by Receive_CLIENT_GETMAP().
NetworkRecvStatus ServerNetworkGameSocketHandler::SendWelcome | ( | ) | [protected] |
Send the client a welcome message with some basic information.
Definition at line 476 of file network_server.cpp.
References _network_game_info, _settings_client, _settings_game, NetworkGameSocketHandler::client_id, CLIENT_ID_SERVER, NetworkServerGameInfo::clients_on, CloseConnection(), FOR_ALL_CLIENT_SOCKETS, GameSettings::game_creation, GameCreationSettings::generation_seed, NetworkClientInfo::GetByClientID(), ClientSettings::network, NetworkSettings::network_id, NETWORK_RECV_STATUS_MALFORMED_PACKET, PACKET_SERVER_WELCOME, Packet::Send_string(), Packet::Send_uint32(), SendClientInfo(), SendPacket(), status, and STATUS_AUTHORIZED.
Referenced by Receive_CLIENT_COMPANY_PASSWORD(), Receive_CLIENT_GAME_PASSWORD(), and Receive_CLIENT_NEWGRFS_CHECKED().