OpenTTD Source  20240919-master-gdf0233f4c2
network_query.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef NETWORK_QUERY_H
11 #define NETWORK_QUERY_H
12 
13 #include "network_internal.h"
14 
17 private:
18  static std::vector<std::unique_ptr<QueryNetworkGameSocketHandler>> queries;
19  std::string connection_string;
20 
21 protected:
26 
28 
29  bool CheckConnection();
30  void Send();
31  bool Receive();
32 
33 public:
40 
46  static void QueryServer(SOCKET s, const std::string &connection_string)
47  {
48  auto query = std::make_unique<QueryNetworkGameSocketHandler>(s, connection_string);
49  query->SendGameInfo();
50 
51  QueryNetworkGameSocketHandler::queries.push_back(std::move(query));
52  }
53 
54  static void SendReceive();
55 
57 };
58 
59 #endif /* NETWORK_QUERY_H */
QueryNetworkGameSocketHandler::Send
void Send()
Send the packets of this socket handler.
Definition: network_query.cpp:74
QueryNetworkGameSocketHandler::Receive
bool Receive()
Check whether we received/can send some data from/to the server and when that's the case handle it ap...
Definition: network_query.cpp:61
NetworkGameSocketHandler
Base socket handler for all TCP sockets.
Definition: tcp_game.h:141
QueryNetworkGameSocketHandler::queries
static std::vector< std::unique_ptr< QueryNetworkGameSocketHandler > > queries
Pending queries.
Definition: network_query.h:18
QueryNetworkGameSocketHandler::CheckConnection
bool CheckConnection()
Check the connection's state, i.e.
Definition: network_query.cpp:42
QueryNetworkGameSocketHandler::CloseConnection
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override
Close the network connection due to the given status.
Definition: network_query.cpp:22
QueryNetworkGameSocketHandler::Receive_SERVER_BANNED
NetworkRecvStatus Receive_SERVER_BANNED(Packet &p) override
Notification that the client trying to join is banned.
Definition: network_query.cpp:103
ZeroedMemoryAllocator
Base class that provides memory initialization on dynamically created objects.
Definition: alloc_type.hpp:85
QueryNetworkGameSocketHandler::Receive_SERVER_FULL
NetworkRecvStatus Receive_SERVER_FULL(Packet &p) override
Notification that the server is full.
Definition: network_query.cpp:90
Packet
Internal entity of a packet.
Definition: packet.h:42
QueryNetworkGameSocketHandler::QueryServer
static void QueryServer(SOCKET s, const std::string &connection_string)
Start to query a server based on an open socket.
Definition: network_query.h:46
NetworkRecvStatus
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition: core.h:23
network_internal.h
QueryNetworkGameSocketHandler::Receive_SERVER_GAME_INFO
NetworkRecvStatus Receive_SERVER_GAME_INFO(Packet &p) override
Sends information about the game.
Definition: network_query.cpp:116
QueryNetworkGameSocketHandler
Class for handling the client side of quering a game server.
Definition: network_query.h:16
QueryNetworkGameSocketHandler::SendReceive
static void SendReceive()
Check if any query needs to send or receive.
Definition: network_query.cpp:164
QueryNetworkGameSocketHandler::SendGameInfo
NetworkRecvStatus SendGameInfo()
Query the server for server information.
Definition: network_query.cpp:82
QueryNetworkGameSocketHandler::connection_string
std::string connection_string
Address we are connected to.
Definition: network_query.h:19
QueryNetworkGameSocketHandler::QueryNetworkGameSocketHandler
QueryNetworkGameSocketHandler(SOCKET s, const std::string &connection_string)
Create a new socket for the client side of quering game server.
Definition: network_query.h:39
QueryNetworkGameSocketHandler::Receive_SERVER_ERROR
NetworkRecvStatus Receive_SERVER_ERROR(Packet &p) override
The client made an error: uint8_t Error code caused (see NetworkErrorCode).
Definition: network_query.cpp:137