2009-08-21 22:21:05 +02:00
/*
* This file is part of OpenTTD .
* OpenTTD is free software ; you can redistribute it and / or modify it under the terms of the GNU General Public License as published by the Free Software Foundation , version 2.
* OpenTTD is distributed in the hope that it will be useful , but WITHOUT ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
* See the GNU General Public License for more details . You should have received a copy of the GNU General Public License along with OpenTTD . If not , see < http : //www.gnu.org/licenses/>.
*/
2009-01-14 13:50:13 +01:00
/**
* @ file tcp_game . h Basic functions to receive and send TCP packets for game purposes .
*/
# ifndef NETWORK_CORE_TCP_GAME_H
# define NETWORK_CORE_TCP_GAME_H
# include "os_abstraction.h"
# include "tcp.h"
2010-01-15 17:41:15 +01:00
# include "../network_type.h"
2009-05-22 17:39:22 +02:00
# include "../../core/pool_type.hpp"
2021-02-25 20:30:16 +01:00
# include <chrono>
2009-01-14 13:50:13 +01:00
/**
2010-10-24 17:22:59 +02:00
* Enum with all types of TCP packets .
* For the exact meaning , look at # NetworkGameSocketHandler .
2009-01-14 13:50:13 +01:00
*/
2024-02-04 12:31:56 +01:00
enum PacketGameType : uint8_t {
2010-10-24 17:22:59 +02:00
/*
2024-03-25 21:59:04 +01:00
* These first ten packets must remain in this order for backward and forward compatibility
* between clients that are trying to join directly . These packets can be received and / or sent
* by the server before the server has processed the ' join ' packet from the client .
2010-10-24 17:22:59 +02:00
*/
/* Packets sent by socket accepting code without ever constructing a client socket instance. */
PACKET_SERVER_FULL , ///< The server is full and has no place for you.
PACKET_SERVER_BANNED , ///< The server has banned you.
/* Packets used by the client to join and an error message when the revision is wrong. */
PACKET_CLIENT_JOIN , ///< The client telling the server it wants to join.
PACKET_SERVER_ERROR , ///< Server sending an error message to the client.
2021-08-14 23:24:02 +02:00
/* Unused packet types, formerly used for the pre-game lobby. */
PACKET_CLIENT_UNUSED , ///< Unused.
PACKET_SERVER_UNUSED , ///< Unused.
2010-10-24 17:22:59 +02:00
2021-04-26 20:02:27 +02:00
/* Packets used to get the game info. */
PACKET_SERVER_GAME_INFO , ///< Information about the server.
2021-04-28 23:09:03 +02:00
PACKET_CLIENT_GAME_INFO , ///< Request information about the server.
2021-04-26 20:02:27 +02:00
2024-03-25 21:59:04 +01:00
/* A server quitting this game. */
PACKET_SERVER_NEWGAME , ///< The server is preparing to start a new game.
PACKET_SERVER_SHUTDOWN , ///< The server is shutting down.
2010-10-24 17:22:59 +02:00
/*
* Packets after here assume that the client
* and server are running the same version . As
* such ordering is unimportant from here on .
*
* The following is the remainder of the packets
* sent as part of authenticating and getting
* the map and other important data .
*/
2024-03-14 21:08:21 +01:00
/* After the join step, the first perform game authentication and enabling encryption. */
PACKET_SERVER_AUTH_REQUEST , ///< The server requests the client to authenticate using a number of methods.
PACKET_CLIENT_AUTH_RESPONSE , ///< The client responds to the authentication request.
2024-03-14 21:36:28 +01:00
PACKET_SERVER_ENABLE_ENCRYPTION , ///< The server tells that authentication has completed and requests to enable encryption with the keys of the last \c PACKET_CLIENT_AUTH_RESPONSE.
2024-03-14 21:08:21 +01:00
/* After the authentication is done, the next step is identification. */
2024-03-13 21:33:28 +01:00
PACKET_CLIENT_IDENTIFY , ///< Client telling the server the client's name and requested company.
/* After the identify step, the next is checking NewGRFs. */
2010-10-24 17:22:59 +02:00
PACKET_SERVER_CHECK_NEWGRFS , ///< Server sends NewGRF IDs and MD5 checksums for the client to check.
PACKET_CLIENT_NEWGRFS_CHECKED , ///< Client acknowledges that it has all required NewGRFs.
2024-03-14 21:08:21 +01:00
/* Checking the company passwords. */
2010-10-24 17:22:59 +02:00
PACKET_SERVER_NEED_COMPANY_PASSWORD , ///< Server requests the (hashed) company password.
PACKET_CLIENT_COMPANY_PASSWORD , ///< Client sends the (hashed) company password.
/* The server welcomes the authenticated client and sends information of other clients. */
PACKET_SERVER_WELCOME , ///< Server welcomes you and gives you your #ClientID.
PACKET_SERVER_CLIENT_INFO , ///< Server sends you information about a client.
/* Getting the savegame/map. */
PACKET_CLIENT_GETMAP , ///< Client requests the actual map.
PACKET_SERVER_WAIT , ///< Server tells the client there are some people waiting for the map as well.
2010-10-24 22:03:33 +02:00
PACKET_SERVER_MAP_BEGIN , ///< Server tells the client that it is beginning to send the map.
2010-12-05 15:34:19 +01:00
PACKET_SERVER_MAP_SIZE , ///< Server tells the client what the (compressed) size of the map is.
2010-10-24 22:03:33 +02:00
PACKET_SERVER_MAP_DATA , ///< Server sends bits of the map to the client.
PACKET_SERVER_MAP_DONE , ///< Server tells it has just sent the last bits of the map to the client.
2010-10-24 17:22:59 +02:00
PACKET_CLIENT_MAP_OK , ///< Client tells the server that it received the whole map.
PACKET_SERVER_JOIN , ///< Tells clients that a new client has joined.
/*
* At this moment the client has the map and
* the client is fully authenticated . Now the
* normal communication starts .
*/
/* Game progress monitoring. */
PACKET_SERVER_FRAME , ///< Server tells the client what frame it is in, and thus to where the client may progress.
PACKET_CLIENT_ACK , ///< The client tells the server which frame it has executed.
PACKET_SERVER_SYNC , ///< Server tells the client what the random state should be.
/* Sending commands around. */
PACKET_CLIENT_COMMAND , ///< Client executed a command and sends it to the server.
PACKET_SERVER_COMMAND , ///< Server distributes a command to (all) the clients.
/* Human communication! */
PACKET_CLIENT_CHAT , ///< Client said something that should be distributed.
PACKET_SERVER_CHAT , ///< Server distributing the message of a client (or itself).
2021-09-19 23:09:06 +02:00
PACKET_SERVER_EXTERNAL_CHAT , ///< Server distributing the message from external source.
2010-10-24 17:22:59 +02:00
/* Remote console. */
PACKET_CLIENT_RCON , ///< Client asks the server to execute some command.
PACKET_SERVER_RCON , ///< Response of the executed command on the server.
/* Moving a client.*/
PACKET_CLIENT_MOVE , ///< A client would like to be moved to another company.
PACKET_SERVER_MOVE , ///< Server tells everyone that someone is moved to another company.
/* Configuration updates. */
PACKET_CLIENT_SET_PASSWORD , ///< A client (re)sets its company's password.
PACKET_CLIENT_SET_NAME , ///< A client changes its name.
PACKET_SERVER_COMPANY_UPDATE , ///< Information (password) of a company changed.
PACKET_SERVER_CONFIG_UPDATE , ///< Some network configuration important to the client changed.
/* A client quitting. */
PACKET_CLIENT_QUIT , ///< A client tells the server it is going to quit.
PACKET_SERVER_QUIT , ///< A server tells that a client has quit.
PACKET_CLIENT_ERROR , ///< A client reports an error to the server.
PACKET_SERVER_ERROR_QUIT , ///< A server tells that a client has hit an error and did quit.
2011-12-19 18:48:04 +01:00
PACKET_END , ///< Must ALWAYS be on the end of this list!! (period)
2009-01-14 13:50:13 +01:00
} ;
/** Packet that wraps a command */
struct CommandPacket ;
2024-02-04 17:02:08 +01:00
/**
* A " queue " of CommandPackets .
* Not a std : : queue because , when paused , some commands remain on the queue .
* In other words , you do not always pop the first element from this queue .
*/
using CommandQueue = std : : vector < CommandPacket > ;
2010-08-16 01:44:45 +02:00
2009-01-14 13:50:13 +01:00
/** Base socket handler for all TCP sockets */
2010-10-15 21:58:56 +02:00
class NetworkGameSocketHandler : public NetworkTCPSocketHandler {
2009-01-14 13:50:13 +01:00
/* TODO: rewrite into a proper class */
private :
2023-06-16 21:54:04 +02:00
NetworkClientInfo * info ; ///< Client info related to this socket
bool is_pending_deletion = false ; ///< Whether this socket is pending deletion
2010-10-15 15:47:37 +02:00
2010-10-15 15:22:00 +02:00
protected :
2011-05-01 13:30:03 +02:00
NetworkRecvStatus ReceiveInvalidPacket ( PacketGameType type ) ;
2010-10-18 22:41:53 +02:00
/**
* Notification that the server is full .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_FULL ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Notification that the client trying to join is banned .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_BANNED ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Try to join the server :
2024-03-17 14:17:35 +01:00
* string OpenTTD revision ( norev0000 if no revision ) .
2024-03-13 21:33:28 +01:00
* 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 ) .
*
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_CLIENT_JOIN ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* The client made an error :
2023-05-08 19:01:06 +02:00
* uint8_t Error code caused ( see NetworkErrorCode ) .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_ERROR ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
2021-04-26 20:02:27 +02:00
/**
* Request game information .
* @ param p The packet that was just received .
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_CLIENT_GAME_INFO ( Packet & p ) ;
2021-04-26 20:02:27 +02:00
/**
* Sends information about the game .
* Serialized NetworkGameInfo . See game_info . h for details .
* @ param p The packet that was just received .
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_GAME_INFO ( Packet & p ) ;
2021-04-26 20:02:27 +02:00
2010-10-18 22:41:53 +02:00
/**
* Send information about a client :
2023-05-08 19:01:06 +02:00
* 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 ) .
2010-10-18 22:41:53 +02:00
* string Name of the client .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
2024-03-13 21:33:28 +01:00
/**
* The client tells the server about the identity of the client :
* string Name of the client ( max NETWORK_NAME_LENGTH ) .
2024-03-23 22:01:57 +01:00
* uint8_t ID of the company to play as ( 1. . MAX_COMPANIES , or COMPANY_SPECTATOR ) .
2024-03-13 21:33:28 +01:00
* @ param p The packet that was just received .
*/
virtual NetworkRecvStatus Receive_CLIENT_IDENTIFY ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
2024-03-14 21:08:21 +01:00
* Indication to the client that it needs to authenticate :
2024-03-23 22:01:57 +01:00
* uint8_t The \ c NetworkAuthenticationMethod to use .
2024-03-14 21:08:21 +01:00
* 32 * uint8_t Public key of the server .
* 24 * uint8_t Nonce for the key exchange .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-03-14 21:08:21 +01:00
virtual NetworkRecvStatus Receive_SERVER_AUTH_REQUEST ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Indication to the client that the server needs a company password :
2023-05-08 19:01:06 +02:00
* uint32_t Generation seed .
2010-10-18 22:41:53 +02:00
* string Network ID of the server .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
2024-03-14 21:08:21 +01:00
* Send the response to the authentication request :
* 32 * uint8_t Public key of the client .
* 16 * uint8_t Message authentication code .
2024-03-23 22:01:57 +01:00
* 8 * uint8_t Random message that got encoded and signed .
2024-03-14 21:08:21 +01:00
* @ param p The packet that was just received .
*/
virtual NetworkRecvStatus Receive_CLIENT_AUTH_RESPONSE ( Packet & p ) ;
/**
2024-03-14 21:36:28 +01:00
* Indication to the client that authentication is complete and encryption has to be used from here on forward .
2024-03-31 12:41:28 +02:00
* The encryption uses the shared keys generated by the last AUTH_REQUEST key exchange .
* 24 * uint8_t Nonce for encrypted connection .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-03-14 21:36:28 +01:00
virtual NetworkRecvStatus Receive_SERVER_ENABLE_ENCRYPTION ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Send a password to the server to authorize
2023-05-08 19:01:06 +02:00
* uint8_t Password type ( see NetworkPasswordType ) .
2010-10-18 22:41:53 +02:00
* string The password .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
2021-05-09 19:02:17 +02:00
* The client is joined and ready to receive their map :
2023-05-08 19:01:06 +02:00
* uint32_t Own client ID .
* uint32_t Generation seed .
2010-10-18 22:41:53 +02:00
* string Network ID of the server .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_WELCOME ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Request the map from the server .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_CLIENT_GETMAP ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Notification that another client is currently receiving the map :
2023-05-08 19:01:06 +02:00
* uint8_t Number of clients waiting in front of you .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_WAIT ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
2010-10-24 22:03:33 +02:00
* Sends that the server will begin with sending the map to the client :
2023-05-08 19:01:06 +02:00
* uint32_t Current frame .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_MAP_BEGIN ( Packet & p ) ;
2010-10-24 22:03:33 +02:00
2010-12-05 15:34:19 +01:00
/**
* Sends the size of the map to the client .
2023-05-08 19:01:06 +02:00
* uint32_t Size of the ( compressed ) map ( in bytes ) .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-12-05 15:34:19 +01:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_MAP_SIZE ( Packet & p ) ;
2010-12-05 15:34:19 +01:00
2010-10-24 22:03:33 +02:00
/**
* Sends the data of the map to the client :
* Contains a part of the map ( until max size of packet ) .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-24 22:03:33 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_MAP_DATA ( Packet & p ) ;
2010-10-24 22:03:33 +02:00
/**
* Sends that all data of the map are sent to the client :
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-24 22:03:33 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_MAP_DONE ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Tell the server that we are done receiving / loading the map .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_CLIENT_MAP_OK ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* A client joined ( PACKET_CLIENT_MAP_OK ) , what usually directly follows is a PACKET_SERVER_CLIENT_INFO :
2023-05-08 19:01:06 +02:00
* uint32_t ID of the client that just joined the game .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_JOIN ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Sends the current frame counter to the client :
2023-05-08 19:01:06 +02:00
* 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 ) .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_FRAME ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Sends a sync - check to the client :
2023-05-08 19:01:06 +02:00
* uint32_t Frame counter .
* uint32_t General seed 1.
* uint32_t General seed 2 ( dependent on compile settings , not default ) .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_SYNC ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Tell the server we are done with this frame :
2023-05-08 19:01:06 +02:00
* uint32_t Current frame counter of the client .
* uint8_t The random token that the server sent in the PACKET_SERVER_FRAME packet .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_CLIENT_ACK ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Send a DoCommand to the Server :
2023-05-08 19:01:06 +02:00
* uint8_t ID of the company ( 0. . MAX_COMPANIES - 1 ) .
* uint32_t ID of the command ( see command . h ) .
2023-04-15 11:10:09 +02:00
* < var > Command specific buffer with encoded parameters of variable length .
* The content differs per command and can change without notification .
2023-05-08 19:01:06 +02:00
* uint8_t ID of the callback .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_CLIENT_COMMAND ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Sends a DoCommand to the client :
2023-05-08 19:01:06 +02:00
* uint8_t ID of the company ( 0. . MAX_COMPANIES - 1 ) .
* uint32_t ID of the command ( see command . h ) .
2023-04-15 11:10:09 +02:00
* < var > Command specific buffer with encoded parameters of variable length .
* The content differs per command and can change without notification .
2023-05-08 19:01:06 +02:00
* uint8_t ID of the callback .
* uint32_t Frame of execution .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_COMMAND ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Sends a chat - packet to the server :
2023-05-08 19:01:06 +02:00
* 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 ) .
2010-10-18 22:41:53 +02:00
* string Message ( max NETWORK_CHAT_LENGTH ) .
2023-05-08 19:01:06 +02:00
* uint64_t data ( used e . g . for ' give money ' actions ) .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_CLIENT_CHAT ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Sends a chat - packet to the client :
2023-05-08 19:01:06 +02:00
* uint8_t ID of the action ( see NetworkAction ) .
* uint32_t ID of the client ( origin of the chat ) .
2010-10-18 22:41:53 +02:00
* string Message ( max NETWORK_CHAT_LENGTH ) .
2023-05-08 19:01:06 +02:00
* uint64_t data ( used e . g . for ' give money ' actions ) .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_CHAT ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
2021-09-19 23:09:06 +02:00
/**
* Sends a chat - packet for external source to the client :
* string Name of the source this message came from .
2023-05-08 19:01:06 +02:00
* uint16_t TextColour to use for the message .
2021-09-19 23:09:06 +02:00
* string Name of the user who sent the messsage .
* string Message ( max NETWORK_CHAT_LENGTH ) .
* @ param p The packet that was just received .
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_EXTERNAL_CHAT ( Packet & p ) ;
2021-09-19 23:09:06 +02:00
2010-10-18 22:41:53 +02:00
/**
* Set the password for the clients current company :
* string The password .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_CLIENT_SET_PASSWORD ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Gives the client a new name :
* string New name of the client .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_CLIENT_SET_NAME ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
2013-01-08 23:46:42 +01:00
* The client is quitting the game .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_CLIENT_QUIT ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
2013-01-08 23:46:42 +01:00
* The client made an error and is quitting the game .
2023-05-08 19:01:06 +02:00
* uint8_t Error of the code caused ( see NetworkErrorCode ) .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_CLIENT_ERROR ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Notification that a client left the game :
2023-05-08 19:01:06 +02:00
* uint32_t ID of the client .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_QUIT ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Inform all clients that one client made an error and thus has quit / been disconnected :
2023-05-08 19:01:06 +02:00
* uint32_t ID of the client that caused the error .
* uint8_t Code of the error caused ( see NetworkErrorCode ) .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_ERROR_QUIT ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Let the clients know that the server is closing .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Let the clients know that the server is loading a new map .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_NEWGAME ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Send the result of an issues RCon command back to the client :
2023-05-08 19:01:06 +02:00
* uint16_t Colour code .
2010-10-18 22:41:53 +02:00
* string Output of the RCon command
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_RCON ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Send an RCon command to the server :
* string RCon password .
* string Command to be executed .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_CLIENT_RCON ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Sends information about all used GRFs to the client :
2023-05-08 19:01:06 +02:00
* 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
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Tell the server that we have the required GRFs
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Move a client from one company into another :
2023-05-08 19:01:06 +02:00
* uint32_t ID of the client .
* uint8_t ID of the new company .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_MOVE ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Request the server to move this client into another company :
2023-05-08 19:01:06 +02:00
* uint8_t ID of the company the client wants to join .
2010-10-18 22:41:53 +02:00
* string Password , if the company is password protected .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_CLIENT_MOVE ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Update the clients knowledge of which company is password protected :
2023-05-08 19:01:06 +02:00
* uint16_t Bitwise representation of each company
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE ( Packet & p ) ;
2010-10-18 22:41:53 +02:00
/**
* Update the clients knowledge of the max settings :
2023-05-08 19:01:06 +02:00
* uint8_t Maximum number of companies allowed .
* uint8_t Maximum number of spectators allowed .
2011-05-01 13:30:03 +02:00
* @ param p The packet that was just received .
2010-10-18 22:41:53 +02:00
*/
2024-02-03 20:28:52 +01:00
virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE ( Packet & p ) ;
2010-10-15 15:47:37 +02:00
2024-02-03 20:28:52 +01:00
NetworkRecvStatus HandlePacket ( Packet & p ) ;
2010-10-15 15:47:37 +02:00
2010-10-15 15:22:00 +02:00
NetworkGameSocketHandler ( SOCKET s ) ;
2009-01-14 13:50:13 +01:00
public :
2010-10-15 22:29:59 +02:00
ClientID client_id ; ///< Client identifier
2023-05-08 19:01:06 +02:00
uint32_t last_frame ; ///< Last frame we have executed
uint32_t last_frame_server ; ///< Last frame the server has executed
2010-08-19 00:40:17 +02:00
CommandQueue incoming_queue ; ///< The command-queue awaiting handling
2021-02-25 20:30:16 +01:00
std : : chrono : : steady_clock : : time_point last_packet ; ///< Time we received the last frame.
2009-01-14 13:50:13 +01:00
2019-03-24 17:24:06 +01:00
NetworkRecvStatus CloseConnection ( bool error = true ) override ;
2011-05-01 15:29:40 +02:00
/**
* Close the network connection due to the given status .
* @ param status The reason the connection got closed .
*/
2010-10-15 20:42:52 +02:00
virtual NetworkRecvStatus CloseConnection ( NetworkRecvStatus status ) = 0 ;
2023-05-14 23:31:03 +02:00
virtual ~ NetworkGameSocketHandler ( ) = default ;
2009-01-14 13:50:13 +01:00
2011-05-01 15:29:40 +02:00
/**
* Sets the client info for this socket handler .
* @ param info The new client info .
*/
inline void SetInfo ( NetworkClientInfo * info )
{
2019-04-10 23:07:06 +02:00
assert ( info ! = nullptr & & this - > info = = nullptr ) ;
2011-05-01 15:29:40 +02:00
this - > info = info ;
}
/**
* Gets the client info of this socket handler .
* @ return The client info .
*/
inline NetworkClientInfo * GetInfo ( ) const
{
return this - > info ;
}
2009-01-14 13:50:13 +01:00
2010-11-30 14:38:46 +01:00
NetworkRecvStatus ReceivePackets ( ) ;
2010-10-15 15:47:37 +02:00
2024-02-04 17:20:25 +01:00
const char * ReceiveCommand ( Packet & p , CommandPacket & cp ) ;
void SendCommand ( Packet & p , const CommandPacket & cp ) ;
2023-06-16 21:54:04 +02:00
bool IsPendingDeletion ( ) const { return this - > is_pending_deletion ; }
void DeferDeletion ( ) ;
static void ProcessDeferredDeletions ( ) ;
2009-01-14 13:50:13 +01:00
} ;
# endif /* NETWORK_CORE_TCP_GAME_H */