OpenTTD Source: ClientNetworkUDPSocketHandler Class Reference

OpenTTD Source 1.11.0-RC1

Protected Member Functions
ClientNetworkUDPSocketHandler Class Reference

‍*** Communication with servers (we are client) ***‍/ More...

Inheritance diagram for ClientNetworkUDPSocketHandler:

## Protected Member Functions
void | Receive_SERVER_RESPONSE (Packet *p, NetworkAddress *client_addr) override
| Return of server information to the client. More...
void | Receive_MASTER_RESPONSE_LIST (Packet *p, NetworkAddress *client_addr) override
| The server sends a list of servers. More...
void | Receive_SERVER_NEWGRFS (Packet *p, NetworkAddress *client_addr) override
| The return of the client's request of the names of some NewGRFs.
void | HandleIncomingNetworkGameInfoGRFConfig (GRFConfig *config) override
| Function that is called for every GRFConfig that is read when receiving a NetworkGameInfo. More...
Protected Member Functions inherited from NetworkUDPSocketHandler
NetworkRecvStatus | CloseConnection (bool error=true) override
| 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. More...
void | ReceiveInvalidPacket (PacketUDPType, NetworkAddress *client_addr)
| Helper for logging receiving invalid packets. More...
virtual void | Receive_CLIENT_FIND_SERVER (Packet *p, NetworkAddress *client_addr)
| Queries to the server for information about the game. More...
virtual void | Receive_CLIENT_DETAIL_INFO (Packet *p, NetworkAddress *client_addr)
| Query for detailed information about companies. More...
virtual void | Receive_SERVER_DETAIL_INFO (Packet *p, NetworkAddress *client_addr)
| Reply with detailed company information. More...
virtual void | Receive_SERVER_REGISTER (Packet *p, NetworkAddress *client_addr)
| Registers the server to the master server. More...
virtual void | Receive_MASTER_ACK_REGISTER (Packet *p, NetworkAddress *client_addr)
| The master server acknowledges the registration. More...
virtual void | Receive_CLIENT_GET_LIST (Packet *p, NetworkAddress *client_addr)
| The client requests a list of servers. More...
virtual void | Receive_SERVER_UNREGISTER (Packet *p, NetworkAddress *client_addr)
| A server unregisters itself at the master server. More...
virtual void | Receive_CLIENT_GET_NEWGRFS (Packet *p, NetworkAddress *client_addr)
| The client requests information about some NewGRFs. More...
virtual void | Receive_MASTER_SESSION_KEY (Packet *p, NetworkAddress *client_addr)
| The master server sends us a session key. More...
void | HandleUDPPacket (Packet *p, NetworkAddress *client_addr)
| Handle an incoming packets by sending it to the correct function. More...

## Additional Inherited Members
Public Member Functions inherited from NetworkUDPSocketHandler
| NetworkUDPSocketHandler (NetworkAddressList *bind=nullptr)
| Create an UDP socket but don't listen yet. More...
virtual | ~NetworkUDPSocketHandler ()
| On destructing of this class, the socket needs to be closed.
bool | Listen ()
| Start listening on the given host and port. More...
void | Close () override
| Close the given UDP socket.
void | SendPacket (Packet *p, NetworkAddress *recv, bool all=false, bool broadcast=false)
| Send a packet over UDP. More...
void | ReceivePackets ()
| Receive a packet at UDP level.
void | SendNetworkGameInfo (Packet *p, const NetworkGameInfo *info)
| Serializes the NetworkGameInfo struct to the packet. More...
void | ReceiveNetworkGameInfo (Packet *p, NetworkGameInfo *info)
| Deserializes the NetworkGameInfo struct from the packet. More...
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. More...
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. More...
void | ReceiveGRFIdentifier (Packet *p, GRFIdentifier *grf)
| Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet. More...
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. More...
Protected Attributes inherited from NetworkUDPSocketHandler
NetworkAddressList | bind
| The address to bind to.
SocketList | sockets
| The opened sockets.

## Detailed Description

‍*** Communication with servers (we are client) ***‍/

Helper class for handling all client side communication.

Definition at line 293 of file network_udp.cpp.

## Member Function Documentation

## ◆ HandleIncomingNetworkGameInfoGRFConfig()

void ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig | ( | GRFConfig * | config | ) |
| overrideprotectedvirtual

Function that is called for every GRFConfig that is read when receiving a NetworkGameInfo.

