10#ifndef NETWORK_CLIENT_H
11#define NETWORK_CLIENT_H
20 std::shared_ptr<struct PacketReader>
savegame =
nullptr;
109struct NetworkJoinInfo {
Class for handling the client side of the game connection.
static ClientNetworkGameSocketHandler * my_client
This is us!
NetworkRecvStatus ReceiveServerQuit(Packet &p) override
Notification that a client left the game: uint32_t ID of the client.
NetworkRecvStatus ReceiveServerFull(Packet &p) override
Notification that the server is full.
static NetworkRecvStatus SendQuit()
Tell the server we would like to quit.
NetworkRecvStatus ReceiveServerExternalChat(Packet &p) override
Sends a chat-packet for external source to the client: string Name of the source this message came fr...
NetworkRecvStatus ReceiveServerCommand(Packet &p) override
Sends a DoCommand to the client: uint8_t ID of the company (0..MAX_COMPANIES-1).
static bool Receive()
Check whether we received/can send some data from/to the server and when that's the case handle it ap...
NetworkRecvStatus ReceiveServerClientInfo(Packet &p) override
Send information about a client: uint32_t ID of the client (always unique on a server.
std::string connection_string
Address we are connected to.
~ClientNetworkGameSocketHandler() override
Clear whatever we assigned.
NetworkRecvStatus ReceiveServerBanned(Packet &p) override
Notification that the client trying to join is banned.
static NetworkRecvStatus SendIdentify()
Identify ourselves to the server.
ServerStatus status
Status of the connection with the server.
static NetworkRecvStatus SendMove(CompanyID company)
Ask the server to move us.
std::unique_ptr< class NetworkAuthenticationClientHandler > authentication_handler
The handler for the authentication.
std::shared_ptr< struct PacketReader > savegame
Packet reader for reading the savegame.
static bool IsConnected()
Check whether the client is actually connected (and in the game).
NetworkRecvStatus ReceiveServerChat(Packet &p) override
Sends a chat-packet to the client: uint8_t ID of the action (see NetworkAction).
uint8_t token
The token we need to send back to the server to prove we're the right client.
static NetworkRecvStatus SendSetName(const std::string &name)
Tell the server that we like to change the name of the client.
NetworkRecvStatus ReceiveServerNewGame(Packet &p) override
Let the clients know that the server is loading a new map.
NetworkRecvStatus ReceiveServerEnableEncryption(Packet &p) override
Indication to the client that authentication is complete and encryption has to be used from here on f...
friend void NetworkExecuteLocalCommandQueue()
Execute all commands on the local command queue that ought to be executed this frame.
static NetworkRecvStatus SendNewGRFsOk()
Tell the server we got all the NewGRFs.
static NetworkRecvStatus SendChat(NetworkAction action, NetworkChatDestinationType type, int dest, std::string_view msg, int64_t data)
Send a chat-packet over the network.
static NetworkRecvStatus SendMapOk()
Tell the server we received the complete map.
NetworkRecvStatus ReceiveServerMapBegin(Packet &p) override
Sends that the server will begin with sending the map to the client: uint32_t Current frame.
void CheckConnection()
Check the connection's state, i.e.
NetworkRecvStatus ReceiveServerCheckNewGRFs(Packet &p) override
Sends information about all used GRFs to the client: uint8_t Amount of GRFs (the following data is re...
NetworkRecvStatus ReceiveServerWaitForMap(Packet &p) override
Notification that another client is currently receiving the map: uint8_t Number of clients waiting in...
ClientNetworkGameSocketHandler(SOCKET s, std::string_view connection_string)
Create a new socket for the client side of the game connection.
NetworkRecvStatus ReceiveServerRemoteConsoleCommand(Packet &p) override
Send the result of an issues RCon command back to the client: uint16_t Colour code.
NetworkRecvStatus ReceiveServerShutdown(Packet &p) override
Let the clients know that the server is closing.
NetworkRecvStatus ReceiveServerMapDone(Packet &p) override
Sends that all data of the map are sent to the client:
void ClientError(NetworkRecvStatus res)
Handle an error coming from the client side.
static NetworkRecvStatus SendAck()
Send an acknowledgement from the server's ticks.
NetworkRecvStatus ReceiveServerMove(Packet &p) override
Move a client from one company into another: uint32_t ID of the client.
static NetworkRecvStatus SendAuthResponse()
Set the game password as requested.
NetworkRecvStatus ReceiveServerFrame(Packet &p) override
Sends the current frame counter to the client: uint32_t Frame counter uint32_t Frame counter max (how...
NetworkRecvStatus ReceiveServerSync(Packet &p) override
Sends a sync-check to the client: uint32_t Frame counter.
static bool GameLoop()
Actual game loop for the client.
NetworkRecvStatus ReceiveServerError(Packet &p) override
The client made an error: uint8_t Error code caused (see NetworkErrorCode).
static void Send()
Send the packets of this socket handler.
ServerStatus
Status of the connection with the server.
@ STATUS_JOIN
We are trying to join a server.
@ STATUS_ENCRYPTED
The game authentication has completed and from here on the connection to the server is encrypted.
@ STATUS_NEWGRFS_CHECK
Last action was checking NewGRFs.
@ STATUS_MAP
The client is downloading the map.
@ STATUS_END
Must ALWAYS be on the end of this list!! (period).
@ STATUS_AUTH_GAME
Last action was requesting game (server) password.
@ STATUS_ACTIVE
The client is active within in the game.
@ STATUS_MAP_WAIT
The client is waiting as someone else is downloading the map.
@ STATUS_INACTIVE
The client is not connected nor active.
@ STATUS_AUTHORIZED
The client is authorized at the server.
static NetworkRecvStatus SendRCon(std::string_view password, std::string_view command)
Send a console command.
static NetworkRecvStatus SendCommand(const CommandPacket &cp)
Send a command to the server.
NetworkRecvStatus ReceiveServerErrorQuit(Packet &p) override
Inform all clients that one client made an error and thus has quit/been disconnected: uint32_t ID of ...
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override
Close the network connection due to the given status.
NetworkRecvStatus ReceiveServerMapData(Packet &p) override
Sends the data of the map to the client: Contains a part of the map (until max size of packet).
static NetworkRecvStatus SendGetMap()
Request the map from the server.
NetworkRecvStatus ReceiveServerConfigurationUpdate(Packet &p) override
Update the clients knowledge of the max settings: uint8_t Maximum number of companies allowed.
static NetworkRecvStatus SendError(NetworkErrorCode errorno)
Send an error-packet over the network.
NetworkRecvStatus ReceiveServerWelcome(Packet &p) override
The client is joined and ready to receive their map: uint32_t Own client ID.
NetworkRecvStatus ReceiveServerMapSize(Packet &p) override
Sends the size of the map to the client.
NetworkRecvStatus ReceiveServerClientJoined(Packet &p) override
A client joined (PacketGameType::ClientMapOk), what usually directly follows is a PacketGameType::Ser...
static NetworkRecvStatus SendJoin()
Tell the server we would like to join.
NetworkRecvStatus ReceiveServerAuthenticationRequest(Packet &p) override
Indication to the client that it needs to authenticate: uint8_t The NetworkAuthenticationMethod to us...
friend void NetworkClose(bool close_admins)
Close current connections.
NetworkGameSocketHandler(SOCKET s)
Create a new socket for the game connection.
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
NetworkJoinInfo _network_join
Information about the game to join to.
void NetworkClient_Connected()
Is called after a client is connected to the server.
ClientNetworkGameSocketHandler MyClient
Helper to make the code look somewhat nicer.
Variables and function used internally.
NetworkErrorCode
The error codes we send around in the protocols.
NetworkAction
Actions that can be used for NetworkTextMessage.
NetworkChatDestinationType
Destination of our chat messages.
Everything we need to know about a command to be able to execute it.
Information required to join a server.
std::string connection_string
The address of the server to join.
std::string server_password
The password of the server to join.
CompanyID company
The company to join.