Delete pointless project file remnants.
[openttd-joker.git] / src / network / network_client.h
blobe23579535ee91b828194b278ba0c240c1cf61092
1 /* $Id: network_client.h 24900 2013-01-08 22:46:42Z planetmaker $ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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 */
10 /** @file network_client.h Client part of the network protocol. */
12 #ifndef NETWORK_CLIENT_H
13 #define NETWORK_CLIENT_H
15 #ifdef ENABLE_NETWORK
17 #include "network_internal.h"
19 /** Class for handling the client side of the game connection. */
20 class ClientNetworkGameSocketHandler : public NetworkGameSocketHandler {
21 private:
22 struct PacketReader *savegame; ///< Packet reader for reading the savegame.
23 byte token; ///< The token we need to send back to the server to prove we're the right client.
25 /** Status of the connection with the server. */
26 enum ServerStatus {
27 STATUS_INACTIVE, ///< The client is not connected nor active.
28 STATUS_COMPANY_INFO, ///< We are trying to get company information.
29 STATUS_JOIN, ///< We are trying to join a server.
30 STATUS_NEWGRFS_CHECK, ///< Last action was checking NewGRFs.
31 STATUS_AUTH_GAME, ///< Last action was requesting game (server) password.
32 STATUS_AUTH_COMPANY, ///< Last action was requesting company password.
33 STATUS_AUTHORIZED, ///< The client is authorized at the server.
34 STATUS_MAP_WAIT, ///< The client is waiting as someone else is downloading the map.
35 STATUS_MAP, ///< The client is downloading the map.
36 STATUS_ACTIVE, ///< The client is active within in the game.
37 STATUS_END, ///< Must ALWAYS be on the end of this list!! (period)
40 ServerStatus status; ///< Status of the connection with the server.
42 protected:
43 friend void NetworkExecuteLocalCommandQueue();
44 friend void NetworkClose(bool close_admins);
45 static ClientNetworkGameSocketHandler *my_client; ///< This is us!
47 virtual NetworkRecvStatus Receive_SERVER_FULL(Packet *p);
48 virtual NetworkRecvStatus Receive_SERVER_BANNED(Packet *p);
49 virtual NetworkRecvStatus Receive_SERVER_ERROR(Packet *p);
50 virtual NetworkRecvStatus Receive_SERVER_COMPANY_INFO(Packet *p);
51 virtual NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p);
52 virtual NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p);
53 virtual NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p);
54 virtual NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p);
55 virtual NetworkRecvStatus Receive_SERVER_WAIT(Packet *p);
56 virtual NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p);
57 virtual NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet *p);
58 virtual NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet *p);
59 virtual NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet *p);
60 virtual NetworkRecvStatus Receive_SERVER_JOIN(Packet *p);
61 virtual NetworkRecvStatus Receive_SERVER_FRAME(Packet *p);
62 virtual NetworkRecvStatus Receive_SERVER_SYNC(Packet *p);
63 virtual NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p);
64 virtual NetworkRecvStatus Receive_SERVER_CHAT(Packet *p);
65 virtual NetworkRecvStatus Receive_SERVER_QUIT(Packet *p);
66 virtual NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet *p);
67 virtual NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p);
68 virtual NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p);
69 virtual NetworkRecvStatus Receive_SERVER_RCON(Packet *p);
70 virtual NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet *p);
71 virtual NetworkRecvStatus Receive_SERVER_MOVE(Packet *p);
72 virtual NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p);
73 virtual NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p);
75 static NetworkRecvStatus SendNewGRFsOk();
76 static NetworkRecvStatus SendGetMap();
77 static NetworkRecvStatus SendMapOk();
78 void CheckConnection();
79 public:
80 ClientNetworkGameSocketHandler(SOCKET s);
81 ~ClientNetworkGameSocketHandler();
83 NetworkRecvStatus CloseConnection(NetworkRecvStatus status);
84 void ClientError(NetworkRecvStatus res);
86 static NetworkRecvStatus SendCompanyInformationQuery();
88 static NetworkRecvStatus SendJoin();
89 static NetworkRecvStatus SendCommand(const CommandPacket *cp);
90 static NetworkRecvStatus SendError(NetworkErrorCode errorno);
91 static NetworkRecvStatus SendQuit();
92 static NetworkRecvStatus SendAck();
94 static NetworkRecvStatus SendGamePassword(const char *password);
95 static NetworkRecvStatus SendCompanyPassword(const char *password);
97 static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, NetworkTextMessageData data);
98 static NetworkRecvStatus SendSetPassword(const char *password);
99 static NetworkRecvStatus SendSetName(const char *name);
100 static NetworkRecvStatus SendRCon(const char *password, const char *command);
101 static NetworkRecvStatus SendMove(CompanyID company, const char *password);
103 static bool IsConnected();
105 static void Send();
106 static bool Receive();
107 static bool GameLoop();
110 /** Helper to make the code look somewhat nicer. */
111 typedef ClientNetworkGameSocketHandler MyClient;
113 void NetworkClient_Connected();
114 void NetworkClientSetCompanyPassword(const char *password);
116 extern CompanyID _network_join_as;
118 extern const char *_network_join_server_password;
119 extern const char *_network_join_company_password;
121 #endif /* ENABLE_NETWORK */
123 #endif /* NETWORK_CLIENT_H */