12#ifndef NETWORK_CORE_TCP_GAME_H
13#define NETWORK_CORE_TCP_GAME_H
17#include "../network_type.h"
18#include "../../core/pool_type.hpp"
507 assert(
info !=
nullptr && this->info ==
nullptr);
527 void DeferDeletion();
528 static void ProcessDeferredDeletions();
Base socket handler for all TCP sockets.
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 wan...
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.
NetworkRecvStatus ReceivePackets()
Do the actual receiving of packets.
bool is_pending_deletion
Whether this socket is pending deletion.
virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet &p)
Update the clients knowledge of the max settings: uint8_t Maximum number of companies allowed.
virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet &p)
Notification that the client trying to join is banned.
virtual NetworkRecvStatus Receive_SERVER_SYNC(Packet &p)
Sends a sync-check to the client: uint32_t Frame counter.
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_SERVER_MAP_DONE(Packet &p)
Sends that all data of the map are sent to the client:
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_SERVER_ENABLE_ENCRYPTION(Packet &p)
Indication to the client that authentication is complete and encryption has to be used from here on f...
virtual NetworkRecvStatus Receive_SERVER_GAME_INFO(Packet &p)
Sends information about the game.
uint32_t last_frame
Last frame we have executed.
virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet &p)
The client is joined and ready to receive their map: uint32_t Own client ID.
NetworkClientInfo * GetInfo() const
Gets the client info of this socket handler.
virtual NetworkRecvStatus Receive_CLIENT_QUIT(Packet &p)
The client is quitting the game.
virtual NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet &p)
Tell the server that we have the required GRFs.
virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet &p)
Let the clients know that the server is closing.
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...
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_MOVE(Packet &p)
Move a client from one company into another: uint32_t ID of the client.
virtual NetworkRecvStatus Receive_SERVER_AUTH_REQUEST(Packet &p)
Indication to the client that it needs to authenticate: uint8_t The NetworkAuthenticationMethod to us...
virtual NetworkRecvStatus Receive_SERVER_QUIT(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.
virtual NetworkRecvStatus Receive_CLIENT_GETMAP(Packet &p)
Request the map from the server.
ClientID client_id
Client identifier.
virtual NetworkRecvStatus CloseConnection(NetworkRecvStatus status)=0
Close the network connection due to the given status.
CommandQueue incoming_queue
The command-queue awaiting handling.
std::chrono::steady_clock::time_point last_packet
Time we received the last frame.
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 re...
virtual NetworkRecvStatus Receive_CLIENT_JOIN(Packet &p)
Try to join the server: string OpenTTD revision (norev0000 if no revision).
void SetInfo(NetworkClientInfo *info)
Sets the client info for this socket handler.
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 ...
const char * ReceiveCommand(Packet &p, CommandPacket &cp)
Receives a command from the network.
virtual NetworkRecvStatus Receive_CLIENT_RCON(Packet &p)
Send an RCon command to the server: string RCon password.
uint32_t last_frame_server
Last frame the server has executed.
virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet &p)
The client made an error: uint8_t Error code caused (see NetworkErrorCode).
virtual NetworkRecvStatus Receive_CLIENT_CHAT(Packet &p)
Sends a chat-packet to the server: uint8_t ID of the action (see NetworkAction).
NetworkClientInfo * info
Client info related to this socket.
NetworkRecvStatus HandlePacket(Packet &p)
Handle the given packet, i.e.
virtual NetworkRecvStatus Receive_CLIENT_GAME_INFO(Packet &p)
Request game information.
virtual NetworkRecvStatus Receive_CLIENT_MAP_OK(Packet &p)
Tell the server that we are done receiving/loading the map.
void SendCommand(Packet &p, const CommandPacket &cp)
Sends a command over the network.
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_RCON(Packet &p)
Send the result of an issues RCon command back to the client: uint16_t Colour code.
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_JOIN(Packet &p)
A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO:...
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_SERVER_WAIT(Packet &p)
Notification that another client is currently receiving the map: uint8_t Number of clients waiting in...
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_...
virtual NetworkRecvStatus Receive_SERVER_FULL(Packet &p)
Notification that the server is full.
NetworkRecvStatus CloseConnection(bool error=true) override
Functions to help ReceivePacket/SendPacket a bit A socket can make errors.
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_CLIENT_ERROR(Packet &p)
The client made an error and is quitting the game.
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 fr...
virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet &p)
Let the clients know that the server is loading a new map.
virtual NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet &p)
Gives the client a new name: string New name of the client.
Base socket handler for all TCP sockets.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
ClientID
'Unique' identifier to be given to clients
Network stuff has many things that needs to be included and/or implemented by default.
Everything we need to know about a command to be able to execute it.
Container for all information known about a client.
Internal entity of a packet.
Basic functions to receive and send TCP packets.
PacketGameType
Enum with all types of TCP packets.
@ PACKET_SERVER_UNUSED
Unused.
@ PACKET_CLIENT_IDENTIFY
Client telling the server the client's name and requested company.
@ PACKET_SERVER_JOIN
Tells clients that a new client has joined.
@ PACKET_SERVER_MAP_SIZE
Server tells the client what the (compressed) size of the map is.
@ PACKET_SERVER_RCON
Response of the executed command on the server.
@ PACKET_SERVER_MAP_BEGIN
Server tells the client that it is beginning to send the map.
@ PACKET_SERVER_SYNC
Server tells the client what the random state should be.
@ PACKET_CLIENT_GETMAP
Client requests the actual map.
@ PACKET_CLIENT_ERROR
A client reports an error to the server.
@ PACKET_SERVER_WAIT
Server tells the client there are some people waiting for the map as well.
@ PACKET_END
Must ALWAYS be on the end of this list!! (period)
@ PACKET_SERVER_CONFIG_UPDATE
Some network configuration important to the client changed.
@ PACKET_CLIENT_JOIN
The client telling the server it wants to join.
@ PACKET_CLIENT_AUTH_RESPONSE
The client responds to the authentication request.
@ PACKET_CLIENT_NEWGRFS_CHECKED
Client acknowledges that it has all required NewGRFs.
@ PACKET_SERVER_ENABLE_ENCRYPTION
The server tells that authentication has completed and requests to enable encryption with the keys of...
@ PACKET_SERVER_GAME_INFO
Information about the server.
@ PACKET_CLIENT_COMMAND
Client executed a command and sends it to the server.
@ PACKET_SERVER_ERROR_QUIT
A server tells that a client has hit an error and did quit.
@ PACKET_SERVER_CLIENT_INFO
Server sends you information about a client.
@ PACKET_CLIENT_SET_NAME
A client changes its name.
@ PACKET_SERVER_WELCOME
Server welcomes you and gives you your ClientID.
@ PACKET_CLIENT_ACK
The client tells the server which frame it has executed.
@ PACKET_SERVER_BANNED
The server has banned you.
@ PACKET_SERVER_FRAME
Server tells the client what frame it is in, and thus to where the client may progress.
@ PACKET_SERVER_EXTERNAL_CHAT
Server distributing the message from external source.
@ PACKET_SERVER_CHAT
Server distributing the message of a client (or itself).
@ PACKET_SERVER_COMMAND
Server distributes a command to (all) the clients.
@ PACKET_SERVER_SHUTDOWN
The server is shutting down.
@ PACKET_SERVER_AUTH_REQUEST
The server requests the client to authenticate using a number of methods.
@ PACKET_CLIENT_RCON
Client asks the server to execute some command.
@ PACKET_SERVER_NEWGAME
The server is preparing to start a new game.
@ PACKET_SERVER_MOVE
Server tells everyone that someone is moved to another company.
@ PACKET_CLIENT_UNUSED
Unused.
@ PACKET_SERVER_MAP_DATA
Server sends bits of the map to the client.
@ PACKET_CLIENT_MAP_OK
Client tells the server that it received the whole map.
@ PACKET_CLIENT_QUIT
A client tells the server it is going to quit.
@ PACKET_CLIENT_MOVE
A client would like to be moved to another company.
@ PACKET_SERVER_FULL
The server is full and has no place for you.
@ PACKET_SERVER_QUIT
A server tells that a client has quit.
@ PACKET_SERVER_ERROR
Server sending an error message to the client.
@ PACKET_SERVER_CHECK_NEWGRFS
Server sends NewGRF IDs and MD5 checksums for the client to check.
@ PACKET_SERVER_MAP_DONE
Server tells it has just sent the last bits of the map to the client.
@ PACKET_CLIENT_CHAT
Client said something that should be distributed.
@ PACKET_CLIENT_GAME_INFO
Request information about the server.
std::vector< CommandPacket > CommandQueue
A "queue" of CommandPackets.