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:
Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, 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 ()
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 ()
 This sends the map to the client.
NetworkRecvStatus SendErrorQuit (ClientID client_id, NetworkErrorCode errorno)
 Tell the client another client quit with an error.
NetworkRecvStatus SendQuit (ClientID client_id)
 Tell the client another client quit.
NetworkRecvStatus SendShutdown ()
 Tell the client we're shutting down.
NetworkRecvStatus SendNewGame ()
 Tell the client we're starting a new game.
NetworkRecvStatus SendRConResult (uint16 colour, const char *command)
 Send the result of a console action.
NetworkRecvStatus SendMove (ClientID client_id, CompanyID company_id)
 Tell that a client moved to another company.
NetworkRecvStatus SendClientInfo (NetworkClientInfo *ci)
 Send the client information about a client.
NetworkRecvStatus SendError (NetworkErrorCode error)
 Send an error to the client, and close its connection.
NetworkRecvStatus SendChat (NetworkAction action, ClientID client_id, bool self_send, const char *msg, int64 data)
 Send a chat message.
NetworkRecvStatus SendJoin (ClientID client_id)
 Tell that a client joined.
NetworkRecvStatus SendFrame ()
 Tell the client that they may run to a particular frame.
NetworkRecvStatus SendSync ()
 Request the client to sync.
NetworkRecvStatus SendCommand (const CommandPacket *cp)
 Send a command to the client to execute.
NetworkRecvStatus SendCompanyUpdate ()
 Send an update about the company password states.
NetworkRecvStatus SendConfigUpdate ()
 Send an update about the max company/spectator counts.
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)
 Handle the accepting of a connection to the server.
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)
 Return the client state given it's client-identifier.

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.
struct PacketWritersavegame
 Writer used to write the savegame.
NetworkAddress client_address
 IP-address of the client (so he can be banned).

Protected Member Functions

virtual NetworkRecvStatus Receive_CLIENT_JOIN (Packet *p)
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_INFO (Packet *p)
virtual NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD (Packet *p)
virtual NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD (Packet *p)
virtual NetworkRecvStatus Receive_CLIENT_GETMAP (Packet *p)
virtual NetworkRecvStatus Receive_CLIENT_MAP_OK (Packet *p)
virtual NetworkRecvStatus Receive_CLIENT_ACK (Packet *p)
virtual NetworkRecvStatus Receive_CLIENT_COMMAND (Packet *p)
 The client has done a command and wants us to handle it.
virtual NetworkRecvStatus Receive_CLIENT_CHAT (Packet *p)
virtual NetworkRecvStatus Receive_CLIENT_SET_PASSWORD (Packet *p)
virtual NetworkRecvStatus Receive_CLIENT_SET_NAME (Packet *p)
virtual NetworkRecvStatus Receive_CLIENT_QUIT (Packet *p)
virtual NetworkRecvStatus Receive_CLIENT_ERROR (Packet *p)
virtual NetworkRecvStatus Receive_CLIENT_RCON (Packet *p)
virtual NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED (Packet *p)
virtual NetworkRecvStatus Receive_CLIENT_MOVE (Packet *p)
NetworkRecvStatus SendCompanyInfo ()
 Send the client information about the companies.
NetworkRecvStatus SendNewGRFCheck ()
 Send the check for the NewGRFs.
NetworkRecvStatus SendWelcome ()
 Send the client a welcome message with some basic information.
NetworkRecvStatus SendWait ()
 Tell the client that its put in a waiting queue.
NetworkRecvStatus SendNeedGamePassword ()
 Request the game password.
NetworkRecvStatus SendNeedCompanyPassword ()
 Request the company password.

Detailed Description

Class for handling the server side of the game connection.

Definition at line 29 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 57 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 221 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, Tpool_type, Tcache, Tzero >::MAX_SIZE, ClientSettings::network, receive_limit, and status.

Referenced by AcceptConnection().


Member Function Documentation

void ServerNetworkGameSocketHandler::AcceptConnection ( SOCKET  s,
const NetworkAddress address 
) [static]

Handle the accepting of a connection to the server.

Parameters:
s The socket of the new connection.
address The address of the peer.

Definition at line 495 of file network.cpp.

References client_address, ServerNetworkGameSocketHandler(), SetWindowDirty(), and WC_CLIENT_LIST.

ServerNetworkGameSocketHandler * ServerNetworkGameSocketHandler::GetByClientID ( ClientID  client_id  )  [static]

Return the client state given it's client-identifier.

Parameters:
client_id the ClientID to search for
Returns:
return a pointer to the corresponding NetworkClientSocket struct or NULL when not found

Definition at line 129 of file network.cpp.

References FOR_ALL_CLIENT_SOCKETS.

Referenced by SendCompanyInfo().

const char * ServerNetworkGameSocketHandler::GetClientIP (  ) 

Get the IP address/hostname of the connected client.

Returns:
The IP address.

Definition at line 1953 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 2141 of file network_server.cpp.

References NetworkGameSocketHandler::client_id, NetworkClientInfo::client_name, NetworkGameSocketHandler::GetInfo(), StrEmpty(), and ttd_strlcpy().

Referenced by SendError().

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 114 of file network_server.h.

void ServerNetworkGameSocketHandler::Send (  )  [static]

Send the packets for the server sockets.

Definition at line 325 of file network_server.cpp.

References FOR_ALL_CLIENT_SOCKETS, and SPS_CLOSED.

