|
OpenTTD Source
14.0-beta3
|
Class for handling the client side of quering a game server. More...
#include <network_query.h>
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... | |
| bool | IsPendingDeletion () const |
| void | DeferDeletion () |
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 (std::unique_ptr< 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 std::unique_ptr< 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 ()=default |
| 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. | |
Static Public Member Functions inherited from NetworkGameSocketHandler | |
| static void | ProcessDeferredDeletions () |
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_t 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_t 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_t Generation seed. More... | |
| virtual NetworkRecvStatus | Receive_CLIENT_GAME_PASSWORD (Packet &p) |
| Send a password to the server to authorize: uint8_t Password type (see NetworkPasswordType). More... | |
| virtual NetworkRecvStatus | Receive_CLIENT_COMPANY_PASSWORD (Packet &p) |
| Send a password to the server to authorize uint8_t Password type (see NetworkPasswordType). More... | |
| virtual NetworkRecvStatus | Receive_SERVER_WELCOME (Packet &p) |
| The client is joined and ready to receive their map: uint32_t 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_t 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_t 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_t 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_t Frame counter uint32_t Frame counter max (how far may the client walk before the server?) uint32_t 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_t Frame counter. More... | |
| virtual NetworkRecvStatus | Receive_CLIENT_ACK (Packet &p) |
| Tell the server we are done with this frame: uint32_t Current frame counter of the client. More... | |
| virtual NetworkRecvStatus | Receive_CLIENT_COMMAND (Packet &p) |
| Send a DoCommand to the Server: uint8_t ID of the company (0..MAX_COMPANIES-1). More... | |
| virtual NetworkRecvStatus | Receive_SERVER_COMMAND (Packet &p) |
| Sends a DoCommand to the client: uint8_t ID of the company (0..MAX_COMPANIES-1). More... | |
| virtual NetworkRecvStatus | Receive_CLIENT_CHAT (Packet &p) |
| Sends a chat-packet to the server: uint8_t ID of the action (see NetworkAction). More... | |
| virtual NetworkRecvStatus | Receive_SERVER_CHAT (Packet &p) |
| Sends a chat-packet to the client: uint8_t 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_t 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_t 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_t 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_t 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_t ID of the client. More... | |
| virtual NetworkRecvStatus | Receive_CLIENT_MOVE (Packet &p) |
| Request the server to move this client into another company: uint8_t 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_t Bitwise representation of each company. More... | |
| virtual NetworkRecvStatus | Receive_SERVER_CONFIG_UPDATE (Packet &p) |
| Update the clients knowledge of the max settings: uint8_t 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_t | last_frame |
| Last frame we have executed. | |
| uint32_t | 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? | |
Class for handling the client side of quering a game server.
Definition at line 16 of file network_query.h.
|
inline |
Create a new socket for the client side of quering game server.
| s | The socket to connect with. |
| connection_string | The connection string of the server. |
Definition at line 39 of file network_query.h.
|
protected |
Check the connection's state, i.e.
is the connection still up?
Definition at line 42 of file network_query.cpp.
References CloseConnection(), connection_string, Debug, NetworkGameSocketHandler::last_packet, and NETWORK_RECV_STATUS_CONNECTION_LOST.
|
overridevirtual |
Close the network connection due to the given status.
| status | The reason the connection got closed. |
Implements NetworkGameSocketHandler.
Definition at line 22 of file network_query.cpp.
References connection_string, NETWORK_RECV_STATUS_OKAY, NetworkGameListAddItem(), NGLS_OFFLINE, NetworkGameList::refreshing, NetworkTCPSocketHandler::sock, NetworkGameList::status, and UpdateNetworkGameWindow().
Referenced by CheckConnection(), and Receive().
|
inlinestatic |
Start to query a server based on an open socket.
| 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.
|
protected |
Check whether we received/can send some data from/to the server and when that's the case handle it appropriately.
Definition at line 61 of file network_query.cpp.
References NetworkTCPSocketHandler::CanSendReceive(), CloseConnection(), NETWORK_RECV_STATUS_OKAY, and NetworkGameSocketHandler::ReceivePackets().
|
overrideprotectedvirtual |
Notification that the client trying to join is banned.
| p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 103 of file network_query.cpp.
References connection_string, Debug, NETWORK_RECV_STATUS_CLOSE_QUERY, NetworkGameListAddItem(), NGLS_BANNED, NetworkGameList::refreshing, NetworkGameList::status, and UpdateNetworkGameWindow().
|
overrideprotectedvirtual |
The client made an error: uint8_t Error code caused (see NetworkErrorCode).
| p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 137 of file network_query.cpp.
References connection_string, Debug, NetworkGameListAddItem(), and Packet::Recv_uint8().
|
overrideprotectedvirtual |
Notification that the server is full.
| p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 90 of file network_query.cpp.
References connection_string, Debug, NETWORK_RECV_STATUS_CLOSE_QUERY, NetworkGameListAddItem(), NGLS_FULL, NetworkGameList::refreshing, NetworkGameList::status, and UpdateNetworkGameWindow().
|
overrideprotectedvirtual |
Sends information about the game.
Serialized NetworkGameInfo. See game_info.h for details.
| p | The packet that was just received. |
Reimplemented from NetworkGameSocketHandler.
Definition at line 116 of file network_query.cpp.
References ClearGRFConfigList(), connection_string, Debug, NetworkServerGameInfo::grfconfig, NetworkGameList::info, NETWORK_RECV_STATUS_CLOSE_QUERY, NetworkGameListAddItem(), NGLS_ONLINE, NetworkGameList::refreshing, NetworkGameList::status, and UpdateNetworkGameWindow().