OpenTTD: NetworkGameSocketHandler Class Reference

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- Data Structures
- Class Hierarchy
- Data Fields

Public Member Functions | Data Fields | Protected Member Functions | Private Attributes
NetworkGameSocketHandler Class Reference

Base socket handler for all TCP sockets. More...

`#include <tcp_game.h>`

Inheritance diagram for NetworkGameSocketHandler:

## Public Member Functions
NetworkRecvStatus | CloseConnection (bool error=true)
| Functions to help ReceivePacket/SendPacket a bit A socket can make errors.
virtual NetworkRecvStatus | CloseConnection (NetworkRecvStatus status)=0
| Close the network connection due to the given status.
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.
Public Member Functions inherited from NetworkTCPSocketHandler
bool | IsConnected () const
| Whether this socket is currently bound to a socket.
virtual void | SendPacket (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 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 ()
| Close the socket when destructing the socket handler.
virtual void | Close ()
| Really close the socket.
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.
void | SendGRFIdentifier (Packet *p, const GRFIdentifier *grf)
| Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet.
void | ReceiveGRFIdentifier (Packet *p, GRFIdentifier *grf)
| Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.
void | SendCompanyInformation (Packet *p, const struct Company *c, const struct NetworkCompanyStats *stats, uint max_len=NETWORK_COMPANY_NAME_LENGTH)
| Package some generic company information into a packet.

## Data Fields
ClientID | client_id
| Client identifier.
uint32 | last_frame
| Last frame we have executed.
uint32 | last_frame_server
| Last frame the server has executed.
CommandQueue | incoming_queue
| The command-queue awaiting handling.
uint | 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 Member Functions
NetworkRecvStatus | ReceiveInvalidPacket (PacketGameType type)
| Helper for logging receiving invalid packets.
virtual NetworkRecvStatus | Receive_SERVER_FULL (Packet *p)
| Notification that the server is full.
virtual NetworkRecvStatus | Receive_SERVER_BANNED (Packet *p)
| Notification that the client trying to join is banned.
virtual NetworkRecvStatus | Receive_CLIENT_JOIN (Packet *p)
| Try to join the server: string OpenTTD revision (norev000 if no revision).
virtual NetworkRecvStatus | Receive_SERVER_ERROR (Packet *p)
| The client made an error: uint8 Error code caused (see NetworkErrorCode).
virtual NetworkRecvStatus | Receive_CLIENT_COMPANY_INFO (Packet *p)
| Request company information (in detail).
virtual NetworkRecvStatus | Receive_SERVER_COMPANY_INFO (Packet *p)
| Sends information about the companies (one packet per company): uint8 Version of the structure of this packet (NETWORK_COMPANY_INFO_VERSION).
virtual NetworkRecvStatus | Receive_SERVER_CLIENT_INFO (Packet *p)
| Send information about a client: uint32 ID of the client (always unique on a server.
virtual NetworkRecvStatus | Receive_SERVER_NEED_GAME_PASSWORD (Packet *p)
| Indication to the client that the server needs a game password.
virtual NetworkRecvStatus | Receive_SERVER_NEED_COMPANY_PASSWORD (Packet *p)
| Indication to the client that the server needs a company password: uint32 Generation seed.
virtual NetworkRecvStatus | Receive_CLIENT_GAME_PASSWORD (Packet *p)
| Send a password to the server to authorize: uint8 Password type (see NetworkPasswordType).
virtual NetworkRecvStatus | Receive_CLIENT_COMPANY_PASSWORD (Packet *p)
| Send a password to the server to authorize uint8 Password type (see NetworkPasswordType).
virtual NetworkRecvStatus | Receive_SERVER_WELCOME (Packet *p)
| The client is joined and ready to receive his map: uint32 Own client ID.
virtual NetworkRecvStatus | Receive_CLIENT_GETMAP (Packet *p)
| Request the map from the server.
virtual NetworkRecvStatus | Receive_SERVER_WAIT (Packet *p)
| Notification that another client is currently receiving the map: uint8 Number of clients waiting in front of you.
virtual NetworkRecvStatus | Receive_SERVER_MAP_BEGIN (Packet *p)
| Sends that the server will begin with sending the map to the client: uint32 Current frame.
virtual NetworkRecvStatus | Receive_SERVER_MAP_SIZE (Packet *p)
| Sends the size of the map to the client.
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_SERVER_MAP_DONE (Packet *p)
| Sends that all data of the map are sent to the client:
virtual NetworkRecvStatus | Receive_CLIENT_MAP_OK (Packet *p)
| Tell the server that we are done receiving/loading the map.
virtual NetworkRecvStatus | Receive_SERVER_JOIN (Packet *p)
| 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.
virtual NetworkRecvStatus | Receive_SERVER_FRAME (Packet *p)
| 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 (dependent on compile settings, not default).
virtual NetworkRecvStatus | Receive_SERVER_SYNC (Packet *p)
| Sends a sync-check to the client: uint32 Frame counter.
virtual NetworkRecvStatus | Receive_CLIENT_ACK (Packet *p)
| Tell the server we are done with this frame: uint32 Current frame counter of the client.
virtual NetworkRecvStatus | Receive_CLIENT_COMMAND (Packet *p)
| Send a DoCommand to the Server: uint8 ID of the company (0..MAX_COMPANIES-1).
virtual NetworkRecvStatus | Receive_SERVER_COMMAND (Packet *p)
| Sends a DoCommand to the client: uint8 ID of the company (0..MAX_COMPANIES-1).
virtual NetworkRecvStatus | Receive_CLIENT_CHAT (Packet *p)
| Sends a chat-packet to the server: uint8 ID of the action (see NetworkAction).
virtual NetworkRecvStatus | Receive_SERVER_CHAT (Packet *p)
| Sends a chat-packet to the client: uint8 ID of the action (see NetworkAction).
virtual NetworkRecvStatus | Receive_CLIENT_SET_PASSWORD (Packet *p)
| Set the password for the clients current company: string The password.
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_SERVER_QUIT (Packet *p)
| Notification that a client left the game: uint32 ID of the client.
virtual NetworkRecvStatus | Receive_SERVER_ERROR_QUIT (Packet *p)
| Inform all clients that one client made an error and thus has quit/been disconnected: uint32 ID of the client that caused the error.
virtual NetworkRecvStatus | Receive_SERVER_SHUTDOWN (Packet *p)
| Let the clients know that the server is closing.
virtual NetworkRecvStatus | Receive_SERVER_NEWGAME (Packet *p)
| Let the clients know that the server is loading a new map.
virtual NetworkRecvStatus | Receive_SERVER_RCON (Packet *p)
| Send the result of an issues RCon command back to the client: uint16 Colour code.
virtual NetworkRecvStatus | Receive_CLIENT_RCON (Packet *p)
| Send an RCon command to the server: string RCon password.
virtual NetworkRecvStatus | Receive_SERVER_CHECK_NEWGRFS (Packet *p)
| Sends information about all used GRFs to the client: uint8 Amount of GRFs (the following data is repeated this many times, i.e.
virtual NetworkRecvStatus | Receive_CLIENT_NEWGRFS_CHECKED (Packet *p)
| Tell the server that we have the required GRFs.
virtual NetworkRecvStatus | Receive_SERVER_MOVE (Packet *p)
| Move a client from one company into another: uint32 ID of the client.
virtual NetworkRecvStatus | Receive_CLIENT_MOVE (Packet *p)
| Request the server to move this client into another company: uint8 ID of the company the client wants to join.
virtual NetworkRecvStatus | Receive_SERVER_COMPANY_UPDATE (Packet *p)
| Update the clients knowledge of which company is password protected: uint16 Bitwise representation of each company.
virtual NetworkRecvStatus | Receive_SERVER_CONFIG_UPDATE (Packet *p)
| Update the clients knowledge of the max settings: uint8 Maximum number of companies allowed.
NetworkRecvStatus | HandlePacket (Packet *p)
| Handle the given packet, i.e.
| NetworkGameSocketHandler (SOCKET s)
| Create a new socket for the game connection.

## Private Attributes
NetworkClientInfo * | info
| Client info related to this socket.

## Detailed Description

Base socket handler for all TCP sockets.

Definition at line 152 of file tcp_game.h.

## Constructor & Destructor Documentation

NetworkGameSocketHandler::NetworkGameSocketHandler | ( | SOCKET | s | ) |
| protected

Create a new socket for the game connection.

Parameters

  s | The socket to connect with.

Definition at line 31 of file tcp_game.cpp.

References NetworkTCPSocketHandler::sock.

## Member Function Documentation

NetworkRecvStatus NetworkGameSocketHandler::CloseConnection | ( | bool | error = `true` | ) |
| virtual

Functions to help ReceivePacket/SendPacket a bit A socket can make errors.

When that happens this handles what to do. For clients: close connection and drop back to main-menu For servers: close connection and that is it

Returns
  the new status

Reimplemented from NetworkTCPSocketHandler.

Definition at line 44 of file tcp_game.cpp.

References _network_server, _networking, _switch_mode, INVALID_STRING_ID, NETWORK_RECV_STATUS_CONN_LOST, NETWORK_RECV_STATUS_SERVER_ERROR, ShowErrorMessage(), SM_MENU, and WL_CRITICAL.

Referenced by HandlePacket().

virtual NetworkRecvStatus NetworkGameSocketHandler::CloseConnection | ( | NetworkRecvStatus | status | ) |
| pure virtual

Close the network connection due to the given status.

Parameters

  status | The reason the connection got closed.

Implemented in ServerNetworkGameSocketHandler, and ClientNetworkGameSocketHandler.

NetworkClientInfo* NetworkGameSocketHandler::GetInfo | ( |  | ) | const
| inline

Gets the client info of this socket handler.

Returns
  The client info.

Definition at line 550 of file tcp_game.h.

References info.

Referenced by ClientNetworkGameSocketHandler::CloseConnection(), ServerNetworkGameSocketHandler::CloseConnection(), ServerNetworkGameSocketHandler::GetClientName(), ServerNetworkGameSocketHandler::Receive_CLIENT_CHAT(), ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(), ServerNetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWORD(), ServerNetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD(), ServerNetworkGameSocketHandler::Receive_CLIENT_MAP_OK(), ServerNetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED(), ServerNetworkGameSocketHandler::Receive_CLIENT_SET_NAME(), ServerNetworkGameSocketHandler::Receive_CLIENT_SET_PASSWORD(), and ServerNetworkGameSocketHandler::SendWait().

NetworkRecvStatus NetworkGameSocketHandler::HandlePacket | ( | Packet * | p | ) |
| protected

Handle the given packet, i.e.

pass it to the right parser receive command.

Parameters

  p | the packet to handle

Returns
  NetworkRecvStatus of handling.

Definition at line 64 of file tcp_game.cpp.

References _realtime_tick, client_id, CloseConnection(), DEBUG, NetworkSocketHandler::HasClientQuit(), last_packet, NETWORK_RECV_STATUS_MALFORMED_PACKET, PACKET_CLIENT_ACK, PACKET_CLIENT_CHAT, PACKET_CLIENT_COMMAND, PACKET_CLIENT_COMPANY_INFO, PACKET_CLIENT_COMPANY_PASSWORD, PACKET_CLIENT_ERROR, PACKET_CLIENT_GAME_PASSWORD, PACKET_CLIENT_GETMAP, PACKET_CLIENT_JOIN, PACKET_CLIENT_MAP_OK, PACKET_CLIENT_MOVE, PACKET_CLIENT_NEWGRFS_CHECKED, PACKET_CLIENT_QUIT, PACKET_CLIENT_RCON, PACKET_CLIENT_SET_NAME, PACKET_CLIENT_SET_PASSWORD, PACKET_END, PACKET_SERVER_BANNED, PACKET_SERVER_CHAT, PACKET_SERVER_CHECK_NEWGRFS, PACKET_SERVER_CLIENT_INFO, PACKET_SERVER_COMMAND, PACKET_SERVER_COMPANY_INFO, PACKET_SERVER_COMPANY_UPDATE, PACKET_SERVER_CONFIG_UPDATE, PACKET_SERVER_ERROR, PACKET_SERVER_ERROR_QUIT, PACKET_SERVER_FRAME, PACKET_SERVER_FULL, PACKET_SERVER_JOIN, PACKET_SERVER_MAP_BEGIN, PACKET_SERVER_MAP_DATA, PACKET_SERVER_MAP_DONE, PACKET_SERVER_MAP_SIZE, PACKET_SERVER_MOVE, PACKET_SERVER_NEED_COMPANY_PASSWORD, PACKET_SERVER_NEED_GAME_PASSWORD, PACKET_SERVER_NEWGAME, PACKET_SERVER_QUIT, PACKET_SERVER_RCON, PACKET_SERVER_SHUTDOWN, PACKET_SERVER_SYNC, PACKET_SERVER_WAIT, PACKET_SERVER_WELCOME, Receive_CLIENT_ACK(), Receive_CLIENT_CHAT(), Receive_CLIENT_COMMAND(), Receive_CLIENT_COMPANY_INFO(), Receive_CLIENT_COMPANY_PASSWORD(), Receive_CLIENT_ERROR(), Receive_CLIENT_GAME_PASSWORD(), Receive_CLIENT_GETMAP(), Receive_CLIENT_JOIN(), Receive_CLIENT_MAP_OK(), Receive_CLIENT_MOVE(), Receive_CLIENT_NEWGRFS_CHECKED(), Receive_CLIENT_QUIT(), Receive_CLIENT_RCON(), Receive_CLIENT_SET_NAME(), Receive_CLIENT_SET_PASSWORD(), Receive_SERVER_BANNED(), Receive_SERVER_CHAT(), Receive_SERVER_CHECK_NEWGRFS(), Receive_SERVER_CLIENT_INFO(), Receive_SERVER_COMMAND(), Receive_SERVER_COMPANY_INFO(), Receive_SERVER_COMPANY_UPDATE(), Receive_SERVER_CONFIG_UPDATE(), Receive_SERVER_ERROR(), Receive_SERVER_ERROR_QUIT(), Receive_SERVER_FRAME(), Receive_SERVER_FULL(), Receive_SERVER_JOIN(), Receive_SERVER_MAP_BEGIN(), Receive_SERVER_MAP_DATA(), Receive_SERVER_MAP_DONE(), Receive_SERVER_MAP_SIZE(), Receive_SERVER_MOVE(), Receive_SERVER_NEED_COMPANY_PASSWORD(), Receive_SERVER_NEED_GAME_PASSWORD(), Receive_SERVER_NEWGAME(), Receive_SERVER_QUIT(), Receive_SERVER_RCON(), Receive_SERVER_SHUTDOWN(), Receive_SERVER_SYNC(), Receive_SERVER_WAIT(), Receive_SERVER_WELCOME(), and Packet::Recv_uint8().

Referenced by ReceivePackets().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_ACK | ( | Packet * | p | ) |
| protectedvirtual

Tell the server we are done with this frame: uint32 Current frame counter of the client.

uint8 The random token that the server sent in the PACKET_SERVER_FRAME packet.

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 179 of file tcp_game.cpp.

References PACKET_CLIENT_ACK, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_CHAT | ( | Packet * | p | ) |
| protectedvirtual

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

uint8 ID of the destination type (see DestType). uint32 ID of the client or company (destination of the chat). string Message (max NETWORK_CHAT_LENGTH). uint64 data (used e.g. for 'give money' actions).

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 182 of file tcp_game.cpp.

References PACKET_CLIENT_CHAT, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMMAND | ( | Packet * | p | ) |
| protectedvirtual

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

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

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 180 of file tcp_game.cpp.

References PACKET_CLIENT_COMMAND, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMPANY_INFO | ( | Packet * | p | ) |
| protectedvirtual

Request company information (in detail).

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 161 of file tcp_game.cpp.

References PACKET_CLIENT_COMPANY_INFO, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWORD | ( | Packet * | p | ) |
| protectedvirtual

Send a password to the server to authorize uint8 Password type (see NetworkPasswordType).

string The password.

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 167 of file tcp_game.cpp.

References PACKET_CLIENT_COMPANY_PASSWORD, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_ERROR | ( | Packet * | p | ) |
| protectedvirtual

The client made an error and is quitting the game.

uint8 Error of the code caused (see NetworkErrorCode).

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 187 of file tcp_game.cpp.

References PACKET_CLIENT_ERROR, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GAME_PASSWORD | ( | Packet * | p | ) |
| protectedvirtual

Send a password to the server to authorize: uint8 Password type (see NetworkPasswordType).

string The password.

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 166 of file tcp_game.cpp.

References PACKET_CLIENT_GAME_PASSWORD, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_GETMAP | ( | Packet * | p | ) |
| protectedvirtual

Request the map from the server.

uint32 NewGRF version (release versions of OpenTTD only).

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 169 of file tcp_game.cpp.

References PACKET_CLIENT_GETMAP, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_JOIN | ( | Packet * | p | ) |
| protectedvirtual

Try to join the server: string OpenTTD revision (norev000 if no revision).

string Name of the client (max NETWORK_NAME_LENGTH). uint8 ID of the company to play as (1..MAX_COMPANIES). uint8 ID of the clients Language.

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 159 of file tcp_game.cpp.

References PACKET_CLIENT_JOIN, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_MAP_OK | ( | Packet * | p | ) |
| protectedvirtual

Tell the server that we are done receiving/loading the map.

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 175 of file tcp_game.cpp.

References PACKET_CLIENT_MAP_OK, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_MOVE | ( | Packet * | p | ) |
| protectedvirtual

Request the server to move this client into another company: uint8 ID of the company the client wants to join.

string Password, if the company is password protected.

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 197 of file tcp_game.cpp.

References PACKET_CLIENT_MOVE, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_NEWGRFS_CHECKED | ( | Packet * | p | ) |
| protectedvirtual

Tell the server that we have the required GRFs.

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 195 of file tcp_game.cpp.

References PACKET_CLIENT_NEWGRFS_CHECKED, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_QUIT | ( | Packet * | p | ) |
| protectedvirtual

The client is quitting the game.

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 186 of file tcp_game.cpp.

References PACKET_CLIENT_QUIT, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_RCON | ( | Packet * | p | ) |
| protectedvirtual

Send an RCon command to the server: string RCon password.

string Command to be executed.

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 193 of file tcp_game.cpp.

References PACKET_CLIENT_RCON, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_SET_NAME | ( | Packet * | p | ) |
| protectedvirtual

Gives the client a new name: string New name of the client.

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 185 of file tcp_game.cpp.

References PACKET_CLIENT_SET_NAME, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_CLIENT_SET_PASSWORD | ( | Packet * | p | ) |
| protectedvirtual

Set the password for the clients current company: string The password.

Parameters

  p | The packet that was just received.

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 184 of file tcp_game.cpp.

References PACKET_CLIENT_SET_PASSWORD, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_BANNED | ( | Packet * | p | ) |
| protectedvirtual

Notification that the client trying to join is banned.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 158 of file tcp_game.cpp.

References PACKET_SERVER_BANNED, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CHAT | ( | Packet * | p | ) |
| protectedvirtual

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).

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 183 of file tcp_game.cpp.

References PACKET_SERVER_CHAT, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS | ( | Packet * | p | ) |
| protectedvirtual

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

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 194 of file tcp_game.cpp.

References PACKET_SERVER_CHECK_NEWGRFS, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO | ( | Packet * | p | ) |
| protectedvirtual

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.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 163 of file tcp_game.cpp.

References PACKET_SERVER_CLIENT_INFO, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMMAND | ( | Packet * | p | ) |
| protectedvirtual

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.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 181 of file tcp_game.cpp.

References PACKET_SERVER_COMMAND, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMPANY_INFO | ( | Packet * | p | ) |
| protectedvirtual

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)

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 162 of file tcp_game.cpp.

References PACKET_SERVER_COMPANY_INFO, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE | ( | Packet * | p | ) |
| protectedvirtual

Update the clients knowledge of which company is password protected: uint16 Bitwise representation of each company.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 198 of file tcp_game.cpp.

References PACKET_SERVER_COMPANY_UPDATE, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE | ( | Packet * | p | ) |
| protectedvirtual

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

uint8 Maximum number of spectators allowed.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 199 of file tcp_game.cpp.

References PACKET_SERVER_CONFIG_UPDATE, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR | ( | Packet * | p | ) |
| protectedvirtual

The client made an error: uint8 Error code caused (see NetworkErrorCode).

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 160 of file tcp_game.cpp.

References PACKET_SERVER_ERROR, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_ERROR_QUIT | ( | Packet * | p | ) |
| protectedvirtual

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).

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 189 of file tcp_game.cpp.

