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/>.
10 /** @file network_type.h Types used for networking. */
12 #ifndef NETWORK_TYPE_H
13 #define NETWORK_TYPE_H
15 #include "core/game.h"
19 /** How many clients can we have */
20 static const uint MAX_CLIENTS
= 255;
23 * The number of slots; must be at least 1 more than MAX_CLIENTS. It must
24 * furthermore be less than or equal to 256 as client indices (sent over
25 * the network) are 8 bits. It needs 1 more for the dedicated server.
27 static const uint MAX_CLIENT_SLOTS
= 256;
30 * Vehicletypes in the order they are send in info packets.
32 enum NetworkVehicleType
{
33 NETWORK_VEH_TRAIN
= 0,
42 /** 'Unique' identifier to be given to clients */
44 INVALID_CLIENT_ID
= 0, ///< Client is not part of anything
45 CLIENT_ID_SERVER
= 1, ///< Servers always have this ID
46 CLIENT_ID_FIRST
= 2, ///< The first client ID
49 /** Indices into the client tables */
50 typedef uint8 ClientIndex
;
52 /** Indices into the admin tables. */
53 typedef uint8 AdminIndex
;
55 /** Maximum number of allowed admins. */
56 static const AdminIndex MAX_ADMINS
= 16;
57 /** An invalid admin marker. */
58 static const AdminIndex INVALID_ADMIN_ID
= UINT8_MAX
;
60 /** Simple calculated statistics of a company */
61 struct NetworkCompanyStats
{
62 uint16 num_vehicle
[NETWORK_VEH_END
]; ///< How many vehicles are there of this type?
63 uint16 num_station
[NETWORK_VEH_END
]; ///< How many stations are there of this type?
64 bool ai
; ///< Is this company an AI
67 /** Some state information of a company, especially for servers */
68 struct NetworkCompanyState
{
69 char password
[NETWORK_PASSWORD_LENGTH
]; ///< The password for the company
70 uint16 months_empty
; ///< How many months the company is empty
73 struct NetworkClientInfo
;
75 /** The type of password we're asking for. */
76 enum NetworkPasswordType
{
77 NETWORK_GAME_PASSWORD
, ///< The password of the game.
78 NETWORK_COMPANY_PASSWORD
, ///< The password of the company.
81 /** Destination of our chat messages. */
83 DESTTYPE_BROADCAST
, ///< Send message/notice to all clients (All)
84 DESTTYPE_TEAM
, ///< Send message/notice to everyone playing the same company (Team)
85 DESTTYPE_CLIENT
, ///< Send message/notice to only a certain client (Private)
88 /** Actions that can be used for NetworkTextMessage */
92 NETWORK_ACTION_SERVER_MESSAGE
,
94 NETWORK_ACTION_CHAT_COMPANY
,
95 NETWORK_ACTION_CHAT_CLIENT
,
96 NETWORK_ACTION_GIVE_MONEY
,
97 NETWORK_ACTION_NAME_CHANGE
,
98 NETWORK_ACTION_COMPANY_SPECTATOR
,
99 NETWORK_ACTION_COMPANY_JOIN
,
100 NETWORK_ACTION_COMPANY_NEW
,
103 /** The error codes we send around in the protocols. */
104 enum NetworkErrorCode
{
105 NETWORK_ERROR_GENERAL
, // Try to use this one like never
107 /* Signals from clients */
108 NETWORK_ERROR_DESYNC
,
109 NETWORK_ERROR_SAVEGAME_FAILED
,
110 NETWORK_ERROR_CONNECTION_LOST
,
111 NETWORK_ERROR_ILLEGAL_PACKET
,
112 NETWORK_ERROR_NEWGRF_MISMATCH
,
114 /* Signals from servers */
115 NETWORK_ERROR_NOT_AUTHORIZED
,
116 NETWORK_ERROR_NOT_EXPECTED
,
117 NETWORK_ERROR_WRONG_REVISION
,
118 NETWORK_ERROR_NAME_IN_USE
,
119 NETWORK_ERROR_WRONG_PASSWORD
,
120 NETWORK_ERROR_COMPANY_MISMATCH
, // Happens in CLIENT_COMMAND
121 NETWORK_ERROR_KICKED
,
122 NETWORK_ERROR_CHEATER
,
124 NETWORK_ERROR_TOO_MANY_COMMANDS
,
125 NETWORK_ERROR_TIMEOUT_PASSWORD
,
126 NETWORK_ERROR_TIMEOUT_COMPUTER
,
127 NETWORK_ERROR_TIMEOUT_MAP
,
128 NETWORK_ERROR_TIMEOUT_JOIN
,
133 #endif /* ENABLE_NETWORK */
134 #endif /* NETWORK_TYPE_H */