18#include "table/strings.h"
63 this->
last_packet = std::chrono::steady_clock::now();
110 Debug(net, 0,
"[tcp/game] Received invalid packet type {} from client {}", type, this->
client_id);
125 std::unique_ptr<Packet> p;
141 Debug(net, 0,
"[tcp/game] Received illegal packet type {} from client {}", type, this->
client_id);
virtual NetworkRecvStatus ReceiveClientAuthenticationResponse(Packet &p)
Send the response to the authentication request: 32 * uint8_t Public key of the client.
virtual NetworkRecvStatus ReceiveServerChat(Packet &p)
Sends a chat-packet to the client: uint8_t ID of the action (see NetworkAction).
virtual NetworkRecvStatus ReceiveServerRemoteConsoleCommand(Packet &p)
Send the result of an issues RCon command back to the client: uint16_t Colour code.
NetworkRecvStatus ReceivePackets()
Do the actual receiving of packets.
bool is_pending_deletion
Whether this socket is pending deletion.
virtual NetworkRecvStatus ReceiveServerCommand(Packet &p)
Sends a DoCommand to the client: uint8_t ID of the company (0..MAX_COMPANIES-1).
virtual NetworkRecvStatus ReceiveServerClientInfo(Packet &p)
Send information about a client: uint32_t ID of the client (always unique on a server.
virtual NetworkRecvStatus ReceiveClientGameInfo(Packet &p)
Request game information.
virtual NetworkRecvStatus ReceiveServerExternalChat(Packet &p)
Sends a chat-packet for external source to the client: string Name of the source this message came fr...
virtual NetworkRecvStatus ReceiveServerCheckNewGRFs(Packet &p)
Sends information about all used GRFs to the client: uint8_t Amount of GRFs (the following data is re...
virtual NetworkRecvStatus ReceiveClientCommand(Packet &p)
Send a DoCommand to the Server: uint8_t ID of the company (0..MAX_COMPANIES-1).
NetworkGameSocketHandler(SOCKET s)
Create a new socket for the game connection.
virtual NetworkRecvStatus ReceiveServerConfigurationUpdate(Packet &p)
Update the clients knowledge of the max settings: uint8_t Maximum number of companies allowed.
uint32_t last_frame
Last frame we have executed.
virtual NetworkRecvStatus ReceiveServerBanned(Packet &p)
Notification that the client trying to join is banned.
static void ProcessDeferredDeletions()
Actually delete the socket handlers that were marked for deletion.
virtual NetworkRecvStatus ReceiveClientError(Packet &p)
The client made an error and is quitting the game.
virtual NetworkRecvStatus ReceiveServerMapDone(Packet &p)
Sends that all data of the map are sent to the client:
virtual NetworkRecvStatus ReceiveClientGetMap(Packet &p)
Request the map from the server.
virtual NetworkRecvStatus ReceiveServerAuthenticationRequest(Packet &p)
Indication to the client that it needs to authenticate: uint8_t The NetworkAuthenticationMethod to us...
virtual NetworkRecvStatus ReceiveServerErrorQuit(Packet &p)
Inform all clients that one client made an error and thus has quit/been disconnected: uint32_t ID of ...
virtual NetworkRecvStatus ReceiveServerQuit(Packet &p)
Notification that a client left the game: uint32_t ID of the client.
NetworkRecvStatus ReceiveInvalidPacket(PacketGameType type)
Helper for logging receiving invalid packets.
ClientID client_id
Client identifier.
virtual NetworkRecvStatus ReceiveClientRemoteConsoleCommand(Packet &p)
Send an RCon command to the server: string RCon password.
std::chrono::steady_clock::time_point last_packet
Time we received the last frame.
virtual NetworkRecvStatus ReceiveServerFull(Packet &p)
Notification that the server is full.
virtual NetworkRecvStatus ReceiveServerGameInfo(Packet &p)
Sends information about the game.
virtual NetworkRecvStatus ReceiveServerMove(Packet &p)
Move a client from one company into another: uint32_t ID of the client.
virtual NetworkRecvStatus ReceiveClientSetName(Packet &p)
Gives the client a new name: string New name of the client.
virtual NetworkRecvStatus ReceiveClientJoin(Packet &p)
Try to join the server: string OpenTTD revision (norev0000 if no revision).
virtual NetworkRecvStatus ReceiveServerEnableEncryption(Packet &p)
Indication to the client that authentication is complete and encryption has to be used from here on f...
virtual NetworkRecvStatus ReceiveClientAck(Packet &p)
Tell the server we are done with this frame: uint32_t Current frame counter of the client.
uint32_t last_frame_server
Last frame the server has executed.
virtual NetworkRecvStatus ReceiveServerError(Packet &p)
The client made an error: uint8_t Error code caused (see NetworkErrorCode).
virtual NetworkRecvStatus ReceiveServerSync(Packet &p)
Sends a sync-check to the client: uint32_t Frame counter.
virtual NetworkRecvStatus ReceiveClientMapOk(Packet &p)
Tell the server that we are done receiving/loading the map.
virtual NetworkRecvStatus ReceiveServerShutdown(Packet &p)
Let the clients know that the server is closing.
virtual NetworkRecvStatus ReceiveClientIdentify(Packet &p)
The client tells the server about the identity of the client: string Name of the client (max NETWORK_...
NetworkRecvStatus HandlePacket(Packet &p)
Handle the given packet, i.e.
virtual NetworkRecvStatus ReceiveClientNewGRFsChecked(Packet &p)
Tell the server that we have the required GRFs.
virtual NetworkRecvStatus ReceiveServerMapData(Packet &p)
Sends the data of the map to the client: Contains a part of the map (until max size of packet).
virtual NetworkRecvStatus ReceiveClientMove(Packet &p)
Request the server to move this client into another company: uint8_t ID of the company the client wan...
virtual NetworkRecvStatus ReceiveClientQuit(Packet &p)
The client is quitting the game.
virtual NetworkRecvStatus ReceiveServerWelcome(Packet &p)
The client is joined and ready to receive their map: uint32_t Own client ID.
void DeferDeletion()
Mark this socket handler for deletion, once iterating the socket handlers is done.
virtual NetworkRecvStatus ReceiveServerMapBegin(Packet &p)
Sends that the server will begin with sending the map to the client: uint32_t Current frame.
virtual NetworkRecvStatus ReceiveServerNewGame(Packet &p)
Let the clients know that the server is loading a new map.
virtual NetworkRecvStatus ReceiveClientChat(Packet &p)
Sends a chat-packet to the server: uint8_t ID of the action (see NetworkAction).
virtual NetworkRecvStatus ReceiveServerWaitForMap(Packet &p)
Notification that another client is currently receiving the map: uint8_t Number of clients waiting in...
virtual NetworkRecvStatus ReceiveServerFrame(Packet &p)
Sends the current frame counter to the client: uint32_t Frame counter uint32_t Frame counter max (how...
NetworkRecvStatus CloseConnection(bool error=true) override
Functions to help ReceivePacket/SendPacket a bit A socket can make errors.
virtual NetworkRecvStatus ReceiveServerMapSize(Packet &p)
Sends the size of the map to the client.
virtual NetworkRecvStatus ReceiveServerClientJoined(Packet &p)
A client joined (PacketGameType::ClientMapOk), what usually directly follows is a PacketGameType::Ser...
virtual std::unique_ptr< Packet > ReceivePacket()
Receives a packet for the given client.
NetworkTCPSocketHandler(SOCKET s=INVALID_SOCKET)
Construct a socket handler for a TCP connection.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
@ NETWORK_RECV_STATUS_CLIENT_QUIT
The connection is lost gracefully. Other clients are already informed of this leaving client.
@ NETWORK_RECV_STATUS_OKAY
Everything is okay.
@ NETWORK_RECV_STATUS_CONNECTION_LOST
The connection is lost unexpectedly.
@ NETWORK_RECV_STATUS_MALFORMED_PACKET
We apparently send a malformed packet.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Functions related to errors.
@ WL_CRITICAL
Critical errors, the MessageBox is shown in all cases.
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
SwitchMode _switch_mode
The next mainloop command.
uint32_t _frame_counter
The current frame.
bool _networking
are we in networking mode?
bool _network_server
network-server is active
Basic functions/variables used all over the place.
void ClientNetworkEmergencySave()
Create an emergency savegame when the network connection is lost.
Variables and function used internally.
@ SM_MENU
Switch to game intro menu.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Functions related to OTTD's strings.
uint8_t Recv_uint8()
Read a 8 bits integer from the packet.
static std::vector< std::unique_ptr< NetworkGameSocketHandler > > _deferred_deletions
NetworkGameSocketHandler that still need to be deleted.
PacketGameType
Enum with all types of TCP packets.
@ ServerAuthenticationRequest
The server requests the client to authenticate using a number of methods.
@ ClientCommand
Client executed a command and sends it to the server.
@ ServerClientInfo
Server sends you information about a client.
@ ServerShutdown
The server is shutting down.
@ ServerMapDone
Server tells it has just sent the last bits of the map to the client.
@ ServerMapBegin
Server tells the client that it is beginning to send the map.
@ ServerFrame
Server tells the client what frame it is in, and thus to where the client may progress.
@ ServerMapData
Server sends bits of the map to the client.
@ ServerClientJoined
Tells clients that a new client has joined.
@ ServerGameInfo
Information about the server.
@ ClientQuit
A client tells the server it is going to quit.
@ ServerMapSize
Server tells the client what the (compressed) size of the map is.
@ ClientAck
The client tells the server which frame it has executed.
@ ServerFull
The server is full and has no place for you.
@ ServerMove
Server tells everyone that someone is moved to another company.
@ ServerQuit
A server tells that a client has quit.
@ ClientRemoteConsoleCommand
Client asks the server to execute some command.
@ ServerBanned
The server has banned you.
@ ClientJoin
The client telling the server it wants to join.
@ ServerError
Server sending an error message to the client.
@ ClientNewGRFsChecked
Client acknowledges that it has all required NewGRFs.
@ ServerSync
Server tells the client what the random state should be.
@ ClientSetName
A client changes its name.
@ ClientError
A client reports an error to the server.
@ ServerConfigurationUpdate
Some network configuration important to the client changed.
@ ServerRemoteConsoleCommand
Response of the executed command on the server.
@ ClientMapOk
Client tells the server that it received the whole map.
@ ServerExternalChat
Server distributing the message from external source.
@ ServerErrorQuit
A server tells that a client has hit an error and did quit.
@ ServerWelcome
Server welcomes you and gives you your ClientID.
@ ServerCommand
Server distributes a command to (all) the clients.
@ ServerChat
Server distributing the message of a client (or itself).
@ ClientMove
A client would like to be moved to another company.
@ ServerCheckNewGRFs
Server sends NewGRF IDs and MD5 checksums for the client to check.
@ ServerWaitForMap
Server tells the client there are some people waiting for the map as well.
@ ClientGameInfo
Request information about the server.
@ ServerEnableEncryption
The server tells that authentication has completed and requests to enable encryption with the keys of...
@ ClientGetMap
Client requests the actual map.
@ ClientChat
Client said something that should be distributed.
@ ServerNewGame
The server is preparing to start a new game.
@ ClientAuthenticationResponse
The client responds to the authentication request.
@ ClientIdentify
Client telling the server the client's name and requested company.