References PACKET_SERVER_ERROR_QUIT, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_FRAME | ( | Packet * | p | ) |
| protectedvirtual

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 (dependent on compile settings, not default).

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

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 177 of file tcp_game.cpp.

References PACKET_SERVER_FRAME, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_FULL | ( | Packet * | p | ) |
| protectedvirtual

Notification that the server is full.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 157 of file tcp_game.cpp.

References PACKET_SERVER_FULL, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_JOIN | ( | Packet * | p | ) |
| protectedvirtual

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.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 176 of file tcp_game.cpp.

References PACKET_SERVER_JOIN, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_BEGIN | ( | Packet * | p | ) |
| protectedvirtual

Sends that the server will begin with sending the map to the client: uint32 Current frame.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 171 of file tcp_game.cpp.

References PACKET_SERVER_MAP_BEGIN, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_DATA | ( | Packet * | p | ) |
| protectedvirtual

Sends the data of the map to the client: Contains a part of the map (until max size of packet).

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 173 of file tcp_game.cpp.

References PACKET_SERVER_MAP_DATA, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_DONE | ( | Packet * | p | ) |
| protectedvirtual

Sends that all data of the map are sent to the client:

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 174 of file tcp_game.cpp.

References PACKET_SERVER_MAP_DONE, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MAP_SIZE | ( | Packet * | p | ) |
| protectedvirtual

