# ClientNetworkGameSocketHandler Class Reference

Class for handling the client side of the game connection. More...

`#include <network_client.h>`

Inheritance diagram for ClientNetworkGameSocketHandler:

## Public Member Functions
| ClientNetworkGameSocketHandler (SOCKET s)
| Create a new socket for the client side of the game connection.
| ~ClientNetworkGameSocketHandler ()
| Clear whatever we assigned.
NetworkRecvStatus | CloseConnection (NetworkRecvStatus status)
void | ClientError (NetworkRecvStatus res)
| Handle an error coming from the client side.
## Static Public Member Functions
static NetworkRecvStatus | SendCompanyInformationQuery ()
static NetworkRecvStatus | SendJoin ()
static NetworkRecvStatus | SendCommand (const CommandPacket *cp)
static NetworkRecvStatus | SendError (NetworkErrorCode errorno)
static NetworkRecvStatus | SendQuit ()
static NetworkRecvStatus | SendAck ()
static NetworkRecvStatus | SendGamePassword (const char *password)
static NetworkRecvStatus | SendCompanyPassword (const char *password)
static NetworkRecvStatus | SendChat (NetworkAction action, DestType type, int dest, const char *msg, int64 data)
static NetworkRecvStatus | SendSetPassword (const char *password)
static NetworkRecvStatus | SendSetName (const char *name)
static NetworkRecvStatus | SendRCon (const char *password, const char *command)
static NetworkRecvStatus | SendMove (CompanyID company, const char *password)
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.
## Protected Member Functions
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_FULL)
| Notification that the server is full.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_BANNED)
| Notification that the client trying to join is banned.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_ERROR)
| The client made an error: uint8 Error code caused (see NetworkErrorCode).
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_COMPANY_INFO)
| Sends information about the companies (one packet per company): uint8 Version of the structure of this packet (NETWORK_COMPANY_INFO_VERSION).
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_CLIENT_INFO)
| Send information about a client: uint32 ID of the client (always unique on a server.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_NEED_GAME_PASSWORD)
| Indication to the client that the server needs a game password.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_NEED_COMPANY_PASSWORD)
| Indication to the client that the server needs a company password: uint32 Generation seed.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_WELCOME)
| The client is joined and ready to receive his map: uint32 Own client ID.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_WAIT)
| Notification that another client is currently receiving the map: uint8 Number of clients awaiting the map.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_MAP_BEGIN)
| Sends that the server will begin with sending the map to the client: uint32 Current frame.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_MAP_SIZE)
| Sends the size of the map to the client.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_MAP_DATA)
| Sends the data of the map to the client: Contains a part of the map (until max size of packet).
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_MAP_DONE)
| Sends that all data of the map are sent to the client:.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_JOIN)
| A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO: uint32 ID of the client that just joined the game.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_FRAME)
| Sends the current frame counter to the client: uint32 Frame counter uint32 Frame counter max (how far may the client walk before the server?) uint32 General seed 1 (dependant on compile settings, not default).
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_SYNC)
| Sends a sync-check to the client: uint32 Frame counter.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_COMMAND)
| Sends a DoCommand to the client: uint8 ID of the company (0..MAX_COMPANIES-1).
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_CHAT)
| Sends a chat-packet to the client: uint8 ID of the action (see NetworkAction).
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_QUIT)
| Notification that a client left the game: uint32 ID of the client.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_ERROR_QUIT)
| Inform all clients that one client made an error and thus has quit/been disconnected: uint32 ID of the client that caused the error.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_SHUTDOWN)
| Let the clients know that the server is closing.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_NEWGAME)
| Let the clients know that the server is loading a new map.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_RCON)
| Send the result of an issues RCon command back to the client: uint16 Colour code.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_CHECK_NEWGRFS)
| Sends information about all used GRFs to the client: uint8 Amount of GRFs (the following data is repeated this many times, i.e.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_MOVE)
| Move a client from one company into another: uint32 ID of the client.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_COMPANY_UPDATE)
| Update the clients knowledge of which company is password protected: uint16 Bitwise representation of each company.
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_SERVER_CONFIG_UPDATE)
| Update the clients knowledge of the max settings: uint8 Maximum number of companies allowed.
void | CheckConnection ()
| Check the connection's state, i.e.
## Static Protected Member Functions
static NetworkRecvStatus | SendNewGRFsOk ()
static NetworkRecvStatus | SendGetMap ()
static NetworkRecvStatus | SendMapOk ()
## Static Protected Attributes
static ClientNetworkGameSocketHandler * | my_client = NULL
| Our client's connection.
## Private Types
enum | ServerStatus { STATUS_INACTIVE, STATUS_COMPANY_INFO, STATUS_JOIN, STATUS_NEWGRFS_CHECK, STATUS_AUTH_GAME, STATUS_AUTH_COMPANY, STATUS_AUTHORIZED, STATUS_MAP_WAIT, STATUS_MAP, STATUS_ACTIVE, STATUS_END }
| Status of the connection with the server. More...
## Private Attributes
struct PacketReader * | savegame
| Packet reader for reading the savegame.
byte | 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.

