Polyphase Game Engine
Loading...
Searching...
No Matches
NetMsg.h
Go to the documentation of this file.
1#pragma once
2
3#include "Constants.h"
4#include "EngineTypes.h"
5#include "Stream.h"
6#include "Datum.h"
7
8#define NET_MESSAGE_MAGIC_STR "OCTM"
9
10#define NET_MSG_INTERFACE(Name) \
11 virtual void Read(Stream& stream) override; \
12 virtual void Write(Stream& stream) const override; \
13 virtual void Execute(NetHost sender) override; \
14 virtual NetMsgType GetType() const override { return NetMsgType::Name; }
15
16#define NET_MSG_INTERFACE_RELIABLE(Name) \
17 NET_MSG_INTERFACE(Name) \
18 virtual bool IsReliable() const override { return true; }
19
20enum class NetMsgType : uint8_t
21{
22 Connect,
23 Accept,
24 Reject,
26 Kick,
27 Ready,
28 Spawn,
29 Destroy,
30 Ping,
33 Invoke,
36 Ack,
37
38 Count
39};
40
41struct NetMsg
42{
43 virtual void Read(Stream& stream);
44 virtual void Write(Stream& stream) const;
45 virtual void Execute(NetHost sender);
46 virtual bool IsReliable() const;
47 virtual NetMsgType GetType() const = 0;
48};
49
50struct NetMsgConnect : public NetMsg
51{
53
54 uint32_t mGameCode = 0;
55 uint32_t mVersion = 0;
56};
57
64
65struct NetMsgReject : public NetMsg
66{
68
69 enum class Reason : uint8_t
70 {
74
75 Count
76 };
77
79};
80
85
86struct NetMsgKick : public NetMsg
87{
89
90 enum class Reason : uint8_t
91 {
93 Timeout,
94 Forced,
95
96 Count
97 };
98
100};
101
106
107struct NetMsgPing : public NetMsg
108{
110};
111
122
129
130struct NetMsgReplicate : public NetMsg
131{
133
134 virtual bool IsReliable() const override;
135
137 uint16_t mNumVariables = 0;
138 std::vector<uint16_t> mIndices;
139 std::vector<Datum> mData;
140 bool mReliable = false;
141};
142
147
148struct NetMsgInvoke : public NetMsg
149{
151
152 virtual bool IsReliable() const override;
153
155 uint16_t mIndex = 0;
156 uint8_t mNumParams = 0;
157 bool mReliable = false;
158 std::vector<Datum> mParams;
159};
160
161// Creating a separate message for script invoke so we don't need
162// to serialize an extra bool for whether the netfunc belongs to the script.
167
168struct NetMsgBroadcast : public NetMsg
169{
171
172 static const uint32_t sMagicNumber;
173
175 uint32_t mGameCode = 0;
176 uint32_t mVersion = 0;
177
179 uint8_t mMaxPlayers = 0;
180 uint8_t mNumPlayers = 0;
181};
182
183struct NetMsgAck : public NetMsg
184{
186
187 uint16_t mSequenceNumber = 0;
188};
#define INVALID_TYPE_ID
Definition Constants.h:40
#define INVALID_HOST_ID
Definition Constants.h:44
#define OCT_SESSION_NAME_LEN
Definition Constants.h:50
#define INVALID_NET_ID
Definition Constants.h:41
uint32_t NetId
Definition EngineTypes.h:65
uint8_t NetHostId
Definition EngineTypes.h:486
uint32_t TypeId
Definition EngineTypes.h:64
NetMsgType
Definition NetMsg.h:21
Definition Stream.h:21
Definition EngineTypes.h:489
Definition NetMsg.h:59
NetHostId mAssignedHostId
Definition NetMsg.h:62
NET_MSG_INTERFACE_RELIABLE(Accept)
Definition NetMsg.h:184
uint16_t mSequenceNumber
Definition NetMsg.h:187
NET_MSG_INTERFACE(Ack)
Definition NetMsg.h:169
NET_MSG_INTERFACE(Broadcast)
uint8_t mMaxPlayers
Definition NetMsg.h:179
uint32_t mMagic
Definition NetMsg.h:174
uint8_t mNumPlayers
Definition NetMsg.h:180
uint32_t mGameCode
Definition NetMsg.h:175
static const uint32_t sMagicNumber
Definition NetMsg.h:172
uint32_t mVersion
Definition NetMsg.h:176
char mName[OCT_SESSION_NAME_LEN+1]
Definition NetMsg.h:178
Definition NetMsg.h:51
uint32_t mGameCode
Definition NetMsg.h:54
NET_MSG_INTERFACE(Connect)
uint32_t mVersion
Definition NetMsg.h:55
Definition NetMsg.h:124
NetId mNetId
Definition NetMsg.h:127
NET_MSG_INTERFACE_RELIABLE(Destroy)
Definition NetMsg.h:82
NET_MSG_INTERFACE(Disconnect)
Definition NetMsg.h:164
NET_MSG_INTERFACE(InvokeScript)
Definition NetMsg.h:149
NET_MSG_INTERFACE(Invoke)
uint16_t mIndex
Definition NetMsg.h:155
bool mReliable
Definition NetMsg.h:157
virtual bool IsReliable() const override
Definition NetMsg.cpp:525
uint8_t mNumParams
Definition NetMsg.h:156
std::vector< Datum > mParams
Definition NetMsg.h:158
NetId mNodeNetId
Definition NetMsg.h:154
Definition NetMsg.h:87
NET_MSG_INTERFACE(Kick)
Reason
Definition NetMsg.h:91
Reason mReason
Definition NetMsg.h:99
Definition NetMsg.h:108
NET_MSG_INTERFACE(Ping)
Definition NetMsg.h:103
NET_MSG_INTERFACE_RELIABLE(Ready)
Definition NetMsg.h:66
Reason mReason
Definition NetMsg.h:78
Reason
Definition NetMsg.h:70
NET_MSG_INTERFACE(Reject)
Definition NetMsg.h:144
NET_MSG_INTERFACE(ReplicateScript)
Definition NetMsg.h:131
uint16_t mNumVariables
Definition NetMsg.h:137
NetId mNodeNetId
Definition NetMsg.h:136
bool mReliable
Definition NetMsg.h:140
NET_MSG_INTERFACE(Replicate)
virtual bool IsReliable() const override
Definition NetMsg.cpp:389
std::vector< uint16_t > mIndices
Definition NetMsg.h:138
std::vector< Datum > mData
Definition NetMsg.h:139
Definition NetMsg.h:113
NetId mParentNetId
Definition NetMsg.h:118
TypeId mNodeTypeId
Definition NetMsg.h:116
NetId mNetId
Definition NetMsg.h:117
bool mReplicateTransform
Definition NetMsg.h:119
std::string mSceneName
Definition NetMsg.h:120
NET_MSG_INTERFACE_RELIABLE(Spawn)
Definition NetMsg.h:42
virtual void Execute(NetHost sender)
Definition NetMsg.cpp:33
virtual void Write(Stream &stream) const
Definition NetMsg.cpp:28
virtual void Read(Stream &stream)
Definition NetMsg.cpp:17
virtual NetMsgType GetType() const =0
virtual bool IsReliable() const
Definition NetMsg.cpp:38