Sends the size of the map to the client.

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

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 172 of file tcp_game.cpp.

References PACKET_SERVER_MAP_SIZE, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_MOVE | ( | Packet * | p | ) |
| protectedvirtual

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

uint8 ID of the new company.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 196 of file tcp_game.cpp.

References PACKET_SERVER_MOVE, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEED_COMPANY_PASSWORD | ( | Packet * | p | ) |
| protectedvirtual

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

string Network ID of the server.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 165 of file tcp_game.cpp.

References PACKET_SERVER_NEED_COMPANY_PASSWORD, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEED_GAME_PASSWORD | ( | Packet * | p | ) |
| protectedvirtual

Indication to the client that the server needs a game password.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 164 of file tcp_game.cpp.

References PACKET_SERVER_NEED_GAME_PASSWORD, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_NEWGAME | ( | Packet * | p | ) |
| protectedvirtual

Let the clients know that the server is loading a new map.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 191 of file tcp_game.cpp.

References PACKET_SERVER_NEWGAME, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_QUIT | ( | Packet * | p | ) |
| protectedvirtual

Notification that a client left the game: uint32 ID of the client.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 188 of file tcp_game.cpp.

References PACKET_SERVER_QUIT, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_RCON | ( | Packet * | p | ) |
| protectedvirtual

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

