1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/* Starshatter: The Open Source Project
Copyright (c) 2021-2024, Starshatter: The Open Source Project Contributors
Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
Copyright (c) 1997-2006, Destroyer Studios LLC.
AUTHOR: John DiCamillo
OVERVIEW
========
User level network message
*/
#ifndef NetMsg_h
#define NetMsg_h
#include <cstdint>
class NetMsg
{
public:
static const char* TYPENAME() { return "NetMsg"; }
enum FLAGS { RELIABLE = 0x01, PRIORITY = 0x02, SCATTER = 0x04 };
enum TYPES { INVALID = 0,
RESERVED = 0xF0,
MULTIPART = 0xF1
};
enum { MAX_SIZE = 250 };
NetMsg(std::uint32_t nid, void* d, int l, std::uint8_t f=0);
NetMsg(std::uint32_t nid, std::uint8_t type, const char* text, int len, std::uint8_t f=0);
~NetMsg();
int operator == (const NetMsg& m) const { return msgid == m.msgid &&
netid == m.netid; }
int operator < (const NetMsg& m) const;
std::uint32_t Sequence() const { return msgid; }
std::uint32_t NetID() const { return netid; }
std::uint8_t* Data() { return data; }
std::uint8_t Type() const { return data ? *data : 0; }
int Length() const { return len; }
std::uint8_t Flags() const { return flags; }
bool IsReliable() const { return flags & RELIABLE ? true : false; }
bool IsPriority() const { return flags & PRIORITY ? true : false; }
bool IsScatter() const { return flags & SCATTER ? true : false; }
void SetSequence(std::uint32_t s) { msgid = s; }
private:
std::uint32_t msgid;
std::uint32_t netid;
std::uint8_t* data;
int len;
std::uint8_t flags;
};
struct NetMsgMultipart {
std::uint8_t type;
std::uint8_t len;
std::uint32_t msgid;
std::uint32_t partno;
std::uint32_t nparts;
std::uint8_t payload[256];
};
#endif // NetMsg_h
|