Only grfid and md5sum are set, the rest is zero. This function must set all appropriate fields. This GRF is later appended to the grfconfig list of the NetworkGameInfo.

Parameters

  config | the GRF to handle

Reimplemented from NetworkUDPSocketHandler.

Definition at line 436 of file network_udp.cpp.

References FGCM_EXACT, GRFConfig::filename, FindGRFConfig(), FindUnknownGRFName(), GRFConfig::flags, GCF_COPY, GCS_NOT_FOUND, GRFIdentifier::grfid, GRFConfig::ident, GRFConfig::info, GRFIdentifier::md5sum, GRFConfig::name, SetBit(), GRFConfig::status, and GRFConfig::url.

## ◆ Receive_MASTER_RESPONSE_LIST()

void ClientNetworkUDPSocketHandler::Receive_MASTER_RESPONSE_LIST | ( | Packet * | p,
|  | NetworkAddress * | client_addr
| ) |  |
| overrideprotectedvirtual

The server sends a list of servers.

uint8 The protocol version. For each server: 4 or 16 bytes of IPv4 or IPv6 address. uint8 The port.

Parameters

  p | The received packet.
  client_addr | The origin of the packet.

Reimplemented from NetworkUDPSocketHandler.

Definition at line 369 of file network_udp.cpp.

References Packet::Recv_uint16(), Packet::Recv_uint8(), SLT_END, and SLT_IPv4.

## ◆ Receive_SERVER_RESPONSE()

void ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE | ( | Packet * | p,
|  | NetworkAddress * | client_addr
| ) |  |
| overrideprotectedvirtual

Return of server information to the client.

This packet has several legacy versions, so we list the version and size of each "field":

Version: Bytes: Description: all 1 the version of this packet's structure

4+ 1 number of GRFs attached (n) 4+ n * 20 unique identifier for GRF files. Consists of:

- one 4 byte variable with the GRF ID
- 16 bytes (sent sequentially) for the MD5 checksum of the GRF

3+ 4 current game date in days since 1-1-0 (DMY) 3+ 4 game introduction date in days since 1-1-0 (DMY)

2+ 1 maximum number of companies allowed on the server 2+ 1 number of companies on the server 2+ 1 maximum number of spectators allowed on the server

1+ var string with the name of the server 1+ var string with the revision of the server 1+ 1 the language run on the server (0 = any, 1 = English, 2 = German, 3 = French) 1+ 1 whether the server uses a password (0 = no, 1 = yes) 1+ 1 maximum number of clients allowed on the server 1+ 1 number of clients on the server 1+ 1 number of spectators on the server 1 & 2 2 current game date in days since 1-1-1920 (DMY) 1 & 2 2 game introduction date in days since 1-1-1920 (DMY) 1+ var string with the name of the map 1+ 2 width of the map in tiles 1+ 2 height of the map in tiles 1+ 1 type of map: (0 = temperate, 1 = arctic, 2 = desert, 3 = toyland) 1+ 1 whether the server is dedicated (0 = no, 1 = yes)

Parameters

  p | The received packet.
  client_addr | The origin of the packet.

Reimplemented from NetworkUDPSocketHandler.

Definition at line 303 of file network_udp.cpp.

References _network_udp_server, NetworkGameList::address, ClearGRFConfigList(), NetworkGameInfo::compatible, DEBUG, GCS_NOT_FOUND, NetworkAddress::GetAddress(), NetworkAddress::GetAddressAsString(), NetworkAddress::GetHostname(), GRFConfig::GetName(), NetworkGameInfo::grfconfig, NetworkGameInfo::hostname, NetworkGameList::info, IsNetworkCompatibleVersion(), lastof, NETWORK_MAX_GRF_COUNT, NetworkGameListAddItem(), GRFConfig::next, NetworkGameList::online, PACKET_UDP_CLIENT_GET_NEWGRFS, NetworkUDPSocketHandler::ReceiveNetworkGameInfo(), Packet::Send_uint8(), NetworkSocketHandler::SendGRFIdentifier(), NetworkUDPSocketHandler::SendPacket(), seprintf(), NetworkGameInfo::server_name, NetworkGameInfo::server_revision, GRFConfig::status, strecat(), UNKNOWN_GRF_NAME_PLACEHOLDER, UpdateNetworkGameWindow(), and NetworkGameInfo::version_compatible.

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

- src/network/network_udp.cpp