OpenTTD
Public Member Functions | Protected Member Functions
ServerNetworkUDPSocketHandler Class Reference

*** Communication with clients (we are server) ***/ More...

Inheritance diagram for ServerNetworkUDPSocketHandler:
NetworkUDPSocketHandler NetworkSocketHandler

Public Member Functions

 ServerNetworkUDPSocketHandler (NetworkAddressList *addresses)
 Create the socket.
- Public Member Functions inherited from NetworkUDPSocketHandler
 NetworkUDPSocketHandler (NetworkAddressList *bind=NULL)
 Create an UDP socket but don't listen yet.
virtual ~NetworkUDPSocketHandler ()
 On destructing of this class, the socket needs to be closed.
bool Listen ()
 Start listening on the given host and port.
void Close ()
 Close the given UDP socket.
void SendPacket (Packet *p, NetworkAddress *recv, bool all=false, bool broadcast=false)
 Send a packet over UDP.
void ReceivePackets ()
 Receive a packet at UDP level.
void SendNetworkGameInfo (Packet *p, const NetworkGameInfo *info)
 Serializes the NetworkGameInfo struct to the packet.
void ReceiveNetworkGameInfo (Packet *p, NetworkGameInfo *info)
 Deserializes the NetworkGameInfo struct from the packet.
- Public Member Functions inherited from NetworkSocketHandler
 NetworkSocketHandler ()
 Create a new unbound socket.
virtual ~NetworkSocketHandler ()
 Close the socket when destructing the socket handler.
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.

Protected Member Functions

virtual void Receive_CLIENT_FIND_SERVER (Packet *p, NetworkAddress *client_addr)
 Queries to the server for information about the game.
virtual void Receive_CLIENT_DETAIL_INFO (Packet *p, NetworkAddress *client_addr)
 Query for detailed information about companies.
virtual void Receive_CLIENT_GET_NEWGRFS (Packet *p, NetworkAddress *client_addr)
 A client has requested the names of some NewGRFs.
- Protected Member Functions inherited from NetworkUDPSocketHandler
NetworkRecvStatus CloseConnection (bool error=true)
 Close the current connection; for TCP this will be mostly equivalent to Close(), but for UDP it just means the packet has to be dropped.
void ReceiveInvalidPacket (PacketUDPType, NetworkAddress *client_addr)
 Helper for logging receiving invalid packets.
virtual void Receive_SERVER_RESPONSE (Packet *p, NetworkAddress *client_addr)
 Return of server information to the client.
virtual void Receive_SERVER_DETAIL_INFO (Packet *p, NetworkAddress *client_addr)
 Reply with detailed company information.
virtual void Receive_SERVER_REGISTER (Packet *p, NetworkAddress *client_addr)
 Registers the server to the master server.
virtual void Receive_MASTER_ACK_REGISTER (Packet *p, NetworkAddress *client_addr)
 The master server acknowledges the registration.
virtual void Receive_CLIENT_GET_LIST (Packet *p, NetworkAddress *client_addr)
 The client requests a list of servers.
virtual void Receive_MASTER_RESPONSE_LIST (Packet *p, NetworkAddress *client_addr)
 The server sends a list of servers.
virtual void Receive_SERVER_UNREGISTER (Packet *p, NetworkAddress *client_addr)
 A server unregisters itself at the master server.
virtual void Receive_SERVER_NEWGRFS (Packet *p, NetworkAddress *client_addr)
 The server returns information about some NewGRFs.
virtual void Receive_MASTER_SESSION_KEY (Packet *p, NetworkAddress *client_addr)
 The master server sends us a session key.
void HandleUDPPacket (Packet *p, NetworkAddress *client_addr)
 Handle an incoming packets by sending it to the correct function.
virtual void HandleIncomingNetworkGameInfoGRFConfig (GRFConfig *config)
 Function that is called for every GRFConfig that is read when receiving a NetworkGameInfo.

Additional Inherited Members

- Protected Attributes inherited from NetworkUDPSocketHandler
NetworkAddressList bind
 The address to bind to.
