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,141 @@
|
|
|
1
|
+
export class ProtocolVersion {
|
|
2
|
+
static _versions = new Map();
|
|
3
|
+
static _byProtocolId = new Map();
|
|
4
|
+
|
|
5
|
+
constructor(name, protocolId, isSnapshot = false) {
|
|
6
|
+
this.name = name;
|
|
7
|
+
this.protocolId = protocolId;
|
|
8
|
+
this.isSnapshot = isSnapshot;
|
|
9
|
+
|
|
10
|
+
ProtocolVersion._versions.set(name, this);
|
|
11
|
+
ProtocolVersion._byProtocolId.set(protocolId, this);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static getByName(name) {
|
|
15
|
+
return ProtocolVersion._versions.get(name);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static getByProtocolId(protocolId) {
|
|
19
|
+
return ProtocolVersion._byProtocolId.get(protocolId);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static getAllVersions() {
|
|
23
|
+
return Array.from(ProtocolVersion._versions.values());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static getLatest() {
|
|
27
|
+
return ProtocolVersion.V1_21_11;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
isNewerThan(other) {
|
|
31
|
+
return this.protocolId > other.protocolId;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
isOlderThan(other) {
|
|
35
|
+
return this.protocolId < other.protocolId;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
isBetween(min, max) {
|
|
39
|
+
return this.protocolId >= min.protocolId && this.protocolId <= max.protocolId;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
equals(other) {
|
|
43
|
+
if (!(other instanceof ProtocolVersion)) return false;
|
|
44
|
+
return this.protocolId === other.protocolId;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
toString() {
|
|
48
|
+
return this.name;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
toJSON() {
|
|
52
|
+
return {
|
|
53
|
+
name: this.name,
|
|
54
|
+
protocolId: this.protocolId,
|
|
55
|
+
isSnapshot: this.isSnapshot
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static V1_21_11 = new ProtocolVersion('1.21.11', 770);
|
|
60
|
+
static V1_21_10 = new ProtocolVersion('1.21.10', 770);
|
|
61
|
+
static V1_21_9 = new ProtocolVersion('1.21.9', 770);
|
|
62
|
+
static V1_21_8 = new ProtocolVersion('1.21.8', 770);
|
|
63
|
+
static V1_21_7 = new ProtocolVersion('1.21.7', 770);
|
|
64
|
+
static V1_21_6 = new ProtocolVersion('1.21.6', 770);
|
|
65
|
+
static V1_21_5 = new ProtocolVersion('1.21.5', 770);
|
|
66
|
+
static V1_21_4 = new ProtocolVersion('1.21.4', 769);
|
|
67
|
+
static V1_21_3 = new ProtocolVersion('1.21.3', 768);
|
|
68
|
+
static V1_21_2 = new ProtocolVersion('1.21.2', 768);
|
|
69
|
+
static V1_21_1 = new ProtocolVersion('1.21.1', 767);
|
|
70
|
+
static V1_21 = new ProtocolVersion('1.21', 767);
|
|
71
|
+
|
|
72
|
+
static V1_20_6 = new ProtocolVersion('1.20.6', 766);
|
|
73
|
+
static V1_20_5 = new ProtocolVersion('1.20.5', 766);
|
|
74
|
+
static V1_20_4 = new ProtocolVersion('1.20.4', 765);
|
|
75
|
+
static V1_20_3 = new ProtocolVersion('1.20.3', 765);
|
|
76
|
+
static V1_20_2 = new ProtocolVersion('1.20.2', 764);
|
|
77
|
+
static V1_20_1 = new ProtocolVersion('1.20.1', 763);
|
|
78
|
+
static V1_20 = new ProtocolVersion('1.20', 763);
|
|
79
|
+
|
|
80
|
+
static V1_19_4 = new ProtocolVersion('1.19.4', 762);
|
|
81
|
+
static V1_19_3 = new ProtocolVersion('1.19.3', 761);
|
|
82
|
+
static V1_19_2 = new ProtocolVersion('1.19.2', 760);
|
|
83
|
+
static V1_19_1 = new ProtocolVersion('1.19.1', 760);
|
|
84
|
+
static V1_19 = new ProtocolVersion('1.19', 759);
|
|
85
|
+
|
|
86
|
+
static V1_18_2 = new ProtocolVersion('1.18.2', 758);
|
|
87
|
+
static V1_18_1 = new ProtocolVersion('1.18.1', 757);
|
|
88
|
+
static V1_18 = new ProtocolVersion('1.18', 757);
|
|
89
|
+
|
|
90
|
+
static V1_17_1 = new ProtocolVersion('1.17.1', 756);
|
|
91
|
+
static V1_17 = new ProtocolVersion('1.17', 755);
|
|
92
|
+
|
|
93
|
+
static V1_16_5 = new ProtocolVersion('1.16.5', 754);
|
|
94
|
+
static V1_16_4 = new ProtocolVersion('1.16.4', 754);
|
|
95
|
+
static V1_16_3 = new ProtocolVersion('1.16.3', 753);
|
|
96
|
+
static V1_16_2 = new ProtocolVersion('1.16.2', 751);
|
|
97
|
+
static V1_16_1 = new ProtocolVersion('1.16.1', 736);
|
|
98
|
+
static V1_16 = new ProtocolVersion('1.16', 735);
|
|
99
|
+
|
|
100
|
+
static V1_15_2 = new ProtocolVersion('1.15.2', 578);
|
|
101
|
+
static V1_15_1 = new ProtocolVersion('1.15.1', 575);
|
|
102
|
+
static V1_15 = new ProtocolVersion('1.15', 573);
|
|
103
|
+
|
|
104
|
+
static V1_14_4 = new ProtocolVersion('1.14.4', 498);
|
|
105
|
+
static V1_14_3 = new ProtocolVersion('1.14.3', 490);
|
|
106
|
+
static V1_14_2 = new ProtocolVersion('1.14.2', 485);
|
|
107
|
+
static V1_14_1 = new ProtocolVersion('1.14.1', 480);
|
|
108
|
+
static V1_14 = new ProtocolVersion('1.14', 477);
|
|
109
|
+
|
|
110
|
+
static V1_13_2 = new ProtocolVersion('1.13.2', 404);
|
|
111
|
+
static V1_13_1 = new ProtocolVersion('1.13.1', 401);
|
|
112
|
+
static V1_13 = new ProtocolVersion('1.13', 393);
|
|
113
|
+
|
|
114
|
+
static V1_12_2 = new ProtocolVersion('1.12.2', 340);
|
|
115
|
+
static V1_12_1 = new ProtocolVersion('1.12.1', 338);
|
|
116
|
+
static V1_12 = new ProtocolVersion('1.12', 335);
|
|
117
|
+
|
|
118
|
+
static V1_11_2 = new ProtocolVersion('1.11.2', 316);
|
|
119
|
+
static V1_11_1 = new ProtocolVersion('1.11.1', 316);
|
|
120
|
+
static V1_11 = new ProtocolVersion('1.11', 315);
|
|
121
|
+
|
|
122
|
+
static V1_10_2 = new ProtocolVersion('1.10.2', 210);
|
|
123
|
+
static V1_10_1 = new ProtocolVersion('1.10.1', 210);
|
|
124
|
+
static V1_10 = new ProtocolVersion('1.10', 210);
|
|
125
|
+
|
|
126
|
+
static V1_9_4 = new ProtocolVersion('1.9.4', 110);
|
|
127
|
+
static V1_9_3 = new ProtocolVersion('1.9.3', 110);
|
|
128
|
+
static V1_9_2 = new ProtocolVersion('1.9.2', 109);
|
|
129
|
+
static V1_9_1 = new ProtocolVersion('1.9.1', 108);
|
|
130
|
+
static V1_9 = new ProtocolVersion('1.9', 107);
|
|
131
|
+
|
|
132
|
+
static V1_8_9 = new ProtocolVersion('1.8.9', 47);
|
|
133
|
+
static V1_8_8 = new ProtocolVersion('1.8.8', 47);
|
|
134
|
+
static V1_8 = new ProtocolVersion('1.8', 47);
|
|
135
|
+
|
|
136
|
+
static V1_7_10 = new ProtocolVersion('1.7.10', 5);
|
|
137
|
+
static V1_7_6 = new ProtocolVersion('1.7.6', 5);
|
|
138
|
+
static V1_7_2 = new ProtocolVersion('1.7.2', 4);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export default ProtocolVersion;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { PacketBuffer } from '../../utils/PacketBuffer.js';
|
|
2
|
+
|
|
3
|
+
export class Packet {
|
|
4
|
+
|
|
5
|
+
static get packetId() {
|
|
6
|
+
throw new Error('Packet class must implement static packetId getter');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static get packetName() {
|
|
10
|
+
return this.name;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor() {
|
|
14
|
+
this._timestamp = Date.now();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get packetId() {
|
|
18
|
+
return this.constructor.packetId;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get packetName() {
|
|
22
|
+
return this.constructor.packetName;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get timestamp() {
|
|
26
|
+
return this._timestamp;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
read(buffer, context) {
|
|
30
|
+
throw new Error(`${this.packetName}.read() must be implemented`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
write(buffer, context) {
|
|
34
|
+
throw new Error(`${this.packetName}.write() must be implemented`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
encode(context = {}) {
|
|
38
|
+
const buffer = PacketBuffer.writer();
|
|
39
|
+
buffer.writeVarInt(this.packetId);
|
|
40
|
+
this.write(buffer, context);
|
|
41
|
+
return buffer.getBuffer();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static decode(data, context = {}) {
|
|
45
|
+
const packet = new this();
|
|
46
|
+
const buffer = PacketBuffer.reader(data);
|
|
47
|
+
packet.read(buffer, context);
|
|
48
|
+
return packet;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
toJSON() {
|
|
52
|
+
const json = {
|
|
53
|
+
packetId: this.packetId,
|
|
54
|
+
packetName: this.packetName,
|
|
55
|
+
timestamp: this._timestamp
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
for (const key of Object.keys(this)) {
|
|
59
|
+
if (!key.startsWith('_')) {
|
|
60
|
+
json[key] = this[key];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return json;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
toString() {
|
|
68
|
+
return `${this.packetName}(0x${this.packetId.toString(16).padStart(2, '0')})`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
clone() {
|
|
72
|
+
const PacketClass = this.constructor;
|
|
73
|
+
const packet = new PacketClass();
|
|
74
|
+
|
|
75
|
+
for (const key of Object.keys(this)) {
|
|
76
|
+
const value = this[key];
|
|
77
|
+
|
|
78
|
+
if (value === null || value === undefined) {
|
|
79
|
+
packet[key] = value;
|
|
80
|
+
} else if (Buffer.isBuffer(value)) {
|
|
81
|
+
packet[key] = Buffer.from(value);
|
|
82
|
+
} else if (Array.isArray(value)) {
|
|
83
|
+
packet[key] = [...value];
|
|
84
|
+
} else if (typeof value === 'object' && value.clone) {
|
|
85
|
+
packet[key] = value.clone();
|
|
86
|
+
} else if (typeof value === 'object') {
|
|
87
|
+
packet[key] = { ...value };
|
|
88
|
+
} else {
|
|
89
|
+
packet[key] = value;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return packet;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function PacketInfo(metadata) {
|
|
98
|
+
return function(PacketClass) {
|
|
99
|
+
PacketClass._metadata = metadata;
|
|
100
|
+
|
|
101
|
+
if (metadata.id !== undefined) {
|
|
102
|
+
Object.defineProperty(PacketClass, 'packetId', {
|
|
103
|
+
get: () => metadata.id,
|
|
104
|
+
configurable: true
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (metadata.name) {
|
|
109
|
+
Object.defineProperty(PacketClass, 'packetName', {
|
|
110
|
+
get: () => metadata.name,
|
|
111
|
+
configurable: true
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return PacketClass;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default Packet;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { ConnectionState } from '../ConnectionState.js';
|
|
2
|
+
import { PacketDirection } from '../PacketDirection.js';
|
|
3
|
+
import { Logger } from '../../utils/Logger.js';
|
|
4
|
+
|
|
5
|
+
const logger = Logger.getLogger('PacketRegistry');
|
|
6
|
+
|
|
7
|
+
export class PacketRegistry {
|
|
8
|
+
constructor() {
|
|
9
|
+
|
|
10
|
+
this._registry = new Map();
|
|
11
|
+
|
|
12
|
+
this._classToInfo = new Map();
|
|
13
|
+
|
|
14
|
+
for (const state of Object.values(ConnectionState)) {
|
|
15
|
+
const stateMap = new Map();
|
|
16
|
+
stateMap.set(PacketDirection.SERVERBOUND, new Map());
|
|
17
|
+
stateMap.set(PacketDirection.CLIENTBOUND, new Map());
|
|
18
|
+
this._registry.set(state.name, stateMap);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
register({ packetClass, state, direction, packetId, name }) {
|
|
23
|
+
const stateName = typeof state === 'object' ? state.name : state;
|
|
24
|
+
|
|
25
|
+
if (!this._registry.has(stateName)) {
|
|
26
|
+
throw new Error(`Unknown state: ${stateName}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const stateMap = this._registry.get(stateName);
|
|
30
|
+
const directionMap = stateMap.get(direction);
|
|
31
|
+
|
|
32
|
+
if (!directionMap) {
|
|
33
|
+
throw new Error(`Unknown direction: ${direction}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (directionMap.has(packetId)) {
|
|
37
|
+
logger.warn(`Overwriting packet registration for ${stateName}/${direction}/0x${packetId.toString(16)}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
directionMap.set(packetId, packetClass);
|
|
41
|
+
|
|
42
|
+
this._classToInfo.set(packetClass, {
|
|
43
|
+
state: stateName,
|
|
44
|
+
direction,
|
|
45
|
+
packetId,
|
|
46
|
+
name: name || packetClass.packetName || packetClass.name
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
logger.trace(`Registered packet: ${packetClass.name} (${stateName}/${direction}/0x${packetId.toString(16)})`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
registerAll(packets) {
|
|
53
|
+
for (const packet of packets) {
|
|
54
|
+
this.register(packet);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getPacketClass(state, direction, packetId) {
|
|
59
|
+
const stateName = typeof state === 'object' ? state.name : state;
|
|
60
|
+
|
|
61
|
+
const stateMap = this._registry.get(stateName);
|
|
62
|
+
if (!stateMap) return undefined;
|
|
63
|
+
|
|
64
|
+
const directionMap = stateMap.get(direction);
|
|
65
|
+
if (!directionMap) return undefined;
|
|
66
|
+
|
|
67
|
+
return directionMap.get(packetId);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
getPacketInfo(packetClass) {
|
|
71
|
+
return this._classToInfo.get(packetClass);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
createPacket(state, direction, packetId, data, context = {}) {
|
|
75
|
+
const PacketClass = this.getPacketClass(state, direction, packetId);
|
|
76
|
+
|
|
77
|
+
if (!PacketClass) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
return PacketClass.decode(data, context);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
logger.error(`Failed to decode packet 0x${packetId.toString(16)}:`, error);
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
hasPacket(state, direction, packetId) {
|
|
90
|
+
return this.getPacketClass(state, direction, packetId) !== undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getPackets(state, direction) {
|
|
94
|
+
const stateName = typeof state === 'object' ? state.name : state;
|
|
95
|
+
const stateMap = this._registry.get(stateName);
|
|
96
|
+
|
|
97
|
+
if (!stateMap) return new Map();
|
|
98
|
+
|
|
99
|
+
return stateMap.get(direction) || new Map();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
getAllPacketClasses() {
|
|
103
|
+
return Array.from(this._classToInfo.keys());
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
clear() {
|
|
107
|
+
for (const stateMap of this._registry.values()) {
|
|
108
|
+
for (const directionMap of stateMap.values()) {
|
|
109
|
+
directionMap.clear();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
this._classToInfo.clear();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getStats() {
|
|
116
|
+
const stats = {
|
|
117
|
+
total: 0,
|
|
118
|
+
byState: {},
|
|
119
|
+
byDirection: {
|
|
120
|
+
[PacketDirection.SERVERBOUND]: 0,
|
|
121
|
+
[PacketDirection.CLIENTBOUND]: 0
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
for (const [stateName, stateMap] of this._registry) {
|
|
126
|
+
stats.byState[stateName] = {
|
|
127
|
+
[PacketDirection.SERVERBOUND]: 0,
|
|
128
|
+
[PacketDirection.CLIENTBOUND]: 0
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
for (const [direction, directionMap] of stateMap) {
|
|
132
|
+
const count = directionMap.size;
|
|
133
|
+
stats.byState[stateName][direction] = count;
|
|
134
|
+
stats.byDirection[direction] += count;
|
|
135
|
+
stats.total += count;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return stats;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export const defaultRegistry = new PacketRegistry();
|
|
144
|
+
|
|
145
|
+
export default PacketRegistry;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Packet } from '../Packet.js';
|
|
2
|
+
|
|
3
|
+
export class HandshakePacket extends Packet {
|
|
4
|
+
static get packetId() { return 0x00; }
|
|
5
|
+
static get packetName() { return 'Handshake'; }
|
|
6
|
+
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
this.protocolVersion = 0;
|
|
11
|
+
|
|
12
|
+
this.serverAddress = '';
|
|
13
|
+
|
|
14
|
+
this.serverPort = 25565;
|
|
15
|
+
|
|
16
|
+
this.nextState = 1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
read(buffer, context) {
|
|
20
|
+
this.protocolVersion = buffer.readVarInt();
|
|
21
|
+
this.serverAddress = buffer.readString(255);
|
|
22
|
+
this.serverPort = buffer.readUShort();
|
|
23
|
+
this.nextState = buffer.readVarInt();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
write(buffer, context) {
|
|
27
|
+
buffer.writeVarInt(this.protocolVersion);
|
|
28
|
+
buffer.writeString(this.serverAddress);
|
|
29
|
+
buffer.writeUShort(this.serverPort);
|
|
30
|
+
buffer.writeVarInt(this.nextState);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
toJSON() {
|
|
34
|
+
return {
|
|
35
|
+
...super.toJSON(),
|
|
36
|
+
protocolVersion: this.protocolVersion,
|
|
37
|
+
serverAddress: this.serverAddress,
|
|
38
|
+
serverPort: this.serverPort,
|
|
39
|
+
nextState: this.nextState
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default HandshakePacket;
|