OpenTTD Source 20241224-master-gf74b0cf984
|
Class for handling the client side of the game connection. More...
#include <network_client.h>
Public Member Functions | |
ClientNetworkGameSocketHandler (SOCKET s, const std::string &connection_string) | |
Create a new socket for the client side of the game connection. | |
~ClientNetworkGameSocketHandler () | |
Clear whatever we assigned. | |
NetworkRecvStatus | CloseConnection (NetworkRecvStatus status) override |
Close the network connection due to the given status. | |
void | ClientError (NetworkRecvStatus res) |
Handle an error coming from the client side. | |
Public Member Functions inherited from ZeroedMemoryAllocator | |
void * | operator new (size_t size) |
Memory allocator for a single class instance. | |
void * | operator new[] (size_t size) |
Memory allocator for an array of class instances. | |
void | operator delete (void *ptr) |
Memory release for a single class instance. | |
void | operator delete[] (void *ptr) |
Memory release for an array of class instances. | |
Public Member Functions inherited from NetworkGameSocketHandler | |
NetworkRecvStatus | CloseConnection (bool error=true) override |
Functions to help ReceivePacket/SendPacket a bit A socket can make errors. | |
void | SetInfo (NetworkClientInfo *info) |
Sets the client info for this socket handler. | |
NetworkClientInfo * | GetInfo () const |
Gets the client info of this socket handler. | |
NetworkRecvStatus | ReceivePackets () |
Do the actual receiving of packets. | |
const char * | ReceiveCommand (Packet &p, CommandPacket &cp) |
Receives a command from the network. | |
void | SendCommand (Packet &p, const CommandPacket &cp) |
Sends a command over the network. | |
bool | IsPendingDeletion () const |
void | DeferDeletion () |
Public Member Functions inherited from NetworkTCPSocketHandler | |
bool | IsConnected () const |
Whether this socket is currently bound to a socket. | |
void | CloseSocket () |
Close the actual socket of the connection. | |
virtual void | SendPacket (std::unique_ptr< Packet > &&packet) |
This function puts the packet in the send-queue and it is send as soon as possible. | |
SendPacketsState | SendPackets (bool closing_down=false) |
Sends all the buffered packets out for this client. | |
virtual std::unique_ptr< Packet > | ReceivePacket () |
Receives a packet for the given client. | |
bool | CanSendReceive () |
Check whether this socket can send or receive something. | |
bool | HasSendQueue () |
Whether there is something pending in the send queue. | |
NetworkTCPSocketHandler (SOCKET s=INVALID_SOCKET) | |
Construct a socket handler for a TCP connection. | |
Public Member Functions inherited from NetworkSocketHandler | |
NetworkSocketHandler () | |
Create a new unbound socket. | |
virtual | ~NetworkSocketHandler ()=default |
Close the socket when destructing the socket handler. | |
void | MarkClosed () |
Mark the connection as closed. | |
bool | HasClientQuit () const |
Whether the current client connected to the socket has quit. | |
void | Reopen () |
Reopen the socket so we can send/receive stuff again. | |
Static Public Member Functions | |
static NetworkRecvStatus | SendJoin () |
Tell the server we would like to join. | |
static NetworkRecvStatus | SendCommand (const CommandPacket &cp) |
Send a command to the server. | |
static NetworkRecvStatus | SendError (NetworkErrorCode errorno) |
Send an error-packet over the network. | |
static NetworkRecvStatus | SendQuit () |
Tell the server we would like to quit. | |
static NetworkRecvStatus | SendAck () |
Send an acknowledgement from the server's ticks. | |
static NetworkRecvStatus | SendAuthResponse () |
Set the game password as requested. | |
static NetworkRecvStatus | SendChat (NetworkAction action, DestType type, int dest, const std::string &msg, int64_t data) |
Send a chat-packet over the network. | |
static NetworkRecvStatus | SendSetName (const std::string &name) |
Tell the server that we like to change the name of the client. | |
static NetworkRecvStatus | SendRCon (const std::string &password, const std::string &command) |
Send a console command. | |
static NetworkRecvStatus | SendMove (CompanyID company) |
Ask the server to move us. | |
static bool | IsConnected () |
Check whether the client is actually connected (and in the game). | |
static void | Send () |
Send the packets of this socket handler. | |
static bool | Receive () |
Check whether we received/can send some data from/to the server and when that's the case handle it appropriately. | |
static bool | GameLoop () |
Actual game loop for the client. | |
Static Public Member Functions inherited from NetworkGameSocketHandler | |
static void | ProcessDeferredDeletions () |
Protected Member Functions | |
NetworkRecvStatus | Receive_SERVER_FULL (Packet &p) override |
Notification that the server is full. | |
NetworkRecvStatus | Receive_SERVER_BANNED (Packet &p) override |
Notification that the client trying to join is banned. | |
NetworkRecvStatus | Receive_SERVER_ERROR (Packet &p) override |
The client made an error: uint8_t Error code caused (see NetworkErrorCode). | |
NetworkRecvStatus | Receive_SERVER_CLIENT_INFO (Packet &p) override |
Send information about a client: uint32_t ID of the client (always unique on a server. | |
NetworkRecvStatus | Receive_SERVER_AUTH_REQUEST (Packet &p) override |
Indication to the client that it needs to authenticate: uint8_t The NetworkAuthenticationMethod to use. | |
NetworkRecvStatus | Receive_SERVER_ENABLE_ENCRYPTION (Packet &p) override |
Indication to the client that authentication is complete and encryption has to be used from here on forward. | |
NetworkRecvStatus | Receive_SERVER_WELCOME (Packet &p) override |
The client is joined and ready to receive their map: uint32_t Own client ID. | |
NetworkRecvStatus | Receive_SERVER_WAIT (Packet &p) override |
Notification that another client is currently receiving the map: uint8_t Number of clients waiting in front of you. | |
NetworkRecvStatus | Receive_SERVER_MAP_BEGIN (Packet &p) override |
Sends that the server will begin with sending the map to the client: uint32_t Current frame. | |
NetworkRecvStatus | Receive_SERVER_MAP_SIZE (Packet &p) override |
Sends the size of the map to the client. | |
NetworkRecvStatus | Receive_SERVER_MAP_DATA (Packet &p) override |
Sends the data of the map to the client: Contains a part of the map (until max size of packet). | |
NetworkRecvStatus | Receive_SERVER_MAP_DONE (Packet &p) override |
Sends that all data of the map are sent to the client: | |
NetworkRecvStatus | Receive_SERVER_JOIN (Packet &p) override |
A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO: uint32_t ID of the client that just joined the game. | |
NetworkRecvStatus | Receive_SERVER_FRAME (Packet &p) override |
Sends the current frame counter to the client: 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). | |
NetworkRecvStatus | Receive_SERVER_SYNC (Packet &p) override |
Sends a sync-check to the client: uint32_t Frame counter. | |
NetworkRecvStatus | Receive_SERVER_COMMAND (Packet &p) override |
Sends a DoCommand to the client: uint8_t ID of the company (0..MAX_COMPANIES-1). | |
NetworkRecvStatus | Receive_SERVER_CHAT (Packet &p) override |
Sends a chat-packet to the client: uint8_t ID of the action (see NetworkAction). | |
NetworkRecvStatus | Receive_SERVER_EXTERNAL_CHAT (Packet &p) override |
Sends a chat-packet for external source to the client: string Name of the source this message came from. | |
NetworkRecvStatus | Receive_SERVER_QUIT (Packet &p) override |
Notification that a client left the game: uint32_t ID of the client. | |
NetworkRecvStatus | Receive_SERVER_ERROR_QUIT (Packet &p) override |
Inform all clients that one client made an error and thus has quit/been disconnected: uint32_t ID of the client that caused the error. | |
NetworkRecvStatus | Receive_SERVER_SHUTDOWN (Packet &p) override |
Let the clients know that the server is closing. | |
NetworkRecvStatus | Receive_SERVER_NEWGAME (Packet &p) override |
Let the clients know that the server is loading a new map. | |
NetworkRecvStatus | Receive_SERVER_RCON (Packet &p) override |
Send the result of an issues RCon command back to the client: uint16_t Colour code. | |
NetworkRecvStatus | Receive_SERVER_CHECK_NEWGRFS (Packet &p) override |
Sends information about all used GRFs to the client: uint8_t Amount of GRFs (the following data is repeated this many times, i.e. | |
NetworkRecvStatus | Receive_SERVER_MOVE (Packet &p) override |
Move a client from one company into another: uint32_t ID of the client. | |
NetworkRecvStatus | Receive_SERVER_CONFIG_UPDATE (Packet &p) override |
Update the clients knowledge of the max settings: uint8_t Maximum number of companies allowed. | |
void | CheckConnection () |
Check the connection's state, i.e. | |
Protected Member Functions inherited from NetworkGameSocketHandler | |
NetworkRecvStatus | ReceiveInvalidPacket (PacketGameType type) |
Helper for logging receiving invalid packets. | |
virtual NetworkRecvStatus | Receive_CLIENT_JOIN (Packet &p) |
Try to join the server: string OpenTTD revision (norev0000 if no revision). | |
virtual NetworkRecvStatus | Receive_CLIENT_GAME_INFO (Packet &p) |
Request game information. | |
virtual NetworkRecvStatus | Receive_SERVER_GAME_INFO (Packet &p) |
Sends information about the game. | |
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_NAME_LENGTH). | |
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_CLIENT_GETMAP (Packet &p) |
Request the map from the server. | |
virtual NetworkRecvStatus | Receive_CLIENT_MAP_OK (Packet &p) |
Tell the server that we are done receiving/loading the map. | |
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_CLIENT_COMMAND (Packet &p) |
Send a DoCommand to the Server: uint8_t ID of the company (0..MAX_COMPANIES-1). | |
virtual NetworkRecvStatus | Receive_CLIENT_CHAT (Packet &p) |
Sends a chat-packet to the server: uint8_t ID of the action (see NetworkAction). | |
virtual NetworkRecvStatus | Receive_CLIENT_SET_NAME (Packet &p) |
Gives the client a new name: string New name of the client. | |
virtual NetworkRecvStatus | Receive_CLIENT_QUIT (Packet &p) |
The client is quitting the game. | |
virtual NetworkRecvStatus | Receive_CLIENT_ERROR (Packet &p) |
The client made an error and is quitting the game. | |
virtual NetworkRecvStatus | Receive_CLIENT_RCON (Packet &p) |
Send an RCon command to the server: string RCon password. | |
virtual NetworkRecvStatus | Receive_CLIENT_NEWGRFS_CHECKED (Packet &p) |
Tell the server that we have the required GRFs. | |
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 wants to join. | |
NetworkRecvStatus | HandlePacket (Packet &p) |
Handle the given packet, i.e. | |
NetworkGameSocketHandler (SOCKET s) | |
Create a new socket for the game connection. | |
Static Protected Member Functions | |
static NetworkRecvStatus | SendNewGRFsOk () |
Tell the server we got all the NewGRFs. | |
static NetworkRecvStatus | SendGetMap () |
Request the map from the server. | |
static NetworkRecvStatus | SendMapOk () |
Tell the server we received the complete map. | |
static NetworkRecvStatus | SendIdentify () |
Static Protected Attributes | |
static ClientNetworkGameSocketHandler * | my_client = nullptr |
This is us! | |
Private Types | |
enum | ServerStatus { STATUS_INACTIVE , STATUS_JOIN , STATUS_AUTH_GAME , STATUS_ENCRYPTED , STATUS_NEWGRFS_CHECK , STATUS_AUTHORIZED , STATUS_MAP_WAIT , STATUS_MAP , STATUS_ACTIVE , STATUS_END } |
Status of the connection with the server. More... | |
Private Attributes | |
std::unique_ptr< class NetworkAuthenticationClientHandler > | authentication_handler |
The handler for the authentication. | |
std::string | connection_string |
Address we are connected to. | |
std::shared_ptr< struct PacketReader > | savegame |
Packet reader for reading the savegame. | |
uint8_t | token |
The token we need to send back to the server to prove we're the right client. | |
ServerStatus | status |
Status of the connection with the server. | |
Friends | |
void | NetworkExecuteLocalCommandQueue () |
Execute all commands on the local command queue that ought to be executed this frame. | |
void | NetworkClose (bool close_admins) |
Close current connections. | |
Additional Inherited Members | |
Data Fields inherited from NetworkGameSocketHandler | |
ClientID | client_id |
Client identifier. | |
uint32_t | last_frame |
Last frame we have executed. | |
uint32_t | last_frame_server |
Last frame the server has executed. | |
CommandQueue | incoming_queue |
The command-queue awaiting handling. | |
std::chrono::steady_clock::time_point | last_packet |
Time we received the last frame. | |
Data Fields inherited from NetworkTCPSocketHandler | |
SOCKET | sock |
The socket currently connected to. | |
bool | writable |
Can we write to this socket? | |
Protected Attributes inherited from NetworkSocketHandler | |
std::unique_ptr< class NetworkEncryptionHandler > | receive_encryption_handler |
The handler for decrypting received packets. | |
std::unique_ptr< class NetworkEncryptionHandler > | send_encryption_handler |
The handler for encrypting sent packets. | |
Class for handling the client side of the game connection.
Definition at line 16 of file network_client.h.
|
private |
Status of the connection with the server.
Definition at line 24 of file network_client.h.
ClientNetworkGameSocketHandler::ClientNetworkGameSocketHandler | ( | SOCKET | s, |
const std::string & | connection_string | ||
) |
Create a new socket for the client side of the game connection.
s | The socket to connect with. |
Definition at line 146 of file network_client.cpp.
References my_client.
ClientNetworkGameSocketHandler::~ClientNetworkGameSocketHandler | ( | ) |
Clear whatever we assigned.
Definition at line 153 of file network_client.cpp.
References NetworkGameSocketHandler::GetInfo(), and my_client.
|
protected |
Check the connection's state, i.e.
is the connection still up?
Definition at line 1202 of file network_client.cpp.
References NetworkGameSocketHandler::CloseConnection(), NetworkGameSocketHandler::last_packet, SetDParam(), ShowErrorMessage(), status, STATUS_AUTHORIZED, and WL_INFO.
Referenced by Send().
void ClientNetworkGameSocketHandler::ClientError | ( | NetworkRecvStatus | res | ) |
Handle an error coming from the client side.
res | The "error" that happened. |
Definition at line 189 of file network_client.cpp.
References _networking, _switch_mode, ClientNetworkEmergencySave(), CloseConnection(), CloseWindowById(), NetworkSocketHandler::MarkClosed(), NETWORK_RECV_STATUS_CLOSE_QUERY, NETWORK_RECV_STATUS_DESYNC, NETWORK_RECV_STATUS_NEWGRF_MISMATCH, NETWORK_RECV_STATUS_SAVEGAME, NETWORK_RECV_STATUS_SERVER_BANNED, NETWORK_RECV_STATUS_SERVER_ERROR, NETWORK_RECV_STATUS_SERVER_FULL, SendError(), SM_MENU, WC_NETWORK_STATUS_WINDOW, and WN_NETWORK_STATUS_WINDOW_JOIN.
Referenced by GameLoop(), and Receive().
|
overridevirtual |
Close the network connection due to the given status.
status | The reason the connection got closed. |
Implements NetworkGameSocketHandler.
Definition at line 161 of file network_client.cpp.
References NetworkGameSocketHandler::client_id, CSleep(), Debug, NetworkSocketHandler::HasClientQuit(), MILLISECONDS_PER_TICK, NETWORK_RECV_STATUS_OKAY, NetworkTCPSocketHandler::SendPackets(), NetworkTCPSocketHandler::sock, and status.
Referenced by ClientError().
|
static |
Actual game loop for the client.
Definition at line 268 of file network_client.cpp.
References _frame_counter, _network_first_time, _random, _sync_frame, _sync_seed_1, ClientError(), TimerGameEconomy::date, TimerGameEconomy::date_fract, Debug, my_client, NETWORK_RECV_STATUS_DESYNC, NetworkExecuteLocalCommandQueue, SendAck(), Randomizer::state, and StateGameLoop().
|
static |
Check whether the client is actually connected (and in the game).
Definition at line 528 of file network_client.cpp.
References my_client, status, and STATUS_ACTIVE.
Referenced by DEF_CONSOLE_HOOK().
|
static |
Check whether we received/can send some data from/to the server and when that's the case handle it appropriately.
Definition at line 243 of file network_client.cpp.
References _networking, NetworkTCPSocketHandler::CanSendReceive(), ClientError(), my_client, NETWORK_RECV_STATUS_OKAY, and NetworkGameSocketHandler::ReceivePackets().
Referenced by NetworkReceive().
|
overrideprotectedvirtual |
Indication to the client that it needs to authenticate: uint8_t The NetworkAuthenticationMethod
to use.
32 * uint8_t Public key of the server. 24 * uint8_t Nonce for the key exchange.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 718 of file network_client.cpp.
References _settings_client, authentication_handler, NetworkAuthenticationClientHandler::AWAIT_USER_INPUT, NetworkSettings::client_public_key, NetworkSettings::client_secret_key, NetworkAuthenticationClientHandler::Create(), Debug, NetworkAuthenticationClientHandler::INVALID, ClientSettings::network, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, NetworkAuthenticationClientHandler::READY_FOR_RESPONSE, SendAuthResponse(), status, STATUS_AUTH_GAME, and STATUS_JOIN.
|
overrideprotectedvirtual |
Notification that the client trying to join is banned.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 550 of file network_client.cpp.
References Debug, INVALID_STRING_ID, NETWORK_RECV_STATUS_SERVER_BANNED, ShowErrorMessage(), and WL_CRITICAL.
|
overrideprotectedvirtual |
Sends a chat-packet to the client: uint8_t ID of the action (see NetworkAction).
uint32_t ID of the client (origin of the chat). string Message (max NETWORK_CHAT_LENGTH). uint64_t data (used e.g. for 'give money' actions).
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 977 of file network_client.cpp.
References _network_own_client_id, NetworkGameSocketHandler::client_id, NetworkClientInfo::client_playas, Debug, NetworkClientInfo::GetByClientID(), GetDrawStringCompanyColour(), GetString(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), NETWORK_CHAT_LENGTH, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_bool(), Packet::Recv_string(), Packet::Recv_uint32(), Packet::Recv_uint64(), Packet::Recv_uint8(), SetDParam(), status, and STATUS_ACTIVE.
|
overrideprotectedvirtual |
Sends information about all used GRFs to the client: 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
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 673 of file network_client.cpp.
References BSWAP32(), Debug, FGCM_EXACT, FindGRFConfig(), FormatArrayAsHex(), GRFIdentifier::grfid, INVALID_STRING_ID, GRFIdentifier::md5sum, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_NEWGRF_MISMATCH, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint8(), SendNewGRFsOk(), ShowErrorMessage(), status, STATUS_ENCRYPTED, and WL_CRITICAL.
|
overrideprotectedvirtual |
Send information about a client: 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). string Name of the client. string Public key of the client.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 563 of file network_client.cpp.
References _network_own_client_id, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_networkclientinfo_pool >::CanAllocateItem(), CC_DEFAULT, NetworkGameSocketHandler::client_id, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, COMPANY_SPECTATOR, Debug, NetworkClientInfo::GetByClientID(), NetworkSocketHandler::HasClientQuit(), InvalidateWindowData(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), NETWORK_NAME_LENGTH, NETWORK_PUBLIC_KEY_LENGTH, NETWORK_RECV_STATUS_CLIENT_QUIT, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, NetworkIsValidClientName(), NetworkClientInfo::public_key, Packet::Recv_string(), Packet::Recv_uint32(), Packet::Recv_uint8(), NetworkGameSocketHandler::SetInfo(), SetLocalCompany(), status, STATUS_AUTHORIZED, and WC_CLIENT_LIST.
|
overrideprotectedvirtual |
Sends a DoCommand to the client: uint8_t ID of the company (0..MAX_COMPANIES-1).
uint32_t ID of the command (see command.h). Command specific buffer with encoded parameters of variable length. The content differs per command and can change without notification. uint8_t ID of the callback. uint32_t Frame of execution.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 956 of file network_client.cpp.
References CC_WARNING, CommandPacket::cmd, Debug, CommandPacket::frame, IConsolePrint(), NetworkGameSocketHandler::incoming_queue, CommandPacket::my_cmd, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, NetworkGameSocketHandler::ReceiveCommand(), Packet::Recv_bool(), Packet::Recv_uint32(), status, and STATUS_ACTIVE.
|
overrideprotectedvirtual |
Update the clients knowledge of the max settings: uint8_t Maximum number of companies allowed.
uint8_t Maximum number of spectators allowed.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1185 of file network_client.cpp.
References _network_server_max_companies, _network_server_name, Debug, InvalidateWindowData(), NETWORK_NAME_LENGTH, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_string(), Packet::Recv_uint8(), status, STATUS_ACTIVE, and WC_CLIENT_LIST.
|
overrideprotectedvirtual |
Indication to the client that authentication is complete and encryption has to be used from here on forward.
The encryption uses the shared keys generated by the last AUTH_REQUEST key exchange. 24 * uint8_t Nonce for encrypted connection.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 743 of file network_client.cpp.
References authentication_handler, Debug, NETWORK_RECV_STATUS_MALFORMED_PACKET, NetworkSocketHandler::receive_encryption_handler, NetworkSocketHandler::send_encryption_handler, status, STATUS_AUTH_GAME, and STATUS_ENCRYPTED.
|
overrideprotectedvirtual |
The client made an error: uint8_t Error code caused (see NetworkErrorCode).
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 624 of file network_client.cpp.
References Packet::CanReadFromPacket(), ClientNetworkEmergencySave(), Debug, INVALID_STRING_ID, lengthof, NETWORK_CHAT_LENGTH, NETWORK_RECV_STATUS_SERVER_ERROR, Packet::Recv_string(), Packet::Recv_uint8(), SetDParamStr(), ShowErrorMessage(), status, STATUS_ACTIVE, and WL_CRITICAL.
|
overrideprotectedvirtual |
Inform all clients that one client made an error and thus has quit/been disconnected: uint32_t ID of the client that caused the error.
uint8_t Code of the error caused (see NetworkErrorCode).
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1046 of file network_client.cpp.
References CC_DEFAULT, NetworkGameSocketHandler::client_id, NetworkClientInfo::client_name, Debug, NetworkClientInfo::GetByClientID(), GetNetworkErrorMsg(), InvalidateWindowData(), NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), Packet::Recv_uint8(), status, STATUS_AUTHORIZED, and WC_CLIENT_LIST.
|
overrideprotectedvirtual |
Sends a chat-packet for external source to the client: string Name of the source this message came from.
uint16_t TextColour to use for the message. string Name of the user who sent the messsage. string Message (max NETWORK_CHAT_LENGTH).
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1028 of file network_client.cpp.
References Debug, IsValidConsoleColour(), NETWORK_CHAT_LENGTH, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_string(), Packet::Recv_uint16(), status, and STATUS_ACTIVE.
|
overrideprotectedvirtual |
Sends the current frame counter to the client: 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).
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 906 of file network_client.cpp.
References _frame_counter, _frame_counter_max, _frame_counter_server, _network_first_time, _sync_frame, _sync_seed_1, Packet::CanReadFromPacket(), Ticks::DAY_TICKS, Debug, last_ack_frame, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), Packet::Recv_uint8(), SendAck(), status, STATUS_ACTIVE, and token.
|
overrideprotectedvirtual |
Notification that the server is full.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 540 of file network_client.cpp.
References Debug, INVALID_STRING_ID, NETWORK_RECV_STATUS_SERVER_FULL, ShowErrorMessage(), and WL_CRITICAL.
|
overrideprotectedvirtual |
A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO: uint32_t ID of the client that just joined the game.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1087 of file network_client.cpp.
References CC_DEFAULT, NetworkGameSocketHandler::client_id, NetworkClientInfo::client_name, Debug, NetworkClientInfo::GetByClientID(), InvalidateWindowData(), NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), status, STATUS_AUTHORIZED, and WC_CLIENT_LIST.
|
overrideprotectedvirtual |
Sends that the server will begin with sending the map to the client: uint32_t Current frame.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 791 of file network_client.cpp.
References _frame_counter, _frame_counter_max, _frame_counter_server, _network_join_bytes, _network_join_bytes_total, _network_join_status, Debug, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), savegame, SetWindowDirty(), status, STATUS_MAP, WC_NETWORK_STATUS_WINDOW, and WN_NETWORK_STATUS_WINDOW_JOIN.
|
overrideprotectedvirtual |
Sends the data of the map to the client: Contains a part of the map (until max size of packet).
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 828 of file network_client.cpp.
References _network_join_bytes, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, savegame, SetWindowDirty(), status, STATUS_MAP, WC_NETWORK_STATUS_WINDOW, and WN_NETWORK_STATUS_WINDOW_JOIN.
|
overrideprotectedvirtual |
Sends that all data of the map are sent to the client:
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 842 of file network_client.cpp.
References _file_to_saveload, _game_session_stats, _network_join, _network_join_status, _network_own_client_id, CCA_NEW, ClearErrorMessages(), NetworkJoinInfo::company, COMPANY_NEW_COMPANY, COMPANY_SPECTATOR, CRR_NONE, Debug, DFT_GAME_FILE, SocialIntegration::EventEnterMultiplayer(), FT_SAVEGAME, INVALID_COMPANY, INVALID_STRING_ID, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), NetworkGameSocketHandler::last_packet, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, NETWORK_RECV_STATUS_SAVEGAME, NO_DIRECTORY, savegame, GameSessionStats::savegame_size, SendMapOk(), SetLocalCompany(), FileToSaveLoad::SetMode(), SetWindowDirty(), ShowErrorMessage(), Map::SizeX(), Map::SizeY(), SLO_LOAD, GameSessionStats::start_time, status, STATUS_MAP, WC_NETWORK_STATUS_WINDOW, WL_CRITICAL, and WN_NETWORK_STATUS_WINDOW_JOIN.
|
overrideprotectedvirtual |
Sends the size of the map to the client.
uint32_t Size of the (compressed) map (in bytes).
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 815 of file network_client.cpp.
References _network_join_bytes_total, Debug, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), savegame, SetWindowDirty(), status, STATUS_MAP, WC_NETWORK_STATUS_WINDOW, and WN_NETWORK_STATUS_WINDOW_JOIN.
|
overrideprotectedvirtual |
Move a client from one company into another: uint32_t ID of the client.
uint8_t ID of the new company.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1155 of file network_client.cpp.
References _network_own_client_id, NetworkGameSocketHandler::client_id, COMPANY_SPECTATOR, Debug, NetworkClientInfo::GetByClientID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), Packet::Recv_uint8(), SetLocalCompany(), status, and STATUS_AUTHORIZED.
|
overrideprotectedvirtual |
Let the clients know that the server is loading a new map.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1120 of file network_client.cpp.
References _network_own_client_id, _network_reconnect, ClientNetworkEmergencySave(), Debug, INVALID_STRING_ID, NETWORK_RECV_STATUS_SERVER_ERROR, ShowErrorMessage(), status, STATUS_ACTIVE, STATUS_JOIN, and WL_CRITICAL.
|
overrideprotectedvirtual |
Notification that a client left the game: uint32_t ID of the client.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1065 of file network_client.cpp.
References CC_DEFAULT, NetworkGameSocketHandler::client_id, NetworkClientInfo::client_name, Debug, NetworkClientInfo::GetByClientID(), InvalidateWindowData(), NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), status, STATUS_AUTHORIZED, and WC_CLIENT_LIST.
|
overrideprotectedvirtual |
Send the result of an issues RCon command back to the client: uint16_t Colour code.
string Output of the RCon command
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1139 of file network_client.cpp.
References Debug, IConsolePrint(), IsValidConsoleColour(), NETWORK_RCONCOMMAND_LENGTH, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_string(), Packet::Recv_uint16(), status, and STATUS_AUTHORIZED.
|
overrideprotectedvirtual |
Let the clients know that the server is closing.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 1105 of file network_client.cpp.
References ClientNetworkEmergencySave(), Debug, INVALID_STRING_ID, NETWORK_RECV_STATUS_SERVER_ERROR, ShowErrorMessage(), status, STATUS_ACTIVE, STATUS_JOIN, and WL_CRITICAL.
|
overrideprotectedvirtual |
Sends a sync-check to the client: uint32_t Frame counter.
uint32_t General seed 1. uint32_t General seed 2 (dependent on compile settings, not default).
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 941 of file network_client.cpp.
References _sync_frame, _sync_seed_1, Debug, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint32(), status, and STATUS_ACTIVE.
|
overrideprotectedvirtual |
Notification that another client is currently receiving the map: uint8_t Number of clients waiting in front of you.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 775 of file network_client.cpp.
References _network_join_status, _network_join_waiting, Debug, NETWORK_RECV_STATUS_MALFORMED_PACKET, NETWORK_RECV_STATUS_OKAY, Packet::Recv_uint8(), SetWindowDirty(), status, STATUS_MAP_WAIT, WC_NETWORK_STATUS_WINDOW, and WN_NETWORK_STATUS_WINDOW_JOIN.
|
overrideprotectedvirtual |
The client is joined and ready to receive their map: uint32_t Own client ID.
p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 761 of file network_client.cpp.
References _network_own_client_id, Debug, NETWORK_RECV_STATUS_MALFORMED_PACKET, Packet::Recv_uint32(), SendGetMap(), status, and STATUS_AUTHORIZED.
|
static |
Send the packets of this socket handler.
Definition at line 258 of file network_client.cpp.
References CheckConnection(), my_client, and NetworkTCPSocketHandler::SendPackets().
|
static |
Send an acknowledgement from the server's ticks.
Definition at line 410 of file network_client.cpp.
References _frame_counter, Debug, my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_ACK, NetworkTCPSocketHandler::SendPacket(), and token.
Referenced by GameLoop(), and Receive_SERVER_FRAME().
|
static |
Set the game password as requested.
password | The game password. |
Definition at line 372 of file network_client.cpp.
References authentication_handler, Debug, my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_AUTH_RESPONSE, and NetworkTCPSocketHandler::SendPacket().
Referenced by Receive_SERVER_AUTH_REQUEST(), and ClientGamePasswordRequestHandler::SendResponse().
|
static |
Send a chat-packet over the network.
Definition at line 438 of file network_client.cpp.
References Debug, my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_CHAT, and NetworkTCPSocketHandler::SendPacket().
Referenced by NetworkClientSendChat(), and SendChat().
|
static |
Send a command to the server.
cp | The command to send. |
Definition at line 426 of file network_client.cpp.
References CommandPacket::cmd, Debug, my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_COMMAND, and NetworkTCPSocketHandler::SendPacket().
Referenced by NetworkSendCommand().
|
static |
Send an error-packet over the network.
Definition at line 455 of file network_client.cpp.
References Debug, my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_ERROR, and NetworkTCPSocketHandler::SendPacket().
Referenced by ClientError().
|
staticprotected |
Request the map from the server.
Definition at line 384 of file network_client.cpp.
References Debug, my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_GETMAP, NetworkTCPSocketHandler::SendPacket(), status, and STATUS_MAP_WAIT.
Referenced by Receive_SERVER_WELCOME().
|
staticprotected |
Definition at line 347 of file network_client.cpp.
|
static |
Tell the server we would like to join.
Definition at line 329 of file network_client.cpp.
References _network_join_status, Debug, my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_JOIN, NetworkTCPSocketHandler::SendPacket(), SetWindowDirty(), status, STATUS_JOIN, WC_NETWORK_STATUS_WINDOW, and WN_NETWORK_STATUS_WINDOW_JOIN.
Referenced by NetworkClient_Connected().
|
staticprotected |
Tell the server we received the complete map.
Definition at line 397 of file network_client.cpp.
References Debug, my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_MAP_OK, NetworkTCPSocketHandler::SendPacket(), status, and STATUS_ACTIVE.
Referenced by Receive_SERVER_MAP_DONE().
|
static |
Ask the server to move us.
company | The company to move to. |
Definition at line 514 of file network_client.cpp.
References Debug, my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_MOVE, and NetworkTCPSocketHandler::SendPacket().
Referenced by NetworkClientRequestMove().
|
staticprotected |
Tell the server we got all the NewGRFs.
Definition at line 359 of file network_client.cpp.
References Debug, my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_NEWGRFS_CHECKED, and NetworkTCPSocketHandler::SendPacket().
Referenced by Receive_SERVER_CHECK_NEWGRFS().
|
static |
Tell the server we would like to quit.
Definition at line 484 of file network_client.cpp.
References Debug, my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_QUIT, and NetworkTCPSocketHandler::SendPacket().
|
static |
Send a console command.
pass | The password for the remote command. |
command | The actual command. |
Definition at line 499 of file network_client.cpp.
References Debug, my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_RCON, and NetworkTCPSocketHandler::SendPacket().
Referenced by NetworkClientSendRcon().
|
static |
Tell the server that we like to change the name of the client.
name | The new name. |
Definition at line 470 of file network_client.cpp.
References Debug, my_client, NETWORK_RECV_STATUS_OKAY, PACKET_CLIENT_SET_NAME, and NetworkTCPSocketHandler::SendPacket().
Referenced by NetworkUpdateClientName().
|
friend |
Close current connections.
close_admins | Whether the admin connections have to be closed as well. |
Definition at line 592 of file network.cpp.
|
friend |
Execute all commands on the local command queue that ought to be executed this frame.
Definition at line 245 of file network_command.cpp.
Referenced by GameLoop().
|
private |
The handler for the authentication.
Definition at line 18 of file network_client.h.
Referenced by Receive_SERVER_AUTH_REQUEST(), Receive_SERVER_ENABLE_ENCRYPTION(), and SendAuthResponse().
|
private |
Address we are connected to.
Definition at line 19 of file network_client.h.
|
staticprotected |
This is us!
Our client's connection.
Definition at line 42 of file network_client.h.
Referenced by ClientNetworkGameSocketHandler(), GameLoop(), IsConnected(), Receive(), Send(), SendAck(), SendAuthResponse(), SendChat(), SendCommand(), SendError(), SendGetMap(), SendJoin(), SendMapOk(), SendMove(), SendNewGRFsOk(), SendQuit(), SendRCon(), SendSetName(), and ~ClientNetworkGameSocketHandler().
|
private |
Packet reader for reading the savegame.
Definition at line 20 of file network_client.h.
Referenced by Receive_SERVER_MAP_BEGIN(), Receive_SERVER_MAP_DATA(), Receive_SERVER_MAP_DONE(), and Receive_SERVER_MAP_SIZE().
|
private |
Status of the connection with the server.
Definition at line 37 of file network_client.h.
Referenced by CheckConnection(), CloseConnection(), IsConnected(), Receive_SERVER_AUTH_REQUEST(), Receive_SERVER_CHAT(), Receive_SERVER_CHECK_NEWGRFS(), Receive_SERVER_CLIENT_INFO(), Receive_SERVER_COMMAND(), Receive_SERVER_CONFIG_UPDATE(), Receive_SERVER_ENABLE_ENCRYPTION(), Receive_SERVER_ERROR(), Receive_SERVER_ERROR_QUIT(), Receive_SERVER_EXTERNAL_CHAT(), Receive_SERVER_FRAME(), Receive_SERVER_JOIN(), Receive_SERVER_MAP_BEGIN(), Receive_SERVER_MAP_DATA(), Receive_SERVER_MAP_DONE(), Receive_SERVER_MAP_SIZE(), Receive_SERVER_MOVE(), Receive_SERVER_NEWGAME(), Receive_SERVER_QUIT(), Receive_SERVER_RCON(), Receive_SERVER_SHUTDOWN(), Receive_SERVER_SYNC(), Receive_SERVER_WAIT(), Receive_SERVER_WELCOME(), SendGetMap(), SendJoin(), and SendMapOk().
|
private |
The token we need to send back to the server to prove we're the right client.
Definition at line 21 of file network_client.h.
Referenced by Receive_SERVER_FRAME(), and SendAck().