packet-events-js 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +398 -0
- package/package.json +31 -0
- package/src/auth/AuthHandler.js +138 -0
- package/src/auth/MojangAPI.js +186 -0
- package/src/client/MinecraftClient.js +336 -0
- package/src/crypto/Encryption.js +125 -0
- package/src/events/EventEmitter.js +267 -0
- package/src/events/PacketEvent.js +78 -0
- package/src/index.js +18 -0
- package/src/manager/PacketManager.js +258 -0
- package/src/protocol/ConnectionState.js +37 -0
- package/src/protocol/PacketDirection.js +8 -0
- package/src/protocol/ProtocolVersion.js +141 -0
- package/src/protocol/packets/Packet.js +119 -0
- package/src/protocol/packets/PacketRegistry.js +145 -0
- package/src/protocol/packets/handshake/HandshakePacket.js +44 -0
- package/src/protocol/packets/index.js +265 -0
- package/src/protocol/packets/login/DisconnectPacket.js +71 -0
- package/src/protocol/packets/login/EncryptionRequestPacket.js +47 -0
- package/src/protocol/packets/login/EncryptionResponsePacket.js +34 -0
- package/src/protocol/packets/login/LoginStartPacket.js +35 -0
- package/src/protocol/packets/login/LoginSuccessPacket.js +61 -0
- package/src/protocol/packets/login/SetCompressionPacket.js +29 -0
- package/src/protocol/packets/play/ChatPacket.js +238 -0
- package/src/protocol/packets/play/ChunkPacket.js +122 -0
- package/src/protocol/packets/play/EntityPacket.js +302 -0
- package/src/protocol/packets/play/KeepAlivePacket.js +55 -0
- package/src/protocol/packets/play/PlayerPositionPacket.js +266 -0
- package/src/protocol/packets/status/PingPacket.js +29 -0
- package/src/protocol/packets/status/PongPacket.js +29 -0
- package/src/protocol/packets/status/StatusRequestPacket.js +20 -0
- package/src/protocol/packets/status/StatusResponsePacket.js +58 -0
- package/src/protocol/types/NBT.js +594 -0
- package/src/protocol/types/Position.js +125 -0
- package/src/protocol/types/TextComponent.js +355 -0
- package/src/protocol/types/UUID.js +105 -0
- package/src/protocol/types/VarInt.js +144 -0
- package/src/protocol/types/index.js +5 -0
- package/src/utils/Logger.js +207 -0
- package/src/utils/PacketBuffer.js +389 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { Packet } from '../Packet.js';
|
|
2
|
+
|
|
3
|
+
export class SetPlayerPositionPacket extends Packet {
|
|
4
|
+
static get packetId() { return 0x1A; }
|
|
5
|
+
static get packetName() { return 'SetPlayerPosition'; }
|
|
6
|
+
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
this.x = 0;
|
|
11
|
+
|
|
12
|
+
this.y = 0;
|
|
13
|
+
|
|
14
|
+
this.z = 0;
|
|
15
|
+
|
|
16
|
+
this.onGround = false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
read(buffer, context) {
|
|
20
|
+
this.x = buffer.readDouble();
|
|
21
|
+
this.y = buffer.readDouble();
|
|
22
|
+
this.z = buffer.readDouble();
|
|
23
|
+
this.onGround = buffer.readBoolean();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
write(buffer, context) {
|
|
27
|
+
buffer.writeDouble(this.x);
|
|
28
|
+
buffer.writeDouble(this.y);
|
|
29
|
+
buffer.writeDouble(this.z);
|
|
30
|
+
buffer.writeBoolean(this.onGround);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
toJSON() {
|
|
34
|
+
return {
|
|
35
|
+
...super.toJSON(),
|
|
36
|
+
x: this.x,
|
|
37
|
+
y: this.y,
|
|
38
|
+
z: this.z,
|
|
39
|
+
onGround: this.onGround
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class SetPlayerPositionAndRotationPacket extends Packet {
|
|
45
|
+
static get packetId() { return 0x1B; }
|
|
46
|
+
static get packetName() { return 'SetPlayerPositionAndRotation'; }
|
|
47
|
+
|
|
48
|
+
constructor() {
|
|
49
|
+
super();
|
|
50
|
+
|
|
51
|
+
this.x = 0;
|
|
52
|
+
|
|
53
|
+
this.y = 0;
|
|
54
|
+
|
|
55
|
+
this.z = 0;
|
|
56
|
+
|
|
57
|
+
this.yaw = 0;
|
|
58
|
+
|
|
59
|
+
this.pitch = 0;
|
|
60
|
+
|
|
61
|
+
this.onGround = false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
read(buffer, context) {
|
|
65
|
+
this.x = buffer.readDouble();
|
|
66
|
+
this.y = buffer.readDouble();
|
|
67
|
+
this.z = buffer.readDouble();
|
|
68
|
+
this.yaw = buffer.readFloat();
|
|
69
|
+
this.pitch = buffer.readFloat();
|
|
70
|
+
this.onGround = buffer.readBoolean();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
write(buffer, context) {
|
|
74
|
+
buffer.writeDouble(this.x);
|
|
75
|
+
buffer.writeDouble(this.y);
|
|
76
|
+
buffer.writeDouble(this.z);
|
|
77
|
+
buffer.writeFloat(this.yaw);
|
|
78
|
+
buffer.writeFloat(this.pitch);
|
|
79
|
+
buffer.writeBoolean(this.onGround);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
toJSON() {
|
|
83
|
+
return {
|
|
84
|
+
...super.toJSON(),
|
|
85
|
+
x: this.x,
|
|
86
|
+
y: this.y,
|
|
87
|
+
z: this.z,
|
|
88
|
+
yaw: this.yaw,
|
|
89
|
+
pitch: this.pitch,
|
|
90
|
+
onGround: this.onGround
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class SetPlayerRotationPacket extends Packet {
|
|
96
|
+
static get packetId() { return 0x1C; }
|
|
97
|
+
static get packetName() { return 'SetPlayerRotation'; }
|
|
98
|
+
|
|
99
|
+
constructor() {
|
|
100
|
+
super();
|
|
101
|
+
|
|
102
|
+
this.yaw = 0;
|
|
103
|
+
|
|
104
|
+
this.pitch = 0;
|
|
105
|
+
|
|
106
|
+
this.onGround = false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
read(buffer, context) {
|
|
110
|
+
this.yaw = buffer.readFloat();
|
|
111
|
+
this.pitch = buffer.readFloat();
|
|
112
|
+
this.onGround = buffer.readBoolean();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
write(buffer, context) {
|
|
116
|
+
buffer.writeFloat(this.yaw);
|
|
117
|
+
buffer.writeFloat(this.pitch);
|
|
118
|
+
buffer.writeBoolean(this.onGround);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
toJSON() {
|
|
122
|
+
return {
|
|
123
|
+
...super.toJSON(),
|
|
124
|
+
yaw: this.yaw,
|
|
125
|
+
pitch: this.pitch,
|
|
126
|
+
onGround: this.onGround
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export class SetPlayerOnGroundPacket extends Packet {
|
|
132
|
+
static get packetId() { return 0x1D; }
|
|
133
|
+
static get packetName() { return 'SetPlayerOnGround'; }
|
|
134
|
+
|
|
135
|
+
constructor() {
|
|
136
|
+
super();
|
|
137
|
+
|
|
138
|
+
this.onGround = false;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
read(buffer, context) {
|
|
142
|
+
this.onGround = buffer.readBoolean();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
write(buffer, context) {
|
|
146
|
+
buffer.writeBoolean(this.onGround);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
toJSON() {
|
|
150
|
+
return {
|
|
151
|
+
...super.toJSON(),
|
|
152
|
+
onGround: this.onGround
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export class SynchronizePlayerPositionPacket extends Packet {
|
|
158
|
+
static get packetId() { return 0x40; }
|
|
159
|
+
static get packetName() { return 'SynchronizePlayerPosition'; }
|
|
160
|
+
|
|
161
|
+
constructor() {
|
|
162
|
+
super();
|
|
163
|
+
|
|
164
|
+
this.x = 0;
|
|
165
|
+
|
|
166
|
+
this.y = 0;
|
|
167
|
+
|
|
168
|
+
this.z = 0;
|
|
169
|
+
|
|
170
|
+
this.yaw = 0;
|
|
171
|
+
|
|
172
|
+
this.pitch = 0;
|
|
173
|
+
|
|
174
|
+
this.flags = 0;
|
|
175
|
+
|
|
176
|
+
this.teleportId = 0;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
read(buffer, context) {
|
|
180
|
+
this.x = buffer.readDouble();
|
|
181
|
+
this.y = buffer.readDouble();
|
|
182
|
+
this.z = buffer.readDouble();
|
|
183
|
+
this.yaw = buffer.readFloat();
|
|
184
|
+
this.pitch = buffer.readFloat();
|
|
185
|
+
this.flags = buffer.readByte();
|
|
186
|
+
this.teleportId = buffer.readVarInt();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
write(buffer, context) {
|
|
190
|
+
buffer.writeDouble(this.x);
|
|
191
|
+
buffer.writeDouble(this.y);
|
|
192
|
+
buffer.writeDouble(this.z);
|
|
193
|
+
buffer.writeFloat(this.yaw);
|
|
194
|
+
buffer.writeFloat(this.pitch);
|
|
195
|
+
buffer.writeByte(this.flags);
|
|
196
|
+
buffer.writeVarInt(this.teleportId);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
isXRelative() {
|
|
200
|
+
return (this.flags & 0x01) !== 0;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
isYRelative() {
|
|
204
|
+
return (this.flags & 0x02) !== 0;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
isZRelative() {
|
|
208
|
+
return (this.flags & 0x04) !== 0;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
isYawRelative() {
|
|
212
|
+
return (this.flags & 0x08) !== 0;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
isPitchRelative() {
|
|
216
|
+
return (this.flags & 0x10) !== 0;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
toJSON() {
|
|
220
|
+
return {
|
|
221
|
+
...super.toJSON(),
|
|
222
|
+
x: this.x,
|
|
223
|
+
y: this.y,
|
|
224
|
+
z: this.z,
|
|
225
|
+
yaw: this.yaw,
|
|
226
|
+
pitch: this.pitch,
|
|
227
|
+
flags: this.flags,
|
|
228
|
+
teleportId: this.teleportId
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export class ConfirmTeleportationPacket extends Packet {
|
|
234
|
+
static get packetId() { return 0x00; }
|
|
235
|
+
static get packetName() { return 'ConfirmTeleportation'; }
|
|
236
|
+
|
|
237
|
+
constructor() {
|
|
238
|
+
super();
|
|
239
|
+
|
|
240
|
+
this.teleportId = 0;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
read(buffer, context) {
|
|
244
|
+
this.teleportId = buffer.readVarInt();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
write(buffer, context) {
|
|
248
|
+
buffer.writeVarInt(this.teleportId);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
toJSON() {
|
|
252
|
+
return {
|
|
253
|
+
...super.toJSON(),
|
|
254
|
+
teleportId: this.teleportId
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export default {
|
|
260
|
+
SetPlayerPositionPacket,
|
|
261
|
+
SetPlayerPositionAndRotationPacket,
|
|
262
|
+
SetPlayerRotationPacket,
|
|
263
|
+
SetPlayerOnGroundPacket,
|
|
264
|
+
SynchronizePlayerPositionPacket,
|
|
265
|
+
ConfirmTeleportationPacket
|
|
266
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Packet } from '../Packet.js';
|
|
2
|
+
|
|
3
|
+
export class PingPacket extends Packet {
|
|
4
|
+
static get packetId() { return 0x01; }
|
|
5
|
+
static get packetName() { return 'Ping'; }
|
|
6
|
+
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
this.payload = 0n;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
read(buffer, context) {
|
|
14
|
+
this.payload = buffer.readLong();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
write(buffer, context) {
|
|
18
|
+
buffer.writeLong(this.payload);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
toJSON() {
|
|
22
|
+
return {
|
|
23
|
+
...super.toJSON(),
|
|
24
|
+
payload: this.payload.toString()
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default PingPacket;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Packet } from '../Packet.js';
|
|
2
|
+
|
|
3
|
+
export class PongPacket extends Packet {
|
|
4
|
+
static get packetId() { return 0x01; }
|
|
5
|
+
static get packetName() { return 'Pong'; }
|
|
6
|
+
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
this.payload = 0n;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
read(buffer, context) {
|
|
14
|
+
this.payload = buffer.readLong();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
write(buffer, context) {
|
|
18
|
+
buffer.writeLong(this.payload);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
toJSON() {
|
|
22
|
+
return {
|
|
23
|
+
...super.toJSON(),
|
|
24
|
+
payload: this.payload.toString()
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default PongPacket;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Packet } from '../Packet.js';
|
|
2
|
+
|
|
3
|
+
export class StatusRequestPacket extends Packet {
|
|
4
|
+
static get packetId() { return 0x00; }
|
|
5
|
+
static get packetName() { return 'StatusRequest'; }
|
|
6
|
+
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
read(buffer, context) {
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
write(buffer, context) {
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default StatusRequestPacket;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Packet } from '../Packet.js';
|
|
2
|
+
|
|
3
|
+
export class StatusResponsePacket extends Packet {
|
|
4
|
+
static get packetId() { return 0x00; }
|
|
5
|
+
static get packetName() { return 'StatusResponse'; }
|
|
6
|
+
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
this.status = null;
|
|
11
|
+
|
|
12
|
+
this.rawJson = '';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
read(buffer, context) {
|
|
16
|
+
this.rawJson = buffer.readString(32767);
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
this.status = JSON.parse(this.rawJson);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
this.status = { error: 'Failed to parse JSON', raw: this.rawJson };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
write(buffer, context) {
|
|
26
|
+
const json = this.rawJson || JSON.stringify(this.status);
|
|
27
|
+
buffer.writeString(json);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get version() {
|
|
31
|
+
return this.status?.version || null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get players() {
|
|
35
|
+
return this.status?.players || null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get description() {
|
|
39
|
+
return this.status?.description || null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get favicon() {
|
|
43
|
+
return this.status?.favicon || null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get enforcesSecureChat() {
|
|
47
|
+
return this.status?.enforcesSecureChat ?? false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
toJSON() {
|
|
51
|
+
return {
|
|
52
|
+
...super.toJSON(),
|
|
53
|
+
status: this.status
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default StatusResponsePacket;
|