Files
@ r28025:9116d6e411b0
Branch filter:
Location: cpp/openttd-patchpack/source/src/network/network_client.h - annotation
r28025:9116d6e411b0
5.8 KiB
text/x-c
Codechange: replace x.size() == 0 with x.empty()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r9111:983de9c5a848 r9111:983de9c5a848 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r14248:a9050881acd7 r14248:a9050881acd7 r16212:9367327f6880 r16224:976f6278a22b r16309:9e58ff5fe31b r25388:32b23efdcf4e r16656:54ad1ebbb45f r16656:54ad1ebbb45f r16309:9e58ff5fe31b r16315:1f149159e278 r16315:1f149159e278 r16315:1f149159e278 r16315:1f149159e278 r16315:1f149159e278 r16315:1f149159e278 r19944:25a78576fb5e r16315:1f149159e278 r16315:1f149159e278 r16315:1f149159e278 r16315:1f149159e278 r18737:1ee35da7fa2f r16315:1f149159e278 r16315:1f149159e278 r16315:1f149159e278 r16315:1f149159e278 r16213:0b4dd45d6d32 r16224:976f6278a22b r16255:08842c21f00b r17641:a80e43fd2f5e r16214:7fd822f2f61a r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r25978:1911877bcb73 r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r23506:bba4d0c6d70d r16214:7fd822f2f61a r16214:7fd822f2f61a r16214:7fd822f2f61a r16214:7fd822f2f61a r16520:a55f3db91e92 r16212:9367327f6880 r25388:32b23efdcf4e r16214:7fd822f2f61a r16214:7fd822f2f61a r23506:bba4d0c6d70d r16222:694bed5fd015 r16218:1e9669cfbb04 r16214:7fd822f2f61a r16214:7fd822f2f61a r16214:7fd822f2f61a r16214:7fd822f2f61a r16214:7fd822f2f61a r16214:7fd822f2f61a r25476:1ecee9aa75c0 r25475:0426c207464e r16214:7fd822f2f61a r27737:728d55b97775 r25475:0426c207464e r25570:d402b1c974e3 r25570:d402b1c974e3 r25475:0426c207464e r16222:694bed5fd015 r17313:722abf9129a8 r17313:722abf9129a8 r16222:694bed5fd015 r16222:694bed5fd015 r16222:694bed5fd015 r16212:9367327f6880 r16212:9367327f6880 r17641:a80e43fd2f5e r16214:7fd822f2f61a r5475:3f5cd13d1b63 r6247:96e840dbefcc r25475:0426c207464e r5475:3f5cd13d1b63 r25346:21c8ec239c8f r25346:21c8ec239c8f r25476:1ecee9aa75c0 r25388:32b23efdcf4e r25388:32b23efdcf4e r25476:1ecee9aa75c0 r25475:0426c207464e r25346:21c8ec239c8f r11951:a522cb996935 r25346:21c8ec239c8f r12134:0a6111a3288d r5475:3f5cd13d1b63 | /*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/
/** @file network_client.h Client part of the network protocol. */
#ifndef NETWORK_CLIENT_H
#define NETWORK_CLIENT_H
#include "network_internal.h"
/** Class for handling the client side of the game connection. */
class ClientNetworkGameSocketHandler : public ZeroedMemoryAllocator, public NetworkGameSocketHandler {
private:
std::string connection_string; ///< Address we are connected to.
struct PacketReader *savegame; ///< Packet reader for reading the savegame.
byte token; ///< The token we need to send back to the server to prove we're the right client.
/** Status of the connection with the server. */
enum ServerStatus {
STATUS_INACTIVE, ///< The client is not connected nor active.
STATUS_JOIN, ///< We are trying to join a server.
STATUS_NEWGRFS_CHECK, ///< Last action was checking NewGRFs.
STATUS_AUTH_GAME, ///< Last action was requesting game (server) password.
STATUS_AUTH_COMPANY, ///< Last action was requesting company password.
STATUS_AUTHORIZED, ///< The client is authorized at the server.
STATUS_MAP_WAIT, ///< The client is waiting as someone else is downloading the map.
STATUS_MAP, ///< The client is downloading the map.
STATUS_ACTIVE, ///< The client is active within in the game.
STATUS_END, ///< Must ALWAYS be on the end of this list!! (period)
};
ServerStatus status; ///< Status of the connection with the server.
protected:
friend void NetworkExecuteLocalCommandQueue();
friend void NetworkClose(bool close_admins);
static ClientNetworkGameSocketHandler *my_client; ///< This is us!
NetworkRecvStatus Receive_SERVER_FULL(Packet *p) override;
NetworkRecvStatus Receive_SERVER_BANNED(Packet *p) override;
NetworkRecvStatus Receive_SERVER_ERROR(Packet *p) override;
NetworkRecvStatus Receive_SERVER_CLIENT_INFO(Packet *p) override;
NetworkRecvStatus Receive_SERVER_NEED_GAME_PASSWORD(Packet *p) override;
NetworkRecvStatus Receive_SERVER_NEED_COMPANY_PASSWORD(Packet *p) override;
NetworkRecvStatus Receive_SERVER_WELCOME(Packet *p) override;
NetworkRecvStatus Receive_SERVER_WAIT(Packet *p) override;
NetworkRecvStatus Receive_SERVER_MAP_BEGIN(Packet *p) override;
NetworkRecvStatus Receive_SERVER_MAP_SIZE(Packet *p) override;
NetworkRecvStatus Receive_SERVER_MAP_DATA(Packet *p) override;
NetworkRecvStatus Receive_SERVER_MAP_DONE(Packet *p) override;
NetworkRecvStatus Receive_SERVER_JOIN(Packet *p) override;
NetworkRecvStatus Receive_SERVER_FRAME(Packet *p) override;
NetworkRecvStatus Receive_SERVER_SYNC(Packet *p) override;
NetworkRecvStatus Receive_SERVER_COMMAND(Packet *p) override;
NetworkRecvStatus Receive_SERVER_CHAT(Packet *p) override;
NetworkRecvStatus Receive_SERVER_EXTERNAL_CHAT(Packet *p) override;
NetworkRecvStatus Receive_SERVER_QUIT(Packet *p) override;
NetworkRecvStatus Receive_SERVER_ERROR_QUIT(Packet *p) override;
NetworkRecvStatus Receive_SERVER_SHUTDOWN(Packet *p) override;
NetworkRecvStatus Receive_SERVER_NEWGAME(Packet *p) override;
NetworkRecvStatus Receive_SERVER_RCON(Packet *p) override;
NetworkRecvStatus Receive_SERVER_CHECK_NEWGRFS(Packet *p) override;
NetworkRecvStatus Receive_SERVER_MOVE(Packet *p) override;
NetworkRecvStatus Receive_SERVER_COMPANY_UPDATE(Packet *p) override;
NetworkRecvStatus Receive_SERVER_CONFIG_UPDATE(Packet *p) override;
static NetworkRecvStatus SendNewGRFsOk();
static NetworkRecvStatus SendGetMap();
static NetworkRecvStatus SendMapOk();
void CheckConnection();
public:
ClientNetworkGameSocketHandler(SOCKET s, const std::string &connection_string);
~ClientNetworkGameSocketHandler();
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override;
void ClientError(NetworkRecvStatus res);
static NetworkRecvStatus SendJoin();
static NetworkRecvStatus SendCommand(const CommandPacket *cp);
static NetworkRecvStatus SendError(NetworkErrorCode errorno);
static NetworkRecvStatus SendQuit();
static NetworkRecvStatus SendAck();
static NetworkRecvStatus SendGamePassword(const std::string &password);
static NetworkRecvStatus SendCompanyPassword(const std::string &password);
static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64_t data);
static NetworkRecvStatus SendSetPassword(const std::string &password);
static NetworkRecvStatus SendSetName(const std::string &name);
static NetworkRecvStatus SendRCon(const std::string &password, const std::string &command);
static NetworkRecvStatus SendMove(CompanyID company, const std::string &password);
static bool IsConnected();
static void Send();
static bool Receive();
static bool GameLoop();
};
/** Helper to make the code look somewhat nicer. */
typedef ClientNetworkGameSocketHandler MyClient;
void NetworkClient_Connected();
void NetworkClientSetCompanyPassword(const std::string &password);
/** Information required to join a server. */
struct NetworkJoinInfo {
NetworkJoinInfo() : company(COMPANY_SPECTATOR) {}
std::string connection_string; ///< The address of the server to join.
CompanyID company; ///< The company to join.
std::string server_password; ///< The password of the server to join.
std::string company_password; ///< The password of the company to join.
};
extern NetworkJoinInfo _network_join;
#endif /* NETWORK_CLIENT_H */
|