ServerNetworkGameSocketHandler Class Reference

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

#include <network_server.h>

Inheritance diagram for ServerNetworkGameSocketHandler:
Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_networkclientsocket_pool > NetworkGameSocketHandler TCPListenHandler< ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED > NetworkTCPSocketHandler NetworkSocketHandler

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 PacketReceivePacket ()
 Receives a packet for the given client.
virtual void SendPacket (Packet *packet)
 This function puts the packet in the send-queue and it is send as soon as possible.
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.
Packetsavegame_packets
 Packet queue of the savegame; send these "slowly" to the client.
struct PacketWritersavegame
 Writer used to write the savegame.
ThreadMutexsavegame_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)
 Try to join the server: string OpenTTD revision (norev000 if no revision).
 DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_COMPANY_INFO)
 Request company information (in detail).
 DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_GAME_PASSWORD)
 Send a password to the server to authorize: uint8 Password type (see NetworkPasswordType).
 DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_COMPANY_PASSWORD)
 Send a password to the server to authorize uint8 Password type (see NetworkPasswordType).
 DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_GETMAP)
 Request the map from the server.
 DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_MAP_OK)
 Tell the server that we are done receiving/loading the map.
 DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_ACK)
 Tell the server we are done with this frame: uint32 Current frame counter of the client.
 DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_COMMAND)
 Send a DoCommand to the Server: uint8 ID of the company (0..MAX_COMPANIES-1).
 DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_CHAT)
 Sends a chat-packet to the server: uint8 ID of the action (see NetworkAction).
 DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_SET_PASSWORD)
 Set the password for the clients current company: string The password.
 DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_SET_NAME)
 Gives the client a new name: string New name of the client.
 DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_QUIT)
 The client is quiting the game.
 DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_ERROR)
 The client made an error and is quiting the game.
 DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_RCON)
 Send an RCon command to the server: string RCon password.
 DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_NEWGRFS_CHECKED)
 Tell the server that we have the required GRFs.
 DECLARE_GAME_RECEIVE_COMMAND (PACKET_CLIENT_MOVE)
 Request the server to move this client into another company: uint8 ID of the company the client wants to join.
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

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, status, and STATUS_INACTIVE.


Member Function Documentation

bool ServerNetworkGameSocketHandler::AllowConnection (  )  [static]
ServerNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND ( PACKET_CLIENT_MOVE   )  [protected]

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.

Reimplemented from NetworkGameSocketHandler.

ServerNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND ( PACKET_CLIENT_RCON   )  [protected]

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

string Command to be executed.

Reimplemented from NetworkGameSocketHandler.

ServerNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND ( PACKET_CLIENT_ERROR   )  [protected]

The client made an error and is quiting the game.

uint8 Error of the code caused (see NetworkErrorCode).

Reimplemented from NetworkGameSocketHandler.

ServerNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND ( PACKET_CLIENT_CHAT   )  [protected]

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

Reimplemented from NetworkGameSocketHandler.

ServerNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND ( PACKET_CLIENT_COMMAND   )  [protected]

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.

Reimplemented from NetworkGameSocketHandler.

ServerNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND ( PACKET_CLIENT_ACK   )  [protected]

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.

Reimplemented from NetworkGameSocketHandler.

ServerNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND ( PACKET_CLIENT_GETMAP   )  [protected]

Request the map from the server.

uint32 NewGRF version (release versions of OpenTTD only).

Reimplemented from NetworkGameSocketHandler.

ServerNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND ( PACKET_CLIENT_COMPANY_PASSWORD   )  [protected]

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

string The password.

Reimplemented from NetworkGameSocketHandler.

ServerNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND ( PACKET_CLIENT_GAME_PASSWORD   )  [protected]

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

string The password.

Reimplemented from NetworkGameSocketHandler.

ServerNetworkGameSocketHandler::DECLARE_GAME_RECEIVE_COMMAND ( PACKET_CLIENT_JOIN   )  [protected]

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.

Reimplemented from NetworkGameSocketHandler.

const char * ServerNetworkGameSocketHandler::GetClientIP (  ) 

Get the IP address/hostname of the connected client.

Returns:
The IP address.

Definition at line 1814 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 1967 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.

Packet * ServerNetworkGameSocketHandler::ReceivePacket (  )  [virtual]

Receives a packet for the given client.

Parameters:
status the variable to store the status into
Returns:
the received packet (or NULL when it didn't receive one)

Reimplemented from NetworkTCPSocketHandler.

Definition at line 194 of file network_server.cpp.

References receive_limit, and Packet::size.

void ServerNetworkGameSocketHandler::Send (  )  [static]

Send the packets for the server sockets.

Definition at line 278 of file network_server.cpp.

References SPS_CLOSED, and STATUS_MAP.

void ServerNetworkGameSocketHandler::SendPacket ( Packet packet  )  [virtual]

This function puts the packet in the send-queue and it is send as soon as possible.

This is the next tick, or maybe one tick later if the OS-network-buffer is full)

Parameters:
packet the packet to send

Reimplemented from NetworkTCPSocketHandler.

Definition at line 207 of file network_server.cpp.

References ThreadMutex::BeginCritical(), ThreadMutex::EndCritical(), and savegame_mutex.


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

Generated on Sun May 15 19:21:26 2011 for OpenTTD by  doxygen 1.6.1