OpenTTD Source 20260421-master-gc2fbc6fdeb
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef NETWORK_QUERY_H
11#define NETWORK_QUERY_H
12
13#include "network_internal.h"
14
17private:
18 static std::vector<std::unique_ptr<QueryNetworkGameSocketHandler>> queries;
19 std::string connection_string;
20
21protected:
22 NetworkRecvStatus ReceiveServerFull(Packet &p) override;
23 NetworkRecvStatus ReceiveServerBanned(Packet &p) override;
24 NetworkRecvStatus ReceiveServerError(Packet &p) override;
25 NetworkRecvStatus ReceiveServerGameInfo(Packet &p) override;
26
28
29 bool CheckConnection();
30 void Send();
31 bool Receive();
32
33public:
40
46 static void QueryServer(SOCKET s, std::string_view 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 */
NetworkGameSocketHandler(SOCKET s)
Create a new socket for the game connection.
Definition tcp_game.cpp:28
static std::vector< std::unique_ptr< QueryNetworkGameSocketHandler > > queries
Pending queries.
void Send()
Send the packets of this socket handler.
NetworkRecvStatus ReceiveServerGameInfo(Packet &p) override
Sends information about the game.
NetworkRecvStatus ReceiveServerBanned(Packet &p) override
Notification that the client trying to join is banned.
std::string connection_string
Address we are connected to.
NetworkRecvStatus ReceiveServerFull(Packet &p) override
Notification that the server is full.
static void SendReceive()
Check if any query needs to send or receive.
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override
Close the network connection due to the given status.
bool Receive()
Check whether we received/can send some data from/to the server and when that's the case handle it ap...
NetworkRecvStatus SendGameInfo()
Query the server for server information.
static void QueryServer(SOCKET s, std::string_view connection_string)
Start to query a server based on an open socket.
QueryNetworkGameSocketHandler(SOCKET s, std::string_view connection_string)
Create a new socket for the client side of querying game server.
NetworkRecvStatus ReceiveServerError(Packet &p) override
The client made an error: uint8_t Error code caused (see NetworkErrorCode).
bool CheckConnection()
Check the connection's state, i.e.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition core.h:21
Variables and function used internally.