2009-08-21 22:21:05 +02:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 17:11:33 +02:00
|
|
|
/** @file network_client.h Client part of the network protocol. */
|
|
|
|
|
2004-12-04 18:54:56 +01:00
|
|
|
#ifndef NETWORK_CLIENT_H
|
|
|
|
#define NETWORK_CLIENT_H
|
|
|
|
|
2010-01-15 17:41:15 +01:00
|
|
|
#include "network_internal.h"
|
|
|
|
|
2010-10-15 15:22:00 +02:00
|
|
|
/** Class for handling the client side of the game connection. */
|
2010-10-15 21:58:56 +02:00
|
|
|
class ClientNetworkGameSocketHandler : public ZeroedMemoryAllocator, public NetworkGameSocketHandler {
|
2010-10-24 18:40:02 +02:00
|
|
|
private:
|
2024-03-14 21:08:21 +01:00
|
|
|
std::unique_ptr<class NetworkAuthenticationClientHandler> authentication_handler; ///< The handler for the authentication.
|
2021-05-05 23:21:14 +02:00
|
|
|
std::string connection_string; ///< Address we are connected to.
|
2024-02-02 18:13:38 +01:00
|
|
|
std::shared_ptr<struct PacketReader> savegame; ///< Packet reader for reading the savegame.
|
2024-03-16 23:59:32 +01:00
|
|
|
uint8_t token; ///< The token we need to send back to the server to prove we're the right client.
|
2010-10-24 18:40:02 +02:00
|
|
|
|
2010-10-24 22:51:12 +02:00
|
|
|
/** 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_AUTH_GAME, ///< Last action was requesting game (server) password.
|
2024-03-14 21:36:28 +01:00
|
|
|
STATUS_ENCRYPTED, ///< The game authentication has completed and from here on the connection to the server is encrypted.
|
2024-03-14 21:08:21 +01:00
|
|
|
STATUS_NEWGRFS_CHECK, ///< Last action was checking NewGRFs.
|
2013-01-08 23:46:42 +01:00
|
|
|
STATUS_AUTH_COMPANY, ///< Last action was requesting company password.
|
2010-10-24 22:51:12 +02:00
|
|
|
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.
|
2011-12-19 18:48:04 +01:00
|
|
|
STATUS_END, ///< Must ALWAYS be on the end of this list!! (period)
|
2010-10-24 22:51:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ServerStatus status; ///< Status of the connection with the server.
|
|
|
|
|
2010-10-15 15:47:37 +02:00
|
|
|
protected:
|
2010-10-15 21:58:56 +02:00
|
|
|
friend void NetworkExecuteLocalCommandQueue();
|
2010-10-17 19:35:42 +02:00
|
|
|
friend void NetworkClose(bool close_admins);
|
2011-05-04 22:24:23 +02:00
|
|
|
static ClientNetworkGameSocketHandler *my_client; ///< This is us!
|
2010-10-15 16:29:13 +02:00
|
|
|
|
2024-02-03 20:28:52 +01:00
|
|
|
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;
|
2024-03-14 21:08:21 +01:00
|
|
|
NetworkRecvStatus Receive_SERVER_AUTH_REQUEST(Packet &p) override;
|
2024-03-14 21:36:28 +01:00
|
|
|
NetworkRecvStatus Receive_SERVER_ENABLE_ENCRYPTION(Packet &p) override;
|
2024-02-03 20:28:52 +01:00
|
|
|
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;
|
2010-10-15 16:29:13 +02:00
|
|
|
|
|
|
|
static NetworkRecvStatus SendNewGRFsOk();
|
|
|
|
static NetworkRecvStatus SendGetMap();
|
|
|
|
static NetworkRecvStatus SendMapOk();
|
2024-03-13 21:33:28 +01:00
|
|
|
static NetworkRecvStatus SendIdentify();
|
2010-11-19 16:55:53 +01:00
|
|
|
void CheckConnection();
|
2010-10-15 15:22:00 +02:00
|
|
|
public:
|
2021-05-05 23:21:14 +02:00
|
|
|
ClientNetworkGameSocketHandler(SOCKET s, const std::string &connection_string);
|
2010-10-15 16:29:13 +02:00
|
|
|
~ClientNetworkGameSocketHandler();
|
|
|
|
|
2019-03-24 17:24:06 +01:00
|
|
|
NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override;
|
2010-10-15 21:33:08 +02:00
|
|
|
void ClientError(NetworkRecvStatus res);
|
2010-10-15 20:42:52 +02:00
|
|
|
|
2010-10-15 16:29:13 +02:00
|
|
|
static NetworkRecvStatus SendJoin();
|
2024-02-04 17:20:25 +01:00
|
|
|
static NetworkRecvStatus SendCommand(const CommandPacket &cp);
|
2010-10-15 16:29:13 +02:00
|
|
|
static NetworkRecvStatus SendError(NetworkErrorCode errorno);
|
|
|
|
static NetworkRecvStatus SendQuit();
|
|
|
|
static NetworkRecvStatus SendAck();
|
|
|
|
|
2024-03-14 21:08:21 +01:00
|
|
|
static NetworkRecvStatus SendAuthResponse();
|
2021-05-02 09:07:09 +02:00
|
|
|
static NetworkRecvStatus SendCompanyPassword(const std::string &password);
|
2010-10-15 16:29:13 +02:00
|
|
|
|
2023-05-08 19:01:06 +02:00
|
|
|
static NetworkRecvStatus SendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64_t data);
|
2021-05-02 09:07:09 +02:00
|
|
|
static NetworkRecvStatus SendSetPassword(const std::string &password);
|
2021-05-29 19:52:11 +02:00
|
|
|
static NetworkRecvStatus SendSetName(const std::string &name);
|
|
|
|
static NetworkRecvStatus SendRCon(const std::string &password, const std::string &command);
|
2021-05-02 09:07:09 +02:00
|
|
|
static NetworkRecvStatus SendMove(CompanyID company, const std::string &password);
|
2010-10-15 21:33:08 +02:00
|
|
|
|
2011-02-11 23:10:10 +01:00
|
|
|
static bool IsConnected();
|
|
|
|
|
2010-10-15 21:33:08 +02:00
|
|
|
static void Send();
|
|
|
|
static bool Receive();
|
|
|
|
static bool GameLoop();
|
2010-10-15 15:22:00 +02:00
|
|
|
};
|
|
|
|
|
2011-05-04 22:24:23 +02:00
|
|
|
/** Helper to make the code look somewhat nicer. */
|
2010-10-15 16:29:13 +02:00
|
|
|
typedef ClientNetworkGameSocketHandler MyClient;
|
2004-12-04 18:54:56 +01:00
|
|
|
|
2007-03-07 12:47:46 +01:00
|
|
|
void NetworkClient_Connected();
|
2021-05-02 09:07:09 +02:00
|
|
|
void NetworkClientSetCompanyPassword(const std::string &password);
|
2004-12-04 18:54:56 +01:00
|
|
|
|
2021-05-01 14:21:33 +02:00
|
|
|
/** Information required to join a server. */
|
|
|
|
struct NetworkJoinInfo {
|
2021-05-02 09:10:09 +02:00
|
|
|
NetworkJoinInfo() : company(COMPANY_SPECTATOR) {}
|
2021-05-05 23:21:14 +02:00
|
|
|
std::string connection_string; ///< The address of the server to join.
|
|
|
|
CompanyID company; ///< The company to join.
|
2021-05-02 09:10:09 +02:00
|
|
|
std::string server_password; ///< The password of the server to join.
|
2021-05-02 09:07:09 +02:00
|
|
|
std::string company_password; ///< The password of the company to join.
|
2021-05-01 14:21:33 +02:00
|
|
|
};
|
2009-05-19 23:20:14 +02:00
|
|
|
|
2021-05-01 14:21:33 +02:00
|
|
|
extern NetworkJoinInfo _network_join;
|
2009-06-10 21:00:34 +02:00
|
|
|
|
2005-09-18 22:56:44 +02:00
|
|
|
#endif /* NETWORK_CLIENT_H */
|