OpenTTD Source: QueryNetworkGameSocketHandler Class Reference

OpenTTD Source 13.2.1

Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes
QueryNetworkGameSocketHandler Class Reference

Class for handling the client side of quering a game server. More...

`#include <network_query.h>`

Inheritance diagram for QueryNetworkGameSocketHandler:

## Public Member Functions
| QueryNetworkGameSocketHandler (SOCKET s, const std::string &connection_string)
| Create a new socket for the client side of quering game server. More...
NetworkRecvStatus | CloseConnection (NetworkRecvStatus status) override
| Close the network connection due to the given status. More...
Public Member Functions inherited from ZeroedMemoryAllocator
void * | operator new (size_t size)
| Memory allocator for a single class instance. More...
void * | operator new[] (size_t size)
| Memory allocator for an array of class instances. More...
void | operator delete (void *ptr)
| Memory release for a single class instance. More...
void | operator delete[] (void *ptr)
| Memory release for an array of class instances. More...
Public Member Functions inherited from NetworkGameSocketHandler
NetworkRecvStatus | CloseConnection (bool error=true) override
| Functions to help ReceivePacket/SendPacket a bit A socket can make errors. More...
void | SetInfo (NetworkClientInfo *info)
| Sets the client info for this socket handler. More...
NetworkClientInfo * | GetInfo () const
| Gets the client info of this socket handler. More...
NetworkRecvStatus | ReceivePackets ()
| Do the actual receiving of packets. More...
const char * | ReceiveCommand (Packet *p, CommandPacket *cp)
| Receives a command from the network. More...
void | SendCommand (Packet *p, const CommandPacket *cp)
| Sends a command over the network. More...
Public Member Functions inherited from NetworkTCPSocketHandler
bool | IsConnected () const
| Whether this socket is currently bound to a socket. More...
void | CloseSocket ()
| Close the actual socket of the connection. More...
virtual void | SendPacket (Packet *packet)
| This function puts the packet in the send-queue and it is send as soon as possible. More...
SendPacketsState | SendPackets (bool closing_down=false)
| Sends all the buffered packets out for this client. More...
virtual Packet * | ReceivePacket ()
| Receives a packet for the given client. More...
bool | CanSendReceive ()
| Check whether this socket can send or receive something. More...
bool | HasSendQueue ()
| Whether there is something pending in the send queue. More...
| NetworkTCPSocketHandler (SOCKET s=INVALID_SOCKET)
| Construct a socket handler for a TCP connection. More...
Public Member Functions inherited from NetworkSocketHandler
| NetworkSocketHandler ()
| Create a new unbound socket.
virtual | ~NetworkSocketHandler ()
| Close the socket when destructing the socket handler.
void | MarkClosed ()
| Mark the connection as closed. More...
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.

## Static Public Member Functions
static void | QueryServer (SOCKET s, const std::string &connection_string)
| Start to query a server based on an open socket. More...
static void | SendReceive ()
| Check if any query needs to send or receive.

