Public Types | Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions

# ServerNetworkGameSocketHandler Class Reference

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

`#include <network_server.h>`

Inheritance diagram for ServerNetworkGameSocketHandler:

## Public Types
enum | ClientStatus { STATUS_INACTIVE, STATUS_NEWGRFS_CHECK, STATUS_AUTH_GAME, STATUS_AUTH_COMPANY, STATUS_AUTHORIZED, STATUS_MAP_WAIT, STATUS_MAP, STATUS_DONE_MAP, STATUS_PRE_ACTIVE, STATUS_ACTIVE, STATUS_END }
| Status of a client. More...
## Public Member Functions
| ServerNetworkGameSocketHandler (SOCKET s)
| Create a new socket for the server side of the game connection.
| ~ServerNetworkGameSocketHandler ()
| Clear everything related to this client.
virtual Packet * | ReceivePacket ()
virtual void | SendPacket (Packet *packet)
NetworkRecvStatus | CloseConnection (NetworkRecvStatus status)
void | GetClientName (char *client_name, size_t size) const
| Get the name of the client, if the user did not send it yet, Client #<no> is used.
NetworkRecvStatus | SendMap ()
NetworkRecvStatus | SendErrorQuit (ClientID client_id, NetworkErrorCode errorno)
NetworkRecvStatus | SendQuit (ClientID client_id)
NetworkRecvStatus | SendShutdown ()
NetworkRecvStatus | SendNewGame ()
NetworkRecvStatus | SendRConResult (uint16 colour, const char *command)
NetworkRecvStatus | SendMove (ClientID client_id, CompanyID company_id)
NetworkRecvStatus | SendClientInfo (NetworkClientInfo *ci)
NetworkRecvStatus | SendError (NetworkErrorCode error)
NetworkRecvStatus | SendChat (NetworkAction action, ClientID client_id, bool self_send, const char *msg, int64 data)
NetworkRecvStatus | SendJoin (ClientID client_id)
NetworkRecvStatus | SendFrame ()
NetworkRecvStatus | SendSync ()
NetworkRecvStatus | SendCommand (const CommandPacket *cp)
NetworkRecvStatus | SendCompanyUpdate ()
NetworkRecvStatus | SendConfigUpdate ()
const char * | GetClientIP ()
| Get the IP address/hostname of the connected client.
## Static Public Member Functions
static void | Send ()
| Send the packets for the server sockets.
static void | AcceptConnection (SOCKET s, const NetworkAddress &address)
static bool | AllowConnection ()
| Whether an connection is allowed or not at this moment.
static const char * | GetName ()
| Get the name used by the listener.
static ServerNetworkGameSocketHandler * | GetByClientID (ClientID client_id)
## Data Fields
byte | lag_test
| Byte used for lag-testing the client.
byte | last_token
| The last random token we did send to verify the client is listening.
uint32 | last_token_frame
| The last frame we received the right token.
ClientStatus | status
| Status of this client.
CommandQueue | outgoing_queue
| The command-queue awaiting delivery.
int | receive_limit
| Amount of bytes that we can receive at this moment.
Packet * | savegame_packets
| Packet queue of the savegame; send these "slowly" to the client.
struct PacketWriter * | savegame
| Writer used to write the savegame.
ThreadMutex * | savegame_mutex
| Mutex for making threaded saving safe.
NetworkAddress | client_address
| IP-address of the client (so he can be banned).
## Protected Member Functions
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_JOIN)
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_COMPANY_INFO)
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_GAME_PASSWORD)
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_COMPANY_PASSWORD)
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_GETMAP)
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_MAP_OK)
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_ACK)
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_COMMAND)
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_CHAT)
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_SET_PASSWORD)
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_SET_NAME)
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_QUIT)
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_ERROR)
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_RCON)
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_NEWGRFS_CHECKED)
| DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_MOVE)
NetworkRecvStatus | SendCompanyInfo ()
NetworkRecvStatus | SendNewGRFCheck ()
NetworkRecvStatus | SendWelcome ()
NetworkRecvStatus | SendWait ()
NetworkRecvStatus | SendNeedGamePassword ()
NetworkRecvStatus | SendNeedCompanyPassword ()

## Detailed Description

Class for handling the server side of the game connection.

Definition at line 27 of file network_server.h.

## Member Enumeration Documentation

enum ServerNetworkGameSocketHandler::ClientStatus

Status of a client.

Enumerator:

  STATUS_INACTIVE | The client is not connected nor active.
  STATUS_NEWGRFS_CHECK | The client is checking NewGRFs.
  STATUS_AUTH_GAME | The client is authorizing with game (server) password.
  STATUS_AUTH_COMPANY | The client is authorizing with company password.
  STATUS_AUTHORIZED | The client is authorized.
  STATUS_MAP_WAIT | The client is waiting as someone else is downloading the map.
  STATUS_MAP | The client is downloading the map.
  STATUS_DONE_MAP | The client has downloaded the map.
  STATUS_PRE_ACTIVE | The client is catching up the delayed frames.
  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 55 of file network_server.h.

## Constructor & Destructor Documentation

ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler | ( | SOCKET | s | ) |

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

Parameters:

  | s | The socket to connect with.

Definition at line 154 of file network_server.cpp.

References _network_client_id, _settings_client, NetworkSettings::bytes_per_frame_burst, NetworkGameSocketHandler::client_id, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::MAX_SIZE, ClientSettings::network, receive_limit, and status.

## Member Function Documentation

bool ServerNetworkGameSocketHandler::AllowConnection | ( |  | ) | `[static]`

Whether an connection is allowed or not at this moment.

Returns:
  true if the connection is allowed.

Definition at line 266 of file network_server.cpp.

References _settings_client, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_networkclientsocket_pool >::CanAllocateItem(), NetworkServerGameInfo::clients_on, NetworkSettings::max_clients, MAX_CLIENTS, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::MAX_SIZE, and ClientSettings::network.

const char * ServerNetworkGameSocketHandler::GetClientIP | ( |  | ) |

Get the IP address/hostname of the connected client.

Returns:
  The IP address.

Definition at line 1813 of file network_server.cpp.

References client_address, and NetworkAddress::GetHostname().

void ServerNetworkGameSocketHandler::GetClientName | ( | char * | client_name,
|  | size_t | size |
| ) |  |  | const

Get the name of the client, if the user did not send it yet, Client #<no> is used.

Parameters:

  | client_name | The variable to write the name to.
  | size | The amount of bytes we can write.

Definition at line 1966 of file network_server.cpp.

References NetworkClientInfo::client_name, StrEmpty(), and ttd_strlcpy().

static const char* ServerNetworkGameSocketHandler::GetName | ( |  | ) | `[inline, static]`

Get the name used by the listener.

Returns:
  the name to show in debug logs and the like.

Definition at line 115 of file network_server.h.

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

Send the packets for the server sockets.

Definition at line 279 of file network_server.cpp.

References SPS_CLOSED.

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

- src/network/network_server.h
- src/network/network.cpp
- src/network/network_server.cpp