Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NetMessages.h
Go to the documentation of this file.
1 /* Copyright (C) 2011 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 0x01010005 // Arbitrary protocol
32 #define PS_DEFAULT_PORT 0x5073 // 'P', 's'
33 
34 // Defines the list of message types. The order of the list must not change.
35 // The message types having a negative value are used internally and not sent
36 // over the network. The message types used for network communication have
37 // positive values.
39 {
40  NMT_CONNECT_COMPLETE = -256, // Connection is complete
42  NMT_INVALID = 0, // Invalid message
43  NMT_SERVER_HANDSHAKE, // Handshake stage
46  NMT_AUTHENTICATE, // Authentication stage
48  NMT_CHAT, // Common chat message
51 
56 
58 
62  NMT_SYNC_CHECK, // OOS-detection hash checking
63  NMT_SYNC_ERROR, // OOS-detection error
65  NMT_LAST // Last message in the list
66 };
67 
68 // Authentication result codes
70 {
74 };
75 
76 #endif // NETMESSAGES_H
77 
78 #ifdef CREATING_NMT
79 
80 #define ALLNETMSGS_DONT_CREATE_NMTS
81 #define START_NMT_CLASS_(_nm, _message) START_NMT_CLASS(C##_nm##Message, _message)
82 #define DERIVE_NMT_CLASS_(_base, _nm, _message) START_NMT_CLASS_DERIVED(C ## _base ## Message, C ## _nm ## Message, _message)
83 
84 START_NMTS()
85 
86 START_NMT_CLASS_(SrvHandshake, NMT_SERVER_HANDSHAKE)
87  NMT_FIELD_INT(m_Magic, u32, 4)
88  NMT_FIELD_INT(m_ProtocolVersion, u32, 4)
89  NMT_FIELD_INT(m_SoftwareVersion, u32, 4)
90 END_NMT_CLASS()
91 
92 START_NMT_CLASS_(CliHandshake, NMT_CLIENT_HANDSHAKE)
93  NMT_FIELD_INT(m_MagicResponse, u32, 4)
94  NMT_FIELD_INT(m_ProtocolVersion, u32, 4)
95  NMT_FIELD_INT(m_SoftwareVersion, u32, 4)
96 END_NMT_CLASS()
97 
98 START_NMT_CLASS_(SrvHandshakeResponse, NMT_SERVER_HANDSHAKE_RESPONSE)
99  NMT_FIELD_INT(m_UseProtocolVersion, u32, 4)
100  NMT_FIELD_INT(m_Flags, u32, 4)
101  NMT_FIELD(CStrW, m_Message)
102 END_NMT_CLASS()
103 
104 START_NMT_CLASS_(Authenticate, NMT_AUTHENTICATE)
105  NMT_FIELD(CStr8, m_GUID)
106  NMT_FIELD(CStrW, m_Name)
107  NMT_FIELD(CStrW, m_Password)
108 END_NMT_CLASS()
109 
110 START_NMT_CLASS_(AuthenticateResult, NMT_AUTHENTICATE_RESULT)
111  NMT_FIELD_INT(m_Code, u32, 4)
112  NMT_FIELD_INT(m_HostID, u32, 2)
113  NMT_FIELD(CStrW, m_Message)
114 END_NMT_CLASS()
115 
116 START_NMT_CLASS_(Chat, NMT_CHAT)
117  NMT_FIELD(CStr8, m_GUID) // ignored when client->server, valid when server->client
118  NMT_FIELD(CStrW, m_Message)
119 END_NMT_CLASS()
120 
121 START_NMT_CLASS_(PlayerAssignment, NMT_PLAYER_ASSIGNMENT)
122  NMT_START_ARRAY(m_Hosts)
123  NMT_FIELD(CStr8, m_GUID)
124  NMT_FIELD(CStrW, m_Name)
125  NMT_FIELD_INT(m_PlayerID, u8, 1)
126  NMT_END_ARRAY()
127 END_NMT_CLASS()
128 
129 START_NMT_CLASS_(FileTransferRequest, NMT_FILE_TRANSFER_REQUEST)
130  NMT_FIELD_INT(m_RequestID, u32, 4)
131 END_NMT_CLASS()
132 
133 START_NMT_CLASS_(FileTransferResponse, NMT_FILE_TRANSFER_RESPONSE)
134  NMT_FIELD_INT(m_RequestID, u32, 4)
135  NMT_FIELD_INT(m_Length, u32, 4)
136 END_NMT_CLASS()
137 
138 START_NMT_CLASS_(FileTransferData, NMT_FILE_TRANSFER_DATA)
139  NMT_FIELD_INT(m_RequestID, u32, 4)
140  NMT_FIELD(CStr8, m_Data)
141 END_NMT_CLASS()
142 
143 START_NMT_CLASS_(FileTransferAck, NMT_FILE_TRANSFER_ACK)
144  NMT_FIELD_INT(m_RequestID, u32, 4)
145  NMT_FIELD_INT(m_NumPackets, u32, 4)
146 END_NMT_CLASS()
147 
148 START_NMT_CLASS_(JoinSyncStart, NMT_JOIN_SYNC_START)
149 END_NMT_CLASS()
150 
151 START_NMT_CLASS_(LoadedGame, NMT_LOADED_GAME)
152  NMT_FIELD_INT(m_CurrentTurn, u32, 4)
153 END_NMT_CLASS()
154 
155 START_NMT_CLASS_(GameStart, NMT_GAME_START)
156 END_NMT_CLASS()
157 
158 START_NMT_CLASS_(EndCommandBatch, NMT_END_COMMAND_BATCH)
159  NMT_FIELD_INT(m_Turn, u32, 4)
160  NMT_FIELD_INT(m_TurnLength, u32, 2)
161 END_NMT_CLASS()
162 
163 START_NMT_CLASS_(SyncCheck, NMT_SYNC_CHECK)
164  NMT_FIELD_INT(m_Turn, u32, 4)
165  NMT_FIELD(CStr, m_Hash)
166 END_NMT_CLASS()
167 
168 START_NMT_CLASS_(SyncError, NMT_SYNC_ERROR)
169  NMT_FIELD_INT(m_Turn, u32, 4)
170  NMT_FIELD(CStr, m_HashExpected)
171 END_NMT_CLASS()
172 
173 END_NMTS()
174 
175 #else
176 #ifndef ALLNETMSGS_DONT_CREATE_NMTS
177 
178 # ifdef ALLNETMSGS_IMPLEMENT
179 # define NMT_CREATOR_IMPLEMENT
180 # endif
181 
182 # define NMT_CREATE_HEADER_NAME "NetMessages.h"
183 # include "NMTCreator.h"
184 
185 #endif // #ifndef ALLNETMSGS_DONT_CREATE_NMTS
186 #endif // #ifdef CREATING_NMT
#define u8
Definition: types.h:39
NetMessageType
Definition: NetMessages.h:38
AuthenticateResultCode
Definition: NetMessages.h:69
#define u32
Definition: types.h:41