-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathProtocol_11.hpp
102 lines (93 loc) · 3.98 KB
/
Protocol_11.hpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma once
#include "Protocol_10.hpp"
#include "../Entities/Food.hpp"
#include "../Entities/Ejected.hpp"
class Protocol_11 : public Protocol_10 {
public:
Protocol_11(Player *owner):
Protocol_10(owner) {
}
virtual Buffer &setBorder() {
buffer.writeUInt8(0x40);
buffer.writeDouble_LE(map::bounds().left());
buffer.writeDouble_LE(map::bounds().bottom());
buffer.writeDouble_LE(map::bounds().right());
buffer.writeDouble_LE(map::bounds().top());
buffer.writeUInt32_LE(cfg::game_mode);
return buffer.writeStrNull_UTF8(cfg::server_name);
}
virtual Buffer &updateNodes(const std::vector<e_ptr> &eatNodes, const std::vector<e_ptr> &updNodes,
const std::vector<e_ptr> &delNodes, const std::vector<e_ptr> &addNodes) {
buffer.writeUInt8(0x10);
// Eat record
buffer.writeUInt16_LE((unsigned short)eatNodes.size());
for (e_ptr entity : eatNodes) {
buffer.writeUInt32_LE(entity->killerId());
buffer.writeUInt32_LE((unsigned)entity->nodeId());
}
// Add record
for (e_ptr entity : addNodes) {
buffer.writeUInt32_LE((unsigned)entity->nodeId());
buffer.writeInt32_LE((int)entity->position().x);
buffer.writeInt32_LE((int)entity->position().y);
buffer.writeUInt16_LE((unsigned short)entity->radius());
unsigned char flags = 0; // extendedFlag
if (entity->state & isSpiked)
flags |= 0x01; // has spikes on outline
if (true)
flags |= 0x02; // has color
if (entity->type == PlayerCell::TYPE) {
if (entity->owner()->skinName() != "") flags |= 0x04;
if (entity->owner()->cellNameUTF8() != "") flags |= 0x08;
}
if (entity->state & isAgitated)
flags |= 0x10;
if (entity->type == Ejected::TYPE)
flags |= 0x20;
if (entity->type == Food::TYPE)
flags |= 0x80; // extended flags
buffer.writeUInt8(flags); // flag
if (flags & 0x80)
buffer.writeUInt8(0x01); // flags2
if (flags & 0x02) {
buffer.writeUInt8(entity->color().r); // red
buffer.writeUInt8(entity->color().g); // green
buffer.writeUInt8(entity->color().b); // blue
}
if (flags & 0x04) buffer.writeStrNull_UTF8(entity->owner()->skinName());
if (flags & 0x08) buffer.writeStrNull_UTF8(entity->owner()->cellNameUTF8());
}
// Update record
for (e_ptr entity : updNodes) {
buffer.writeUInt32_LE((unsigned)entity->nodeId());
buffer.writeInt32_LE((int)entity->position().x);
buffer.writeInt32_LE((int)entity->position().y);
buffer.writeUInt16_LE((unsigned short)entity->radius());
unsigned char flags = 0; // extendedFlag
if (entity->state & isSpiked)
flags |= 0x01; // virus
if (entity->type == PlayerCell::TYPE)
flags |= 0x02; // has color
if (entity->state & isAgitated)
flags |= 0x10;
if (entity->type == Ejected::TYPE)
flags |= 0x20;
if (entity->type == Food::TYPE)
flags |= 0x80; // extended flags
buffer.writeUInt8(flags); // flag
if (flags & 0x80)
buffer.writeUInt8(0x01); // flags2
if (flags & 0x02) {
buffer.writeUInt8(entity->color().r); // red
buffer.writeUInt8(entity->color().g); // green
buffer.writeUInt8(entity->color().b); // blue
}
}
buffer.writeUInt32_LE(0); // stop update record
// Remove record
buffer.writeUInt16_LE((unsigned short)delNodes.size());
for (e_ptr entity : delNodes)
buffer.writeUInt32_LE((unsigned int)entity->nodeId());
return buffer;
}
};