string Output of the RCon command

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 192 of file tcp_game.cpp.

References PACKET_SERVER_RCON, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_SHUTDOWN | ( | Packet * | p | ) |
| protectedvirtual

Let the clients know that the server is closing.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 190 of file tcp_game.cpp.

References PACKET_SERVER_SHUTDOWN, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_SYNC | ( | Packet * | p | ) |
| protectedvirtual

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

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

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 178 of file tcp_game.cpp.

References PACKET_SERVER_SYNC, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_WAIT | ( | Packet * | p | ) |
| protectedvirtual

Notification that another client is currently receiving the map: uint8 Number of clients waiting in front of you.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 170 of file tcp_game.cpp.

References PACKET_SERVER_WAIT, and ReceiveInvalidPacket().

Referenced by HandlePacket().

NetworkRecvStatus NetworkGameSocketHandler::Receive_SERVER_WELCOME | ( | Packet * | p | ) |
| protectedvirtual

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

uint32 Generation seed. string Network ID of the server.

Parameters

  p | The packet that was just received.

Reimplemented in ClientNetworkGameSocketHandler.

Definition at line 168 of file tcp_game.cpp.

References PACKET_SERVER_WELCOME, and ReceiveInvalidPacket().

Referenced by HandlePacket().

const char * NetworkGameSocketHandler::ReceiveCommand | ( | Packet * | p,
|  | CommandPacket * | cp
| ) |  |

