Fix #10490: Allow ships to exit depots if another is not moving at the exit point...
[openttd-github.git] / src / network / network_query.h
blob0f7348838f8129305aa248a8aa9da355eeb98a2f
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 */
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 {
17 private:
18 static std::vector<std::unique_ptr<QueryNetworkGameSocketHandler>> queries; ///< Pending queries.
19 std::string connection_string; ///< Address we are connected to.
21 protected:
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();
30 void Send();
31 bool Receive();
33 public:
34 /**
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) {}
41 /**
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 */