## Detailed Description

Class for handling the client side of the game connection.

Definition at line 20 of file network_client.h.

## Member Enumeration Documentation

enum ClientNetworkGameSocketHandler::ServerStatus`[private]`

Status of the connection with the server.

Enumerator:

  STATUS_INACTIVE | The client is not connected nor active.
  STATUS_COMPANY_INFO | We are trying to get company information.
  STATUS_JOIN | We are trying to join a server.
  STATUS_NEWGRFS_CHECK | Last action was checking NewGRFs.
  STATUS_AUTH_GAME | Last action was requesting game (server) password.
  STATUS_AUTH_COMPANY | Last action was requestion company password.
  STATUS_AUTHORIZED | The client is authorized at the server.
  STATUS_MAP_WAIT | The client is waiting as someone else is downloading the map.
  STATUS_MAP | The client is downloading the map.
  STATUS_ACTIVE | The client is active within in the game.
  STATUS_END | Must ALWAYS be on the end of this list!! (period).

Definition at line 26 of file network_client.h.

## Constructor & Destructor Documentation

ClientNetworkGameSocketHandler::ClientNetworkGameSocketHandler | ( | SOCKET | s | ) |

Create a new socket for the client side of the game connection.

Parameters:

  | s | The socket to connect with.

Definition at line 124 of file network_client.cpp.

References my_client.

ClientNetworkGameSocketHandler::~ClientNetworkGameSocketHandler | ( |  | ) |

Clear whatever we assigned.

Definition at line 131 of file network_client.cpp.

References my_client, and savegame.

## Member Function Documentation

void ClientNetworkGameSocketHandler::CheckConnection | ( |  | ) | `[protected]`

Check the connection's state, i.e.

is the connection still up?

Definition at line 1099 of file network_client.cpp.

References _realtime_tick, NetworkGameSocketHandler::CloseConnection(), NetworkGameSocketHandler::last_packet, SetDParam(), ShowErrorMessage(), STATUS_AUTHORIZED, and WL_INFO.

Referenced by Send().

void ClientNetworkGameSocketHandler::ClientError | ( | NetworkRecvStatus | res | ) |

Handle an error coming from the client side.

Parameters:

  | res | The "error" that happened.

Definition at line 165 of file network_client.cpp.

References _networking, _switch_mode, NetworkSocketHandler::CloseConnection(), DeleteWindowById(), 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, and NETWORK_RECV_STATUS_SERVER_FULL.

Referenced by GameLoop(), and Receive().

ClientNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND | ( | PACKET_SERVER_CONFIG_UPDATE |  | ) | `[protected]`

Update the clients knowledge of the max settings: uint8 Maximum number of companies allowed.

uint8 Maximum number of spectators allowed.

Reimplemented from NetworkGameSocketHandler.

ClientNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND | ( | PACKET_SERVER_MOVE |  | ) | `[protected]`

Move a client from one company into another: uint32 ID of the client.

uint8 ID of the new company.

Reimplemented from NetworkGameSocketHandler.

ClientNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND | ( | PACKET_SERVER_CHECK_NEWGRFS |  | ) | `[protected]`

Sends information about all used GRFs to the client: uint8 Amount of GRFs (the following data is repeated this many times, i.e.

per GRF data). uint32 GRF ID 16 * uint8 MD5 checksum of the GRF

Reimplemented from NetworkGameSocketHandler.

ClientNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND | ( | PACKET_SERVER_RCON |  | ) | `[protected]`

Send the result of an issues RCon command back to the client: uint16 Colour code.

string Output of the RCon command

Reimplemented from NetworkGameSocketHandler.

ClientNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND | ( | PACKET_SERVER_ERROR_QUIT |  | ) | `[protected]`

Inform all clients that one client made an error and thus has quit/been disconnected: uint32 ID of the client that caused the error.

uint8 Code of the error caused (see NetworkErrorCode).

Reimplemented from NetworkGameSocketHandler.

ClientNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND | ( | PACKET_SERVER_CHAT |  | ) | `[protected]`

Sends a chat-packet to the client: uint8 ID of the action (see NetworkAction).

uint32 ID of the client (origin of the chat). string Message (max NETWORK_CHAT_LENGTH). uint64 data (used e.g. for 'give money' actions).

Reimplemented from NetworkGameSocketHandler.

ClientNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND | ( | PACKET_SERVER_COMMAND |  | ) | `[protected]`

Sends a DoCommand to the client: uint8 ID of the company (0..MAX_COMPANIES-1).

uint32 ID of the command (see command.h). uint32 P1 (free variable used in DoCommand). uint32 P2. uint32 Tile where this is taking place. string Text. uint8 ID of the callback. uint32 Frame of execution.

Reimplemented from NetworkGameSocketHandler.

ClientNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND | ( | PACKET_SERVER_SYNC |  | ) | `[protected]`

Sends a sync-check to the client: uint32 Frame counter.

uint32 General seed 1. uint32 General seed 2 (dependant on compile settings, not default).

Reimplemented from NetworkGameSocketHandler.

ClientNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND | ( | PACKET_SERVER_FRAME |  | ) | `[protected]`

Sends the current frame counter to the client: uint32 Frame counter uint32 Frame counter max (how far may the client walk before the server?) uint32 General seed 1 (dependant on compile settings, not default).

uint32 General seed 2 (dependant on compile settings, not default). uint8 Random token to validate the client is actually listening (only occasionally present).

Reimplemented from NetworkGameSocketHandler.

ClientNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND | ( | PACKET_SERVER_MAP_SIZE |  | ) | `[protected]`

Sends the size of the map to the client.

uint32 Size of the (compressed) map (in bytes).

Reimplemented from NetworkGameSocketHandler.

ClientNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND | ( | PACKET_SERVER_WELCOME |  | ) | `[protected]`

The client is joined and ready to receive his map: uint32 Own client ID.

uint32 Generation seed. string Network ID of the server.

Reimplemented from NetworkGameSocketHandler.

ClientNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND | ( | PACKET_SERVER_NEED_COMPANY_PASSWORD |  | ) | `[protected]`

Indication to the client that the server needs a company password: uint32 Generation seed.

string Network ID of the server.

Reimplemented from NetworkGameSocketHandler.

ClientNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND | ( | PACKET_SERVER_CLIENT_INFO |  | ) | `[protected]`

Send information about a client: uint32 ID of the client (always unique on a server.

1 = server, 0 is invalid). uint8 ID of the company the client is playing as (255 for spectators). string Name of the client.

Reimplemented from NetworkGameSocketHandler.

ClientNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND | ( | PACKET_SERVER_COMPANY_INFO |  | ) | `[protected]`

Sends information about the companies (one packet per company): uint8 Version of the structure of this packet (NETWORK_COMPANY_INFO_VERSION).

bool Contains data (false marks the end of updates). uint8 ID of the company. string Name of the company. uint32 Year the company was inaugurated. uint64 Value. uint64 Money. uint64 Income. uint16 Performance (last quarter). bool Company is password protected. uint16 Number of trains. uint16 Number of lorries. uint16 Number of busses. uint16 Number of planes. uint16 Number of ships. uint16 Number of train stations. uint16 Number of lorry stations. uint16 Number of bus stops. uint16 Number of airports and heliports. uint16 Number of harbours. bool Company is an AI. string Client names (comma separated list)

Reimplemented from NetworkGameSocketHandler.

bool ClientNetworkGameSocketHandler::GameLoop | ( |  | ) | `[static]`

Actual game loop for the client.

Returns:
  Whether everything went okay, or not.

Definition at line 230 of file network_client.cpp.

References _date, _random, ClientError(), DEBUG, my_client, NETWORK_RECV_STATUS_DESYNC, NetworkExecuteLocalCommandQueue, Randomizer::state, and StateGameLoop().

bool ClientNetworkGameSocketHandler::IsConnected | ( |  | ) | `[static]`

Check whether the client is actually connected (and in the game).

Returns:
  True when the client is connected.

Definition at line 471 of file network_client.cpp.

References my_client, status, and STATUS_ACTIVE.

Referenced by DEF_CONSOLE_HOOK().

bool ClientNetworkGameSocketHandler::Receive | ( |  | ) | `[static]`

Check whether we received/can send some data from/to the server and when that's the case handle it appropriately.

Returns:
  true when everything went okay.

Definition at line 205 of file network_client.cpp.

References _networking, NetworkTCPSocketHandler::CanSendReceive(), ClientError(), my_client, NETWORK_RECV_STATUS_OKAY, and NetworkGameSocketHandler::ReceivePackets().

Referenced by NetworkReceive().

void ClientNetworkGameSocketHandler::Send | ( |  | ) | `[static]`

Send the packets of this socket handler.

Definition at line 220 of file network_client.cpp.

References CheckConnection(), my_client, and NetworkTCPSocketHandler::SendPackets().

## Friends And Related Function Documentation

void NetworkClose | ( | bool | close_admins | ) | `[friend]`

Close current connections.

Parameters:

  | close_admins | Whether the admin connections have to be closed as well.

Definition at line 505 of file network.cpp.

## Field Documentation

ClientNetworkGameSocketHandler * ClientNetworkGameSocketHandler::my_client = NULL`[static, protected]`

Our client's connection.

Definition at line 45 of file network_client.h.

Referenced by ClientNetworkGameSocketHandler(), GameLoop(), IsConnected(), NetworkClose(), NetworkExecuteLocalCommandQueue(), Receive(), Send(), and ~ClientNetworkGameSocketHandler().

The documentation for this class was generated from the following files:

- src/network/network_client.h
- src/network/network_client.cpp