Receives a command from the network.

Parameters

  p | the packet to read from.
  cp | the struct to write the data to.

Returns
  an error message. When NULL there has been no error.

Definition at line 302 of file network_command.cpp.

References _callback_table, _network_server, CommandContainer::callback, CommandContainer::cmd, CMD_FLAGS_MASK, CMD_OFFLINE, CMD_STR_CTRL, CommandPacket::company, GetCommandFlags(), IsValidCommand(), lengthof, CommandContainer::p1, CommandContainer::p2, Packet::Recv_string(), Packet::Recv_uint32(), Packet::Recv_uint8(), SVS_ALLOW_CONTROL_CODE, SVS_REPLACE_WITH_QUESTION_MARK, CommandContainer::text, and CommandContainer::tile.

Referenced by ServerNetworkGameSocketHandler::Receive_CLIENT_COMMAND(), and ClientNetworkGameSocketHandler::Receive_SERVER_COMMAND().

NetworkRecvStatus NetworkGameSocketHandler::ReceiveInvalidPacket | ( | PacketGameType | type | ) |
| protected

Helper for logging receiving invalid packets.

Parameters

  type | The received packet type.

Returns
  The status the network should have, in this case: "malformed packet error".

Definition at line 151 of file tcp_game.cpp.

References client_id, DEBUG, and NETWORK_RECV_STATUS_MALFORMED_PACKET.

