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 () |
| virtual void | SendPacket (Packet *packet) |
| NetworkRecvStatus | CloseConnection (NetworkRecvStatus 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) |
| virtual NetworkRecvStatus | Receive_CLIENT_COMPANY_INFO (Packet *p) |
| virtual NetworkRecvStatus | Receive_CLIENT_GAME_PASSWORD (Packet *p) |
| virtual NetworkRecvStatus | Receive_CLIENT_COMPANY_PASSWORD (Packet *p) |
| virtual NetworkRecvStatus | Receive_CLIENT_GETMAP (Packet *p) |
| virtual NetworkRecvStatus | Receive_CLIENT_MAP_OK (Packet *p) |
| virtual NetworkRecvStatus | Receive_CLIENT_ACK (Packet *p) |
| 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) |
| virtual NetworkRecvStatus | Receive_CLIENT_SET_PASSWORD (Packet *p) |
| virtual NetworkRecvStatus | Receive_CLIENT_SET_NAME (Packet *p) |
| virtual NetworkRecvStatus | Receive_CLIENT_QUIT (Packet *p) |
| virtual NetworkRecvStatus | Receive_CLIENT_ERROR (Packet *p) |
| virtual NetworkRecvStatus | Receive_CLIENT_RCON (Packet *p) |
| virtual NetworkRecvStatus | Receive_CLIENT_NEWGRFS_CHECKED (Packet *p) |
| virtual NetworkRecvStatus | Receive_CLIENT_MOVE (Packet *p) |
| 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 155 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, and status.
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 495 of file network.cpp.
References client_address, ServerNetworkGameSocketHandler(), SetWindowDirty(), and WC_CLIENT_LIST.
| bool ServerNetworkGameSocketHandler::AllowConnection | ( | ) | [static] |
Whether an connection is allowed or not at this moment.
Definition at line 267 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.
| 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 1913 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 2101 of file network_server.cpp.
References NetworkGameSocketHandler::client_id, NetworkClientInfo::client_name, NetworkGameSocketHandler::GetInfo(), StrEmpty(), and ttd_strlcpy().
Referenced by 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_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
Definition at line 1045 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, NetworkServerSendChat(), CommandContainer::p1, CommandContainer::p2, NetworkGameSocketHandler::ReceiveCommand(), and SendError().
| void ServerNetworkGameSocketHandler::Send | ( | ) | [static] |
Send the packets for the server sockets.
Definition at line 280 of file network_server.cpp.
References FOR_ALL_CLIENT_SOCKETS, and SPS_CLOSED.
| 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 709 of file network_server.cpp.
References PACKET_SERVER_CHAT, Packet::Send_bool(), Packet::Send_string(), Packet::Send_uint32(), Packet::Send_uint64(), Packet::Send_uint8(), and STATUS_PRE_ACTIVE.
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendClientInfo | ( | NetworkClientInfo * | ci | ) |
Send the client information about a client.
| ci | The client to send information about. |
Definition at line 304 of file network_server.cpp.
References NetworkClientInfo::client_id, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, INVALID_CLIENT_ID, PACKET_SERVER_CLIENT_INFO, Packet::Send_string(), Packet::Send_uint32(), and Packet::Send_uint8().
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 689 of file network_server.cpp.
References CommandPacket::frame, CommandPacket::my_cmd, PACKET_SERVER_COMMAND, Packet::Send_bool(), and Packet::Send_uint32().
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyInfo | ( | ) | [protected] |
Send the client information about the companies.
Definition at line 318 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, NETWORK_CLIENT_NAME_LENGTH, NETWORK_CLIENTS_LENGTH, NETWORK_COMPANY_INFO_VERSION, NetworkPopulateCompanyStats(), PACKET_SERVER_COMPANY_INFO, Packet::Send_bool(), Packet::Send_string(), Packet::Send_uint8(), strecat(), strecpy(), and StrEmpty().
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyUpdate | ( | ) |
Send an update about the company password states.
Definition at line 802 of file network_server.cpp.
References _network_company_passworded, PACKET_SERVER_COMPANY_UPDATE, and Packet::Send_uint16().
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendConfigUpdate | ( | ) |
Send an update about the max company/spectator counts.
Definition at line 812 of file network_server.cpp.
References _settings_client, NetworkSettings::max_companies, NetworkSettings::max_spectators, ClientSettings::network, PACKET_SERVER_CONFIG_UPDATE, and Packet::Send_uint8().
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendError | ( | NetworkErrorCode | error | ) |
Send an error to the client, and close its connection.
| error | The error to disconnect for. |
Definition at line 384 of file network_server.cpp.
References CC_DEFAULT, NetworkGameSocketHandler::client_id, DEBUG, FOR_ALL_CLIENT_SOCKETS, GetClientName(), GetNetworkErrorMsg(), lastof, NETWORK_CLIENT_NAME_LENGTH, NETWORK_RECV_STATUS_SERVER_ERROR, NetworkAdminClientError(), PACKET_SERVER_ERROR, Packet::Send_uint8(), and STATUS_AUTHORIZED.
Referenced by Receive_CLIENT_COMMAND(), 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 730 of file network_server.cpp.
References PACKET_SERVER_ERROR_QUIT, Packet::Send_uint32(), and Packet::Send_uint8().
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendFrame | ( | ) |
Tell the client that they may run to a particular frame.
Definition at line 649 of file network_server.cpp.
References _frame_counter, _frame_counter_max, _sync_seed_1, last_token, PACKET_SERVER_FRAME, Packet::Send_uint32(), and Packet::Send_uint8().
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendJoin | ( | ClientID | client_id | ) |
Tell that a client joined.
| client_id | The client that joined. |
Definition at line 638 of file network_server.cpp.
References PACKET_SERVER_JOIN, and Packet::Send_uint32().
| 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 791 of file network_server.cpp.
References PACKET_SERVER_MOVE, Packet::Send_uint32(), and Packet::Send_uint8().
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedCompanyPassword | ( | ) | [protected] |
Request the company password.
Definition at line 462 of file network_server.cpp.
References _frame_counter, _settings_client, _settings_game, GameSettings::game_creation, GameCreationSettings::generation_seed, NetworkGameSocketHandler::last_frame, NetworkGameSocketHandler::last_frame_server, ClientSettings::network, NetworkSettings::network_id, NETWORK_RECV_STATUS_MALFORMED_PACKET, PACKET_SERVER_NEED_COMPANY_PASSWORD, Packet::Send_string(), Packet::Send_uint32(), and STATUS_AUTH_COMPANY.
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedGamePassword | ( | ) | [protected] |
Request the game password.
Definition at line 447 of file network_server.cpp.
References _frame_counter, NetworkGameSocketHandler::last_frame, NetworkGameSocketHandler::last_frame_server, NETWORK_RECV_STATUS_MALFORMED_PACKET, PACKET_SERVER_NEED_GAME_PASSWORD, and STATUS_AUTH_GAME.
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGame | ( | ) |
Tell the client we're starting a new game.
Definition at line 764 of file network_server.cpp.
References PACKET_SERVER_NEWGAME.
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGRFCheck | ( | ) | [protected] |
Send the check for the NewGRFs.
Definition at line 427 of file network_server.cpp.
References _grfconfig, GRFConfig::flags, GCF_STATIC, HasBit(), GRFConfig::ident, GRFConfig::next, PACKET_SERVER_CHECK_NEWGRFS, Packet::Send_uint8(), and NetworkSocketHandler::SendGRFIdentifier().
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendQuit | ( | ClientID | client_id | ) |
Tell the client another client quit.
| client_id | The client that quit. |
Definition at line 745 of file network_server.cpp.
References PACKET_SERVER_QUIT, and Packet::Send_uint32().
| 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 776 of file network_server.cpp.
References PACKET_SERVER_RCON, Packet::Send_string(), and Packet::Send_uint16().
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendShutdown | ( | ) |
Tell the client we're shutting down.
Definition at line 756 of file network_server.cpp.
References PACKET_SERVER_SHUTDOWN.
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendSync | ( | ) |
Request the client to sync.
Definition at line 672 of file network_server.cpp.
References _frame_counter, _sync_seed_1, PACKET_SERVER_SYNC, and Packet::Send_uint32().
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendWait | ( | ) | [protected] |
Tell the client that its put in a waiting queue.
Definition at line 510 of file network_server.cpp.
References NetworkGameSocketHandler::client_id, FOR_ALL_CLIENT_SOCKETS, NetworkGameSocketHandler::GetInfo(), NetworkClientInfo::join_date, PACKET_SERVER_WAIT, Packet::Send_uint8(), and STATUS_MAP_WAIT.
| NetworkRecvStatus ServerNetworkGameSocketHandler::SendWelcome | ( | ) | [protected] |
Send the client a welcome message with some basic information.
Definition at line 479 of file network_server.cpp.
References _frame_counter, _network_game_info, _settings_client, _settings_game, NetworkGameSocketHandler::client_id, CLIENT_ID_SERVER, NetworkServerGameInfo::clients_on, FOR_ALL_CLIENT_SOCKETS, GameSettings::game_creation, GameCreationSettings::generation_seed, NetworkClientInfo::GetByClientID(), NetworkGameSocketHandler::last_frame, NetworkGameSocketHandler::last_frame_server, ClientSettings::network, NetworkSettings::network_id, NETWORK_RECV_STATUS_MALFORMED_PACKET, PACKET_SERVER_WELCOME, Packet::Send_string(), Packet::Send_uint32(), SendClientInfo(), and STATUS_AUTHORIZED.
1.7.1