NetworkRecvStatus ServerNetworkGameSocketHandler::SendChat ( NetworkAction  action,
ClientID  client_id,
bool  self_send,
const char *  msg,
int64  data 
)

Send a chat message.

Parameters:
action The action associated with the message.
client_id The origin of the chat message.
self_send Whether we did send the message.
msg The actual message.
data Arbitrary extra data.

Definition at line 749 of file network_server.cpp.

References PACKET_SERVER_CHAT, Packet::Send_bool(), Packet::Send_string(), Packet::Send_uint32(), Packet::Send_uint64(), Packet::Send_uint8(), NetworkTCPSocketHandler::SendPacket(), and STATUS_PRE_ACTIVE.

NetworkRecvStatus ServerNetworkGameSocketHandler::SendClientInfo ( NetworkClientInfo ci  ) 

Send the client information about a client.

Parameters:
ci The client to send information about.

Definition at line 349 of file network_server.cpp.

References NetworkClientInfo::client_id, NetworkClientInfo::client_name, NetworkClientInfo::client_playas, INVALID_CLIENT_ID, PACKET_SERVER_CLIENT_INFO, Packet::Send_string(), Packet::Send_uint32(), Packet::Send_uint8(), and NetworkTCPSocketHandler::SendPacket().

Referenced by SendWelcome().

NetworkRecvStatus ServerNetworkGameSocketHandler::SendCommand ( const CommandPacket cp  ) 

Send a command to the client to execute.

Parameters:
cp The command to send.

Definition at line 729 of file network_server.cpp.

References CommandPacket::frame, CommandPacket::my_cmd, PACKET_SERVER_COMMAND, Packet::Send_bool(), Packet::Send_uint32(), and NetworkTCPSocketHandler::SendPacket().

NetworkRecvStatus ServerNetworkGameSocketHandler::SendCompanyUpdate (  ) 

Send an update about the company password states.

Definition at line 842 of file network_server.cpp.

References _network_company_passworded, PACKET_SERVER_COMPANY_UPDATE, Packet::Send_uint16(), and NetworkTCPSocketHandler::SendPacket().

NetworkRecvStatus ServerNetworkGameSocketHandler::SendConfigUpdate (  ) 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendError ( NetworkErrorCode  error  ) 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendErrorQuit ( ClientID  client_id,
NetworkErrorCode  errorno 
)

Tell the client another client quit with an error.

Parameters:
client_id The client that quit.
errorno The reason the client quit.

Definition at line 770 of file network_server.cpp.

References PACKET_SERVER_ERROR_QUIT, Packet::Send_uint32(), Packet::Send_uint8(), and NetworkTCPSocketHandler::SendPacket().

NetworkRecvStatus ServerNetworkGameSocketHandler::SendFrame (  ) 

Tell the client that they may run to a particular frame.

Definition at line 689 of file network_server.cpp.

References _frame_counter, _frame_counter_max, _sync_seed_1, last_token, PACKET_SERVER_FRAME, Packet::Send_uint32(), Packet::Send_uint8(), and NetworkTCPSocketHandler::SendPacket().

NetworkRecvStatus ServerNetworkGameSocketHandler::SendJoin ( ClientID  client_id  ) 

Tell that a client joined.

Parameters:
client_id The client that joined.

Definition at line 678 of file network_server.cpp.

References PACKET_SERVER_JOIN, Packet::Send_uint32(), and NetworkTCPSocketHandler::SendPacket().

NetworkRecvStatus ServerNetworkGameSocketHandler::SendMove ( ClientID  client_id,
CompanyID  company_id 
)

Tell that a client moved to another company.

Parameters:
client_id The client that moved.
company_id The company the client moved to.

Definition at line 831 of file network_server.cpp.

References PACKET_SERVER_MOVE, Packet::Send_uint32(), Packet::Send_uint8(), and NetworkTCPSocketHandler::SendPacket().

NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGame (  ) 

Tell the client we're starting a new game.

Definition at line 804 of file network_server.cpp.

References PACKET_SERVER_NEWGAME, and NetworkTCPSocketHandler::SendPacket().

NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGRFCheck (  )  [protected]
NetworkRecvStatus ServerNetworkGameSocketHandler::SendQuit ( ClientID  client_id  ) 

Tell the client another client quit.

Parameters:
client_id The client that quit.

Definition at line 785 of file network_server.cpp.

References PACKET_SERVER_QUIT, Packet::Send_uint32(), and NetworkTCPSocketHandler::SendPacket().

NetworkRecvStatus ServerNetworkGameSocketHandler::SendRConResult ( uint16  colour,
const char *  command 
)

Send the result of a console action.

Parameters:
colour The colour of the result.
command The command that was executed.

Definition at line 816 of file network_server.cpp.

References PACKET_SERVER_RCON, Packet::Send_string(), Packet::Send_uint16(), and NetworkTCPSocketHandler::SendPacket().

NetworkRecvStatus ServerNetworkGameSocketHandler::SendShutdown (  ) 

Tell the client we're shutting down.

Definition at line 796 of file network_server.cpp.

References PACKET_SERVER_SHUTDOWN, and NetworkTCPSocketHandler::SendPacket().

NetworkRecvStatus ServerNetworkGameSocketHandler::SendSync (  ) 

Request the client to sync.

Definition at line 712 of file network_server.cpp.

References _frame_counter, _sync_seed_1, PACKET_SERVER_SYNC, Packet::Send_uint32(), and NetworkTCPSocketHandler::SendPacket().

NetworkRecvStatus ServerNetworkGameSocketHandler::SendWait (  )  [protected]

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