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/>.
8 /** @file network_query.h Query part of the network protocol. */
10 #ifndef NETWORK_QUERY_H
11 #define NETWORK_QUERY_H
13 #include "network_internal.h"
15 /** Class for handling the client side of quering a game server. */
16 class QueryNetworkGameSocketHandler
: public ZeroedMemoryAllocator
, public NetworkGameSocketHandler
{
18 static std::vector
<std::unique_ptr
<QueryNetworkGameSocketHandler
>> queries
; ///< Pending queries.
19 std::string connection_string
; ///< Address we are connected to.
22 NetworkRecvStatus
Receive_SERVER_FULL(Packet
&p
) override
;
23 NetworkRecvStatus
Receive_SERVER_BANNED(Packet
&p
) override
;
24 NetworkRecvStatus
Receive_SERVER_ERROR(Packet
&p
) override
;
25 NetworkRecvStatus
Receive_SERVER_GAME_INFO(Packet
&p
) override
;
27 NetworkRecvStatus
SendGameInfo();
29 bool CheckConnection();
35 * Create a new socket for the client side of quering game server.
36 * @param s The socket to connect with.
37 * @param connection_string The connection string of the server.
39 QueryNetworkGameSocketHandler(SOCKET s
, const std::string
&connection_string
) : NetworkGameSocketHandler(s
), connection_string(connection_string
) {}
42 * Start to query a server based on an open socket.
43 * @param s The socket to connect with.
44 * @param connection_string The connection string of the server.
46 static void QueryServer(SOCKET s
, const std::string
&connection_string
)
48 auto query
= std::make_unique
<QueryNetworkGameSocketHandler
>(s
, connection_string
);
49 query
->SendGameInfo();
51 QueryNetworkGameSocketHandler::queries
.push_back(std::move(query
));
54 static void SendReceive();
56 NetworkRecvStatus
CloseConnection(NetworkRecvStatus status
) override
;
59 #endif /* NETWORK_QUERY_H */