Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
NetMessages.h
Go to the documentation of this file.
1/* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18/**
19 * @file
20 * The list of messages used by the network subsystem.
21 */
22
23#ifndef NETMESSAGES_H
24#define NETMESSAGES_H
25
26#include "ps/CStr.h"
28
29#define PS_PROTOCOL_MAGIC 0x5073013f // 'P', 's', 0x01, '?'
30#define PS_PROTOCOL_MAGIC_RESPONSE 0x50630121 // 'P', 'c', 0x01, '!'
31#define PS_PROTOCOL_VERSION 0x01010018 // Arbitrary protocol
32#define PS_DEFAULT_PORT 0x5073 // 'P', 's'
33
34// Set when lobby authentication is required. Used in the SrvHandshakeResponseMessage.
35#define PS_NETWORK_FLAG_REQUIRE_LOBBYAUTH 0x1
36
37// Defines the list of message types. The order of the list must not change.
38// The message types having a negative value are used internally and not sent
39// over the network. The message types used for network communication have
40// positive values.
42{
46
50
53
60
65
67
70
75
79
80 NMT_SYNC_CHECK, // OOS-detection hash checking
81 NMT_SYNC_ERROR, // OOS-detection error
82
84};
85
86// Authentication result codes
88{
92};
93
94#endif // NETMESSAGES_H
95
96#ifdef CREATING_NMT
97
98#define ALLNETMSGS_DONT_CREATE_NMTS
99#define START_NMT_CLASS_(_nm, _message) START_NMT_CLASS(C##_nm##Message, _message)
100#define DERIVE_NMT_CLASS_(_base, _nm, _message) START_NMT_CLASS_DERIVED(C ## _base ## Message, C ## _nm ## Message, _message)
101
102START_NMTS()
103
104START_NMT_CLASS_(SrvHandshake, NMT_SERVER_HANDSHAKE)
105 NMT_FIELD_INT(m_Magic, u32, 4)
106 NMT_FIELD_INT(m_ProtocolVersion, u32, 4)
107 NMT_FIELD_INT(m_SoftwareVersion, u32, 4)
108END_NMT_CLASS()
109
110START_NMT_CLASS_(CliHandshake, NMT_CLIENT_HANDSHAKE)
111 NMT_FIELD_INT(m_MagicResponse, u32, 4)
112 NMT_FIELD_INT(m_ProtocolVersion, u32, 4)
113 NMT_FIELD_INT(m_SoftwareVersion, u32, 4)
114END_NMT_CLASS()
115
116START_NMT_CLASS_(SrvHandshakeResponse, NMT_SERVER_HANDSHAKE_RESPONSE)
117 NMT_FIELD_INT(m_UseProtocolVersion, u32, 4)
118 NMT_FIELD_INT(m_Flags, u32, 4)
119 NMT_FIELD(CStr, m_GUID)
120END_NMT_CLASS()
121
122START_NMT_CLASS_(Authenticate, NMT_AUTHENTICATE)
123 NMT_FIELD(CStrW, m_Name)
124 NMT_FIELD_SECRET(CStr, m_Password)
125 NMT_FIELD_SECRET(CStr, m_ControllerSecret)
126END_NMT_CLASS()
127
128START_NMT_CLASS_(AuthenticateResult, NMT_AUTHENTICATE_RESULT)
129 NMT_FIELD_INT(m_Code, u32, 4)
130 NMT_FIELD_INT(m_HostID, u32, 2)
131 NMT_FIELD_INT(m_IsController, u8, 1)
132 NMT_FIELD(CStrW, m_Message)
133END_NMT_CLASS()
134
135START_NMT_CLASS_(Chat, NMT_CHAT)
136 NMT_FIELD(CStr, m_GUID) // ignored when client->server, valid when server->client
137 NMT_FIELD(CStrW, m_Message)
138END_NMT_CLASS()
139
140START_NMT_CLASS_(Ready, NMT_READY)
141 NMT_FIELD(CStr, m_GUID)
142 NMT_FIELD_INT(m_Status, u8, 1)
143END_NMT_CLASS()
144
145START_NMT_CLASS_(ClearAllReady, NMT_CLEAR_ALL_READY)
146END_NMT_CLASS()
147
149 NMT_START_ARRAY(m_Hosts)
150 NMT_FIELD(CStr, m_GUID)
151 NMT_FIELD(CStrW, m_Name)
152 NMT_FIELD_INT(m_PlayerID, i8, 1)
153 NMT_FIELD_INT(m_Status, u8, 1)
154 NMT_END_ARRAY()
155END_NMT_CLASS()
156
157START_NMT_CLASS_(FileTransferRequest, NMT_FILE_TRANSFER_REQUEST)
158 NMT_FIELD_INT(m_RequestID, u32, 4)
159END_NMT_CLASS()
160
161START_NMT_CLASS_(FileTransferResponse, NMT_FILE_TRANSFER_RESPONSE)
162 NMT_FIELD_INT(m_RequestID, u32, 4)
163 NMT_FIELD_INT(m_Length, u32, 4)
164END_NMT_CLASS()
165
166START_NMT_CLASS_(FileTransferData, NMT_FILE_TRANSFER_DATA)
167 NMT_FIELD_INT(m_RequestID, u32, 4)
168 NMT_FIELD(CStr, m_Data)
169END_NMT_CLASS()
170
171START_NMT_CLASS_(FileTransferAck, NMT_FILE_TRANSFER_ACK)
172 NMT_FIELD_INT(m_RequestID, u32, 4)
173 NMT_FIELD_INT(m_NumPackets, u32, 4)
174END_NMT_CLASS()
175
176START_NMT_CLASS_(JoinSyncStart, NMT_JOIN_SYNC_START)
177 NMT_FIELD(CStr, m_InitAttributes)
178END_NMT_CLASS()
179
180START_NMT_CLASS_(Rejoined, NMT_REJOINED)
181 NMT_FIELD(CStr, m_GUID)
182END_NMT_CLASS()
183
184START_NMT_CLASS_(Kicked, NMT_KICKED)
185 NMT_FIELD(CStrW, m_Name)
186 NMT_FIELD_INT(m_Ban, u8, 1)
187END_NMT_CLASS()
188
189START_NMT_CLASS_(ClientTimeout, NMT_CLIENT_TIMEOUT)
190 NMT_FIELD(CStr, m_GUID)
191 NMT_FIELD_INT(m_LastReceivedTime, u32, 4)
192END_NMT_CLASS()
193
194START_NMT_CLASS_(ClientPerformance, NMT_CLIENT_PERFORMANCE)
195 NMT_START_ARRAY(m_Clients)
196 NMT_FIELD(CStr, m_GUID)
197 NMT_FIELD_INT(m_MeanRTT, u32, 4)
198 NMT_END_ARRAY()
199END_NMT_CLASS()
200
201START_NMT_CLASS_(ClientsLoading, NMT_CLIENTS_LOADING)
202 NMT_START_ARRAY(m_Clients)
203 NMT_FIELD(CStr, m_GUID)
204 NMT_END_ARRAY()
205END_NMT_CLASS()
206
207START_NMT_CLASS_(ClientPaused, NMT_CLIENT_PAUSED)
208 NMT_FIELD(CStr, m_GUID)
209 NMT_FIELD_INT(m_Pause, u8, 1)
210END_NMT_CLASS()
211
212START_NMT_CLASS_(LoadedGame, NMT_LOADED_GAME)
213 NMT_FIELD_INT(m_CurrentTurn, u32, 4)
214END_NMT_CLASS()
215
216START_NMT_CLASS_(GameStart, NMT_GAME_START)
217 NMT_FIELD(CStr, m_InitAttributes)
218END_NMT_CLASS()
219
220START_NMT_CLASS_(EndCommandBatch, NMT_END_COMMAND_BATCH)
221 NMT_FIELD_INT(m_Turn, u32, 4)
222 NMT_FIELD_INT(m_TurnLength, u32, 2)
223END_NMT_CLASS()
224
225START_NMT_CLASS_(SyncCheck, NMT_SYNC_CHECK)
226 NMT_FIELD_INT(m_Turn, u32, 4)
227 NMT_FIELD(CStr, m_Hash)
228END_NMT_CLASS()
229
230START_NMT_CLASS_(SyncError, NMT_SYNC_ERROR)
231 NMT_FIELD_INT(m_Turn, u32, 4)
232 NMT_FIELD(CStr, m_HashExpected)
233 NMT_START_ARRAY(m_PlayerNames)
234 NMT_FIELD(CStrW, m_Name)
235 NMT_END_ARRAY()
236END_NMT_CLASS()
237
238START_NMT_CLASS_(AssignPlayer, NMT_ASSIGN_PLAYER)
239 NMT_FIELD_INT(m_PlayerID, i8, 1)
240 NMT_FIELD(CStr, m_GUID)
241END_NMT_CLASS()
242
243END_NMTS()
244
245#else
246#ifndef ALLNETMSGS_DONT_CREATE_NMTS
247
248# ifdef ALLNETMSGS_IMPLEMENT
249# define NMT_CREATOR_IMPLEMENT
250# endif
251
252# define NMT_CREATE_HEADER_NAME "NetMessages.h"
253# include "NMTCreator.h"
254
255#endif // #ifndef ALLNETMSGS_DONT_CREATE_NMTS
256#endif // #ifdef CREATING_NMT
AuthenticateResultCode
Definition: NetMessages.h:88
@ ARC_PASSWORD_INVALID
Definition: NetMessages.h:91
@ ARC_OK_REJOINING
Definition: NetMessages.h:90
@ ARC_OK
Definition: NetMessages.h:89
NetMessageType
Definition: NetMessages.h:42
@ NMT_SYNC_CHECK
Definition: NetMessages.h:80
@ NMT_INVALID
Definition: NetMessages.h:45
@ NMT_CLIENTS_LOADING
Definition: NetMessages.h:73
@ NMT_CLIENT_PAUSED
Definition: NetMessages.h:74
@ NMT_GAME_SETUP
Definition: NetMessages.h:57
@ NMT_REJOINED
Definition: NetMessages.h:68
@ NMT_CLIENT_HANDSHAKE
Definition: NetMessages.h:48
@ NMT_FILE_TRANSFER_DATA
Definition: NetMessages.h:63
@ NMT_END_COMMAND_BATCH
Definition: NetMessages.h:78
@ NMT_SERVER_HANDSHAKE_RESPONSE
Definition: NetMessages.h:49
@ NMT_CLIENT_TIMEOUT
Definition: NetMessages.h:71
@ NMT_FILE_TRANSFER_RESPONSE
Definition: NetMessages.h:62
@ NMT_KICKED
Definition: NetMessages.h:69
@ NMT_SYNC_ERROR
Definition: NetMessages.h:81
@ NMT_JOIN_SYNC_START
Definition: NetMessages.h:66
@ NMT_CLIENT_PERFORMANCE
Definition: NetMessages.h:72
@ NMT_PLAYER_ASSIGNMENT
Definition: NetMessages.h:59
@ NMT_FILE_TRANSFER_REQUEST
Definition: NetMessages.h:61
@ NMT_AUTHENTICATE_RESULT
Definition: NetMessages.h:52
@ NMT_CLEAR_ALL_READY
Definition: NetMessages.h:56
@ NMT_LOADED_GAME
Definition: NetMessages.h:76
@ NMT_AUTHENTICATE
Definition: NetMessages.h:51
@ NMT_ASSIGN_PLAYER
Definition: NetMessages.h:58
@ NMT_CHAT
Definition: NetMessages.h:54
@ NMT_CONNECT_COMPLETE
Definition: NetMessages.h:43
@ NMT_READY
Definition: NetMessages.h:55
@ NMT_SIMULATION_COMMAND
Definition: NetMessages.h:83
@ NMT_FILE_TRANSFER_ACK
Definition: NetMessages.h:64
@ NMT_SERVER_HANDSHAKE
Definition: NetMessages.h:47
@ NMT_CONNECTION_LOST
Definition: NetMessages.h:44
@ NMT_GAME_START
Definition: NetMessages.h:77
Definition: NetHost.h:36
uint8_t u8
Definition: types.h:37
int8_t i8
Definition: types.h:32
uint32_t u32
Definition: types.h:39