forked from RavEngine/RavEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetworkBase.cpp
49 lines (36 loc) · 1.05 KB
/
NetworkBase.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
#include "NetworkBase.hpp"
#include <fmt/format.h>
#include <cstdint>
#include "World.hpp"
using namespace std;
using namespace RavEngine;
std::string RavEngine::NetworkBase::CreateSpawnCommand(uuids::uuid& id, ctti_t type, std::string_view& worldID)
{
constexpr uint16_t size = 16 + sizeof(type) + World::id_size + 1;
char message[size];
memset(message, 0, size);
//set command code
message[0] = CommandCode::Spawn;
char offset = 1;
//set type
memcpy(message + offset, &type, sizeof(type));
offset += sizeof(type);
//set uuid
auto raw = id.raw();
memcpy(message + offset, raw.data(), 16);
offset += 16;
//set worldid
memcpy(message + offset, worldID.data(), World::id_size);
return string(message,size);
}
std::string RavEngine::NetworkBase::CreateDestroyCommand(uuids::uuid& id)
{
constexpr uint16_t size = 16 + 1;
char message[size];
//set command code
message[0] = CommandCode::Destroy;
//set uuid
auto raw = id.raw();
memcpy(message + 1, raw.data(), 16);
return string(message,size);
}