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
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ Compilation outputs ESM modules alongside type declarations in `dist/`.
|
|
|
33
33
|
|
|
34
34
|
## Quick start example
|
|
35
35
|
|
|
36
|
-
You can run the included sandbox example to see the connection flow
|
|
36
|
+
You can run the included sandbox example to see the connection flow:
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
39
|
# Optional overrides for host/port/player name
|
|
@@ -87,6 +87,17 @@ connection.on("chat", (message) => {
|
|
|
87
87
|
console.log("[chat]", message);
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
+
connection.on("blockUpdate", (updates) => {
|
|
91
|
+
for (const update of updates) {
|
|
92
|
+
console.log(
|
|
93
|
+
"Block changed at",
|
|
94
|
+
update.position,
|
|
95
|
+
"to block ID",
|
|
96
|
+
update.block
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
90
101
|
connection.on("protocol", (event) => {
|
|
91
102
|
console.log("Protocol event:", event.protocolId);
|
|
92
103
|
});
|
|
@@ -122,6 +133,7 @@ interface CubyzConnectionOptions {
|
|
|
122
133
|
- **`connected`**: Emitted when the channel handshake with the server completes
|
|
123
134
|
- **`handshakeComplete()`**: Emitted when the server handshake finishes and the bot is ready
|
|
124
135
|
- **`chat(message: string)`**: Emitted when a chat message is received from the server
|
|
136
|
+
- **`blockUpdate(updates: BlockUpdate[])`**: Emitted when blocks are placed or broken (includes position, block ID, and optional block entity data)
|
|
125
137
|
- **`players(players: PlayerData[])`**: Emitted when the player list updates (each player has `id` and `name`)
|
|
126
138
|
- **`entityPositions(packet: EntityPositionPacket)`**: Emitted when entity/item position updates are received
|
|
127
139
|
- **`protocol(event: ProtocolEvent)`**: Emitted for other protocol messages
|
|
@@ -201,6 +213,12 @@ export interface ItemSnapshot {
|
|
|
201
213
|
timestamp: number;
|
|
202
214
|
}
|
|
203
215
|
|
|
216
|
+
export interface BlockUpdate {
|
|
217
|
+
position: Vector3;
|
|
218
|
+
block: number; // Block type ID
|
|
219
|
+
blockEntityData: Buffer; // Additional block entity data (may be empty)
|
|
220
|
+
}
|
|
221
|
+
|
|
204
222
|
export interface EntityPositionPacket {
|
|
205
223
|
timestamp: number;
|
|
206
224
|
basePosition: Vector3;
|
package/dist/binary.js
CHANGED
|
@@ -3,31 +3,41 @@ export function encodeVarInt(value) {
|
|
|
3
3
|
if (value < 0) {
|
|
4
4
|
throw new RangeError("VarInt cannot encode negative values");
|
|
5
5
|
}
|
|
6
|
+
// Cubyz uses big-endian varint encoding (MSB first)
|
|
6
7
|
const bytes = [];
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
const val = value >>> 0;
|
|
9
|
+
if (val === 0) {
|
|
10
|
+
return Buffer.from([0]);
|
|
11
|
+
}
|
|
12
|
+
// Calculate number of bits needed
|
|
13
|
+
const bits = val === 0 ? 1 : Math.floor(Math.log2(val)) + 1;
|
|
14
|
+
// Calculate number of 7-bit chunks needed
|
|
15
|
+
const numBytes = Math.ceil(bits / 7);
|
|
16
|
+
// Encode big-endian (most significant byte first)
|
|
17
|
+
for (let i = 0; i < numBytes; i++) {
|
|
18
|
+
const shift = 7 * (numBytes - i - 1);
|
|
19
|
+
let byte = (val >>> shift) & 0x7f;
|
|
20
|
+
// Set continuation bit on all bytes except the last
|
|
21
|
+
if (i < numBytes - 1) {
|
|
12
22
|
byte |= 0x80;
|
|
13
23
|
}
|
|
14
24
|
bytes.push(byte);
|
|
15
|
-
}
|
|
25
|
+
}
|
|
16
26
|
return Buffer.from(bytes);
|
|
17
27
|
}
|
|
18
28
|
export function decodeVarInt(buffer, offset = 0) {
|
|
29
|
+
// Cubyz uses big-endian varint decoding (MSB first)
|
|
19
30
|
let value = 0;
|
|
20
31
|
let consumed = 0;
|
|
21
|
-
let shift = 0;
|
|
22
32
|
while (offset + consumed < buffer.length) {
|
|
23
33
|
const byte = buffer[offset + consumed];
|
|
24
|
-
value
|
|
34
|
+
value = (value << 7) | (byte & 0x7f);
|
|
25
35
|
consumed += 1;
|
|
36
|
+
// Last byte has no continuation bit
|
|
26
37
|
if ((byte & 0x80) === 0) {
|
|
27
38
|
return { value: value >>> 0, consumed };
|
|
28
39
|
}
|
|
29
|
-
|
|
30
|
-
if (shift >= 35) {
|
|
40
|
+
if (consumed >= 5) {
|
|
31
41
|
throw new Error("VarInt decoding failed: value too large");
|
|
32
42
|
}
|
|
33
43
|
}
|
package/dist/binary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binary.js","sourceRoot":"","sources":["../src/binary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACd,MAAM,IAAI,UAAU,CAAC,sCAAsC,CAAC,CAAC;IA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|
+
const textDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
4
|
+
// Chat message limits
|
|
5
|
+
// Note: The server allows up to 10,000 bytes and 1,000 visible characters,
|
|
6
|
+
// but the client must respect MTU constraints for LOSSY channel packets.
|
|
7
|
+
// MTU = 548 bytes:
|
|
8
|
+
// - Channel ID + Sequence: 5 bytes
|
|
9
|
+
// - Protocol ID: 1 byte
|
|
10
|
+
// - VarInt size (2 bytes for messages under ~16KB): 2 bytes
|
|
11
|
+
// - Maximum payload: 548 - 5 - 1 - 2 = 540 bytes
|
|
12
|
+
const MAX_VISIBLE_CHARACTERS = 1000;
|
|
13
|
+
const MAX_MESSAGE_BYTES = 540;
|
|
14
|
+
function readCodePoint(text, cursor) {
|
|
15
|
+
if (cursor.index >= text.length) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const value = text.codePointAt(cursor.index);
|
|
19
|
+
if (value === undefined) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const size = value > 0xffff ? 2 : 1;
|
|
23
|
+
cursor.index += size;
|
|
24
|
+
return { value, size };
|
|
25
|
+
}
|
|
26
|
+
export function countVisibleCharacters(text) {
|
|
27
|
+
const cursor = { index: 0 };
|
|
28
|
+
let current = readCodePoint(text, cursor);
|
|
29
|
+
let count = 0;
|
|
30
|
+
outer: while (current !== null) {
|
|
31
|
+
switch (current.value) {
|
|
32
|
+
case 0x2a: {
|
|
33
|
+
// '*'
|
|
34
|
+
current = readCodePoint(text, cursor);
|
|
35
|
+
continue outer;
|
|
36
|
+
}
|
|
37
|
+
case 0x5f: {
|
|
38
|
+
// '_'
|
|
39
|
+
const next = readCodePoint(text, cursor);
|
|
40
|
+
if (next === null) {
|
|
41
|
+
break outer;
|
|
42
|
+
}
|
|
43
|
+
if (next.value === 0x5f) {
|
|
44
|
+
current = readCodePoint(text, cursor);
|
|
45
|
+
continue outer;
|
|
46
|
+
}
|
|
47
|
+
count += 1;
|
|
48
|
+
current = next;
|
|
49
|
+
continue outer;
|
|
50
|
+
}
|
|
51
|
+
case 0x7e: {
|
|
52
|
+
// '~'
|
|
53
|
+
const next = readCodePoint(text, cursor);
|
|
54
|
+
if (next === null) {
|
|
55
|
+
break outer;
|
|
56
|
+
}
|
|
57
|
+
if (next.value === 0x7e) {
|
|
58
|
+
current = readCodePoint(text, cursor);
|
|
59
|
+
continue outer;
|
|
60
|
+
}
|
|
61
|
+
count += 1;
|
|
62
|
+
current = next;
|
|
63
|
+
continue outer;
|
|
64
|
+
}
|
|
65
|
+
case 0x5c: {
|
|
66
|
+
// '\'
|
|
67
|
+
const escaped = readCodePoint(text, cursor);
|
|
68
|
+
if (escaped === null) {
|
|
69
|
+
count += 1;
|
|
70
|
+
break outer;
|
|
71
|
+
}
|
|
72
|
+
count += 1;
|
|
73
|
+
current = readCodePoint(text, cursor);
|
|
74
|
+
continue outer;
|
|
75
|
+
}
|
|
76
|
+
case 0x23: {
|
|
77
|
+
// '#'
|
|
78
|
+
let next = null;
|
|
79
|
+
for (let i = 0; i < 7; i += 1) {
|
|
80
|
+
next = readCodePoint(text, cursor);
|
|
81
|
+
if (next === null) {
|
|
82
|
+
current = null;
|
|
83
|
+
break outer;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
current = next;
|
|
87
|
+
continue outer;
|
|
88
|
+
}
|
|
89
|
+
case 0xa7: {
|
|
90
|
+
// '§'
|
|
91
|
+
current = readCodePoint(text, cursor);
|
|
92
|
+
continue outer;
|
|
93
|
+
}
|
|
94
|
+
default: {
|
|
95
|
+
count += 1;
|
|
96
|
+
current = readCodePoint(text, cursor);
|
|
97
|
+
continue outer;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return count;
|
|
102
|
+
}
|
|
103
|
+
function assertNoInvalidUtf8(bytes) {
|
|
104
|
+
try {
|
|
105
|
+
textDecoder.decode(bytes);
|
|
106
|
+
}
|
|
107
|
+
catch (_error) {
|
|
108
|
+
throw new RangeError("Chat message contains invalid UTF-8 encoding");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export function prepareChatMessage(rawMessage) {
|
|
112
|
+
let normalized = rawMessage.replace(/\r\n?/g, "\n");
|
|
113
|
+
if (countVisibleCharacters(normalized) === 0) {
|
|
114
|
+
throw new RangeError("Chat message cannot be empty");
|
|
115
|
+
}
|
|
116
|
+
let payload = Buffer.from(normalized, "utf8");
|
|
117
|
+
assertNoInvalidUtf8(payload);
|
|
118
|
+
// Trim message if it exceeds byte limit
|
|
119
|
+
if (payload.length > MAX_MESSAGE_BYTES) {
|
|
120
|
+
// Binary search for the right cut point (UTF-8 safe)
|
|
121
|
+
let low = 0;
|
|
122
|
+
let high = normalized.length;
|
|
123
|
+
while (low < high) {
|
|
124
|
+
const mid = Math.floor((low + high + 1) / 2);
|
|
125
|
+
const testBuf = Buffer.from(`${normalized.slice(0, mid)}...`, "utf8");
|
|
126
|
+
if (testBuf.length <= MAX_MESSAGE_BYTES) {
|
|
127
|
+
low = mid;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
high = mid - 1;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
normalized = `${normalized.slice(0, low)}...`;
|
|
134
|
+
payload = Buffer.from(normalized, "utf8");
|
|
135
|
+
}
|
|
136
|
+
// Trim if visible character count exceeds limit
|
|
137
|
+
const visibleCharacters = countVisibleCharacters(normalized);
|
|
138
|
+
if (visibleCharacters > MAX_VISIBLE_CHARACTERS) {
|
|
139
|
+
// Trim character by character until we're under the limit
|
|
140
|
+
let trimmed = normalized;
|
|
141
|
+
while (countVisibleCharacters(`${trimmed}...`) > MAX_VISIBLE_CHARACTERS &&
|
|
142
|
+
trimmed.length > 0) {
|
|
143
|
+
// Remove one character at a time (UTF-8 safe)
|
|
144
|
+
const encoder = new TextEncoder();
|
|
145
|
+
const decoder = new TextDecoder("utf-8");
|
|
146
|
+
const bytes = encoder.encode(trimmed);
|
|
147
|
+
let cutPoint = bytes.length - 1;
|
|
148
|
+
// Skip continuation bytes (0x80-0xBF)
|
|
149
|
+
while (cutPoint > 0 && (bytes[cutPoint] & 0xc0) === 0x80) {
|
|
150
|
+
cutPoint--;
|
|
151
|
+
}
|
|
152
|
+
trimmed = decoder.decode(bytes.slice(0, cutPoint));
|
|
153
|
+
}
|
|
154
|
+
normalized = `${trimmed}...`;
|
|
155
|
+
payload = Buffer.from(normalized, "utf8");
|
|
156
|
+
}
|
|
157
|
+
// Final validation
|
|
158
|
+
for (const byte of payload) {
|
|
159
|
+
if (byte === 0xff || byte === 0xfe) {
|
|
160
|
+
throw new Error("Chat message contains invalid UTF-8 sentinel bytes");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return payload;
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=chatFormat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatFormat.js","sourceRoot":"","sources":["../src/chatFormat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAE9D,sBAAsB;AACtB,2EAA2E;AAC3E,yEAAyE;AACzE,mBAAmB;AACnB,qCAAqC;AACrC,0BAA0B;AAC1B,8DAA8D;AAC9D,mDAAmD;AACnD,MAAM,sBAAsB,GAAG,IAAI,CAAC;AACpC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAO9B,SAAS,aAAa,CACpB,IAAY,EACZ,MAAyB;IAEzB,IAAI,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7C,IAAI,KAAK,K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ACD,UAAU,GAAG,GAAG,OAAO,KAAK,CAAC;QAC7B,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED,mBAAmB;IACnB,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/connection.d.ts
CHANGED
|
@@ -1,81 +1,7 @@
|
|
|
1
|
-
import { Buffer } from "node:buffer";
|
|
2
1
|
import { EventEmitter } from "node:events";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
readonly warn: 2;
|
|
7
|
-
readonly error: 3;
|
|
8
|
-
readonly silent: 4;
|
|
9
|
-
};
|
|
10
|
-
export type LogLevel = keyof typeof LOG_LEVEL_ORDER;
|
|
11
|
-
export interface Vector3 {
|
|
12
|
-
x: number;
|
|
13
|
-
y: number;
|
|
14
|
-
z: number;
|
|
15
|
-
}
|
|
16
|
-
export interface PlayerState {
|
|
17
|
-
position: Vector3;
|
|
18
|
-
velocity: Vector3;
|
|
19
|
-
rotation: Vector3;
|
|
20
|
-
}
|
|
21
|
-
export interface EntitySnapshot {
|
|
22
|
-
id: number;
|
|
23
|
-
position: Vector3;
|
|
24
|
-
velocity: Vector3;
|
|
25
|
-
rotation: Vector3;
|
|
26
|
-
timestamp: number;
|
|
27
|
-
}
|
|
28
|
-
export interface ItemSnapshot {
|
|
29
|
-
index: number;
|
|
30
|
-
position: Vector3;
|
|
31
|
-
velocity: Vector3;
|
|
32
|
-
timestamp: number;
|
|
33
|
-
}
|
|
34
|
-
export interface EntityPositionPacket {
|
|
35
|
-
timestamp: number;
|
|
36
|
-
basePosition: Vector3;
|
|
37
|
-
entities: EntitySnapshot[];
|
|
38
|
-
items: ItemSnapshot[];
|
|
39
|
-
}
|
|
40
|
-
export interface ProtocolEvent {
|
|
41
|
-
channelId: number;
|
|
42
|
-
protocolId: number;
|
|
43
|
-
payload: Buffer;
|
|
44
|
-
}
|
|
45
|
-
export interface CubyzConnectionLogger {
|
|
46
|
-
info?: (...args: unknown[]) => void;
|
|
47
|
-
warn?: (...args: unknown[]) => void;
|
|
48
|
-
error?: (...args: unknown[]) => void;
|
|
49
|
-
debug?: (...args: unknown[]) => void;
|
|
50
|
-
}
|
|
51
|
-
export interface CubyzConnectionOptions {
|
|
52
|
-
host: string;
|
|
53
|
-
port: number;
|
|
54
|
-
name: string;
|
|
55
|
-
version?: string;
|
|
56
|
-
logger?: CubyzConnectionLogger;
|
|
57
|
-
logLevel?: LogLevel;
|
|
58
|
-
}
|
|
59
|
-
export interface CloseOptions {
|
|
60
|
-
notify?: boolean;
|
|
61
|
-
}
|
|
62
|
-
type CubyzConnectionEvents = {
|
|
63
|
-
connected: [];
|
|
64
|
-
handshakeComplete: [string];
|
|
65
|
-
chat: [string];
|
|
66
|
-
players: [PlayersEvent];
|
|
67
|
-
entityPositions: [EntityPositionPacket];
|
|
68
|
-
protocol: [ProtocolEvent];
|
|
69
|
-
disconnect: [DisconnectEvent];
|
|
70
|
-
};
|
|
71
|
-
export interface DisconnectEvent {
|
|
72
|
-
reason: "server" | "timeout";
|
|
73
|
-
}
|
|
74
|
-
export type PlayersEvent = PlayerData[];
|
|
75
|
-
export interface PlayerData {
|
|
76
|
-
id: number;
|
|
77
|
-
name: string;
|
|
78
|
-
}
|
|
2
|
+
import { type CloseOptions, type CubyzConnectionEvents, type CubyzConnectionOptions, type EntitySnapshot, type ItemSnapshot, type PlayerData } from "./connectionTypes.js";
|
|
3
|
+
export type { BiomeUpdate, BlockUpdate, CloseOptions, CubyzConnectionLogger, CubyzConnectionOptions, DisconnectEvent, EntityPositionPacket, EntitySnapshot, Gamemode, GamemodeUpdate, GenericUpdate, ItemSnapshot, LogLevel, PlayerData, PlayerState, PlayersEvent, ProtocolEvent, TeleportUpdate, TimeUpdate, Vector3, WorldEditPosUpdate, } from "./connectionTypes.js";
|
|
4
|
+
export { GAMEMODE } from "./connectionTypes.js";
|
|
79
5
|
export declare class CubyzConnection extends EventEmitter {
|
|
80
6
|
readonly host: string;
|
|
81
7
|
readonly port: number;
|
|
@@ -132,6 +58,8 @@ export declare class CubyzConnection extends EventEmitter {
|
|
|
132
58
|
private handleHandshake;
|
|
133
59
|
private handleEntityUpdate;
|
|
134
60
|
private handleEntityPosition;
|
|
61
|
+
private handleBlockUpdate;
|
|
62
|
+
private handleGenericUpdate;
|
|
135
63
|
private emitPlayers;
|
|
136
64
|
getPlayers(): PlayerData[];
|
|
137
65
|
getPlayerNames(): string[];
|
|
@@ -148,4 +76,3 @@ export declare class CubyzConnection extends EventEmitter {
|
|
|
148
76
|
private startPlayerStateLoop;
|
|
149
77
|
private sendDisconnectPacket;
|
|
150
78
|
}
|
|
151
|
-
export {};
|