This repository has been archived by the owner on Apr 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Network.cpp
70 lines (51 loc) · 1.62 KB
/
Network.cpp
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
#include "Network.hpp"
using namespace std;
using namespace RakNet;
NetworkIDManager Network::manager;
Network::NetworkQueue Network::queue;
CriticalSection Network::cs;
bool Network::dequeue = true;
#ifdef VAULTMP_DEBUG
DebugInput<Network> Network::debug;
#endif
void Network::Dispatch(RakPeerInterface* peer, NetworkResponse&& response)
{
for (SingleResponse& s : move(response))
{
#ifdef VAULTMP_DEBUG
debug.print("Sending packet of type ", typeid(s.packet).name(), ", length ", dec, s.packet.length(), ", type ", static_cast<unsigned int>(s.packet.type()));
#endif
for (RakNetGUID& guid : s.targets)
peer->Send(reinterpret_cast<const char*>(s.packet.get()), s.packet.length(), get<0>(s.descriptor), get<1>(s.descriptor), get<2>(s.descriptor), guid, false);
}
}
bool Network::Dispatch(RakPeerInterface* peer)
{
if (queue.empty() || !dequeue)
return false;
cs.StartSession();
const NetworkResponse& response = queue.back();
for (const SingleResponse& s : response)
{
#ifdef VAULTMP_DEBUG
debug.print("Sending packet of type ", typeid(s.packet).name(), ", length ", dec, s.packet.length(), ", type ", static_cast<unsigned int>(s.packet.type()));
#endif
for (const RakNetGUID& guid : s.targets)
peer->Send(reinterpret_cast<const char*>(s.packet.get()), s.packet.length(), get<0>(s.descriptor), get<1>(s.descriptor), get<2>(s.descriptor), guid, false);
}
queue.pop_back();
cs.EndSession();
return true;
}
void Network::Queue(NetworkResponse&& response)
{
cs.StartSession();
queue.emplace_front(move(response));
cs.EndSession();
}
void Network::Flush()
{
cs.StartSession();
queue.clear();
cs.EndSession();
}