Referenced by Receive_CLIENT_ACK(), Receive_CLIENT_CHAT(), Receive_CLIENT_COMMAND(), Receive_CLIENT_COMPANY_INFO(), Receive_CLIENT_COMPANY_PASSWORD(), Receive_CLIENT_ERROR(), Receive_CLIENT_GAME_PASSWORD(), Receive_CLIENT_GETMAP(), Receive_CLIENT_JOIN(), Receive_CLIENT_MAP_OK(), Receive_CLIENT_MOVE(), Receive_CLIENT_NEWGRFS_CHECKED(), Receive_CLIENT_QUIT(), Receive_CLIENT_RCON(), Receive_CLIENT_SET_NAME(), Receive_CLIENT_SET_PASSWORD(), Receive_SERVER_BANNED(), Receive_SERVER_CHAT(), Receive_SERVER_CHECK_NEWGRFS(), Receive_SERVER_CLIENT_INFO(), Receive_SERVER_COMMAND(), Receive_SERVER_COMPANY_INFO(), Receive_SERVER_COMPANY_UPDATE(), Receive_SERVER_CONFIG_UPDATE(), Receive_SERVER_ERROR(), Receive_SERVER_ERROR_QUIT(), Receive_SERVER_FRAME(), Receive_SERVER_FULL(), Receive_SERVER_JOIN(), Receive_SERVER_MAP_BEGIN(), Receive_SERVER_MAP_DATA(), Receive_SERVER_MAP_DONE(), Receive_SERVER_MAP_SIZE(), Receive_SERVER_MOVE(), Receive_SERVER_NEED_COMPANY_PASSWORD(), Receive_SERVER_NEED_GAME_PASSWORD(), Receive_SERVER_NEWGAME(), Receive_SERVER_QUIT(), Receive_SERVER_RCON(), Receive_SERVER_SHUTDOWN(), Receive_SERVER_SYNC(), Receive_SERVER_WAIT(), and Receive_SERVER_WELCOME().

