_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
net_message.h
Go to the documentation of this file.
1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
12 //
13 // (c) Copyright 2013 by Joris Dauphin
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; only version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 // 02111-1307, USA.
28 
29 #ifndef NET_MESSAGE_H
30 #define NET_MESSAGE_H
31 
33 
34 #include <stdint.h>
35 #include <vector>
36 
37 /*----------------------------------------------------------------------------
38 -- Declarations
39 ----------------------------------------------------------------------------*/
40 
45 #define NetPlayerNameSize 16
46 
47 #define MaxNetworkCommands 9
48 
49 
53 {
54 public:
56  size_t Serialize(unsigned char *buf) const;
57  size_t Deserialize(const unsigned char *buf);
58  void Clear();
59  static size_t Size() { return 4 + 2 + 2 + NetPlayerNameSize; }
60 
61  void SetName(const char *name);
62 
63  uint32_t Host;
64  uint16_t Port;
65  uint16_t PlyNr;
67 };
68 
73 {
74 public:
76  size_t Serialize(unsigned char *p) const;
77  size_t Deserialize(const unsigned char *p);
78  static size_t Size() { return 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 * PlayerMax + 1 * PlayerMax + 1 * PlayerMax; }
79  void Clear();
80 
81  bool operator == (const CServerSetup &rhs) const;
82  bool operator != (const CServerSetup &rhs) const { return !(*this == rhs); }
83 public:
84  uint8_t ResourcesOption;
85  uint8_t UnitsOption;
86  uint8_t FogOfWar;
87  uint8_t Inside;
88  uint8_t RevealMap;
89  uint8_t TilesetSelection;
90  uint8_t GameTypeOption;
91  uint8_t Difficulty;
92  uint8_t MapRichness;
93  uint8_t Opponents;
94  uint8_t CompOpt[PlayerMax];
95  uint8_t Ready[PlayerMax];
96  uint8_t Race[PlayerMax];
97  // Fill in here...
98 };
99 
106 
111 
114 
119 
123 
125 
128 };
129 
131 {
132 public:
134  CInitMessage_Header(unsigned char type, unsigned char subtype) :
135  type(type),
136  subtype(subtype)
137  {}
138 
139  unsigned char GetType() const { return type; }
140  unsigned char GetSubType() const { return subtype; }
141 
142  size_t Serialize(unsigned char *p) const;
143  size_t Deserialize(const unsigned char *p);
144  static size_t Size() { return 2; }
145 private:
146  unsigned char type;
147  unsigned char subtype;
148 };
149 
151 {
152 public:
154  explicit CInitMessage_Hello(const char *name);
155  const CInitMessage_Header &GetHeader() const { return header; }
156  const unsigned char *Serialize() const;
157  void Deserialize(const unsigned char *p);
158  static size_t Size() { return CInitMessage_Header::Size() + NetPlayerNameSize + 2 * 4; }
159 private:
160  CInitMessage_Header header;
161 public:
163  int32_t Stratagus;
164  uint32_t Version;
165 };
166 
168 {
169 public:
171  const CInitMessage_Header &GetHeader() const { return header; }
172  const unsigned char *Serialize() const;
173  void Deserialize(const unsigned char *p);
174  static size_t Size() { return CInitMessage_Header::Size() + 4 + PlayerMax * CNetworkHost::Size(); }
175 private:
176  CInitMessage_Header header;
177 public:
178  uint8_t clientIndex;
179  uint8_t hostsCount;
181 };
182 
184 {
185 public:
187  const CInitMessage_Header &GetHeader() const { return header; }
188  const unsigned char *Serialize() const;
189  void Deserialize(const unsigned char *p);
190  static size_t Size() { return CInitMessage_Header::Size() + 4; }
191 private:
192  CInitMessage_Header header;
193 public:
194  int32_t Stratagus;
195 };
196 
198 {
199 public:
201  const CInitMessage_Header &GetHeader() const { return header; }
202  const unsigned char *Serialize() const;
203  void Deserialize(const unsigned char *p);
204  static size_t Size() { return CInitMessage_Header::Size() + 4; }
205 private:
206  CInitMessage_Header header;
207 public:
208  uint32_t Version;
209 };
210 
212 {
213 public:
215  const CInitMessage_Header &GetHeader() const { return header; }
216  const unsigned char *Serialize() const;
217  void Deserialize(const unsigned char *p);
218  static size_t Size() { return CInitMessage_Header::Size() + PlayerMax * CNetworkHost::Size() + 2 * 4; }
219 private:
220  CInitMessage_Header header;
221 public:
223  int32_t Lag;
225 };
226 
228 {
229 public:
231  CInitMessage_Map(const char *path, uint32_t mapUID);
232  const CInitMessage_Header &GetHeader() const { return header; }
233  const unsigned char *Serialize() const;
234  void Deserialize(const unsigned char *p);
235  static size_t Size() { return CInitMessage_Header::Size() + 256 + 4; }
236 private:
237  CInitMessage_Header header;
238 public:
239  char MapPath[256];
240  uint32_t MapUID;
241 };
242 
244 {
245 public:
247  CInitMessage_State(int type, const CServerSetup &data);
248  const CInitMessage_Header &GetHeader() const { return header; }
249  const unsigned char *Serialize() const;
250  void Deserialize(const unsigned char *p);
251  static size_t Size() { return CInitMessage_Header::Size() + CServerSetup::Size(); }
252 private:
253  CInitMessage_Header header;
254 public:
256 };
257 
259 {
260 public:
262  const CInitMessage_Header &GetHeader() const { return header; }
263  const unsigned char *Serialize() const;
264  void Deserialize(const unsigned char *p);
265  static size_t Size() { return CInitMessage_Header::Size() + CNetworkHost::Size() * PlayerMax; }
266 private:
267  CInitMessage_Header header;
268 public:
270 };
271 
281 
286 
288 
312 
314 
315  // ATTN: __MUST__ be last due to spellid encoding!!!
317 };
318 
325 };
326 
331 {
332 public:
333  CNetworkCommand() : Unit(0), X(0), Y(0), Dest(0) {}
334  void Clear() { this->Unit = this->X = this->Y = this->Dest = 0; }
335 
336  size_t Serialize(unsigned char *buf) const;
337  size_t Deserialize(const unsigned char *buf);
338  static size_t Size() { return 2 + 2 + 2 + 2; }
339 
340 public:
341  uint16_t Unit;
342  uint16_t X;
343  uint16_t Y;
344  uint16_t Dest;
345 };
346 
351 {
352 public:
354 
355  size_t Serialize(unsigned char *buf) const;
356  size_t Deserialize(const unsigned char *buf);
357  static size_t Size() { return 1 + 1 + 2 + 2 + 2; }
358 
359  uint8_t ExtendedType;
360  uint8_t Arg1;
361  uint16_t Arg2;
362  uint16_t Arg3;
363  uint16_t Arg4;
364 };
365 
370 {
371 public:
372  size_t Serialize(unsigned char *buf) const;
373  size_t Deserialize(const unsigned char *buf);
374  size_t Size() const;
375 
376 public:
377  std::string Text;
378 };
379 
384 {
385 public:
387  size_t Serialize(unsigned char *buf) const;
388  size_t Deserialize(const unsigned char *buf);
389  static size_t Size() { return 4 + 4; };
390 
391 public:
392  uint32_t syncSeed;
393  uint32_t syncHash;
394 };
395 
400 {
401 public:
403  size_t Serialize(unsigned char *buf) const;
404  size_t Deserialize(const unsigned char *buf);
405  static size_t Size() { return 2; };
406 
407 public:
408  uint16_t player;
409 };
410 
415 {
416 public:
418 
419  size_t Serialize(unsigned char *buf) const;
420  size_t Deserialize(const unsigned char *buf);
421  size_t Size() const;
422 
423 public:
424  uint16_t player;
425  std::vector<uint16_t> Units;
426 };
427 
434 {
435 public:
437  {
438  Cycle = 0;
439  memset(Type, 0, sizeof(Type));
440  OrigPlayer = 255;
441  }
442 
443  size_t Serialize(unsigned char *buf) const;
444  size_t Deserialize(const unsigned char *buf);
445  static size_t Size() { return 1 + 1 + 1 * MaxNetworkCommands; }
446 
448  uint8_t Cycle;
449  uint8_t OrigPlayer;
450 };
451 
458 {
459 public:
460  size_t Serialize(unsigned char *buf, int numcommands) const;
461  void Deserialize(const unsigned char *buf, unsigned int len, int *numcommands);
462  size_t Size(int numcommands) const;
463 
465  std::vector<unsigned char> Command[MaxNetworkCommands];
466 };
467 
469 
470 #endif // !NET_MESSAGE_H
void Deserialize(const unsigned char *p)
Definition: net_message.cpp:399
static size_t Size()
Definition: net_message.h:235
Definition: net_message.h:197
const unsigned char * Serialize() const
Definition: net_message.cpp:560
Heart beat.
Definition: net_message.h:283
Definition: net_message.h:323
Client is ready to run.
Definition: net_message.h:126
const CInitMessage_Header & GetHeader() const
Definition: net_message.h:155
Unit command cancel research.
Definition: net_message.h:313
CNetworkExtendedCommand()
Definition: net_message.h:353
Unit command upgrade.
Definition: net_message.h:309
char PlyName[NetPlayerNameSize]
Player number.
Definition: net_message.h:66
MAP UID doesn't match.
Definition: net_message.h:112
Unit command attack ground.
Definition: net_message.h:298
Definition: net_message.h:183
Unit command cancel training.
Definition: net_message.h:308
Quit game.
Definition: net_message.h:285
uint8_t Inside
Fog of war option.
Definition: net_message.h:87
Unit command unload.
Definition: net_message.h:301
uint16_t Dest
Map position Y.
Definition: net_message.h:344
CNetworkCommand()
Definition: net_message.h:333
uint32_t Version
Stratagus engine version.
Definition: net_message.h:164
size_t Serialize(unsigned char *buf) const
Definition: net_message.cpp:608
char MapPath[256]
Definition: net_message.h:239
Definition: net_message.h:72
const CInitMessage_Header & GetHeader() const
Definition: net_message.h:232
uint8_t clientIndex
Definition: net_message.h:178
CInitMessage_LuaFilesMismatch()
Definition: net_message.cpp:439
uint8_t OrigPlayer
Destination game cycle.
Definition: net_message.h:449
size_t Serialize(unsigned char *buf) const
Definition: net_message.cpp:584
size_t Deserialize(const unsigned char *buf)
Definition: net_message.cpp:211
static size_t Size()
Definition: net_message.h:251
Acknowledge for new client connections.
Definition: net_message.h:115
Unit command attack.
Definition: net_message.h:297
const unsigned char * Serialize() const
Definition: net_message.cpp:356
const unsigned char * Serialize() const
Definition: net_message.cpp:507
uint8_t Ready[PlayerMax]
Free slot option selection {"Available", "Computer", "Closed" }.
Definition: net_message.h:95
int32_t Stratagus
Definition: net_message.h:194
Unit command autorepair.
Definition: net_message.h:296
size_t Serialize(unsigned char *buf) const
Definition: net_message.cpp:634
uint16_t Arg2
Argument 1.
Definition: net_message.h:361
Definition: net_message.h:211
Server asks are you there.
Definition: net_message.h:127
static size_t Size()
Definition: net_message.h:265
Resend message.
Definition: net_message.h:287
CInitMessage_EngineMismatch()
Definition: net_message.cpp:413
size_t Serialize(unsigned char *buf, int numcommands) const
Definition: net_message.cpp:760
uint32_t Host
Definition: net_message.h:63
Unit command resource.
Definition: net_message.h:305
static size_t Size()
Definition: net_message.h:218
CNetworkHost()
Definition: net_message.h:55
CNetworkCommandSync()
Definition: net_message.h:386
#define PlayerMax
Definition: stratagus.h:157
Definition: net_message.h:399
void Deserialize(const unsigned char *buf, unsigned int len, int *numcommands)
Definition: net_message.cpp:771
uint16_t Arg4
Argument 3.
Definition: net_message.h:363
Start connection.
Definition: net_message.h:280
No player slots available.
Definition: net_message.h:113
CNetworkHost hosts[PlayerMax]
Definition: net_message.h:269
uint16_t Unit
Definition: net_message.h:341
static size_t Size()
Definition: net_message.h:204
char PlyName[NetPlayerNameSize]
Definition: net_message.h:162
Unit command stand ground.
Definition: net_message.h:291
Server has quit game.
Definition: net_message.h:121
Definition: net_message.h:414
StateInfo.
Definition: net_message.h:118
uint8_t ExtendedType
Definition: net_message.h:359
uint8_t CompOpt[PlayerMax]
Number of AI opponents.
Definition: net_message.h:94
Command is the next byte.
Definition: net_message.h:316
const CInitMessage_Header & GetHeader() const
Definition: net_message.h:201
void Clear()
Definition: net_message.cpp:222
static size_t Size()
Definition: net_message.h:338
uint8_t Difficulty
Game type option.
Definition: net_message.h:91
Definition: net_message.h:258
Definition: net_message.h:369
void Deserialize(const unsigned char *p)
Definition: net_message.cpp:368
Client has received Welcome and is waiting for Map/State.
Definition: net_message.h:116
CInitMessage_Hello()
Definition: net_message.h:153
Definition: net_message.h:278
Definition: net_message.h:52
_message_type_
Definition: net_message.h:277
bool operator!=(const CServerSetup &rhs) const
Definition: net_message.h:82
size_t Serialize(unsigned char *buf) const
Definition: net_message.cpp:732
static size_t Size()
Definition: net_message.h:158
_extended_message_type_
Definition: net_message.h:322
const unsigned char * Serialize() const
Definition: net_message.cpp:385
void Deserialize(const unsigned char *p)
Definition: net_message.cpp:518
void Deserialize(const unsigned char *p)
Definition: net_message.cpp:572
UNUSED:Engine configuration isn't identical.
Definition: net_message.h:110
uint16_t Arg3
Argument 2.
Definition: net_message.h:362
uint8_t Cycle
Commands in packet.
Definition: net_message.h:448
static size_t Size()
Definition: net_message.h:174
CInitMessage_State()
Definition: net_message.h:246
Definition: net_message.h:150
uint8_t ResourcesOption
Definition: net_message.h:84
static size_t Size()
Definition: net_message.h:59
unsigned char GetSubType() const
Definition: net_message.h:140
MapInfo (and Mapinfo Ack)
Definition: net_message.h:117
Unit command resource location.
Definition: net_message.h:304
const CInitMessage_Header & GetHeader() const
Definition: net_message.h:187
CInitMessage_Map()
Definition: net_message.h:230
Definition: net_message.h:104
CInitMessage_Resync()
Definition: net_message.cpp:555
const CInitMessage_Header & GetHeader() const
Definition: net_message.h:262
CNetworkHost hosts[PlayerMax]
Definition: net_message.h:222
size_t Serialize(unsigned char *p) const
Definition: net_message.cpp:328
const CInitMessage_Header & GetHeader() const
Definition: net_message.h:171
CInitMessage_Header(unsigned char type, unsigned char subtype)
Definition: net_message.h:134
static size_t Size()
Definition: net_message.h:144
size_t Deserialize(const unsigned char *buf)
Definition: net_message.cpp:641
static size_t Size()
Definition: net_message.h:405
size_t Size(int numcommands) const
Definition: net_message.cpp:784
size_t Deserialize(const unsigned char *p)
Definition: net_message.cpp:265
std::vector< unsigned char > Command[MaxNetworkCommands]
Packet Header Info.
Definition: net_message.h:465
Definition: net_message.h:243
size_t Deserialize(const unsigned char *buf)
Definition: net_message.cpp:619
size_t Serialize(unsigned char *buf) const
Definition: net_message.cpp:679
Unit command repair.
Definition: net_message.h:295
size_t Deserialize(const unsigned char *buf)
Definition: net_message.cpp:667
Unit command defend.
Definition: net_message.h:292
Unit command return goods.
Definition: net_message.h:306
uint8_t hostsCount
index of receiver in hosts[]
Definition: net_message.h:179
int32_t Lag
Participants information.
Definition: net_message.h:223
Unit command stop.
Definition: net_message.h:290
Unit command research.
Definition: net_message.h:311
unsigned char GetType() const
Definition: net_message.h:139
Update a Selection from Team Player.
Definition: net_message.h:284
Unit command move.
Definition: net_message.h:294
Ack StateInfo change.
Definition: net_message.h:120
uint32_t syncHash
Definition: net_message.h:393
_ic_message_subtype_
Definition: net_message.h:103
const unsigned char * Serialize() const
Definition: net_message.cpp:445
static size_t Size()
Definition: net_message.h:389
size_t Size() const
Definition: net_message.cpp:723
uint8_t Race[PlayerMax]
Client ready state.
Definition: net_message.h:96
CNetworkCommandQuit()
Definition: net_message.h:402
const unsigned char * Serialize() const
Definition: net_message.cpp:535
size_t Deserialize(const unsigned char *buf)
Definition: net_message.cpp:744
int32_t gameCyclesPerUpdate
Lag time.
Definition: net_message.h:224
void Clear()
Definition: net_message.cpp:290
Unit command build building.
Definition: net_message.h:302
size_t Deserialize(const unsigned char *buf)
Definition: net_message.cpp:594
size_t Serialize(unsigned char *buf) const
Definition: net_message.cpp:659
Definition: net_message.h:433
Unit command follow.
Definition: net_message.h:293
uint8_t RevealMap
Inside option.
Definition: net_message.h:88
CInitMessage_Config()
Definition: net_message.cpp:380
Definition: net_message.h:167
Definition: net_message.h:227
uint8_t Opponents
Map richness option.
Definition: net_message.h:93
CServerSetup State
Definition: net_message.h:255
void Deserialize(const unsigned char *p)
Definition: net_message.cpp:455
CNetworkHost hosts[PlayerMax]
Number of hosts.
Definition: net_message.h:180
static size_t Size()
Definition: net_message.h:357
CInitMessage_Welcome()
Definition: net_message.cpp:465
Definition: net_message.h:350
uint16_t Port
Host address.
Definition: net_message.h:64
bool operator==(const CServerSetup &rhs) const
Definition: net_message.cpp:307
uint8_t MapRichness
Difficulty option.
Definition: net_message.h:92
Change diplomacy.
Definition: net_message.h:324
Definition: net_message.h:130
static size_t Size()
Definition: net_message.h:190
uint8_t UnitsOption
Resources option.
Definition: net_message.h:85
const CInitMessage_Header & GetHeader() const
Definition: net_message.h:215
std::string Text
Definition: net_message.h:377
size_t Deserialize(const unsigned char *buf)
Definition: net_message.cpp:709
uint32_t MapUID
Definition: net_message.h:240
Definition: net_message.h:383
Unit command board.
Definition: net_message.h:300
uint8_t GameTypeOption
Tileset select option.
Definition: net_message.h:90
Client has left game.
Definition: net_message.h:124
void Deserialize(const unsigned char *p)
Definition: net_message.cpp:429
void Deserialize(const unsigned char *p)
Definition: net_message.cpp:486
Client wants to leave game.
Definition: net_message.h:122
const unsigned char * Serialize() const
Definition: net_message.cpp:472
uint8_t Arg1
Extended network command type.
Definition: net_message.h:360
size_t Size() const
Definition: net_message.cpp:648
uint16_t Y
Map position X.
Definition: net_message.h:343
int32_t Stratagus
Name of player.
Definition: net_message.h:163
CNetworkPacketHeader Header
Definition: net_message.h:464
uint32_t syncSeed
Definition: net_message.h:389
CNetworkPacketHeader()
Definition: net_message.h:436
uint16_t X
Command for unit.
Definition: net_message.h:342
size_t Deserialize(const unsigned char *p)
Definition: net_message.cpp:336
When Nothing Is Happening.
Definition: net_message.h:279
const CInitMessage_Header & GetHeader() const
Definition: net_message.h:248
size_t Serialize(unsigned char *buf) const
Definition: net_message.cpp:697
static size_t Size()
Definition: net_message.h:78
size_t Serialize(unsigned char *buf) const
Definition: net_message.cpp:199
static size_t Size()
Definition: net_message.h:445
CInitMessage_Header()
Definition: net_message.h:133
Unit command dismiss unit.
Definition: net_message.h:303
uint8_t Type[MaxNetworkCommands]
Definition: net_message.h:447
Definition: net_message.h:330
Unit command cancel upgrade.
Definition: net_message.h:310
void Deserialize(const unsigned char *p)
Definition: net_message.cpp:545
#define MaxNetworkCommands
Definition: net_message.h:47
uint32_t Version
Definition: net_message.h:208
Setup message configure clients.
Definition: net_message.h:107
Client Request.
Definition: net_message.h:105
uint8_t TilesetSelection
Reveal all the map.
Definition: net_message.h:89
void SetName(const char *name)
Definition: net_message.cpp:230
size_t Serialize(unsigned char *p) const
Definition: net_message.cpp:239
uint16_t player
Definition: net_message.h:405
CServerSetup()
Definition: net_message.h:75
Chat message.
Definition: net_message.h:289
Network protocol version doesn't match.
Definition: net_message.h:109
size_t Deserialize(const unsigned char *buf)
Definition: net_message.cpp:686
uint16_t PlyNr
Port on host.
Definition: net_message.h:65
CNetworkSelection()
Definition: net_message.h:417
void Clear()
Definition: net_message.h:334
uint8_t FogOfWar
Unit # option.
Definition: net_message.h:86
#define NetPlayerNameSize
Definition: net_message.h:45
Connection reply.
Definition: net_message.h:282
std::vector< uint16_t > Units
Definition: net_message.h:425
Unit command patrol.
Definition: net_message.h:299
Unit command train.
Definition: net_message.h:307
uint16_t player
Definition: net_message.h:424
const unsigned char * Serialize() const
Definition: net_message.cpp:419
Definition: net_message.h:457
Stratagus engine version doesn't match.
Definition: net_message.h:108
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.