1 /* 2 * This file is part of OpenTTD. 3 * 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. 4 * 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. 5 * 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/>. 6 */ 7 8 /** @file network_type.h Types used for networking. */ 9 10 #ifndef NETWORK_TYPE_H 11 #define NETWORK_TYPE_H 12 13 /** How many clients can we have */ 14 static const uint MAX_CLIENTS = 255; 15 16 /** 17 * The number of slots; must be at least 1 more than MAX_CLIENTS. It must 18 * furthermore be less than or equal to 256 as client indices (sent over 19 * the network) are 8 bits. It needs 1 more for the dedicated server. 20 */ 21 static const uint MAX_CLIENT_SLOTS = 256; 22 23 /** 24 * Vehicletypes in the order they are send in info packets. 25 */ 26 enum NetworkVehicleType { 27 NETWORK_VEH_TRAIN = 0, 28 NETWORK_VEH_LORRY, 29 NETWORK_VEH_BUS, 30 NETWORK_VEH_PLANE, 31 NETWORK_VEH_SHIP, 32 33 NETWORK_VEH_END 34 }; 35 36 /** 37 * Game type the server can be using. 38 * Used on the network protocol to communicate with Game Coordinator. 39 */ 40 enum ServerGameType : uint8 { 41 SERVER_GAME_TYPE_LOCAL = 0, 42 SERVER_GAME_TYPE_PUBLIC, 43 SERVER_GAME_TYPE_INVITE_ONLY, 44 }; 45 46 /** 'Unique' identifier to be given to clients */ 47 enum ClientID : uint32 { 48 INVALID_CLIENT_ID = 0, ///< Client is not part of anything 49 CLIENT_ID_SERVER = 1, ///< Servers always have this ID 50 CLIENT_ID_FIRST = 2, ///< The first client ID 51 }; 52 53 /** Indices into the client tables */ 54 typedef uint8 ClientIndex; 55 56 /** Indices into the admin tables. */ 57 typedef uint8 AdminIndex; 58 59 /** Maximum number of allowed admins. */ 60 static const AdminIndex MAX_ADMINS = 16; 61 /** An invalid admin marker. */ 62 static const AdminIndex INVALID_ADMIN_ID = UINT8_MAX; 63 64 /** Simple calculated statistics of a company */ 65 struct NetworkCompanyStats { 66 uint16 num_vehicle[NETWORK_VEH_END]; ///< How many vehicles are there of this type? 67 uint16 num_station[NETWORK_VEH_END]; ///< How many stations are there of this type? 68 bool ai; ///< Is this company an AI 69 }; 70 71 /** Some state information of a company, especially for servers */ 72 struct NetworkCompanyState { 73 std::string password; ///< The password for the company 74 uint16 months_empty; ///< How many months the company is empty 75 }; 76 77 struct NetworkClientInfo; 78 79 /** The type of password we're asking for. */ 80 enum NetworkPasswordType { 81 NETWORK_GAME_PASSWORD, ///< The password of the game. 82 NETWORK_COMPANY_PASSWORD, ///< The password of the company. 83 }; 84 85 /** 86 * Destination of our chat messages. 87 * @warning The values of the enum items are part of the admin network API. Only append at the end. 88 */ 89 enum DestType { 90 DESTTYPE_BROADCAST, ///< Send message/notice to all clients (All) 91 DESTTYPE_TEAM, ///< Send message/notice to everyone playing the same company (Team) 92 DESTTYPE_CLIENT, ///< Send message/notice to only a certain client (Private) 93 }; 94 95 /** 96 * Actions that can be used for NetworkTextMessage. 97 * @warning The values of the enum items are part of the admin network API. Only append at the end. 98 */ 99 enum NetworkAction { 100 NETWORK_ACTION_JOIN, 101 NETWORK_ACTION_LEAVE, 102 NETWORK_ACTION_SERVER_MESSAGE, 103 NETWORK_ACTION_CHAT, 104 NETWORK_ACTION_CHAT_COMPANY, 105 NETWORK_ACTION_CHAT_CLIENT, 106 NETWORK_ACTION_GIVE_MONEY, 107 NETWORK_ACTION_NAME_CHANGE, 108 NETWORK_ACTION_COMPANY_SPECTATOR, 109 NETWORK_ACTION_COMPANY_JOIN, 110 NETWORK_ACTION_COMPANY_NEW, 111 NETWORK_ACTION_KICKED, 112 NETWORK_ACTION_EXTERNAL_CHAT, 113 }; 114 115 /** 116 * The error codes we send around in the protocols. 117 * @warning The values of the enum items are part of the admin network API. Only append at the end. 118 */ 119 enum NetworkErrorCode { 120 NETWORK_ERROR_GENERAL, // Try to use this one like never 121 122 /* Signals from clients */ 123 NETWORK_ERROR_DESYNC, 124 NETWORK_ERROR_SAVEGAME_FAILED, 125 NETWORK_ERROR_CONNECTION_LOST, 126 NETWORK_ERROR_ILLEGAL_PACKET, 127 NETWORK_ERROR_NEWGRF_MISMATCH, 128 129 /* Signals from servers */ 130 NETWORK_ERROR_NOT_AUTHORIZED, 131 NETWORK_ERROR_NOT_EXPECTED, 132 NETWORK_ERROR_WRONG_REVISION, 133 NETWORK_ERROR_NAME_IN_USE, 134 NETWORK_ERROR_WRONG_PASSWORD, 135 NETWORK_ERROR_COMPANY_MISMATCH, // Happens in CLIENT_COMMAND 136 NETWORK_ERROR_KICKED, 137 NETWORK_ERROR_CHEATER, 138 NETWORK_ERROR_FULL, 139 NETWORK_ERROR_TOO_MANY_COMMANDS, 140 NETWORK_ERROR_TIMEOUT_PASSWORD, 141 NETWORK_ERROR_TIMEOUT_COMPUTER, 142 NETWORK_ERROR_TIMEOUT_MAP, 143 NETWORK_ERROR_TIMEOUT_JOIN, 144 NETWORK_ERROR_INVALID_CLIENT_NAME, 145 146 NETWORK_ERROR_END, 147 }; 148 149 #endif /* NETWORK_TYPE_H */ 150