Fix: Data races on cursor state in OpenGL backends
[openttd-github.git] / src / network / network_client.h
blobd1ffe1c1d15ff559034a5f503d1642ff15a67131
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_client.h Client part of the network protocol. */
10 #ifndef NETWORK_CLIENT_H
11 #define NETWORK_CLIENT_H
13 #include "network_internal.h"
15 /** Class for handling the client side of the game connection. */
16 class ClientNetworkGameSocketHandler : public ZeroedMemoryAllocator, public NetworkGameSocketHandler {
17 private:
18 struct PacketReader *savegame; ///< Packet reader for reading the savegame.
19 byte token; ///< The token we need to send back to the server to prove we're the right client.
21 /** Status of the connection with the server. */
22 enum ServerStatus {
23 STATUS_INACTIVE, ///< The client is not connected nor active.
24 STATUS_COMPANY_INFO, ///< We are trying to get company information.
25 STATUS_JOIN, ///< We are trying to join a server.
26 STATUS_NEWGRFS_CHECK, ///< Last action was checking NewGRFs.
27 STATUS_AUTH_GAME, ///< Last action was requesting game (server) password.
28 STATUS_AUTH_COMPANY, ///< Last action was requesting company password.
29 STATUS_AUTHORIZED, ///< The client is authorized at the server.
30 STATUS_MAP_WAIT, ///< The client is waiting as someone else is downloading the map.
31 STATUS_MAP, ///< The client is downloading the map.
32 STATUS_ACTIVE, ///< The client is active within in the game.
33 STATUS_END, ///< Must ALWAYS be on the end of this list!! (period)
36 ServerStatus status; ///< Status of the connection with the server.
38 protected:
39 friend void NetworkExecuteLocalCommandQueue();
40 friend void NetworkClose(bool close_admins);
41 static ClientNetworkGameSocketHandler *my_client; ///< This is us!
43 NetworkRecvStatus Receive_SERVER_FULL(Packet *p) override;
44 NetworkRecvStatus Receive_SERVER_BANNED(Packet *p) override;
45 NetworkRecvStatus Receive_SERVER_ERROR(Packet *p) override;
46 NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p) override;
47 NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p) override;
48 NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p) override;
49 NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p) override;
50 NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p) override;
51 NetworkRecvStatus Receive_SERVER_WAIT(Packet *p) override;
52 NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p) override;
53 NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet *p) override;
54 NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet *p) override;
55 NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet *p) override;
56 NetworkRecvStatus Receive_SERVER_JOIN(Packet *p) override;
57 NetworkRecvStatus Receive_SERVER_FRAME(Packet *p) override;
58 NetworkRecvStatus Receive_SERVER_SYNC(Packet *p) override;
59 NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p) override;
60 NetworkRecvStatus Receive_SERVER_CHAT(Packet *p) override;
61 NetworkRecvStatus Receive_SERVER_QUIT(Packet *p) override;
62 NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet *p) override;
63 NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p) override;
64 NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p) override;
65 NetworkRecvStatus Receive_SERVER_RCON(Packet *p) override;
66 NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet *p) override;
67 NetworkRecvStatus Receive_SERVER_MOVE(Packet *p) override;
68 NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p) override;
69 NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p) override;
71 static NetworkRecvStatus SendNewGRFsOk();
72 static NetworkRecvStatus SendGetMap();
73 static NetworkRecvStatus SendMapOk();
74 void CheckConnection();
75 public:
76 ClientNetworkGameSocketHandler(SOCKET s);
77 ~ClientNetworkGameSocketHandler();
79 NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override;
80 void ClientError(NetworkRecvStatus res);
82 static NetworkRecvStatus SendCompanyInformationQuery();
84 static NetworkRecvStatus SendJoin();
85 static NetworkRecvStatus SendCommand(const CommandPacket *cp);
86 static NetworkRecvStatus SendError(NetworkErrorCode errorno);
87 static NetworkRecvStatus SendQuit();
88 static NetworkRecvStatus SendAck();
90 static NetworkRecvStatus SendGamePassword(const char *password);
91 static NetworkRecvStatus SendCompanyPassword(const char *password);
93 static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 data);
94 static NetworkRecvStatus SendSetPassword(const char *password);
95 static NetworkRecvStatus SendSetName(const char *name);
96 static NetworkRecvStatus SendRCon(const char *password, const char *command);
97 static NetworkRecvStatus SendMove(CompanyID company, const char *password);
99 static bool IsConnected();
101 static void Send();
102 static bool Receive();
103 static bool GameLoop();
106 /** Helper to make the code look somewhat nicer. */
107 typedef ClientNetworkGameSocketHandler MyClient;
109 void NetworkClient_Connected();
110 void NetworkClientSetCompanyPassword(const char *password);
112 extern CompanyID _network_join_as;
114 extern const char *_network_join_server_password;
115 extern const char *_network_join_company_password;
117 #endif /* NETWORK_CLIENT_H */