## Protected Member Functions
NetworkRecvStatus | Receive_SERVER_FULL (Packet *p) override
| Notification that the server is full. More...
NetworkRecvStatus | Receive_SERVER_BANNED (Packet *p) override
| Notification that the client trying to join is banned. More...
NetworkRecvStatus | Receive_SERVER_ERROR (Packet *p) override
| The client made an error: uint8 Error code caused (see NetworkErrorCode). More...
NetworkRecvStatus | Receive_SERVER_GAME_INFO (Packet *p) override
| Sends information about the game. More...
NetworkRecvStatus | SendGameInfo ()
| Query the server for server information.
bool | CheckConnection ()
| Check the connection's state, i.e. More...
void | Send ()
| Send the packets of this socket handler.
bool | Receive ()
| Check whether we received/can send some data from/to the server and when that's the case handle it appropriately. More...
Protected Member Functions inherited from NetworkGameSocketHandler
NetworkRecvStatus | ReceiveInvalidPacket (PacketGameType type)
| Helper for logging receiving invalid packets. More...
virtual NetworkRecvStatus | Receive_CLIENT_JOIN (Packet *p)
| Try to join the server: string OpenTTD revision (norev000 if no revision). More...
virtual NetworkRecvStatus | Receive_CLIENT_GAME_INFO (Packet *p)
| Request game information. More...
virtual NetworkRecvStatus | Receive_SERVER_CLIENT_INFO (Packet *p)
| Send information about a client: uint32 ID of the client (always unique on a server. More...
virtual NetworkRecvStatus | Receive_SERVER_NEED_GAME_PASSWORD (Packet *p)
| Indication to the client that the server needs a game password. More...
virtual NetworkRecvStatus | Receive_SERVER_NEED_COMPANY_PASSWORD (Packet *p)
| Indication to the client that the server needs a company password: uint32 Generation seed. More...
virtual NetworkRecvStatus | Receive_CLIENT_GAME_PASSWORD (Packet *p)
| Send a password to the server to authorize: uint8 Password type (see NetworkPasswordType). More...
virtual NetworkRecvStatus | Receive_CLIENT_COMPANY_PASSWORD (Packet *p)
| Send a password to the server to authorize uint8 Password type (see NetworkPasswordType). More...
virtual NetworkRecvStatus | Receive_SERVER_WELCOME (Packet *p)
| The client is joined and ready to receive their map: uint32 Own client ID. More...
virtual NetworkRecvStatus | Receive_CLIENT_GETMAP (Packet *p)
| Request the map from the server. More...
virtual NetworkRecvStatus | Receive_SERVER_WAIT (Packet *p)
| Notification that another client is currently receiving the map: uint8 Number of clients waiting in front of you. More...
virtual NetworkRecvStatus | Receive_SERVER_MAP_BEGIN (Packet *p)
| Sends that the server will begin with sending the map to the client: uint32 Current frame. More...
virtual NetworkRecvStatus | Receive_SERVER_MAP_SIZE (Packet *p)
| Sends the size of the map to the client. More...
virtual NetworkRecvStatus | Receive_SERVER_MAP_DATA (Packet *p)
| Sends the data of the map to the client: Contains a part of the map (until max size of packet). More...
virtual NetworkRecvStatus | Receive_SERVER_MAP_DONE (Packet *p)
| Sends that all data of the map are sent to the client: More...
virtual NetworkRecvStatus | Receive_CLIENT_MAP_OK (Packet *p)
| Tell the server that we are done receiving/loading the map. More...
virtual NetworkRecvStatus | Receive_SERVER_JOIN (Packet *p)
| A client joined (PACKET_CLIENT_MAP_OK), what usually directly follows is a PACKET_SERVER_CLIENT_INFO: uint32 ID of the client that just joined the game. More...
virtual NetworkRecvStatus | Receive_SERVER_FRAME (Packet *p)
| Sends the current frame counter to the client: uint32 Frame counter uint32 Frame counter max (how far may the client walk before the server?) uint32 General seed 1 (dependent on compile settings, not default). More...
virtual NetworkRecvStatus | Receive_SERVER_SYNC (Packet *p)
| Sends a sync-check to the client: uint32 Frame counter. More...
virtual NetworkRecvStatus | Receive_CLIENT_ACK (Packet *p)
| Tell the server we are done with this frame: uint32 Current frame counter of the client. More...
virtual NetworkRecvStatus | Receive_CLIENT_COMMAND (Packet *p)
| Send a DoCommand to the Server: uint8 ID of the company (0..MAX_COMPANIES-1). More...
virtual NetworkRecvStatus | Receive_SERVER_COMMAND (Packet *p)
| Sends a DoCommand to the client: uint8 ID of the company (0..MAX_COMPANIES-1). More...
virtual NetworkRecvStatus | Receive_CLIENT_CHAT (Packet *p)
| Sends a chat-packet to the server: uint8 ID of the action (see NetworkAction). More...
virtual NetworkRecvStatus | Receive_SERVER_CHAT (Packet *p)
| Sends a chat-packet to the client: uint8 ID of the action (see NetworkAction). More...
virtual NetworkRecvStatus | Receive_SERVER_EXTERNAL_CHAT (Packet *p)
| Sends a chat-packet for external source to the client: string Name of the source this message came from. More...
virtual NetworkRecvStatus | Receive_CLIENT_SET_PASSWORD (Packet *p)
| Set the password for the clients current company: string The password. More...
virtual NetworkRecvStatus | Receive_CLIENT_SET_NAME (Packet *p)
| Gives the client a new name: string New name of the client. More...
virtual NetworkRecvStatus | Receive_CLIENT_QUIT (Packet *p)
| The client is quitting the game. More...
virtual NetworkRecvStatus | Receive_CLIENT_ERROR (Packet *p)
| The client made an error and is quitting the game. More...
virtual NetworkRecvStatus | Receive_SERVER_QUIT (Packet *p)
| Notification that a client left the game: uint32 ID of the client. More...
virtual NetworkRecvStatus | Receive_SERVER_ERROR_QUIT (Packet *p)
| Inform all clients that one client made an error and thus has quit/been disconnected: uint32 ID of the client that caused the error. More...
virtual NetworkRecvStatus | Receive_SERVER_SHUTDOWN (Packet *p)
| Let the clients know that the server is closing. More...
virtual NetworkRecvStatus | Receive_SERVER_NEWGAME (Packet *p)
| Let the clients know that the server is loading a new map. More...
virtual NetworkRecvStatus | Receive_SERVER_RCON (Packet *p)
| Send the result of an issues RCon command back to the client: uint16 Colour code. More...
virtual NetworkRecvStatus | Receive_CLIENT_RCON (Packet *p)
| Send an RCon command to the server: string RCon password. More...
virtual NetworkRecvStatus | Receive_SERVER_CHECK_NEWGRFS (Packet *p)
| Sends information about all used GRFs to the client: uint8 Amount of GRFs (the following data is repeated this many times, i.e. More...
virtual NetworkRecvStatus | Receive_CLIENT_NEWGRFS_CHECKED (Packet *p)
| Tell the server that we have the required GRFs. More...
virtual NetworkRecvStatus | Receive_SERVER_MOVE (Packet *p)
| Move a client from one company into another: uint32 ID of the client. More...
virtual NetworkRecvStatus | Receive_CLIENT_MOVE (Packet *p)
| Request the server to move this client into another company: uint8 ID of the company the client wants to join. More...
virtual NetworkRecvStatus | Receive_SERVER_COMPANY_UPDATE (Packet *p)
| Update the clients knowledge of which company is password protected: uint16 Bitwise representation of each company. More...
virtual NetworkRecvStatus | Receive_SERVER_CONFIG_UPDATE (Packet *p)
| Update the clients knowledge of the max settings: uint8 Maximum number of companies allowed. More...
NetworkRecvStatus | HandlePacket (Packet *p)
| Handle the given packet, i.e. More...
| NetworkGameSocketHandler (SOCKET s)
| Create a new socket for the game connection. More...

## Private Attributes
std::string | connection_string
| Address we are connected to.

## Static Private Attributes
static std::vector< std::unique_ptr< QueryNetworkGameSocketHandler > > | queries = {}
| Pending queries.

## Additional Inherited Members
Data Fields inherited from NetworkGameSocketHandler
ClientID | client_id
| Client identifier.
uint32 | last_frame
| Last frame we have executed.
uint32 | last_frame_server
| Last frame the server has executed.
CommandQueue | incoming_queue
| The command-queue awaiting handling.
std::chrono::steady_clock::time_point | last_packet
| Time we received the last frame.
Data Fields inherited from NetworkTCPSocketHandler
SOCKET | sock
| The socket currently connected to.
bool | writable
| Can we write to this socket?

## Detailed Description

Class for handling the client side of quering a game server.

Definition at line 16 of file network_query.h.

## Constructor & Destructor Documentation

## ◆ QueryNetworkGameSocketHandler()

QueryNetworkGameSocketHandler::QueryNetworkGameSocketHandler | ( | SOCKET | s,
|  | const std::string & | connection_string
| ) |  |
| inline

Create a new socket for the client side of quering game server.

Parameters

  s | The socket to connect with.
  connection_string | The connection string of the server.

Definition at line 39 of file network_query.h.

## Member Function Documentation

## ◆ CheckConnection()

bool QueryNetworkGameSocketHandler::CheckConnection | ( |  | ) |
| protected

Check the connection's state, i.e.

is the connection still up?

Definition at line 33 of file network_query.cpp.

References CloseConnection(), NetworkGameSocketHandler::last_packet, and NETWORK_RECV_STATUS_CONNECTION_LOST.

## ◆ CloseConnection()

NetworkRecvStatus QueryNetworkGameSocketHandler::CloseConnection | ( | NetworkRecvStatus | status | ) |
| overridevirtual

Close the network connection due to the given status.

Parameters

  status | The reason the connection got closed.

Implements NetworkGameSocketHandler.

Definition at line 22 of file network_query.cpp.

References NETWORK_RECV_STATUS_OKAY, and NetworkTCPSocketHandler::sock.

Referenced by CheckConnection(), and Receive().

## ◆ QueryServer()

static void QueryNetworkGameSocketHandler::QueryServer | ( | SOCKET | s,
|  | const std::string & | connection_string
| ) |  |
| inlinestatic

Start to query a server based on an open socket.

Parameters

  s | The socket to connect with.
  connection_string | The connection string of the server.

Definition at line 46 of file network_query.h.

References connection_string, and queries.

Referenced by TCPQueryConnecter::OnConnect().

## ◆ Receive()

bool QueryNetworkGameSocketHandler::Receive | ( |  | ) |
| protected

Check whether we received/can send some data from/to the server and when that's the case handle it appropriately.

Returns
  true when everything went okay.

Definition at line 51 of file network_query.cpp.

References NetworkTCPSocketHandler::CanSendReceive(), CloseConnection(), NETWORK_RECV_STATUS_OKAY, and NetworkGameSocketHandler::ReceivePackets().

## ◆ Receive_SERVER_BANNED()

NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_BANNED | ( | Packet * | p | ) |
| overrideprotectedvirtual

Notification that the client trying to join is banned.

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 89 of file network_query.cpp.

References connection_string, NETWORK_RECV_STATUS_CLOSE_QUERY, NetworkGameListAddItem(), NGLS_BANNED, NetworkGameList::refreshing, NetworkGameList::status, and UpdateNetworkGameWindow().

## ◆ Receive_SERVER_ERROR()

NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_ERROR | ( | Packet * | p | ) |
| overrideprotectedvirtual

The client made an error: uint8 Error code caused (see NetworkErrorCode).

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 119 of file network_query.cpp.

References connection_string, error(), NetworkGameListAddItem(), and Packet::Recv_uint8().

## ◆ Receive_SERVER_FULL()

NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_FULL | ( | Packet * | p | ) |
| overrideprotectedvirtual

Notification that the server is full.

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 78 of file network_query.cpp.

References connection_string, NETWORK_RECV_STATUS_CLOSE_QUERY, NetworkGameListAddItem(), NGLS_FULL, NetworkGameList::refreshing, NetworkGameList::status, and UpdateNetworkGameWindow().

## ◆ Receive_SERVER_GAME_INFO()

NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_GAME_INFO | ( | Packet * | p | ) |
| overrideprotectedvirtual

Sends information about the game.

Serialized NetworkGameInfo. See game_info.h for details.

Parameters

  p | The packet that was just received.

Reimplemented from NetworkGameSocketHandler.

Definition at line 100 of file network_query.cpp.

References CheckGameCompatibility(), ClearGRFConfigList(), connection_string, DeserializeNetworkGameInfo(), NetworkServerGameInfo::grfconfig, NetworkGameList::info, NETWORK_RECV_STATUS_CLOSE_QUERY, NetworkGameListAddItem(), NGLS_ONLINE, NetworkGameList::refreshing, NetworkGameList::status, and UpdateNetworkGameWindow().

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

- src/network/network_query.h
- src/network/network_query.cpp