Files @ r25895:573b0b525189
Branch filter:

Location: cpp/openttd-patchpack/source/src/network/network_server.h - annotation

Patric Stout
Fix: [Actions] changelog assumed major.minor.patch versioning (#9482)

We now use major.minor versioning, so it failed to pick up the
correct information.
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
r16227:792ebc5cdc7d
r14248:a9050881acd7
r16224:976f6278a22b
r19944:25a78576fb5e
r16224:976f6278a22b
r17642:ab10f4b22179
r17360:71e102cec3ce
r16224:976f6278a22b
r16224:976f6278a22b
r16212:9367327f6880
r16227:792ebc5cdc7d
r16213:0b4dd45d6d32
r23506:bba4d0c6d70d
r25291:b63dc4fc3205
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
r16225:8b607445bb1a
r25291:b63dc4fc3205
r16225:8b607445bb1a
r16225:8b607445bb1a
r16225:8b607445bb1a
r16225:8b607445bb1a
r16226:c9a49f2c6446
r16212:9367327f6880
r16312:cb5c5460a42f
r16312:cb5c5460a42f
r16312:cb5c5460a42f
r16312:cb5c5460a42f
r16312:cb5c5460a42f
r16312:cb5c5460a42f
r16312:cb5c5460a42f
r16312:cb5c5460a42f
r16312:cb5c5460a42f
r16312:cb5c5460a42f
r16312:cb5c5460a42f
r16312:cb5c5460a42f
r18737:1ee35da7fa2f
r16312:cb5c5460a42f
r16312:cb5c5460a42f
r16226:c9a49f2c6446
r16620:1174af2ca847
r16620:1174af2ca847
r16226:c9a49f2c6446
r16226:c9a49f2c6446
r25248:b859cebb80a5
r16226:c9a49f2c6446
r16657:eea3d874b487
r25407:b37c2c854ce5
r16657:eea3d874b487
r16212:9367327f6880
r16212:9367327f6880
r16218:1e9669cfbb04
r23506:bba4d0c6d70d
r23506:bba4d0c6d70d
r25689:899cf7c4e76b
r16225:8b607445bb1a
r24966:58f5725d6df8
r24966:58f5725d6df8
r24967:987ffc0c7405
r16225:8b607445bb1a
r16225:8b607445bb1a
r16225:8b607445bb1a
r16225:8b607445bb1a
r16225:8b607445bb1a
r25568:66d9ae4f04a1
r16225:8b607445bb1a
r16225:8b607445bb1a
r16225:8b607445bb1a
r25569:ae23e84953e3
r25488:5086f38829a5
r16225:8b607445bb1a
r16225:8b607445bb1a
r16225:8b607445bb1a
r16225:8b607445bb1a
r16225:8b607445bb1a
r16225:8b607445bb1a
r16227:792ebc5cdc7d
r16227:792ebc5cdc7d
r16227:792ebc5cdc7d
r16227:792ebc5cdc7d
r16227:792ebc5cdc7d
r16227:792ebc5cdc7d
r16227:792ebc5cdc7d
r16227:792ebc5cdc7d
r16227:792ebc5cdc7d
r16227:792ebc5cdc7d
r16227:792ebc5cdc7d
r16227:792ebc5cdc7d
r16227:792ebc5cdc7d
r17589:2470c8704f99
r25685:28affbeede23
r17592:fe12d7ef5149
r17589:2470c8704f99
r16212:9367327f6880
r16212:9367327f6880
r5475:3f5cd13d1b63
r25475:0426c207464e
r21467:8b87202cc00f
r5475:3f5cd13d1b63
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_server.h Server part of the network protocol. */

#ifndef NETWORK_SERVER_H
#define NETWORK_SERVER_H

#include "network_internal.h"
#include "core/tcp_listen.h"

class ServerNetworkGameSocketHandler;
/** Make the code look slightly nicer/simpler. */
typedef ServerNetworkGameSocketHandler NetworkClientSocket;
/** Pool with all client sockets. */
typedef Pool<NetworkClientSocket, ClientIndex, 8, MAX_CLIENT_SLOTS, PT_NCLIENT> NetworkClientSocketPool;
extern NetworkClientSocketPool _networkclientsocket_pool;

/** Class for handling the server side of the game connection. */
class ServerNetworkGameSocketHandler : public NetworkClientSocketPool::PoolItem<&_networkclientsocket_pool>, public NetworkGameSocketHandler, public TCPListenHandler<ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED> {
protected:
	NetworkRecvStatus Receive_CLIENT_JOIN(Packet *p) override;
	NetworkRecvStatus Receive_CLIENT_GAME_INFO(Packet *p) override;
	NetworkRecvStatus Receive_CLIENT_GAME_PASSWORD(Packet *p) override;
	NetworkRecvStatus Receive_CLIENT_COMPANY_PASSWORD(Packet *p) override;
	NetworkRecvStatus Receive_CLIENT_GETMAP(Packet *p) override;
	NetworkRecvStatus Receive_CLIENT_MAP_OK(Packet *p) override;
	NetworkRecvStatus Receive_CLIENT_ACK(Packet *p) override;
	NetworkRecvStatus Receive_CLIENT_COMMAND(Packet *p) override;
	NetworkRecvStatus Receive_CLIENT_CHAT(Packet *p) override;
	NetworkRecvStatus Receive_CLIENT_SET_PASSWORD(Packet *p) override;
	NetworkRecvStatus Receive_CLIENT_SET_NAME(Packet *p) override;
	NetworkRecvStatus Receive_CLIENT_QUIT(Packet *p) override;
	NetworkRecvStatus Receive_CLIENT_ERROR(Packet *p) override;
	NetworkRecvStatus Receive_CLIENT_RCON(Packet *p) override;
	NetworkRecvStatus Receive_CLIENT_NEWGRFS_CHECKED(Packet *p) override;
	NetworkRecvStatus Receive_CLIENT_MOVE(Packet *p) override;

	NetworkRecvStatus SendGameInfo();
	NetworkRecvStatus SendNewGRFCheck();
	NetworkRecvStatus SendWelcome();
	NetworkRecvStatus SendNeedGamePassword();
	NetworkRecvStatus SendNeedCompanyPassword();

public:
	/** Status of a client */
	enum ClientStatus {
		STATUS_INACTIVE,      ///< The client is not connected nor active.
		STATUS_NEWGRFS_CHECK, ///< The client is checking NewGRFs.
		STATUS_AUTH_GAME,     ///< The client is authorizing with game (server) password.
		STATUS_AUTH_COMPANY,  ///< The client is authorizing with company password.
		STATUS_AUTHORIZED,    ///< The client is authorized.
		STATUS_MAP_WAIT,      ///< The client is waiting as someone else is downloading the map.
		STATUS_MAP,           ///< The client is downloading the map.
		STATUS_DONE_MAP,      ///< The client has downloaded the map.
		STATUS_PRE_ACTIVE,    ///< The client is catching up the delayed frames.
		STATUS_ACTIVE,        ///< The client is active within in the game.
		STATUS_END,           ///< Must ALWAYS be on the end of this list!! (period).
	};

	byte lag_test;               ///< Byte used for lag-testing the client
	byte last_token;             ///< The last random token we did send to verify the client is listening
	uint32 last_token_frame;     ///< The last frame we received the right token
	ClientStatus status;         ///< Status of this client
	CommandQueue outgoing_queue; ///< The command-queue awaiting delivery
	size_t receive_limit;        ///< Amount of bytes that we can receive at this moment

	struct PacketWriter *savegame; ///< Writer used to write the savegame.
	NetworkAddress client_address; ///< IP-address of the client (so they can be banned)

	ServerNetworkGameSocketHandler(SOCKET s);
	~ServerNetworkGameSocketHandler();

	virtual Packet *ReceivePacket() override;
	NetworkRecvStatus CloseConnection(NetworkRecvStatus status) override;
	std::string GetClientName() const;

	void CheckNextClientToSendMap(NetworkClientSocket *ignore_cs = nullptr);

	NetworkRecvStatus SendWait();
	NetworkRecvStatus SendMap();
	NetworkRecvStatus SendErrorQuit(ClientID client_id, NetworkErrorCode errorno);
	NetworkRecvStatus SendQuit(ClientID client_id);
	NetworkRecvStatus SendShutdown();
	NetworkRecvStatus SendNewGame();
	NetworkRecvStatus SendRConResult(uint16 colour, const std::string &command);
	NetworkRecvStatus SendMove(ClientID client_id, CompanyID company_id);

	NetworkRecvStatus SendClientInfo(NetworkClientInfo *ci);
	NetworkRecvStatus SendError(NetworkErrorCode error, const std::string &reason = {});
	NetworkRecvStatus SendChat(NetworkAction action, ClientID client_id, bool self_send, const std::string &msg, int64 data);
	NetworkRecvStatus SendJoin(ClientID client_id);
	NetworkRecvStatus SendFrame();
	NetworkRecvStatus SendSync();
	NetworkRecvStatus SendCommand(const CommandPacket *cp);
	NetworkRecvStatus SendCompanyUpdate();
	NetworkRecvStatus SendConfigUpdate();

	static void Send();
	static void AcceptConnection(SOCKET s, const NetworkAddress &address);
	static bool AllowConnection();

	/**
	 * Get the name used by the listener.
	 * @return the name to show in debug logs and the like.
	 */
	static const char *GetName()
	{
		return "server";
	}

	const std::string &GetClientIP();

	static ServerNetworkGameSocketHandler *GetByClientID(ClientID client_id);
};

void NetworkServer_Tick(bool send_frame);
void NetworkServerSetCompanyPassword(CompanyID company_id, const std::string &password, bool already_hashed = true);
void NetworkServerUpdateCompanyPassworded(CompanyID company_id, bool passworded);

#endif /* NETWORK_SERVER_H */