-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathProtocol.cpp
132 lines (128 loc) · 3.89 KB
/
Protocol.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "Protocol.hpp"
#include "../Game/Map.hpp"
#include "../Player/Player.hpp"
Protocol::Protocol(Player *owner) :
player(owner) {
}
// Same for each protocol
Buffer &Protocol::addNode(unsigned int nodeId) {
buffer.writeUInt8(0x20);
return buffer.writeUInt32_LE(nodeId);
}
Buffer &Protocol::banPlayer(const std::string &playerNameOrIp) {
buffer.writeUInt8(0x69);
return buffer.writeStrNull_UTF8(playerNameOrIp);
}
Buffer &Protocol::clearAll() {
return buffer.writeUInt8(0x12);
}
Buffer &Protocol::clearOwned() {
return buffer.writeUInt8(0x14);
}
Buffer &Protocol::compressed(std::vector<unsigned char> &_Packet) {
buffer.setBuffer(_Packet);
buffer.writeUInt8(0xff);
buffer.writeUInt32_LE((unsigned int)_Packet.size());
for (const unsigned char &byte : _Packet)
buffer.writeUInt8(byte);
return buffer;
}
Buffer &Protocol::dks2(int _dks2) {
buffer.writeUInt8(0xf1);
return buffer.writeInt32_LE(_dks2);
}
Buffer &Protocol::login() {
return buffer.writeUInt8(0x67);
}
Buffer &Protocol::logout() {
return buffer.writeUInt8(0x68);
}
Buffer &Protocol::mobileData() {
return buffer.writeUInt8(0x66);
}
Buffer &Protocol::ping() {
return buffer.writeUInt8(0xe2);
}
Buffer &Protocol::removeArrow() {
return buffer.writeUInt8(0xa1);
}
Buffer &Protocol::requestCaptcha() {
return buffer.writeUInt8(0x55);
}
Buffer &Protocol::requestClientUpdate() {
return buffer.writeUInt8(0x80);
}
Buffer &Protocol::setBorder() {
buffer.writeUInt8(0x40);
buffer.writeDouble_LE(map::bounds().left());
buffer.writeDouble_LE(map::bounds().bottom());
buffer.writeDouble_LE(map::bounds().right());
return buffer.writeDouble_LE(map::bounds().top());
}
Buffer &Protocol::showArrow(const Vec2 &position, const std::string &playerName) {
buffer.writeUInt8(0xa0);
buffer.writeInt16_LE((short)position.x);
buffer.writeInt16_LE((short)position.y);
return buffer.writeStrNull_UTF8(playerName);
}
// Update these for each protocol
Buffer &Protocol::updateLeaderboardList() {
buffer.writeUInt8(0x31);
unsigned length = (unsigned)map::game->leaders.size();
buffer.writeUInt32_LE(length);
for (unsigned i = 0; i < length; ++i) {
Player *p = map::game->leaders[i];
if (!p || p->state() != PlayerState::PLAYING)
continue;
buffer.writeUInt32_LE(p->cells.back()->nodeId());
buffer.writeStrNull_UCS2(p->cellNameUCS2());
}
return buffer;
}
// Update these for each protocol
Buffer &Protocol::updateLeaderboardRGB(const std::vector<float> &board) {
buffer.writeUInt8(0x32);
buffer.writeUInt32_LE((unsigned int)board.size());
for (const float &color : board)
buffer.writeFloat_LE(color);
return buffer;
}
Buffer &Protocol::updateLeaderboardText(const std::vector<std::string> &board) {
return buffer;
}
// Update these for each protocol
Buffer &Protocol::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) {
return buffer;
}
Buffer &Protocol::updateViewport(const Vec2 &position, float scale) {
buffer.writeUInt8(0x11);
buffer.writeFloat_LE((float)position.x);
buffer.writeFloat_LE((float)position.y);
return buffer.writeFloat_LE(scale);
}
// To be implemented
Buffer &Protocol::chatMessage(/**/) {
return buffer.writeUInt8(0x63);
}
Buffer &Protocol::drawLine(const Vec2 &position) {
buffer.writeUInt8(0x15);
buffer.writeInt16_LE((short)position.x);
return buffer.writeInt16_LE((short)position.y);
}
Buffer &Protocol::serverStat(const std::string &info) {
return buffer;
}
Buffer &Protocol::auth(const std::string &str) {
return buffer;
}
Protocol::~Protocol() {
}
/*
Usertext: 0x30 (48), 4-13
Usertext/Reg: 0x31 (49), 4-10
Reg: 0x33 (51), 11-13
Reg: 0x34 (52), 13
Usertext/Reg: 0x35 (53), 14-18
Reg: 0x36 (54), 15-16
*/