NetworkRecvStatus NetworkGameSocketHandler::ReceivePackets | ( |  | ) |

Do the actual receiving of packets.

As long as HandlePacket returns OKAY packets are handled. Upon failure, or no more packets to process the last result of HandlePacket is returned.

Returns
  NetworkRecvStatus of the last handled packet.

Definition at line 134 of file tcp_game.cpp.

References HandlePacket(), NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::ReceivePacket().

Referenced by ClientNetworkGameSocketHandler::Receive().

void NetworkGameSocketHandler::SendCommand | ( | Packet * | p,
|  | const CommandPacket * | cp
| ) |  |

Sends a command over the network.

Parameters

  p | the packet to send it in.
  cp | the packet to actually send.

Definition at line 327 of file network_command.cpp.

References _callback_table, CommandContainer::callback, CommandContainer::cmd, CommandPacket::company, DEBUG, lengthof, CommandContainer::p1, CommandContainer::p2, Packet::Send_string(), Packet::Send_uint32(), Packet::Send_uint8(), CommandContainer::text, and CommandContainer::tile.

void NetworkGameSocketHandler::SetInfo | ( | NetworkClientInfo * | info | ) |
| inline

Sets the client info for this socket handler.

Parameters

  info | The new client info.

Definition at line 540 of file tcp_game.h.

References info.

Referenced by ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(), and ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO().

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

- src/network/core/tcp_game.h
- src/network/core/tcp_game.cpp
- src/network/network_command.cpp