OpenTTD Source: src/network/network_type.h Source File

OpenTTD Source 15.3

network_type.h
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef NETWORK_TYPE_H
11#define NETWORK_TYPE_H
12
13#include "../core/enum_type.hpp"
14#include "../core/pool_type.hpp"
15
17 static const uint MAX_CLIENTS = 255;
18
22 enum NetworkVehicleType : uint8_t {
23 NETWORK_VEH_TRAIN = 0,
24 NETWORK_VEH_LORRY,
25 NETWORK_VEH_BUS,
26 NETWORK_VEH_PLANE,
27 NETWORK_VEH_SHIP,
28
29 NETWORK_VEH_END
30};
31
36 enum ServerGameType : uint8_t {
37 SERVER_GAME_TYPE_LOCAL = 0,
38 SERVER_GAME_TYPE_PUBLIC,
39 SERVER_GAME_TYPE_INVITE_ONLY,
40};
41
43 enum ClientID : uint32_t {
44 INVALID_CLIENT_ID = 0,
45 CLIENT_ID_SERVER = 1,
46 CLIENT_ID_FIRST = 2,
47};
48
50 using ClientPoolID = PoolID<uint16_t, struct ClientPoolIDTag, MAX_CLIENTS + 1 /* dedicated server. */, 0xFFFF>;
51
53 using AdminID = PoolID<uint8_t, struct AdminIDTag, 16, 0xFF>;
54
56 struct NetworkCompanyStats {
57 uint16_t num_vehicle[NETWORK_VEH_END];
58 uint16_t num_station[NETWORK_VEH_END];
59 bool ai;
60};
61
62struct NetworkClientInfo;
63
68 enum DestType : uint8_t {
69 DESTTYPE_BROADCAST,
70 DESTTYPE_TEAM,
71 DESTTYPE_CLIENT,
72};
73 DECLARE_ENUM_AS_ADDABLE(DestType)
74
75
79enum NetworkAction : uint8_t {
80 NETWORK_ACTION_JOIN,
81 NETWORK_ACTION_LEAVE,
82 NETWORK_ACTION_SERVER_MESSAGE,
83 NETWORK_ACTION_CHAT,
84 NETWORK_ACTION_CHAT_COMPANY,
85 NETWORK_ACTION_CHAT_CLIENT,
86 NETWORK_ACTION_GIVE_MONEY,
87 NETWORK_ACTION_NAME_CHANGE,
88 NETWORK_ACTION_COMPANY_SPECTATOR,
89 NETWORK_ACTION_COMPANY_JOIN,
90 NETWORK_ACTION_COMPANY_NEW,
91 NETWORK_ACTION_KICKED,
92 NETWORK_ACTION_EXTERNAL_CHAT,
93};
94
99 enum NetworkErrorCode : uint8_t {
100 NETWORK_ERROR_GENERAL, // Try to use this one like never
101
102 /* Signals from clients */
103 NETWORK_ERROR_DESYNC,
104 NETWORK_ERROR_SAVEGAME_FAILED,
105 NETWORK_ERROR_CONNECTION_LOST,
106 NETWORK_ERROR_ILLEGAL_PACKET,
107 NETWORK_ERROR_NEWGRF_MISMATCH,
108
109 /* Signals from servers */
110 NETWORK_ERROR_NOT_AUTHORIZED,
111 NETWORK_ERROR_NOT_EXPECTED,
112 NETWORK_ERROR_WRONG_REVISION,
113 NETWORK_ERROR_NAME_IN_USE,
114 NETWORK_ERROR_WRONG_PASSWORD,
115 NETWORK_ERROR_COMPANY_MISMATCH, // Happens in CLIENT_COMMAND
116 NETWORK_ERROR_KICKED,
117 NETWORK_ERROR_CHEATER,
118 NETWORK_ERROR_FULL,
119 NETWORK_ERROR_TOO_MANY_COMMANDS,
120 NETWORK_ERROR_TIMEOUT_PASSWORD,
121 NETWORK_ERROR_TIMEOUT_COMPUTER,
122 NETWORK_ERROR_TIMEOUT_MAP,
123 NETWORK_ERROR_TIMEOUT_JOIN,
124 NETWORK_ERROR_INVALID_CLIENT_NAME,
125 NETWORK_ERROR_NOT_ON_ALLOW_LIST,
126 NETWORK_ERROR_NO_AUTHENTICATION_METHOD_AVAILABLE,
127
128 NETWORK_ERROR_END,
129};
130
137 class NetworkAuthorizedKeys : public std::vector<std::string> {
138public:
139 bool Contains(std::string_view key) const;
140 bool Add(std::string_view key);
141 bool Remove(std::string_view key);
142};
143
144#endif /* NETWORK_TYPE_H */
NetworkAuthorizedKeys
Simple helper to (more easily) manage authorized keys.
Definition network_type.h:137
NetworkAuthorizedKeys::Contains
bool Contains(std::string_view key) const
Check whether the given key is contains in these authorized keys.
Definition network.cpp:180
NetworkAuthorizedKeys::Add
bool Add(std::string_view key)
Add the given key to the authorized keys, when it is not already contained.
Definition network.cpp:190
NetworkAuthorizedKeys::Remove
bool Remove(std::string_view key)
Remove the given key from the authorized keys, when it is exists.
Definition network.cpp:206
DECLARE_ENUM_AS_ADDABLE
#define DECLARE_ENUM_AS_ADDABLE(EnumType)
Operator that allows this enumeration to be added to any other enumeration.
Definition enum_type.hpp:129
NetworkVehicleType
NetworkVehicleType
Vehicletypes in the order they are send in info packets.
Definition network_type.h:22
DestType
DestType
Destination of our chat messages.
Definition network_type.h:68
DESTTYPE_CLIENT
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
Definition network_type.h:71
DESTTYPE_TEAM
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
Definition network_type.h:70
DESTTYPE_BROADCAST
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
Definition network_type.h:69
NetworkErrorCode
NetworkErrorCode
The error codes we send around in the protocols.
Definition network_type.h:99
NetworkAction
NetworkAction
Actions that can be used for NetworkTextMessage.
Definition network_type.h:79
MAX_CLIENTS
static const uint MAX_CLIENTS
How many clients can we have.
Definition network_type.h:17
ClientID
ClientID
'Unique' identifier to be given to clients
Definition network_type.h:43
INVALID_CLIENT_ID
@ INVALID_CLIENT_ID
Client is not part of anything.
Definition network_type.h:44
CLIENT_ID_SERVER
@ CLIENT_ID_SERVER
Servers always have this ID.
Definition network_type.h:45
CLIENT_ID_FIRST
@ CLIENT_ID_FIRST
The first client ID.
Definition network_type.h:46
ServerGameType
ServerGameType
Game type the server can be using.
Definition network_type.h:36
NetworkClientInfo
Container for all information known about a client.
Definition network_base.h:24
NetworkCompanyStats
Simple calculated statistics of a company.
Definition network_type.h:56
NetworkCompanyStats::num_vehicle
uint16_t num_vehicle[NETWORK_VEH_END]
How many vehicles are there of this type?
Definition network_type.h:57
NetworkCompanyStats::num_station
uint16_t num_station[NETWORK_VEH_END]
How many stations are there of this type?
Definition network_type.h:58
NetworkCompanyStats::ai
bool ai
Is this company an AI.
Definition network_type.h:59
PoolID< uint16_t, struct ClientPoolIDTag, MAX_CLIENTS+1, 0xFFFF >