SocketList sockets
 The opened sockets.

Detailed Description

*** Communication with clients (we are server) ***/

Helper class for handling all server side communication.

Definition at line 151 of file network_udp.cpp.

Constructor & Destructor Documentation

ServerNetworkUDPSocketHandler::ServerNetworkUDPSocketHandler ( NetworkAddressList addresses)
inline

Create the socket.

Parameters
addressesThe addresses to bind on.

Definition at line 161 of file network_udp.cpp.

Member Function Documentation

void ServerNetworkUDPSocketHandler::Receive_CLIENT_DETAIL_INFO ( Packet p,
NetworkAddress client_addr 
)
protectedvirtual
void ServerNetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER ( Packet p,
NetworkAddress client_addr 
)
protectedvirtual

Queries to the server for information about the game.

Parameters
pThe received packet.
client_addrThe origin of the packet.

Reimplemented from NetworkUDPSocketHandler.

Definition at line 165 of file network_udp.cpp.

References _date, _grfconfig, _network_dedicated, _network_game_info, _network_udp_server, _settings_client, _settings_game, NetworkGameInfo::clients_max, NetworkServerGameInfo::clients_on, NetworkGameInfo::companies_max, NetworkGameInfo::companies_on, ConvertYMDToDate(), DEBUG, NetworkGameInfo::dedicated, GameSettings::game_creation, NetworkGameInfo::game_date, NetworkAddress::GetHostname(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetNumItems(), NetworkGameInfo::grfconfig, GameCreationSettings::landscape, lastof, NetworkGameInfo::map_height, NetworkServerGameInfo::map_name, NetworkGameInfo::map_set, NetworkGameInfo::map_width, MapSizeX(), MapSizeY(), NetworkSettings::max_clients, NetworkSettings::max_companies, NetworkSettings::max_spectators, ClientSettings::network, PACKET_UDP_SERVER_RESPONSE, NetworkUDPSocketHandler::SendNetworkGameInfo(), NetworkUDPSocketHandler::SendPacket(), NetworkGameInfo::server_lang, NetworkSettings::server_lang, NetworkGameInfo::server_name, NetworkSettings::server_name, NetworkSettings::server_password, NetworkGameInfo::server_revision, NetworkGameInfo::spectators_max, NetworkGameInfo::spectators_on, NetworkGameInfo::start_date, GameCreationSettings::starting_year, strecpy(), StrEmpty(), and NetworkGameInfo::use_password.

void ServerNetworkUDPSocketHandler::Receive_CLIENT_GET_NEWGRFS ( Packet p,
NetworkAddress client_addr 
)
protectedvirtual

A client has requested the names of some NewGRFs.

Replying this can be tricky as we have a limit of SEND_MTU bytes in the reply packet and we can send up to 100 bytes per NewGRF (GRF ID, MD5sum and NETWORK_GRF_NAME_LENGTH bytes for the name). As SEND_MTU is much less than 100 * NETWORK_MAX_GRF_COUNT, it could be that a packet overflows. To stop this we only reply with the first N NewGRFs so that if the first N + 1 NewGRFs would be sent, the packet overflows. in_reply and in_reply_count are used to keep a list of GRFs to send in the reply.

Reimplemented from NetworkUDPSocketHandler.

Definition at line 272 of file network_udp.cpp.

References DEBUG, FGCM_EXACT, FindGRFConfig(), NetworkAddress::GetAddressAsString(), GRFConfig::GetName(), GRFIdentifier::grfid, lastof, GRFIdentifier::md5sum, min(), NETWORK_GRF_NAME_LENGTH, NETWORK_MAX_GRF_COUNT, PACKET_UDP_SERVER_NEWGRFS, NetworkSocketHandler::ReceiveGRFIdentifier(), Packet::Recv_uint8(), SEND_MTU, Packet::Send_string(), Packet::Send_uint8(), NetworkSocketHandler::SendGRFIdentifier(), NetworkUDPSocketHandler::SendPacket(), and strecpy().


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