OpenTTD Source 20241224-master-gf74b0cf984
|
Base socket handler for all TCP sockets. More...
#include <tcp_game.h>
Public Member Functions | |
NetworkRecvStatus | CloseConnection (bool error=true) override |
Functions to help ReceivePacket/SendPacket a bit A socket can make errors. | |
virtual NetworkRecvStatus | CloseConnection (NetworkRecvStatus status)=0 |
Close the network connection due to the given status. | |
void | SetInfo (NetworkClientInfo *info) |
Sets the client info for this socket handler. | |
NetworkClientInfo * | GetInfo () const |
Gets the client info of this socket handler. | |
NetworkRecvStatus | ReceivePackets () |
Do the actual receiving of packets. | |
const char * | ReceiveCommand (Packet &p, CommandPacket &cp) |
Receives a command from the network. | |
void | SendCommand (Packet &p, const CommandPacket &cp) |
Sends a command over the network. | |
bool | IsPendingDeletion () const |
void | DeferDeletion () |
Public Member Functions inherited from NetworkTCPSocketHandler | |
bool | IsConnected () const |
Whether this socket is currently bound to a socket. | |
void | CloseSocket () |
Close the actual socket of the connection. | |
virtual void | SendPacket (std::unique_ptr< Packet > &&packet) |
This function puts the packet in the send-queue and it is send as soon as possible. | |
SendPacketsState | SendPackets (bool closing_down=false) |
Sends all the buffered packets out for this client. | |
virtual std::unique_ptr< Packet > | ReceivePacket () |
Receives a packet for the given client. | |
bool | CanSendReceive () |
Check whether this socket can send or receive something. | |
bool | HasSendQueue () |
Whether there is something pending in the send queue. | |
NetworkTCPSocketHandler (SOCKET s=INVALID_SOCKET) | |
Construct a socket handler for a TCP connection. | |
Public Member Functions inherited from NetworkSocketHandler | |
NetworkSocketHandler () | |
Create a new unbound socket. | |
virtual | ~NetworkSocketHandler ()=default |
Close the socket when destructing the socket handler. | |
void | MarkClosed () |
Mark the connection as closed. | |
bool | HasClientQuit () const |
Whether the current client connected to the socket has quit. | |
void | Reopen () |
Reopen the socket so we can send/receive stuff again. | |
Static Public Member Functions | |
static void | ProcessDeferredDeletions () |
Data Fields | |
ClientID | client_id |
Client identifier. | |
uint32_t | last_frame |
Last frame we have executed. | |
uint32_t | last_frame_server |
Last frame the server has executed. | |
CommandQueue | incoming_queue |
The command-queue awaiting handling. | |
std::chrono::steady_clock::time_point | last_packet |
Time we received the last frame. | |
Data Fields inherited from NetworkTCPSocketHandler | |
SOCKET | sock |
The socket currently connected to. | |
bool | writable |
Can we write to this socket? | |
Protected Member Functions | |
NetworkRecvStatus | ReceiveInvalidPacket (PacketGameType type) |
Helper for logging receiving invalid packets. | |
virtual NetworkRecvStatus | Receive_SERVER_FULL (Packet &p) |
Notification that the server is full. | |
virtual NetworkRecvStatus | Receive_SERVER_BANNED (Packet &p) |
Notification that the client trying to join is banned. | |
virtual NetworkRecvStatus | Receive_CLIENT_JOIN (Packet &p) |
Try to join the server: string OpenTTD revision (norev0000 if no revision). | |
virtual NetworkRecvStatus | Receive_SERVER_ERROR (Packet &p) |
The client made an error: uint8_t Error code caused (see NetworkErrorCode). | |
virtual NetworkRecvStatus | Receive_CLIENT_GAME_INFO (Packet &p) |
Request game information. | |
virtual NetworkRecvStatus | Receive_SERVER_GAME_INFO (Packet &p) |
Sends information about the game. | |
virtual NetworkRecvStatus | Receive_SERVER_CLIENT_INFO (Packet &p) |
Send information about a client: uint32_t ID of the client (always unique on a server. | |
virtual NetworkRecvStatus | Receive_CLIENT_IDENTIFY (Packet &p) |
The client tells the server about the identity of the client: string Name of the client (max NETWORK_NAME_LENGTH). | |
virtual NetworkRecvStatus | Receive_SERVER_AUTH_REQUEST (Packet &p) |
Indication to the client that it needs to authenticate: uint8_t The NetworkAuthenticationMethod to use. | |
virtual NetworkRecvStatus | Receive_CLIENT_AUTH_RESPONSE (Packet &p) |
Send the response to the authentication request: 32 * uint8_t Public key of the client. | |
virtual NetworkRecvStatus | Receive_SERVER_ENABLE_ENCRYPTION (Packet &p) |
Indication to the client that authentication is complete and encryption has to be used from here on forward. | |
virtual NetworkRecvStatus | Receive_SERVER_WELCOME (Packet &p) |
The client is joined and ready to receive their map: uint32_t Own client ID. | |
virtual NetworkRecvStatus | Receive_CLIENT_GETMAP (Packet &p) |
Request the map from the server. | |
virtual NetworkRecvStatus | Receive_SERVER_WAIT (Packet &p) |
Notification that another client is currently receiving the map: uint8_t Number of clients waiting in front of you. | |
virtual NetworkRecvStatus | Receive_SERVER_MAP_BEGIN (Packet &p) |
Sends that the server will begin with sending the map to the client: uint32_t Current frame. | |
virtual NetworkRecvStatus | Receive_SERVER_MAP_SIZE (Packet &p) |
Sends the size of the map to the client. | |
virtual NetworkRecvStatus | Receive_SERVER_MAP_DATA (Packet &p) |
Sends the data of the map to the client: Contains a part of the map (until max size of packet). | |
virtual NetworkRecvStatus | Receive_SERVER_MAP_DONE (Packet &p) |
Sends that all data of the map are sent to the client: | |
virtual NetworkRecvStatus | Receive_CLIENT_MAP_OK (Packet &p) |
Tell the server that we are done receiving/loading the map. | |
virtual NetworkRecvStatus | Receive_SERVER_JOIN (Packet &p) |
A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO: uint32_t ID of the client that just joined the game. | |
virtual NetworkRecvStatus | Receive_SERVER_FRAME (Packet &p) |
Sends the current frame counter to the client: uint32_t Frame counter uint32_t Frame counter max (how far may the client walk before the server?) uint32_t General seed 1 (dependent on compile settings, not default). | |
virtual NetworkRecvStatus | Receive_SERVER_SYNC (Packet &p) |
Sends a sync-check to the client: uint32_t Frame counter. | |
virtual NetworkRecvStatus | Receive_CLIENT_ACK (Packet &p) |
Tell the server we are done with this frame: uint32_t Current frame counter of the client. | |
virtual NetworkRecvStatus | Receive_CLIENT_COMMAND (Packet &p) |
Send a DoCommand to the Server: uint8_t ID of the company (0..MAX_COMPANIES-1). | |
virtual NetworkRecvStatus | Receive_SERVER_COMMAND (Packet &p) |
Sends a DoCommand to the client: uint8_t ID of the company (0..MAX_COMPANIES-1). | |
virtual NetworkRecvStatus | Receive_CLIENT_CHAT (Packet &p) |
Sends a chat-packet to the server: uint8_t ID of the action (see NetworkAction). | |
virtual NetworkRecvStatus | Receive_SERVER_CHAT (Packet &p) |
Sends a chat-packet to the client: uint8_t ID of the action (see NetworkAction). | |
virtual NetworkRecvStatus | Receive_SERVER_EXTERNAL_CHAT (Packet &p) |
Sends a chat-packet for external source to the client: string Name of the source this message came from. | |
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 quitting the game. | |
virtual NetworkRecvStatus | Receive_CLIENT_ERROR (Packet &p) |
The client made an error and is quitting the game. | |
virtual NetworkRecvStatus | Receive_SERVER_QUIT (Packet &p) |
Notification that a client left the game: uint32_t ID of the client. | |
virtual NetworkRecvStatus | Receive_SERVER_ERROR_QUIT (Packet &p) |
Inform all clients that one client made an error and thus has quit/been disconnected: uint32_t ID of the client that caused the error. | |
virtual NetworkRecvStatus | Receive_SERVER_SHUTDOWN (Packet &p) |
Let the clients know that the server is closing. | |
virtual NetworkRecvStatus | Receive_SERVER_NEWGAME (Packet &p) |
Let the clients know that the server is loading a new map. | |
virtual NetworkRecvStatus | Receive_SERVER_RCON (Packet &p) |
Send the result of an issues RCon command back to the client: uint16_t Colour code. | |
virtual NetworkRecvStatus | Receive_CLIENT_RCON (Packet &p) |
Send an RCon command to the server: string RCon password. | |
virtual NetworkRecvStatus | Receive_SERVER_CHECK_NEWGRFS (Packet &p) |
Sends information about all used GRFs to the client: uint8_t Amount of GRFs (the following data is repeated this many times, i.e. | |
virtual NetworkRecvStatus | Receive_CLIENT_NEWGRFS_CHECKED (Packet &p) |
Tell the server that we have the required GRFs. | |
virtual NetworkRecvStatus | Receive_SERVER_MOVE (Packet &p) |
Move a client from one company into another: uint32_t ID of the client. | |
virtual NetworkRecvStatus | Receive_CLIENT_MOVE (Packet &p) |
Request the server to move this client into another company: uint8_t ID of the company the client wants to join. | |
virtual NetworkRecvStatus | Receive_SERVER_CONFIG_UPDATE (Packet &p) |
Update the clients knowledge of the max settings: uint8_t Maximum number of companies allowed. | |
NetworkRecvStatus | HandlePacket (Packet &p) |
Handle the given packet, i.e. | |
NetworkGameSocketHandler (SOCKET s) | |
Create a new socket for the game connection. | |
Private Attributes | |
NetworkClientInfo * | info |
Client info related to this socket. | |
bool | is_pending_deletion = false |
Whether this socket is pending deletion. | |
Additional Inherited Members | |
Protected Attributes inherited from NetworkSocketHandler | |
std::unique_ptr< class NetworkEncryptionHandler > | receive_encryption_handler |
The handler for decrypting received packets. | |
std::unique_ptr< class NetworkEncryptionHandler > | send_encryption_handler |
The handler for encrypting sent packets. | |
Base socket handler for all TCP sockets.
Definition at line 141 of file tcp_game.h.
|
protected |
Create a new socket for the game connection.
s | The socket to connect with. |
Definition at line 29 of file tcp_game.cpp.
References last_packet, and NetworkTCPSocketHandler::sock.
|
overridevirtual |
Functions to help ReceivePacket/SendPacket a bit A socket can make errors.
When that happens this handles what to do. For clients: close connection and drop back to main-menu For servers: close connection and that is it
Reimplemented from NetworkTCPSocketHandler.
Definition at line 43 of file tcp_game.cpp.
References _network_server, _networking, _switch_mode, ClientNetworkEmergencySave(), CloseConnection(), INVALID_STRING_ID, NETWORK_RECV_STATUS_CLIENT_QUIT, NETWORK_RECV_STATUS_CONNECTION_LOST, ShowErrorMessage(), SM_MENU, and WL_CRITICAL.
Referenced by ClientNetworkGameSocketHandler::CheckConnection(), CloseConnection(), and HandlePacket().
|
pure virtual |
Close the network connection due to the given status.
status | The reason the connection got closed. |
Implemented in ClientNetworkGameSocketHandler, QueryNetworkGameSocketHandler, and ServerNetworkGameSocketHandler.
void NetworkGameSocketHandler::DeferDeletion | ( | ) |
Definition at line 199 of file tcp_game.cpp.
|
inline |
Gets the client info of this socket handler.
Definition at line 515 of file tcp_game.h.
References info.
Referenced by ServerNetworkGameSocketHandler::GetClientName(), ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT(), ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(), ServerNetworkGameSocketHandler::Receive_CLIENT_MAP_OK(), ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME(), ServerNetworkGameSocketHandler::SendWait(), ClientNetworkGameSocketHandler::~ClientNetworkGameSocketHandler(), and ServerNetworkGameSocketHandler::~ServerNetworkGameSocketHandler().
|
protected |
Handle the given packet, i.e.
pass it to the right parser receive command.
p | the packet to handle |
Definition at line 64 of file tcp_game.cpp.
References client_id, CloseConnection(), Debug, NetworkSocketHandler::HasClientQuit(), last_packet, NETWORK_RECV_STATUS_MALFORMED_PACKET, PACKET_CLIENT_ACK, PACKET_CLIENT_AUTH_RESPONSE, PACKET_CLIENT_CHAT, PACKET_CLIENT_COMMAND, PACKET_CLIENT_ERROR, PACKET_CLIENT_GAME_INFO, PACKET_CLIENT_GETMAP, PACKET_CLIENT_IDENTIFY, PACKET_CLIENT_JOIN, PACKET_CLIENT_MAP_OK, PACKET_CLIENT_MOVE, PACKET_CLIENT_NEWGRFS_CHECKED, PACKET_CLIENT_QUIT, PACKET_CLIENT_RCON, PACKET_CLIENT_SET_NAME, PACKET_SERVER_AUTH_REQUEST, PACKET_SERVER_BANNED, PACKET_SERVER_CHAT, PACKET_SERVER_CHECK_NEWGRFS, PACKET_SERVER_CLIENT_INFO, PACKET_SERVER_COMMAND, PACKET_SERVER_CONFIG_UPDATE, PACKET_SERVER_ENABLE_ENCRYPTION, PACKET_SERVER_ERROR, PACKET_SERVER_ERROR_QUIT, PACKET_SERVER_EXTERNAL_CHAT, PACKET_SERVER_FRAME, PACKET_SERVER_FULL, PACKET_SERVER_GAME_INFO, PACKET_SERVER_JOIN, PACKET_SERVER_MAP_BEGIN, PACKET_SERVER_MAP_DATA, PACKET_SERVER_MAP_DONE, PACKET_SERVER_MAP_SIZE, PACKET_SERVER_MOVE, PACKET_SERVER_NEWGAME, PACKET_SERVER_QUIT, PACKET_SERVER_RCON, PACKET_SERVER_SHUTDOWN, PACKET_SERVER_SYNC, PACKET_SERVER_WAIT, PACKET_SERVER_WELCOME, Receive_CLIENT_ACK(), Receive_CLIENT_AUTH_RESPONSE(), Receive_CLIENT_CHAT(), Receive_CLIENT_COMMAND(), Receive_CLIENT_ERROR(), Receive_CLIENT_GAME_INFO(), Receive_CLIENT_GETMAP(), Receive_CLIENT_IDENTIFY(), Receive_CLIENT_JOIN(), Receive_CLIENT_MAP_OK(), Receive_CLIENT_MOVE(), Receive_CLIENT_NEWGRFS_CHECKED(), Receive_CLIENT_QUIT(), Receive_CLIENT_RCON(), Receive_CLIENT_SET_NAME(), Receive_SERVER_AUTH_REQUEST(), Receive_SERVER_BANNED(), Receive_SERVER_CHAT(), Receive_SERVER_CHECK_NEWGRFS(), Receive_SERVER_CLIENT_INFO(), Receive_SERVER_COMMAND(), Receive_SERVER_CONFIG_UPDATE(), Receive_SERVER_ENABLE_ENCRYPTION(), Receive_SERVER_ERROR(), Receive_SERVER_ERROR_QUIT(), Receive_SERVER_EXTERNAL_CHAT(), Receive_SERVER_FRAME(), Receive_SERVER_FULL(), Receive_SERVER_GAME_INFO(), Receive_SERVER_JOIN(), Receive_SERVER_MAP_BEGIN(), Receive_SERVER_MAP_DATA(), Receive_SERVER_MAP_DONE(), Receive_SERVER_MAP_SIZE(), Receive_SERVER_MOVE(), Receive_SERVER_NEWGAME(), Receive_SERVER_QUIT(), Receive_SERVER_RCON(), Receive_SERVER_SHUTDOWN(), Receive_SERVER_SYNC(), Receive_SERVER_WAIT(), Receive_SERVER_WELCOME(), and Packet::Recv_uint8().
Referenced by ReceivePackets().
|
inline |
Definition at line 525 of file tcp_game.h.
|
static |
Definition at line 205 of file tcp_game.cpp.
|
protectedvirtual |
Tell the server we are done with this frame: uint32_t Current frame counter of the client.
uint8_t The random token that the server sent in the PACKET_SERVER_FRAME packet.
p | The packet that was just received. |
Reimplemented in ServerNetworkGameSocketHandler.
Definition at line 178 of file tcp_game.cpp.
References PACKET_CLIENT_ACK, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Send the response to the authentication request: 32 * uint8_t Public key of the client.
16 * uint8_t Message authentication code. 8 * uint8_t Random message that got encoded and signed.
p | The packet that was just received. |
Reimplemented in ServerNetworkGameSocketHandler.
Definition at line 165 of file tcp_game.cpp.
References PACKET_CLIENT_AUTH_RESPONSE, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Sends a chat-packet to the server: uint8_t ID of the action (see NetworkAction).
uint8_t ID of the destination type (see DestType). uint32_t ID of the client or company (destination of the chat). string Message (max NETWORK_CHAT_LENGTH). uint64_t data (used e.g. for 'give money' actions).
p | The packet that was just received. |
Reimplemented in ServerNetworkGameSocketHandler.
Definition at line 181 of file tcp_game.cpp.
References PACKET_CLIENT_CHAT, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Send a DoCommand to the Server: uint8_t ID of the company (0..MAX_COMPANIES-1).
uint32_t ID of the command (see command.h). Command specific buffer with encoded parameters of variable length. The content differs per command and can change without notification. uint8_t ID of the callback.
p | The packet that was just received. |
Reimplemented in ServerNetworkGameSocketHandler.
Definition at line 179 of file tcp_game.cpp.
References PACKET_CLIENT_COMMAND, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
The client made an error and is quitting the game.
uint8_t Error of the code caused (see NetworkErrorCode).
p | The packet that was just received. |
Reimplemented in ServerNetworkGameSocketHandler.
Definition at line 186 of file tcp_game.cpp.
References PACKET_CLIENT_ERROR, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Request game information.
p | The packet that was just received. |
Reimplemented in ServerNetworkGameSocketHandler.
Definition at line 160 of file tcp_game.cpp.
References PACKET_CLIENT_GAME_INFO, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Request the map from the server.
p | The packet that was just received. |
Reimplemented in ServerNetworkGameSocketHandler.
Definition at line 168 of file tcp_game.cpp.
References PACKET_CLIENT_GETMAP, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
The client tells the server about the identity of the client: string Name of the client (max NETWORK_NAME_LENGTH).
uint8_t ID of the company to play as (1..MAX_COMPANIES, or COMPANY_SPECTATOR).
p | The packet that was just received. |
Reimplemented in ServerNetworkGameSocketHandler.
Definition at line 163 of file tcp_game.cpp.
References PACKET_CLIENT_IDENTIFY, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Try to join the server: string OpenTTD revision (norev0000 if no revision).
uint32_t NewGRF version (added in 1.2). string Name of the client (max NETWORK_NAME_LENGTH) (removed in 15). uint8_t ID of the company to play as (1..MAX_COMPANIES) (removed in 15). uint8_t ID of the clients Language (removed in 15). string Client's unique identifier (removed in 1.0).
p | The packet that was just received. |
Reimplemented in ServerNetworkGameSocketHandler.
Definition at line 158 of file tcp_game.cpp.
References PACKET_CLIENT_JOIN, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Tell the server that we are done receiving/loading the map.
p | The packet that was just received. |
Reimplemented in ServerNetworkGameSocketHandler.
Definition at line 174 of file tcp_game.cpp.
References PACKET_CLIENT_MAP_OK, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Request the server to move this client into another company: uint8_t ID of the company the client wants to join.
p | The packet that was just received. |
Reimplemented in ServerNetworkGameSocketHandler.
Definition at line 196 of file tcp_game.cpp.
References PACKET_CLIENT_MOVE, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Tell the server that we have the required GRFs.
p | The packet that was just received. |
Reimplemented in ServerNetworkGameSocketHandler.
Definition at line 194 of file tcp_game.cpp.
References PACKET_CLIENT_NEWGRFS_CHECKED, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
The client is quitting the game.
p | The packet that was just received. |
Reimplemented in ServerNetworkGameSocketHandler.
Definition at line 185 of file tcp_game.cpp.
References PACKET_CLIENT_QUIT, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Send an RCon command to the server: string RCon password.
string Command to be executed.
p | The packet that was just received. |
Reimplemented in ServerNetworkGameSocketHandler.
Definition at line 192 of file tcp_game.cpp.
References PACKET_CLIENT_RCON, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Gives the client a new name: string New name of the client.
p | The packet that was just received. |
Reimplemented in ServerNetworkGameSocketHandler.
Definition at line 184 of file tcp_game.cpp.
References PACKET_CLIENT_SET_NAME, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Indication to the client that it needs to authenticate: uint8_t The NetworkAuthenticationMethod
to use.
32 * uint8_t Public key of the server. 24 * uint8_t Nonce for the key exchange.
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 164 of file tcp_game.cpp.
References PACKET_SERVER_AUTH_REQUEST, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Notification that the client trying to join is banned.
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler, and QueryNetworkGameSocketHandler.
Definition at line 157 of file tcp_game.cpp.
References PACKET_SERVER_BANNED, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Sends a chat-packet to the client: uint8_t ID of the action (see NetworkAction).
uint32_t ID of the client (origin of the chat). string Message (max NETWORK_CHAT_LENGTH). uint64_t data (used e.g. for 'give money' actions).
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 182 of file tcp_game.cpp.
References PACKET_SERVER_CHAT, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Sends information about all used GRFs to the client: uint8_t Amount of GRFs (the following data is repeated this many times, i.e.
per GRF data). uint32_t GRF ID 16 * uint8_t MD5 checksum of the GRF
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 193 of file tcp_game.cpp.
References PACKET_SERVER_CHECK_NEWGRFS, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Send information about a client: uint32_t ID of the client (always unique on a server.
1 = server, 0 is invalid). uint8_t ID of the company the client is playing as (255 for spectators). string Name of the client. string Public key of the client.
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 162 of file tcp_game.cpp.
References PACKET_SERVER_CLIENT_INFO, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Sends a DoCommand to the client: uint8_t ID of the company (0..MAX_COMPANIES-1).
uint32_t ID of the command (see command.h). Command specific buffer with encoded parameters of variable length. The content differs per command and can change without notification. uint8_t ID of the callback. uint32_t Frame of execution.
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 180 of file tcp_game.cpp.
References PACKET_SERVER_COMMAND, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Update the clients knowledge of the max settings: uint8_t Maximum number of companies allowed.
uint8_t Maximum number of spectators allowed.
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 197 of file tcp_game.cpp.
References PACKET_SERVER_CONFIG_UPDATE, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Indication to the client that authentication is complete and encryption has to be used from here on forward.
The encryption uses the shared keys generated by the last AUTH_REQUEST key exchange. 24 * uint8_t Nonce for encrypted connection.
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 166 of file tcp_game.cpp.
References PACKET_SERVER_ENABLE_ENCRYPTION, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
The client made an error: uint8_t Error code caused (see NetworkErrorCode).
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler, and QueryNetworkGameSocketHandler.
Definition at line 159 of file tcp_game.cpp.
References PACKET_SERVER_ERROR, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Inform all clients that one client made an error and thus has quit/been disconnected: uint32_t ID of the client that caused the error.
uint8_t Code of the error caused (see NetworkErrorCode).
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 188 of file tcp_game.cpp.
References PACKET_SERVER_ERROR_QUIT, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Sends a chat-packet for external source to the client: string Name of the source this message came from.
uint16_t TextColour to use for the message. string Name of the user who sent the messsage. string Message (max NETWORK_CHAT_LENGTH).
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 183 of file tcp_game.cpp.
References PACKET_SERVER_EXTERNAL_CHAT, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Sends the current frame counter to the client: uint32_t Frame counter uint32_t Frame counter max (how far may the client walk before the server?) uint32_t General seed 1 (dependent on compile settings, not default).
uint32_t General seed 2 (dependent on compile settings, not default). uint8_t Random token to validate the client is actually listening (only occasionally present).
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 176 of file tcp_game.cpp.
References PACKET_SERVER_FRAME, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Notification that the server is full.
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler, and QueryNetworkGameSocketHandler.
Definition at line 156 of file tcp_game.cpp.
References PACKET_SERVER_FULL, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Sends information about the game.
Serialized NetworkGameInfo. See game_info.h for details.
p | The packet that was just received. |
Reimplemented in QueryNetworkGameSocketHandler.
Definition at line 161 of file tcp_game.cpp.
References PACKET_SERVER_GAME_INFO, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO: uint32_t ID of the client that just joined the game.
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 175 of file tcp_game.cpp.
References PACKET_SERVER_JOIN, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Sends that the server will begin with sending the map to the client: uint32_t Current frame.
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 170 of file tcp_game.cpp.
References PACKET_SERVER_MAP_BEGIN, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Sends the data of the map to the client: Contains a part of the map (until max size of packet).
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 172 of file tcp_game.cpp.
References PACKET_SERVER_MAP_DATA, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Sends that all data of the map are sent to the client:
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 173 of file tcp_game.cpp.
References PACKET_SERVER_MAP_DONE, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Sends the size of the map to the client.
uint32_t Size of the (compressed) map (in bytes).
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 171 of file tcp_game.cpp.
References PACKET_SERVER_MAP_SIZE, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Move a client from one company into another: uint32_t ID of the client.
uint8_t ID of the new company.
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 195 of file tcp_game.cpp.
References PACKET_SERVER_MOVE, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Let the clients know that the server is loading a new map.
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 190 of file tcp_game.cpp.
References PACKET_SERVER_NEWGAME, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Notification that a client left the game: uint32_t ID of the client.
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 187 of file tcp_game.cpp.
References PACKET_SERVER_QUIT, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Send the result of an issues RCon command back to the client: uint16_t Colour code.
string Output of the RCon command
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 191 of file tcp_game.cpp.
References PACKET_SERVER_RCON, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Let the clients know that the server is closing.
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 189 of file tcp_game.cpp.
References PACKET_SERVER_SHUTDOWN, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Sends a sync-check to the client: uint32_t Frame counter.
uint32_t General seed 1. uint32_t General seed 2 (dependent on compile settings, not default).
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 177 of file tcp_game.cpp.
References PACKET_SERVER_SYNC, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
Notification that another client is currently receiving the map: uint8_t Number of clients waiting in front of you.
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 169 of file tcp_game.cpp.
References PACKET_SERVER_WAIT, and ReceiveInvalidPacket().
Referenced by HandlePacket().
|
protectedvirtual |
The client is joined and ready to receive their map: uint32_t Own client ID.
p | The packet that was just received. |
Reimplemented in ClientNetworkGameSocketHandler.
Definition at line 167 of file tcp_game.cpp.
References PACKET_SERVER_WELCOME, and ReceiveInvalidPacket().
Referenced by HandlePacket().
const char * NetworkGameSocketHandler::ReceiveCommand | ( | Packet & | p, |
CommandPacket & | cp | ||
) |
Receives a command from the network.
p | the packet to read from. |
cp | the struct to write the data to. |
Definition at line 363 of file network_command.cpp.
References _callback_table, _cmd_dispatch, CommandPacket::callback, CommandPacket::cmd, CMD_OFFLINE, CommandPacket::company, CommandPacket::data, CommandPacket::err_msg, GetCommandFlags(), IsValidCommand(), Packet::Recv_buffer(), Packet::Recv_uint16(), and Packet::Recv_uint8().
Referenced by ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(), and ClientNetworkGameSocketHandler::Receive_SERVER_COMMAND().
|
protected |
Helper for logging receiving invalid packets.
type | The received packet type. |
Definition at line 150 of file tcp_game.cpp.
References client_id, Debug, and NETWORK_RECV_STATUS_MALFORMED_PACKET.
Referenced by Receive_CLIENT_ACK(), Receive_CLIENT_AUTH_RESPONSE(), Receive_CLIENT_CHAT(), Receive_CLIENT_COMMAND(), Receive_CLIENT_ERROR(), Receive_CLIENT_GAME_INFO(), Receive_CLIENT_GETMAP(), Receive_CLIENT_IDENTIFY(), Receive_CLIENT_JOIN(), Receive_CLIENT_MAP_OK(), Receive_CLIENT_MOVE(), Receive_CLIENT_NEWGRFS_CHECKED(), Receive_CLIENT_QUIT(), Receive_CLIENT_RCON(), Receive_CLIENT_SET_NAME(), Receive_SERVER_AUTH_REQUEST(), Receive_SERVER_BANNED(), Receive_SERVER_CHAT(), Receive_SERVER_CHECK_NEWGRFS(), Receive_SERVER_CLIENT_INFO(), Receive_SERVER_COMMAND(), Receive_SERVER_CONFIG_UPDATE(), Receive_SERVER_ENABLE_ENCRYPTION(), Receive_SERVER_ERROR(), Receive_SERVER_ERROR_QUIT(), Receive_SERVER_EXTERNAL_CHAT(), Receive_SERVER_FRAME(), Receive_SERVER_FULL(), Receive_SERVER_GAME_INFO(), Receive_SERVER_JOIN(), Receive_SERVER_MAP_BEGIN(), Receive_SERVER_MAP_DATA(), Receive_SERVER_MAP_DONE(), Receive_SERVER_MAP_SIZE(), Receive_SERVER_MOVE(), Receive_SERVER_NEWGAME(), Receive_SERVER_QUIT(), Receive_SERVER_RCON(), Receive_SERVER_SHUTDOWN(), Receive_SERVER_SYNC(), Receive_SERVER_WAIT(), and Receive_SERVER_WELCOME().
NetworkRecvStatus NetworkGameSocketHandler::ReceivePackets | ( | ) |
Do the actual receiving of packets.
As long as HandlePacket returns OKAY packets are handled. Upon failure, or no more packets to process the last result of HandlePacket is returned.
Definition at line 134 of file tcp_game.cpp.
References HandlePacket(), NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::ReceivePacket().
Referenced by ClientNetworkGameSocketHandler::Receive(), and QueryNetworkGameSocketHandler::Receive().
void NetworkGameSocketHandler::SendCommand | ( | Packet & | p, |
const CommandPacket & | cp | ||
) |
Sends a command over the network.
p | the packet to send it in. |
cp | the packet to actually send. |
Definition at line 384 of file network_command.cpp.
References _cmd_dispatch, CommandPacket::callback, CommandPacket::cmd, CommandPacket::company, CommandPacket::data, Debug, CommandPacket::err_msg, FindCallbackIndex(), Packet::Send_buffer(), Packet::Send_uint16(), and Packet::Send_uint8().
Referenced by ServerNetworkGameSocketHandler::SendCommand().
|
inline |
Sets the client info for this socket handler.
info | The new client info. |
Definition at line 505 of file tcp_game.h.
References info.
Referenced by ServerNetworkGameSocketHandler::Receive_CLIENT_IDENTIFY(), and ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO().
ClientID NetworkGameSocketHandler::client_id |
Client identifier.
Definition at line 486 of file tcp_game.h.
Referenced by ClientNetworkGameSocketHandler::CloseConnection(), ServerNetworkGameSocketHandler::CloseConnection(), ServerNetworkGameSocketHandler::GetByClientID(), ServerNetworkGameSocketHandler::GetClientName(), HandlePacket(), ServerNetworkGameSocketHandler::Receive_CLIENT_ACK(), ServerNetworkGameSocketHandler::Receive_CLIENT_AUTH_RESPONSE(), ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT(), ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(), ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR(), ServerNetworkGameSocketHandler::Receive_CLIENT_GAME_INFO(), ServerNetworkGameSocketHandler::Receive_CLIENT_GETMAP(), ServerNetworkGameSocketHandler::Receive_CLIENT_IDENTIFY(), ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(), ServerNetworkGameSocketHandler::Receive_CLIENT_MAP_OK(), ServerNetworkGameSocketHandler::Receive_CLIENT_MOVE(), ServerNetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED(), ServerNetworkGameSocketHandler::Receive_CLIENT_QUIT(), ServerNetworkGameSocketHandler::Receive_CLIENT_RCON(), ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME(), ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(), ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(), ClientNetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT(), ClientNetworkGameSocketHandler::Receive_SERVER_JOIN(), ClientNetworkGameSocketHandler::Receive_SERVER_MOVE(), ClientNetworkGameSocketHandler::Receive_SERVER_QUIT(), ReceiveInvalidPacket(), ServerNetworkGameSocketHandler::SendAuthRequest(), ServerNetworkGameSocketHandler::SendChat(), ServerNetworkGameSocketHandler::SendClientInfo(), ServerNetworkGameSocketHandler::SendCommand(), ServerNetworkGameSocketHandler::SendConfigUpdate(), ServerNetworkGameSocketHandler::SendEnableEncryption(), ServerNetworkGameSocketHandler::SendError(), ServerNetworkGameSocketHandler::SendErrorQuit(), ServerNetworkGameSocketHandler::SendExternalChat(), ServerNetworkGameSocketHandler::SendGameInfo(), ServerNetworkGameSocketHandler::SendJoin(), ServerNetworkGameSocketHandler::SendMap(), ServerNetworkGameSocketHandler::SendMove(), ServerNetworkGameSocketHandler::SendNewGame(), ServerNetworkGameSocketHandler::SendNewGRFCheck(), ServerNetworkGameSocketHandler::SendQuit(), ServerNetworkGameSocketHandler::SendRConResult(), ServerNetworkGameSocketHandler::SendShutdown(), ServerNetworkGameSocketHandler::SendSync(), ServerNetworkGameSocketHandler::SendWait(), ServerNetworkGameSocketHandler::SendWelcome(), ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(), and ServerNetworkGameSocketHandler::~ServerNetworkGameSocketHandler().
CommandQueue NetworkGameSocketHandler::incoming_queue |
The command-queue awaiting handling.
Definition at line 489 of file tcp_game.h.
Referenced by ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(), and ClientNetworkGameSocketHandler::Receive_SERVER_COMMAND().
|
private |
Client info related to this socket.
Definition at line 144 of file tcp_game.h.
Referenced by GetInfo(), ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(), and SetInfo().
|
private |
Whether this socket is pending deletion.
Definition at line 145 of file tcp_game.h.
uint32_t NetworkGameSocketHandler::last_frame |
Last frame we have executed.
Definition at line 487 of file tcp_game.h.
Referenced by ServerNetworkGameSocketHandler::Receive_CLIENT_ACK(), ServerNetworkGameSocketHandler::Receive_CLIENT_AUTH_RESPONSE(), ServerNetworkGameSocketHandler::Receive_CLIENT_MAP_OK(), ServerNetworkGameSocketHandler::SendAuthRequest(), ServerNetworkGameSocketHandler::SendMap(), and ServerNetworkGameSocketHandler::SendWelcome().
uint32_t NetworkGameSocketHandler::last_frame_server |
Last frame the server has executed.
Definition at line 488 of file tcp_game.h.
Referenced by ServerNetworkGameSocketHandler::Receive_CLIENT_ACK(), ServerNetworkGameSocketHandler::Receive_CLIENT_AUTH_RESPONSE(), ServerNetworkGameSocketHandler::Receive_CLIENT_MAP_OK(), ServerNetworkGameSocketHandler::SendAuthRequest(), ServerNetworkGameSocketHandler::SendMap(), and ServerNetworkGameSocketHandler::SendWelcome().
std::chrono::steady_clock::time_point NetworkGameSocketHandler::last_packet |
Time we received the last frame.
Definition at line 490 of file tcp_game.h.
Referenced by ClientNetworkGameSocketHandler::CheckConnection(), QueryNetworkGameSocketHandler::CheckConnection(), HandlePacket(), NetworkGameSocketHandler(), ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(), and ServerNetworkGameSocketHandler::SendMap().