cubyz-node-client 1.0.1 → 1.2.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 +19 -1
- package/dist/binary.js +20 -10
- package/dist/binary.js.map +1 -1
- package/dist/chatFormat.d.ts +3 -0
- package/dist/chatFormat.js +165 -0
- package/dist/chatFormat.js.map +1 -0
- package/dist/connection.d.ts +5 -78
- package/dist/connection.js +163 -168
- package/dist/connection.js.map +1 -1
- package/dist/connectionTypes.d.ts +141 -0
- package/dist/connectionTypes.js +33 -0
- package/dist/connectionTypes.js.map +1 -0
- package/dist/constants.d.ts +3 -1
- package/dist/constants.js +3 -1
- package/dist/constants.js.map +1 -1
- package/dist/entityParser.d.ts +4 -0
- package/dist/entityParser.js +143 -0
- package/dist/entityParser.js.map +1 -0
- package/dist/handshakeUtils.d.ts +10 -0
- package/dist/handshakeUtils.js +24 -0
- package/dist/handshakeUtils.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { Buffer } from "node:buffer";
|
|
2
|
+
export declare const DEG_TO_RAD: number;
|
|
3
|
+
export declare const LOG_LEVEL_ORDER: {
|
|
4
|
+
readonly debug: 0;
|
|
5
|
+
readonly info: 1;
|
|
6
|
+
readonly warn: 2;
|
|
7
|
+
readonly error: 3;
|
|
8
|
+
readonly silent: 4;
|
|
9
|
+
};
|
|
10
|
+
export declare const ENTITY_POSITION_TYPE: {
|
|
11
|
+
readonly NO_VELOCITY_ENTITY: 0;
|
|
12
|
+
readonly F16_VELOCITY_ENTITY: 1;
|
|
13
|
+
readonly F32_VELOCITY_ENTITY: 2;
|
|
14
|
+
readonly NO_VELOCITY_ITEM: 3;
|
|
15
|
+
readonly F16_VELOCITY_ITEM: 4;
|
|
16
|
+
readonly F32_VELOCITY_ITEM: 5;
|
|
17
|
+
};
|
|
18
|
+
export type EntityPositionType = (typeof ENTITY_POSITION_TYPE)[keyof typeof ENTITY_POSITION_TYPE];
|
|
19
|
+
export type LogLevel = keyof typeof LOG_LEVEL_ORDER;
|
|
20
|
+
export interface Vector3 {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
z: number;
|
|
24
|
+
}
|
|
25
|
+
export interface PlayerState {
|
|
26
|
+
position: Vector3;
|
|
27
|
+
velocity: Vector3;
|
|
28
|
+
rotation: Vector3;
|
|
29
|
+
}
|
|
30
|
+
export interface EntitySnapshot {
|
|
31
|
+
id: number;
|
|
32
|
+
position: Vector3;
|
|
33
|
+
velocity: Vector3;
|
|
34
|
+
rotation: Vector3;
|
|
35
|
+
timestamp: number;
|
|
36
|
+
}
|
|
37
|
+
export interface ItemSnapshot {
|
|
38
|
+
index: number;
|
|
39
|
+
position: Vector3;
|
|
40
|
+
velocity: Vector3;
|
|
41
|
+
timestamp: number;
|
|
42
|
+
}
|
|
43
|
+
export interface BlockUpdate {
|
|
44
|
+
position: Vector3;
|
|
45
|
+
block: number;
|
|
46
|
+
blockEntityData: Buffer;
|
|
47
|
+
}
|
|
48
|
+
export declare const GENERIC_UPDATE_TYPE: {
|
|
49
|
+
readonly GAMEMODE: 0;
|
|
50
|
+
readonly TELEPORT: 1;
|
|
51
|
+
readonly WORLD_EDIT_POS: 2;
|
|
52
|
+
readonly TIME: 3;
|
|
53
|
+
readonly BIOME: 4;
|
|
54
|
+
};
|
|
55
|
+
export type GenericUpdateType = (typeof GENERIC_UPDATE_TYPE)[keyof typeof GENERIC_UPDATE_TYPE];
|
|
56
|
+
export declare const GAMEMODE: {
|
|
57
|
+
readonly SURVIVAL: 0;
|
|
58
|
+
readonly CREATIVE: 1;
|
|
59
|
+
};
|
|
60
|
+
export type Gamemode = (typeof GAMEMODE)[keyof typeof GAMEMODE];
|
|
61
|
+
export declare const WORLD_EDIT_POSITION: {
|
|
62
|
+
readonly SELECTED_POS1: 0;
|
|
63
|
+
readonly SELECTED_POS2: 1;
|
|
64
|
+
readonly CLEAR: 2;
|
|
65
|
+
};
|
|
66
|
+
export type WorldEditPositionType = (typeof WORLD_EDIT_POSITION)[keyof typeof WORLD_EDIT_POSITION];
|
|
67
|
+
export interface GamemodeUpdate {
|
|
68
|
+
type: "gamemode";
|
|
69
|
+
gamemode: Gamemode;
|
|
70
|
+
}
|
|
71
|
+
export interface TeleportUpdate {
|
|
72
|
+
type: "teleport";
|
|
73
|
+
position: Vector3;
|
|
74
|
+
}
|
|
75
|
+
export interface WorldEditPosUpdate {
|
|
76
|
+
type: "worldEditPos";
|
|
77
|
+
positionType: WorldEditPositionType;
|
|
78
|
+
position: Vector3 | null;
|
|
79
|
+
}
|
|
80
|
+
export interface TimeUpdate {
|
|
81
|
+
type: "time";
|
|
82
|
+
time: bigint;
|
|
83
|
+
}
|
|
84
|
+
export interface BiomeUpdate {
|
|
85
|
+
type: "biome";
|
|
86
|
+
biomeId: number;
|
|
87
|
+
}
|
|
88
|
+
export type GenericUpdate = GamemodeUpdate | TeleportUpdate | WorldEditPosUpdate | TimeUpdate | BiomeUpdate;
|
|
89
|
+
export interface EntityPositionPacket {
|
|
90
|
+
timestamp: number;
|
|
91
|
+
basePosition: Vector3;
|
|
92
|
+
entities: EntitySnapshot[];
|
|
93
|
+
items: ItemSnapshot[];
|
|
94
|
+
}
|
|
95
|
+
export interface ProtocolEvent {
|
|
96
|
+
channelId: number;
|
|
97
|
+
protocolId: number;
|
|
98
|
+
payload: Buffer;
|
|
99
|
+
}
|
|
100
|
+
export interface CubyzConnectionLogger {
|
|
101
|
+
info?: (...args: unknown[]) => void;
|
|
102
|
+
warn?: (...args: unknown[]) => void;
|
|
103
|
+
error?: (...args: unknown[]) => void;
|
|
104
|
+
debug?: (...args: unknown[]) => void;
|
|
105
|
+
}
|
|
106
|
+
export interface CubyzConnectionOptions {
|
|
107
|
+
host: string;
|
|
108
|
+
port: number;
|
|
109
|
+
name: string;
|
|
110
|
+
version?: string;
|
|
111
|
+
logger?: CubyzConnectionLogger;
|
|
112
|
+
logLevel?: LogLevel;
|
|
113
|
+
}
|
|
114
|
+
export interface CloseOptions {
|
|
115
|
+
notify?: boolean;
|
|
116
|
+
}
|
|
117
|
+
export type ConnectionState = "awaitingServer" | "connected" | "closing" | "closed";
|
|
118
|
+
export interface PendingConfirmation {
|
|
119
|
+
channelId: number;
|
|
120
|
+
start: number;
|
|
121
|
+
timestamp: number;
|
|
122
|
+
}
|
|
123
|
+
export type CubyzConnectionEvents = {
|
|
124
|
+
connected: [];
|
|
125
|
+
handshakeComplete: [string];
|
|
126
|
+
chat: [string];
|
|
127
|
+
blockUpdate: [BlockUpdate[]];
|
|
128
|
+
players: [PlayersEvent];
|
|
129
|
+
entityPositions: [EntityPositionPacket];
|
|
130
|
+
genericUpdate: [GenericUpdate];
|
|
131
|
+
protocol: [ProtocolEvent];
|
|
132
|
+
disconnect: [DisconnectEvent];
|
|
133
|
+
};
|
|
134
|
+
export interface DisconnectEvent {
|
|
135
|
+
reason: "server" | "timeout";
|
|
136
|
+
}
|
|
137
|
+
export type PlayersEvent = PlayerData[];
|
|
138
|
+
export interface PlayerData {
|
|
139
|
+
id: number;
|
|
140
|
+
name: string;
|
|
141
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const DEG_TO_RAD = Math.PI / 180;
|
|
2
|
+
export const LOG_LEVEL_ORDER = {
|
|
3
|
+
debug: 0,
|
|
4
|
+
info: 1,
|
|
5
|
+
warn: 2,
|
|
6
|
+
error: 3,
|
|
7
|
+
silent: 4,
|
|
8
|
+
};
|
|
9
|
+
export const ENTITY_POSITION_TYPE = {
|
|
10
|
+
NO_VELOCITY_ENTITY: 0,
|
|
11
|
+
F16_VELOCITY_ENTITY: 1,
|
|
12
|
+
F32_VELOCITY_ENTITY: 2,
|
|
13
|
+
NO_VELOCITY_ITEM: 3,
|
|
14
|
+
F16_VELOCITY_ITEM: 4,
|
|
15
|
+
F32_VELOCITY_ITEM: 5,
|
|
16
|
+
};
|
|
17
|
+
export const GENERIC_UPDATE_TYPE = {
|
|
18
|
+
GAMEMODE: 0,
|
|
19
|
+
TELEPORT: 1,
|
|
20
|
+
WORLD_EDIT_POS: 2,
|
|
21
|
+
TIME: 3,
|
|
22
|
+
BIOME: 4,
|
|
23
|
+
};
|
|
24
|
+
export const GAMEMODE = {
|
|
25
|
+
SURVIVAL: 0,
|
|
26
|
+
CREATIVE: 1,
|
|
27
|
+
};
|
|
28
|
+
export const WORLD_EDIT_POSITION = {
|
|
29
|
+
SELECTED_POS1: 0,
|
|
30
|
+
SELECTED_POS2: 1,
|
|
31
|
+
CLEAR: 2,
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=connectionTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connectionTypes.js","sourceRoot":"","sources":["../src/connectionTypes.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC;AAExC,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;CACD,CAAC;AAEX,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,kBAAkB,EAAE,CAAC;IACrB,mBAAmB,EAAE,CAAC;IACtB,mBAAmB,EAAE,CAAC;IACtB,gBAAgB,EAAE,CAAC;IACnB,iBAAiB,EAAE,CAAC;IACpB,iBAAiB,EAAE,CAAC;CACZ,CAAC;AAwCX,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,cAAc,EAAE,CAAC;IACjB,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACA,CAAC;AAKX,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;CACH,CAAC;AAIX,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,aAAa,EAAE,CAAC;IAChB,aAAa,EAAE,CAAC;IAChB,KAAK,EAAE,CAAC;CACA,CAAC"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -11,9 +11,11 @@ export type ChannelId = (typeof CHANNEL)[keyof typeof CHANNEL];
|
|
|
11
11
|
export type SequencedChannelId = typeof CHANNEL.LOSSY | typeof CHANNEL.FAST | typeof CHANNEL.SLOW;
|
|
12
12
|
export declare const PROTOCOL: {
|
|
13
13
|
readonly HANDSHAKE: 1;
|
|
14
|
+
readonly PLAYER_STATE: 4;
|
|
14
15
|
readonly ENTITY_POSITION: 6;
|
|
16
|
+
readonly BLOCK_UPDATE: 7;
|
|
15
17
|
readonly ENTITY: 8;
|
|
16
|
-
readonly
|
|
18
|
+
readonly GENERIC_UPDATE: 9;
|
|
17
19
|
readonly CHAT: 10;
|
|
18
20
|
};
|
|
19
21
|
export type ProtocolId = (typeof PROTOCOL)[keyof typeof PROTOCOL];
|
package/dist/constants.js
CHANGED
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,YAAY,EAAE,CAAC;IACf,IAAI,EAAE,CAAC;IACP,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,CAAC;CACL,CAAC;AAQX,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,SAAS,EAAE,CAAC;IACZ,eAAe,EAAE,CAAC;IAClB,MAAM,EAAE,CAAC;IACT,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,YAAY,EAAE,CAAC;IACf,IAAI,EAAE,CAAC;IACP,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,CAAC;CACL,CAAC;AAQX,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,SAAS,EAAE,CAAC;IACZ,YAAY,EAAE,CAAC;IACf,eAAe,EAAE,CAAC;IAClB,YAAY,EAAE,CAAC;IACf,MAAM,EAAE,CAAC;IACT,cAAc,EAAE,CAAC;IACjB,IAAI,EAAE,EAAE;CACA,CAAC;AAIX,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,KAAK,EAAE,CAAC;IACR,SAAS,EAAE,CAAC;IACZ,MAAM,EAAE,CAAC;IACT,WAAW,EAAE,CAAC;IACd,QAAQ,EAAE,GAAG;CACL,CAAC;AAKX,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC;AAClC,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC;AAEvC,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AACrC,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAC3C,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAC3C,MAAM,CAAC,MAAM,qBAAqB,GAAG,sBAAsB,GAAG,CAAC,CAAC;AAChE,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC;AACjD,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,6CAA6C"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Buffer } from "node:buffer";
|
|
2
|
+
import { type EntityPositionPacket, type LogLevel } from "./connectionTypes.js";
|
|
3
|
+
export type EntityParserLogger = (level: LogLevel, ...args: unknown[]) => void;
|
|
4
|
+
export declare function parseEntityPositionPacket(payload: Buffer, log: EntityParserLogger): EntityPositionPacket | null;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { readFloat16BE } from "./binary.js";
|
|
2
|
+
import { ENTITY_POSITION_TYPE, } from "./connectionTypes.js";
|
|
3
|
+
export function parseEntityPositionPacket(payload, log) {
|
|
4
|
+
const headerSize = 2 + 8 * 3;
|
|
5
|
+
if (payload.length < headerSize) {
|
|
6
|
+
log("warn", "Entity position payload too short", {
|
|
7
|
+
length: payload.length,
|
|
8
|
+
});
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
let offset = 0;
|
|
12
|
+
const ensure = (size) => {
|
|
13
|
+
if (offset + size > payload.length) {
|
|
14
|
+
throw new Error(`Entity position packet truncated, needed ${size} bytes at offset ${offset}`);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const readVec3f32 = () => {
|
|
18
|
+
ensure(12);
|
|
19
|
+
const vector = {
|
|
20
|
+
x: payload.readFloatBE(offset),
|
|
21
|
+
y: payload.readFloatBE(offset + 4),
|
|
22
|
+
z: payload.readFloatBE(offset + 8),
|
|
23
|
+
};
|
|
24
|
+
offset += 12;
|
|
25
|
+
return vector;
|
|
26
|
+
};
|
|
27
|
+
const readVec3f16 = () => {
|
|
28
|
+
ensure(6);
|
|
29
|
+
const vector = {
|
|
30
|
+
x: readFloat16BE(payload, offset),
|
|
31
|
+
y: readFloat16BE(payload, offset + 2),
|
|
32
|
+
z: readFloat16BE(payload, offset + 4),
|
|
33
|
+
};
|
|
34
|
+
offset += 6;
|
|
35
|
+
return vector;
|
|
36
|
+
};
|
|
37
|
+
try {
|
|
38
|
+
ensure(2);
|
|
39
|
+
const timestamp = payload.readInt16BE(offset);
|
|
40
|
+
offset += 2;
|
|
41
|
+
ensure(24);
|
|
42
|
+
const basePosition = {
|
|
43
|
+
x: payload.readDoubleBE(offset),
|
|
44
|
+
y: payload.readDoubleBE(offset + 8),
|
|
45
|
+
z: payload.readDoubleBE(offset + 16),
|
|
46
|
+
};
|
|
47
|
+
offset += 24;
|
|
48
|
+
const nextEntityStates = new Map();
|
|
49
|
+
const nextItemStates = new Map();
|
|
50
|
+
const entitiesForEvent = [];
|
|
51
|
+
const itemsForEvent = [];
|
|
52
|
+
while (offset < payload.length) {
|
|
53
|
+
ensure(1);
|
|
54
|
+
const type = payload[offset];
|
|
55
|
+
offset += 1;
|
|
56
|
+
let velocity = { x: 0, y: 0, z: 0 };
|
|
57
|
+
if (type === ENTITY_POSITION_TYPE.F16_VELOCITY_ENTITY ||
|
|
58
|
+
type === ENTITY_POSITION_TYPE.F16_VELOCITY_ITEM) {
|
|
59
|
+
velocity = readVec3f16();
|
|
60
|
+
}
|
|
61
|
+
else if (type === ENTITY_POSITION_TYPE.F32_VELOCITY_ENTITY ||
|
|
62
|
+
type === ENTITY_POSITION_TYPE.F32_VELOCITY_ITEM) {
|
|
63
|
+
velocity = readVec3f32();
|
|
64
|
+
}
|
|
65
|
+
switch (type) {
|
|
66
|
+
case ENTITY_POSITION_TYPE.NO_VELOCITY_ENTITY:
|
|
67
|
+
case ENTITY_POSITION_TYPE.F16_VELOCITY_ENTITY:
|
|
68
|
+
case ENTITY_POSITION_TYPE.F32_VELOCITY_ENTITY: {
|
|
69
|
+
ensure(4);
|
|
70
|
+
const id = payload.readUInt32BE(offset);
|
|
71
|
+
offset += 4;
|
|
72
|
+
const delta = readVec3f32();
|
|
73
|
+
const rotation = readVec3f32();
|
|
74
|
+
const position = {
|
|
75
|
+
x: basePosition.x + delta.x,
|
|
76
|
+
y: basePosition.y + delta.y,
|
|
77
|
+
z: basePosition.z + delta.z,
|
|
78
|
+
};
|
|
79
|
+
const state = {
|
|
80
|
+
id,
|
|
81
|
+
position,
|
|
82
|
+
velocity,
|
|
83
|
+
rotation,
|
|
84
|
+
timestamp,
|
|
85
|
+
};
|
|
86
|
+
nextEntityStates.set(id, state);
|
|
87
|
+
entitiesForEvent.push({
|
|
88
|
+
id,
|
|
89
|
+
position: { ...position },
|
|
90
|
+
velocity: { ...velocity },
|
|
91
|
+
rotation: { ...rotation },
|
|
92
|
+
timestamp,
|
|
93
|
+
});
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case ENTITY_POSITION_TYPE.NO_VELOCITY_ITEM:
|
|
97
|
+
case ENTITY_POSITION_TYPE.F16_VELOCITY_ITEM:
|
|
98
|
+
case ENTITY_POSITION_TYPE.F32_VELOCITY_ITEM: {
|
|
99
|
+
ensure(2);
|
|
100
|
+
const index = payload.readUInt16BE(offset);
|
|
101
|
+
offset += 2;
|
|
102
|
+
const delta = readVec3f32();
|
|
103
|
+
const position = {
|
|
104
|
+
x: basePosition.x + delta.x,
|
|
105
|
+
y: basePosition.y + delta.y,
|
|
106
|
+
z: basePosition.z + delta.z,
|
|
107
|
+
};
|
|
108
|
+
const state = {
|
|
109
|
+
index,
|
|
110
|
+
position,
|
|
111
|
+
velocity,
|
|
112
|
+
timestamp,
|
|
113
|
+
};
|
|
114
|
+
nextItemStates.set(index, state);
|
|
115
|
+
itemsForEvent.push({
|
|
116
|
+
index,
|
|
117
|
+
position: { ...position },
|
|
118
|
+
velocity: { ...velocity },
|
|
119
|
+
timestamp,
|
|
120
|
+
});
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
default: {
|
|
124
|
+
log("warn", "Unknown entity position entry type", { type });
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
timestamp,
|
|
131
|
+
basePosition: { ...basePosition },
|
|
132
|
+
entities: entitiesForEvent,
|
|
133
|
+
items: itemsForEvent,
|
|
134
|
+
_entityStates: nextEntityStates,
|
|
135
|
+
_itemStates: nextItemStates,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
log("warn", "Failed to decode entity position payload", err);
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=entityParser.js.map
|
|
@@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AAE,cAAc;SAI5B,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,GAAG,CAAC,MAAM,EAAE,0CAA0C,EAAE,GAAG,CAAC,CAAC;QAC7D,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { type HandshakeState } from "./constants.js";
|
|
3
|
+
export declare function randomSequence(): number;
|
|
4
|
+
export declare function escapeZonString(value: string): string;
|
|
5
|
+
export declare function buildHandshakePayload(name: string, version: string): Buffer;
|
|
6
|
+
export interface HandshakeMessage {
|
|
7
|
+
state: HandshakeState;
|
|
8
|
+
data: Buffer;
|
|
9
|
+
}
|
|
10
|
+
export declare function parseHandshake(payload: Buffer): HandshakeMessage;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
import { randomInt } from "node:crypto";
|
|
3
|
+
import { HANDSHAKE_STATE } from "./constants.js";
|
|
4
|
+
export function randomSequence() {
|
|
5
|
+
return randomInt(0, 0x7fffffff);
|
|
6
|
+
}
|
|
7
|
+
export function escapeZonString(value) {
|
|
8
|
+
return value.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
|
|
9
|
+
}
|
|
10
|
+
export function buildHandshakePayload(name, version) {
|
|
11
|
+
const safeName = escapeZonString(name);
|
|
12
|
+
const safeVersion = escapeZonString(version);
|
|
13
|
+
const zon = `.{.version = "${safeVersion}", .name = "${safeName}"}`;
|
|
14
|
+
const prefix = Buffer.from([HANDSHAKE_STATE.USER_DATA]);
|
|
15
|
+
return Buffer.concat([prefix, Buffer.from(zon, "utf8")]);
|
|
16
|
+
}
|
|
17
|
+
export function parseHandshake(payload) {
|
|
18
|
+
if (!payload || payload.length === 0) {
|
|
19
|
+
throw new Error("Handshake payload empty");
|
|
20
|
+
}
|
|
21
|
+
const state = payload[0];
|
|
22
|
+
return { state, data: payload.slice(1) };
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C;IAC3C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAC3C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { addSeq, decodeVarInt, encodeVarInt, seqLessThan } from "./binary.js";
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
2
|
+
export { countVisibleCharacters, prepareChatMessage } from "./chatFormat.js";
|
|
3
|
+
export type { BiomeUpdate, BlockUpdate, CloseOptions, CubyzConnectionLogger, CubyzConnectionOptions, DisconnectEvent, EntityPositionPacket, EntitySnapshot, Gamemode, GamemodeUpdate, GenericUpdate, ItemSnapshot, LogLevel, PlayerState, ProtocolEvent, TeleportUpdate, TimeUpdate, Vector3, WorldEditPosUpdate, } from "./connection.js";
|
|
4
|
+
export { CubyzConnection, GAMEMODE } from "./connection.js";
|
|
4
5
|
export * from "./constants.js";
|
|
5
6
|
export { ReceiveChannel } from "./receiveChannel.js";
|
|
6
7
|
export { SendChannel } from "./sendChannel.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { addSeq, decodeVarInt, encodeVarInt, seqLessThan } from "./binary.js";
|
|
2
|
-
export {
|
|
2
|
+
export { countVisibleCharacters, prepareChatMessage } from "./chatFormat.js";
|
|
3
|
+
export { CubyzConnection, GAMEMODE } from "./connection.js";
|
|
3
4
|
export * from "./constants.js";
|
|
4
5
|
export { ReceiveChannel } from "./receiveChannel.js";
|
|
5
6
|
export { SendChannel } from "./sendChannel.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAsB7E,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC5D,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC"}
|