OpenTTD Source 20250205-master-gfd85ab1e2c
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 <http://www.gnu.org/licenses/>.
6 */
7
10#ifndef NETWORK_TYPE_H
11#define NETWORK_TYPE_H
12
13#include "../core/enum_type.hpp"
14
16static const uint MAX_CLIENTS = 255;
17
23static const uint MAX_CLIENT_SLOTS = 256;
24
28enum NetworkVehicleType : uint8_t {
29 NETWORK_VEH_TRAIN = 0,
30 NETWORK_VEH_LORRY,
31 NETWORK_VEH_BUS,
32 NETWORK_VEH_PLANE,
33 NETWORK_VEH_SHIP,
34
35 NETWORK_VEH_END
36};
37
42enum ServerGameType : uint8_t {
43 SERVER_GAME_TYPE_LOCAL = 0,
44 SERVER_GAME_TYPE_PUBLIC,
45 SERVER_GAME_TYPE_INVITE_ONLY,
46};
47
54
56typedef uint8_t ClientPoolID;
57
59typedef uint8_t AdminID;
60
62static const AdminID INVALID_ADMIN_ID = UINT8_MAX;
63
66 uint16_t num_vehicle[NETWORK_VEH_END];
67 uint16_t num_station[NETWORK_VEH_END];
68 bool ai;
69};
70
72
83
84
88enum NetworkAction : uint8_t {
89 NETWORK_ACTION_JOIN,
90 NETWORK_ACTION_LEAVE,
91 NETWORK_ACTION_SERVER_MESSAGE,
92 NETWORK_ACTION_CHAT,
93 NETWORK_ACTION_CHAT_COMPANY,
94 NETWORK_ACTION_CHAT_CLIENT,
95 NETWORK_ACTION_GIVE_MONEY,
96 NETWORK_ACTION_NAME_CHANGE,
97 NETWORK_ACTION_COMPANY_SPECTATOR,
98 NETWORK_ACTION_COMPANY_JOIN,
99 NETWORK_ACTION_COMPANY_NEW,
100 NETWORK_ACTION_KICKED,
101 NETWORK_ACTION_EXTERNAL_CHAT,
102};
103
108enum NetworkErrorCode : uint8_t {
109 NETWORK_ERROR_GENERAL, // Try to use this one like never
110
111 /* Signals from clients */
112 NETWORK_ERROR_DESYNC,
113 NETWORK_ERROR_SAVEGAME_FAILED,
114 NETWORK_ERROR_CONNECTION_LOST,
115 NETWORK_ERROR_ILLEGAL_PACKET,
116 NETWORK_ERROR_NEWGRF_MISMATCH,
117
118 /* Signals from servers */
119 NETWORK_ERROR_NOT_AUTHORIZED,
120 NETWORK_ERROR_NOT_EXPECTED,
121 NETWORK_ERROR_WRONG_REVISION,
122 NETWORK_ERROR_NAME_IN_USE,
123 NETWORK_ERROR_WRONG_PASSWORD,
124 NETWORK_ERROR_COMPANY_MISMATCH, // Happens in CLIENT_COMMAND
125 NETWORK_ERROR_KICKED,
126 NETWORK_ERROR_CHEATER,
127 NETWORK_ERROR_FULL,
128 NETWORK_ERROR_TOO_MANY_COMMANDS,
129 NETWORK_ERROR_TIMEOUT_PASSWORD,
130 NETWORK_ERROR_TIMEOUT_COMPUTER,
131 NETWORK_ERROR_TIMEOUT_MAP,
132 NETWORK_ERROR_TIMEOUT_JOIN,
133 NETWORK_ERROR_INVALID_CLIENT_NAME,
134 NETWORK_ERROR_NOT_ON_ALLOW_LIST,
135 NETWORK_ERROR_NO_AUTHENTICATION_METHOD_AVAILABLE,
136
137 NETWORK_ERROR_END,
138};
139
146class NetworkAuthorizedKeys : public std::vector<std::string> {
147public:
148 bool Contains(std::string_view key) const;
149 bool Add(std::string_view key);
150 bool Remove(std::string_view key);
151};
152
153#endif /* NETWORK_TYPE_H */
Simple helper to (more easily) manage authorized keys.
bool Contains(std::string_view key) const
Check whether the given key is contains in these authorized keys.
Definition network.cpp:178
bool Add(std::string_view key)
Add the given key to the authorized keys, when it is not already contained.
Definition network.cpp:188
bool Remove(std::string_view key)
Remove the given key from the authorized keys, when it is exists.
Definition network.cpp:204
#define DECLARE_ENUM_AS_ADDABLE(EnumType)
Operator that allows this enumeration to be added to any other enumeration.
Definition enum_type.hpp:78
NetworkVehicleType
Vehicletypes in the order they are send in info packets.
DestType
Destination of our chat messages.
@ DESTTYPE_CLIENT
Send message/notice to only a certain client (Private)
@ DESTTYPE_TEAM
Send message/notice to everyone playing the same company (Team)
@ DESTTYPE_BROADCAST
Send message/notice to all clients (All)
static const AdminID INVALID_ADMIN_ID
An invalid admin marker.
NetworkErrorCode
The error codes we send around in the protocols.
static const uint MAX_CLIENT_SLOTS
The number of slots; must be at least 1 more than MAX_CLIENTS.
NetworkAction
Actions that can be used for NetworkTextMessage.
static const uint MAX_CLIENTS
How many clients can we have.
uint8_t ClientPoolID
Indices into the client related pools.
uint8_t AdminID
Indices into the admin tables.
ClientID
'Unique' identifier to be given to clients
@ INVALID_CLIENT_ID
Client is not part of anything.
@ CLIENT_ID_SERVER
Servers always have this ID.
@ CLIENT_ID_FIRST
The first client ID.
ServerGameType
Game type the server can be using.
Container for all information known about a client.
Simple calculated statistics of a company.
uint16_t num_vehicle[NETWORK_VEH_END]
How many vehicles are there of this type?
uint16_t num_station[NETWORK_VEH_END]
How many stations are there of this type?
bool ai
Is this company an AI.