OpenTTD: src/network/network_client.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

network_client.h
Go to the documentation of this file.
1 /* $Id: network_client.h 24900 2013-01-08 22:46:42Z planetmaker $ */
2
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 */
9
12 #ifndef NETWORK_CLIENT_H
13 #define NETWORK_CLIENT_H
14
15 #ifdef ENABLE_NETWORK
16
17 #include "network_internal.h"
18
20 class ClientNetworkGameSocketHandler : public ZeroedMemoryAllocator, public NetworkGameSocketHandler {
21 private:
22 struct PacketReader *savegame;
23 byte token;
24
26 enum ServerStatus {
27 STATUS_INACTIVE,
28 STATUS_COMPANY_INFO,
29 STATUS_JOIN,
30 STATUS_NEWGRFS_CHECK,
31 STATUS_AUTH_GAME,
32 STATUS_AUTH_COMPANY,
33 STATUS_AUTHORIZED,
34 STATUS_MAP_WAIT,
35 STATUS_MAP,
36 STATUS_ACTIVE,
37 STATUS_END,
38 };
39
40 ServerStatus status;
41
42 protected:
43 friend void NetworkExecuteLocalCommandQueue();
44 friend void NetworkClose(bool close_admins);
45 static ClientNetworkGameSocketHandler *my_client;
46
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);
74
75 static NetworkRecvStatus SendNewGRFsOk();
76 static NetworkRecvStatus SendGetMap();
77 static NetworkRecvStatus SendMapOk();
78 void CheckConnection();
79 public:
80 ClientNetworkGameSocketHandler(SOCKET s);
81 ~ClientNetworkGameSocketHandler();
82
83 NetworkRecvStatus CloseConnection(NetworkRecvStatus status);
84 void ClientError(NetworkRecvStatus res);
85
86 static NetworkRecvStatus SendCompanyInformationQuery();
87
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();
93
94 static NetworkRecvStatus SendGamePassword(const char *password);
95 static NetworkRecvStatus SendCompanyPassword(const char *password);
96
97 static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const char *msg, int64 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);
102
103 static bool IsConnected();
104
105 static void Send();
106 static bool Receive();
107 static bool GameLoop();
108 };
109
111 typedef ClientNetworkGameSocketHandler MyClient;
112
113 void NetworkClient_Connected();
114 void NetworkClientSetCompanyPassword(const char *password);
115
116 extern CompanyID _network_join_as;
117
118 extern const char *_network_join_server_password;
119 extern const char *_network_join_company_password;
120
121 #endif /* ENABLE_NETWORK */
122
123 #endif /* NETWORK_CLIENT_H */