10#ifndef NETWORK_SERVER_H
11#define NETWORK_SERVER_H
74 std::shared_ptr<struct PacketWriter>
savegame =
nullptr;
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
NetworkGameSocketHandler(SOCKET s)
Create a new socket for the game connection.
ClientID client_id
Client identifier.
Class for handling the server side of the game connection.
static std::string_view GetName()
Get the name used by the listener.
NetworkRecvStatus ReceiveClientGameInfo(Packet &p) override
Request game information.
size_t receive_limit
Amount of bytes that we can receive at this moment.
static ServerNetworkGameSocketHandler * GetByClientID(ClientID client_id)
Return the client state given it's client-identifier.
std::shared_ptr< struct PacketWriter > savegame
Writer used to write the savegame.
static void Send()
Send the packets for the server sockets.
NetworkRecvStatus SendQuit(ClientID client_id)
Tell the client another client quit.
uint8_t lag_test
Byte used for lag-testing the client.
static void AcceptConnection(SOCKET s, const NetworkAddress &address)
Handle the accepting of a connection to the server.
NetworkRecvStatus ReceiveClientIdentify(Packet &p) override
The client tells the server about the identity of the client: string Name of the client (max NETWORK_...
std::unique_ptr< Packet > ReceivePacket() override
Receives a packet for the given client.
ClientStatus
Status of a client.
@ STATUS_END
Must ALWAYS be on the end of this list!! (period).
@ STATUS_PRE_ACTIVE
The client is catching up the delayed frames.
@ STATUS_IDENTIFY
The client is identifying itself.
@ STATUS_AUTH_GAME
The client is authorizing with game (server) password.
@ STATUS_NEWGRFS_CHECK
The client is checking NewGRFs.
@ STATUS_AUTHORIZED
The client is authorized.
@ STATUS_INACTIVE
The client is not connected nor active.
@ STATUS_MAP
The client is downloading the map.
@ STATUS_DONE_MAP
The client has downloaded the map.
@ STATUS_ACTIVE
The client is active within in the game.
@ STATUS_MAP_WAIT
The client is waiting as someone else is downloading the map.
NetworkRecvStatus SendRConResult(uint16_t colour, std::string_view command)
Send the result of a console action.
NetworkRecvStatus ReceiveClientAck(Packet &p) override
Tell the server we are done with this frame: uint32_t Current frame counter of the client.
CommandQueue outgoing_queue
The command-queue awaiting delivery; conceptually more a bucket to gather commands in,...
NetworkRecvStatus SendChat(NetworkAction action, ClientID client_id, bool self_send, std::string_view msg, int64_t data)
Send a chat message.
NetworkRecvStatus SendWelcome()
Send the client a welcome message with some basic information.
NetworkRecvStatus SendAuthRequest()
Request the game password.
std::string GetClientName() const
Get the name of the client, if the user did not send it yet, Client ID is used.
NetworkRecvStatus ReceiveClientRemoteConsoleCommand(Packet &p) override
Send an RCon command to the server: string RCon password.
uint8_t last_token
The last random token we did send to verify the client is listening.
NetworkRecvStatus SendFrame()
Tell the client that they may run to a particular frame.
NetworkRecvStatus ReceiveClientSetName(Packet &p) override
Gives the client a new name: string New name of the client.
NetworkRecvStatus SendGameInfo()
Send the client information about the server.
std::string_view GetPeerPublicKey() const
Get the public key of our peer.
NetworkRecvStatus SendJoin(ClientID client_id)
Tell that a client joined.
~ServerNetworkGameSocketHandler() override
Clear everything related to this client.
NetworkRecvStatus ReceiveClientChat(Packet &p) override
Sends a chat-packet to the server: uint8_t ID of the action (see NetworkAction).
NetworkRecvStatus ReceiveClientNewGRFsChecked(Packet &p) override
Tell the server that we have the required GRFs.
std::string peer_public_key
The public key of our client.
NetworkRecvStatus ReceiveClientGetMap(Packet &p) override
Request the map from the server.
NetworkRecvStatus SendClientInfo(NetworkClientInfo *ci)
Send the client information about a client.
static bool AllowConnection()
Whether an connection is allowed or not at this moment.
NetworkRecvStatus SendEnableEncryption()
Notify the client that the authentication has completed and tell that for the remainder of this socke...
NetworkRecvStatus SendExternalChat(std::string_view source, TextColour colour, std::string_view user, std::string_view msg)
Send a chat message from external source.
ServerNetworkGameSocketHandler(ClientPoolID index, SOCKET s)
Create a new socket for the server side of the game connection.
NetworkRecvStatus SendErrorQuit(ClientID client_id, NetworkErrorCode errorno)
Tell the client another client quit with an error.
NetworkAddress client_address
IP-address of the client (so they can be banned).
NetworkRecvStatus SendNewGame()
Tell the client we're starting a new game.
NetworkRecvStatus ReceiveClientCommand(Packet &p) override
Send a DoCommand to the Server: uint8_t ID of the company (0..MAX_COMPANIES-1).
NetworkRecvStatus SendSync()
Request the client to sync.
std::unique_ptr< class NetworkAuthenticationServerHandler > authentication_handler
The handler for the authentication.
NetworkRecvStatus ReceiveClientJoin(Packet &p) override
Try to join the server: string OpenTTD revision (norev0000 if no revision).
NetworkRecvStatus ReceiveClientError(Packet &p) override
The client made an error and is quitting the game.
NetworkRecvStatus SendMove(ClientID client_id, CompanyID company_id)
Tell that a client moved to another company.
NetworkRecvStatus SendError(NetworkErrorCode error, std::string_view reason={})
Send an error to the client, and close its connection.
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override
Close the network connection due to the given status.
NetworkRecvStatus SendMap()
This sends the map to the client.
uint32_t last_token_frame
The last frame we received the right token.
NetworkRecvStatus SendShutdown()
Tell the client we're shutting down.
NetworkRecvStatus ReceiveClientMapOk(Packet &p) override
Tell the server that we are done receiving/loading the map.
NetworkRecvStatus ReceiveClientQuit(Packet &p) override
The client is quitting the game.
ClientStatus status
Status of this client.
void CheckNextClientToSendMap(NetworkClientSocket *ignore_cs=nullptr)
Find the next candidate for joining, and start the joining process for that client.
NetworkRecvStatus SendNewGRFCheck()
Send the check for the NewGRFs.
NetworkRecvStatus ReceiveClientAuthenticationResponse(Packet &p) override
Send the response to the authentication request: 32 * uint8_t Public key of the client.
std::string_view GetClientIP()
Get the IP address/hostname of the connected client.
NetworkRecvStatus SendConfigUpdate()
Send an update about the max company/spectator counts.
NetworkRecvStatus SendWait()
Tell the client that its put in a waiting queue.
NetworkRecvStatus ReceiveClientMove(Packet &p) override
Request the server to move this client into another company: uint8_t ID of the company the client wan...
NetworkRecvStatus SendCommand(const CommandPacket &cp)
Send a command to the client to execute.
Template for TCP listeners.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Variables and function used internally.
class ServerNetworkGameSocketHandler NetworkClientSocket
Class for handling the server side of the game connection.
NetworkClientSocketPool _networkclientsocket_pool
Make very sure the preconditions given in network_type.h are actually followed.
void ChangeNetworkRestartTime(bool reset)
Reset the automatic network restart time interval.
Pool< NetworkClientSocket, ClientPoolID, 8, PoolType::NetworkClient > NetworkClientSocketPool
Pool with all client sockets.
void NetworkServer_Tick(bool send_frame)
This is called every tick if this is a _network_server.
NetworkErrorCode
The error codes we send around in the protocols.
NetworkAction
Actions that can be used for NetworkTextMessage.
ClientID
'Unique' identifier to be given to clients
PoolID< uint16_t, struct ClientPoolIDTag, MAX_CLIENTS+1, 0xFFFF > ClientPoolID
Indices into the client related pools.
Container for all information known about a client.
Internal entity of a packet.
Base class for all pools.
std::vector< CommandPacket > CommandQueue
A "queue" of CommandPackets.
Basic functions to listen for TCP connections.