@honeybbq/teamspeak-client 0.1.1 → 0.2.1
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 +14 -1
- package/dist/client.d.ts +6 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/handshake.d.ts.map +1 -1
- package/dist/handshake.test.d.ts +2 -0
- package/dist/handshake.test.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +206 -185
- package/dist/index.mjs.map +1 -1
- package/dist/types-CGKgXvpG.js.map +1 -1
- package/dist/types-DrnoCdSW.cjs.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { n as e, r as t, t as n } from "./types-CGKgXvpG.js";
|
|
2
|
-
import { C as r, S as i, _ as a, b as o, d as s, g as c, h as l, l as u, o as d, p as
|
|
2
|
+
import { C as r, S as i, _ as a, b as o, d as s, g as c, h as l, l as u, o as d, p as ee, r as f, u as p, v as m, w as h, x as g, y as _ } from "./primitives-BIAYfJ2Y.js";
|
|
3
3
|
import { t as v } from "./crypto-VC7n6YJb.js";
|
|
4
4
|
import { t as y } from "./resolver-DDZWomrF.js";
|
|
5
5
|
import { a as b, t as x } from "./handler-C_JhqGTd.js";
|
|
6
6
|
import { i as S, n as C, t as w } from "./command-caXc4h0n.js";
|
|
7
|
-
import { n as
|
|
8
|
-
import { t as
|
|
9
|
-
import { t as
|
|
10
|
-
import { createHash as
|
|
11
|
-
import { createConnection as
|
|
7
|
+
import { n as te } from "./crypt-handshake-CHmvZ2qs.js";
|
|
8
|
+
import { t as T } from "./crypt-init2-DWX7Tp-_.js";
|
|
9
|
+
import { t as E } from "./parser-CJjP3LlO.js";
|
|
10
|
+
import { createHash as D } from "node:crypto";
|
|
11
|
+
import { createConnection as O } from "node:net";
|
|
12
12
|
//#region src/commands.ts
|
|
13
|
-
var
|
|
13
|
+
var k = class {
|
|
14
14
|
#e = /* @__PURE__ */ new Map();
|
|
15
15
|
#t = 0;
|
|
16
16
|
#n = [];
|
|
@@ -50,7 +50,7 @@ var A = class {
|
|
|
50
50
|
this.#e.clear(), this.#n = [], this.#r = !1, this.#t = 0;
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
-
function
|
|
53
|
+
function A(e) {
|
|
54
54
|
let t = e.id ?? "0", n = e.msg ?? "", i = e.return_code, a = null;
|
|
55
55
|
t !== "0" && (a = new r(t, n));
|
|
56
56
|
let o = null;
|
|
@@ -63,12 +63,12 @@ function j(e) {
|
|
|
63
63
|
rc: o
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function j(e, t) {
|
|
67
67
|
return e.includes("return_code=") ? e : `${e} return_code=${t}`;
|
|
68
68
|
}
|
|
69
69
|
//#endregion
|
|
70
70
|
//#region src/transfer.ts
|
|
71
|
-
var
|
|
71
|
+
var M = class {
|
|
72
72
|
#e = /* @__PURE__ */ new Map();
|
|
73
73
|
#t = 0;
|
|
74
74
|
register() {
|
|
@@ -89,9 +89,9 @@ var N = class {
|
|
|
89
89
|
this.#e.clear(), this.#t = 0;
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
|
-
function
|
|
92
|
+
function N(e, t, n) {
|
|
93
93
|
return new Promise((r, i) => {
|
|
94
|
-
let a =
|
|
94
|
+
let a = O({
|
|
95
95
|
host: e,
|
|
96
96
|
port: t
|
|
97
97
|
}, () => {
|
|
@@ -104,19 +104,19 @@ function P(e, t, n) {
|
|
|
104
104
|
});
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
|
-
async function
|
|
108
|
-
let r = await
|
|
107
|
+
async function P(e, t, n) {
|
|
108
|
+
let r = await N(e, t.port, t.fileTransferKey);
|
|
109
109
|
await new Promise((e, t) => {
|
|
110
110
|
n.pipe(r), r.on("finish", e), r.on("error", t);
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
|
-
async function
|
|
114
|
-
let r = await
|
|
113
|
+
async function F(e, t, n) {
|
|
114
|
+
let r = await N(e, t.port, t.fileTransferKey);
|
|
115
115
|
await new Promise((e, t) => {
|
|
116
116
|
r.pipe(n), n.on("finish", e), r.on("error", t), n.on("error", t);
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
|
-
function
|
|
119
|
+
function I(e, t, n, r, i, a) {
|
|
120
120
|
let o = t.startsWith("/") ? t : `/${t}`;
|
|
121
121
|
return w("ftinitupload", {
|
|
122
122
|
cid: String(e),
|
|
@@ -128,7 +128,7 @@ function L(e, t, n, r, i, a) {
|
|
|
128
128
|
resume: "0"
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
|
-
function
|
|
131
|
+
function L(e, t, n, r) {
|
|
132
132
|
let i = t.startsWith("/") ? t : `/${t}`;
|
|
133
133
|
return w("ftinitdownload", {
|
|
134
134
|
cid: String(e),
|
|
@@ -140,28 +140,28 @@ function R(e, t, n, r) {
|
|
|
140
140
|
}
|
|
141
141
|
//#endregion
|
|
142
142
|
//#region src/events.ts
|
|
143
|
-
function
|
|
143
|
+
function R(e, t) {
|
|
144
144
|
let n = t;
|
|
145
145
|
for (let t = e.length - 1; t >= 0; t--) n = e[t](n);
|
|
146
146
|
return n;
|
|
147
147
|
}
|
|
148
|
-
function
|
|
148
|
+
function z(e, t) {
|
|
149
149
|
let n = t;
|
|
150
150
|
for (let t = e.length - 1; t >= 0; t--) n = e[t](n);
|
|
151
151
|
return n;
|
|
152
152
|
}
|
|
153
153
|
//#endregion
|
|
154
154
|
//#region src/handshake.ts
|
|
155
|
-
function
|
|
155
|
+
function B(e, t) {
|
|
156
156
|
let n = t.alpha ?? "", r = t.beta ?? "", i = t.omega ?? "";
|
|
157
|
-
e.crypt.initCrypto(n, r, i), e.logger.info("crypto initialized (P-256 path), sending clientinit"),
|
|
157
|
+
e.crypt.initCrypto(n, r, i), e.logger.info("crypto initialized (P-256 path), sending clientinit"), K(e);
|
|
158
158
|
}
|
|
159
|
-
function
|
|
159
|
+
function V(e, t) {
|
|
160
160
|
e.logger.info("received initivexpand2"), e.handler.receivedFinalInitAck();
|
|
161
|
-
let n = t.l ?? "", r = t.omega ?? "", i = t.proof ?? "", a = t.beta ?? "", o =
|
|
162
|
-
|
|
161
|
+
let n = t.l ?? "", r = t.omega ?? "", i = t.proof ?? "", a = t.beta ?? "", o = U(e, a);
|
|
162
|
+
T(e.crypt, n, r, i, a, o), K(e);
|
|
163
163
|
}
|
|
164
|
-
function
|
|
164
|
+
function H(e, t) {
|
|
165
165
|
let n = t.aclid ?? t.clid ?? "", r = n ? parseInt(n, 10) : 0;
|
|
166
166
|
r > 0 && (e.clid = r, e.handler.setClientID(r)), e.logger.info("connected to server", { selfId: e.clid }), e._markConnected(), setImmediate(() => {
|
|
167
167
|
let t = w("clientupdate", {
|
|
@@ -171,8 +171,8 @@ function U(e, t) {
|
|
|
171
171
|
e.sendCommandNoWait(t).catch(() => {});
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
|
-
function
|
|
175
|
-
let [n, r] =
|
|
174
|
+
function U(e, t) {
|
|
175
|
+
let [n, r] = f(), i = Buffer.from(n).toString("base64"), a = W(e, n, t), o = C("clientek", [["ek", i], ["proof", a]]);
|
|
176
176
|
return e.handler.sendPacket(b.Command, Buffer.from(o), 0), r;
|
|
177
177
|
}
|
|
178
178
|
function W(e, t, n) {
|
|
@@ -182,27 +182,34 @@ function W(e, t, n) {
|
|
|
182
182
|
return Buffer.from(a).toString("base64");
|
|
183
183
|
}
|
|
184
184
|
function G(e) {
|
|
185
|
-
|
|
185
|
+
return e === "" ? "" : D("sha1").update(e).digest().toString("base64");
|
|
186
|
+
}
|
|
187
|
+
function K(e) {
|
|
188
|
+
let t = q(e);
|
|
189
|
+
e.handler.sendPacket(b.Command, Buffer.from(t), 0);
|
|
190
|
+
}
|
|
191
|
+
function q(e) {
|
|
192
|
+
let t = e.crypt.identity.publicKeyBase64(), n = e.getClientInitOptions(), r = G(n.defaultChannelPassword), i = G(n.serverPassword), a = D("sha1").update(t).digest().toString("base64");
|
|
193
|
+
return C("clientinit", [
|
|
186
194
|
["client_nickname", e.nickname],
|
|
187
195
|
["client_version", "3.?.? [Build: 5680278000]"],
|
|
188
196
|
["client_platform", "Windows"],
|
|
189
197
|
["client_input_hardware", "1"],
|
|
190
198
|
["client_output_hardware", "1"],
|
|
191
|
-
["client_default_channel",
|
|
192
|
-
["client_default_channel_password",
|
|
193
|
-
["client_server_password",
|
|
199
|
+
["client_default_channel", n.defaultChannel],
|
|
200
|
+
["client_default_channel_password", r],
|
|
201
|
+
["client_server_password", i],
|
|
194
202
|
["client_meta_data", ""],
|
|
195
203
|
["client_version_sign", "DX5NIYLvfJEUjuIbCidnoeozxIDRRkpq3I9vVMBmE9L2qnekOoBzSenkzsg2lC9CMv8K5hkEzhr2TYUYSwUXCg=="],
|
|
196
204
|
["client_key_offset", String(e.crypt.identity.offset)],
|
|
197
205
|
["client_nickname_phonetic", ""],
|
|
198
206
|
["client_default_token", ""],
|
|
199
|
-
["hwid",
|
|
207
|
+
["hwid", a]
|
|
200
208
|
]);
|
|
201
|
-
e.handler.sendPacket(b.Command, Buffer.from(r), 0);
|
|
202
209
|
}
|
|
203
210
|
//#endregion
|
|
204
211
|
//#region src/helpers.ts
|
|
205
|
-
function
|
|
212
|
+
function J(e) {
|
|
206
213
|
if (e === "" || e === void 0) return 0n;
|
|
207
214
|
try {
|
|
208
215
|
return BigInt(e);
|
|
@@ -210,21 +217,21 @@ function K(e) {
|
|
|
210
217
|
return 0n;
|
|
211
218
|
}
|
|
212
219
|
}
|
|
213
|
-
function
|
|
220
|
+
function Y(e) {
|
|
214
221
|
let t = parseInt(e, 10);
|
|
215
222
|
return isNaN(t) || t < 0 || t > 65535 ? 0 : t;
|
|
216
223
|
}
|
|
217
|
-
function
|
|
224
|
+
function X(e) {
|
|
218
225
|
let t = parseInt(e, 10);
|
|
219
226
|
return isNaN(t) ? 0 : t;
|
|
220
227
|
}
|
|
221
|
-
function
|
|
228
|
+
function Z(e, t) {
|
|
222
229
|
if (t === e) return !0;
|
|
223
230
|
if (!t.startsWith(e)) return !1;
|
|
224
231
|
let n = t.slice(e.length);
|
|
225
232
|
return /^\d+$/.test(n);
|
|
226
233
|
}
|
|
227
|
-
function
|
|
234
|
+
function Q(e) {
|
|
228
235
|
let t = e.indexOf(" ");
|
|
229
236
|
if (t < 0) return [e];
|
|
230
237
|
let n = e.slice(0, t), r = e.slice(t + 1);
|
|
@@ -235,30 +242,30 @@ function X(e) {
|
|
|
235
242
|
}
|
|
236
243
|
//#endregion
|
|
237
244
|
//#region src/notifications.ts
|
|
238
|
-
function
|
|
245
|
+
function ne(e, t, n, r) {
|
|
239
246
|
switch (e.name) {
|
|
240
|
-
case "notifycliententerview": return
|
|
241
|
-
case "notifyclientleftview": return
|
|
242
|
-
case "notifyclientmoved": return
|
|
243
|
-
case "notifytextmessage": return
|
|
244
|
-
case "notifyclientpoke": return
|
|
247
|
+
case "notifycliententerview": return re(e, n, r);
|
|
248
|
+
case "notifyclientleftview": return ie(e, t, n);
|
|
249
|
+
case "notifyclientmoved": return ae(e, n);
|
|
250
|
+
case "notifytextmessage": return oe(e, n);
|
|
251
|
+
case "notifyclientpoke": return ue(e);
|
|
245
252
|
case "notifystartupload": return {
|
|
246
253
|
kind: "startUpload",
|
|
247
|
-
info:
|
|
254
|
+
info: se(e)
|
|
248
255
|
};
|
|
249
256
|
case "notifystartdownload": return {
|
|
250
257
|
kind: "startDownload",
|
|
251
|
-
info:
|
|
258
|
+
info: ce(e)
|
|
252
259
|
};
|
|
253
260
|
case "notifystatusfiletransfer": return {
|
|
254
261
|
kind: "fileTransferStatus",
|
|
255
|
-
info:
|
|
262
|
+
info: le(e)
|
|
256
263
|
};
|
|
257
264
|
default: return { kind: "unknown" };
|
|
258
265
|
}
|
|
259
266
|
}
|
|
260
|
-
function
|
|
261
|
-
let r =
|
|
267
|
+
function re(e, t, n) {
|
|
268
|
+
let r = Y(e.params.clid ?? ""), i = J(e.params.cid ?? ""), a = X(e.params.client_type ?? ""), o = e.params.client_servergroups ?? "", s = {
|
|
262
269
|
id: r,
|
|
263
270
|
nickname: e.params.client_nickname ?? "",
|
|
264
271
|
uid: e.params.client_unique_identifier ?? "",
|
|
@@ -271,21 +278,21 @@ function Q(e, t, n) {
|
|
|
271
278
|
info: s
|
|
272
279
|
};
|
|
273
280
|
}
|
|
274
|
-
function
|
|
275
|
-
let r =
|
|
281
|
+
function ie(e, t, n) {
|
|
282
|
+
let r = Y(e.params.clid ?? ""), i = X(e.params.reasonid ?? ""), a = r === t;
|
|
276
283
|
return r !== 0 && n.delete(r), {
|
|
277
284
|
kind: "clientLeave",
|
|
278
285
|
event: {
|
|
279
286
|
id: r,
|
|
280
287
|
reasonID: i,
|
|
281
288
|
reasonMsg: e.params.reasonmsg ?? "",
|
|
282
|
-
targetID:
|
|
289
|
+
targetID: Y(e.params.targetid ?? "")
|
|
283
290
|
},
|
|
284
291
|
isSelf: a
|
|
285
292
|
};
|
|
286
293
|
}
|
|
287
|
-
function
|
|
288
|
-
let n =
|
|
294
|
+
function ae(e, t) {
|
|
295
|
+
let n = Y(e.params.clid ?? ""), r = J(e.params.ctid ?? "");
|
|
289
296
|
if (n !== 0) {
|
|
290
297
|
let e = t.get(n);
|
|
291
298
|
e && t.set(n, {
|
|
@@ -298,20 +305,20 @@ function re(e, t) {
|
|
|
298
305
|
event: {
|
|
299
306
|
id: n,
|
|
300
307
|
targetChannelID: r,
|
|
301
|
-
reasonID:
|
|
302
|
-
invokerID:
|
|
308
|
+
reasonID: X(e.params.reasonid ?? ""),
|
|
309
|
+
invokerID: Y(e.params.invokerid ?? ""),
|
|
303
310
|
invokerName: e.params.invokername ?? "",
|
|
304
311
|
invokerUID: e.params.invokeruid ?? ""
|
|
305
312
|
}
|
|
306
313
|
};
|
|
307
314
|
}
|
|
308
|
-
function
|
|
309
|
-
let n =
|
|
315
|
+
function oe(e, t) {
|
|
316
|
+
let n = Y(e.params.invokerid ?? ""), r = t.get(n);
|
|
310
317
|
return {
|
|
311
318
|
kind: "textMessage",
|
|
312
319
|
message: {
|
|
313
|
-
targetMode:
|
|
314
|
-
targetID:
|
|
320
|
+
targetMode: X(e.params.targetmode ?? ""),
|
|
321
|
+
targetID: J(e.params.target ?? ""),
|
|
315
322
|
invokerID: n,
|
|
316
323
|
invokerName: e.params.invokername ?? "",
|
|
317
324
|
invokerUID: e.params.invokeruid ?? r?.uid ?? "",
|
|
@@ -320,36 +327,36 @@ function ie(e, t) {
|
|
|
320
327
|
}
|
|
321
328
|
};
|
|
322
329
|
}
|
|
323
|
-
function
|
|
330
|
+
function se(e) {
|
|
324
331
|
return {
|
|
325
|
-
clientFileTransferID:
|
|
326
|
-
serverFileTransferID:
|
|
332
|
+
clientFileTransferID: Y(e.params.clientftfid ?? ""),
|
|
333
|
+
serverFileTransferID: Y(e.params.serverftfid ?? ""),
|
|
327
334
|
fileTransferKey: e.params.ftkey ?? "",
|
|
328
|
-
port:
|
|
329
|
-
seekPosition:
|
|
335
|
+
port: Y(e.params.port ?? ""),
|
|
336
|
+
seekPosition: J(e.params.seekpos ?? "")
|
|
330
337
|
};
|
|
331
338
|
}
|
|
332
|
-
function
|
|
339
|
+
function ce(e) {
|
|
333
340
|
return {
|
|
334
|
-
clientFileTransferID:
|
|
335
|
-
serverFileTransferID:
|
|
341
|
+
clientFileTransferID: Y(e.params.clientftfid ?? ""),
|
|
342
|
+
serverFileTransferID: Y(e.params.serverftfid ?? ""),
|
|
336
343
|
fileTransferKey: e.params.ftkey ?? "",
|
|
337
|
-
port:
|
|
338
|
-
size:
|
|
344
|
+
port: Y(e.params.port ?? ""),
|
|
345
|
+
size: J(e.params.size ?? "")
|
|
339
346
|
};
|
|
340
347
|
}
|
|
341
|
-
function
|
|
348
|
+
function le(e) {
|
|
342
349
|
return {
|
|
343
|
-
clientFileTransferID:
|
|
344
|
-
status:
|
|
350
|
+
clientFileTransferID: Y(e.params.clientftfid ?? ""),
|
|
351
|
+
status: X(e.params.status ?? ""),
|
|
345
352
|
message: e.params.msg ?? ""
|
|
346
353
|
};
|
|
347
354
|
}
|
|
348
|
-
function
|
|
355
|
+
function ue(e) {
|
|
349
356
|
return {
|
|
350
357
|
kind: "poked",
|
|
351
358
|
event: {
|
|
352
|
-
invokerID:
|
|
359
|
+
invokerID: Y(e.params.invokerid ?? ""),
|
|
353
360
|
invokerName: S(e.params.invokername ?? ""),
|
|
354
361
|
invokerUID: e.params.invokeruid ?? "",
|
|
355
362
|
message: S(e.params.msg ?? "")
|
|
@@ -358,7 +365,7 @@ function se(e) {
|
|
|
358
365
|
}
|
|
359
366
|
//#endregion
|
|
360
367
|
//#region src/throttle.ts
|
|
361
|
-
var
|
|
368
|
+
var de = class e {
|
|
362
369
|
static TOKEN_RATE = 4;
|
|
363
370
|
static TOKEN_MAX = 8;
|
|
364
371
|
#e = 5;
|
|
@@ -380,7 +387,17 @@ var ce = class e {
|
|
|
380
387
|
});
|
|
381
388
|
}
|
|
382
389
|
}
|
|
383
|
-
}
|
|
390
|
+
};
|
|
391
|
+
//#endregion
|
|
392
|
+
//#region src/client.ts
|
|
393
|
+
function fe(e) {
|
|
394
|
+
return {
|
|
395
|
+
serverPassword: e.serverPassword ?? "",
|
|
396
|
+
defaultChannel: e.defaultChannel ?? "",
|
|
397
|
+
defaultChannelPassword: e.defaultChannelPassword ?? ""
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
var pe = class {
|
|
384
401
|
crypt;
|
|
385
402
|
handler;
|
|
386
403
|
logger;
|
|
@@ -389,12 +406,12 @@ var ce = class e {
|
|
|
389
406
|
#e;
|
|
390
407
|
#t;
|
|
391
408
|
#n;
|
|
392
|
-
#r
|
|
393
|
-
#i =
|
|
394
|
-
#a = new
|
|
395
|
-
#o = new
|
|
396
|
-
#s =
|
|
397
|
-
#c =
|
|
409
|
+
#r;
|
|
410
|
+
#i = n.Disconnected;
|
|
411
|
+
#a = new de();
|
|
412
|
+
#o = new k();
|
|
413
|
+
#s = new M();
|
|
414
|
+
#c = /* @__PURE__ */ new Map();
|
|
398
415
|
#l = [];
|
|
399
416
|
#u = [];
|
|
400
417
|
#d = [];
|
|
@@ -406,108 +423,112 @@ var ce = class e {
|
|
|
406
423
|
#_ = [];
|
|
407
424
|
#v = [];
|
|
408
425
|
#y = [];
|
|
409
|
-
#b;
|
|
426
|
+
#b = [];
|
|
410
427
|
#x;
|
|
428
|
+
#S;
|
|
411
429
|
constructor(t, n, r, i = {}) {
|
|
412
|
-
this.#e = t, this.#t = n, this.nickname = r, this.logger = i.logger ?? e, this.#n = i.resolver ?? new y(this.logger), this.crypt = new v(t), this.handler = new x(this.crypt, this.logger), this.handler.onPacket = (e) => this.#
|
|
430
|
+
this.#e = t, this.#t = n, this.nickname = r, this.logger = i.logger ?? e, this.#n = i.resolver ?? new y(this.logger), this.#r = fe(i), this.crypt = new v(t), this.handler = new x(this.crypt, this.logger), this.handler.onPacket = (e) => this.#T(e), this.handler.onClosed = (e) => this.#P(e), i.commandMiddleware && this.#y.push(...i.commandMiddleware), i.eventMiddleware && this.#b.push(...i.eventMiddleware), this.#x = this.#F(), this.#S = this.#I();
|
|
413
431
|
}
|
|
414
432
|
get status() {
|
|
433
|
+
return this.#i;
|
|
434
|
+
}
|
|
435
|
+
getClientInitOptions() {
|
|
415
436
|
return this.#r;
|
|
416
437
|
}
|
|
417
438
|
async connect() {
|
|
418
|
-
if (this.#
|
|
419
|
-
this.#
|
|
420
|
-
let e = await this.#
|
|
439
|
+
if (this.#i !== n.Disconnected) throw new l();
|
|
440
|
+
this.#C(), this.#i = n.Connecting;
|
|
441
|
+
let e = await this.#w();
|
|
421
442
|
this.logger.info("connecting to server", { address: e }), await this.handler.connect(e);
|
|
422
443
|
}
|
|
423
444
|
async disconnect() {
|
|
424
|
-
if (this.#
|
|
425
|
-
let e = this.#
|
|
426
|
-
if (this.#
|
|
445
|
+
if (this.#i === n.Disconnected) return;
|
|
446
|
+
let e = this.#i === n.Connected;
|
|
447
|
+
if (this.#i = n.Disconnected, this.logger.info("disconnecting from server"), e) try {
|
|
427
448
|
await this.execCommand("clientdisconnect reasonmsg=Shutdown", 1e3);
|
|
428
449
|
} catch {}
|
|
429
450
|
this.handler.close();
|
|
430
|
-
let t = this.#
|
|
451
|
+
let t = this.#_.slice();
|
|
431
452
|
for (let e of t) setImmediate(() => e(void 0));
|
|
432
453
|
}
|
|
433
454
|
waitConnected(e) {
|
|
434
|
-
return this.#
|
|
435
|
-
this.#
|
|
455
|
+
return this.#i === n.Connected ? Promise.resolve() : new Promise((t, n) => {
|
|
456
|
+
this.#l.push(t), e && e.addEventListener("abort", () => n(e.reason), { once: !0 });
|
|
436
457
|
});
|
|
437
458
|
}
|
|
438
459
|
async sendCommandNoWait(e) {
|
|
439
|
-
await this.#
|
|
460
|
+
await this.#a.wait(), await this.#x(e);
|
|
440
461
|
}
|
|
441
462
|
async execCommand(e, t = 1e4) {
|
|
442
463
|
await this.execCommandWithResponse(e, t);
|
|
443
464
|
}
|
|
444
465
|
async execCommandWithResponse(e, t = 1e4) {
|
|
445
|
-
let [n, r] = this.#
|
|
466
|
+
let [n, r] = this.#o.register(), i = j(e, n);
|
|
446
467
|
try {
|
|
447
|
-
await this.#
|
|
468
|
+
await this.#a.wait(), await this.#x(i);
|
|
448
469
|
} catch (e) {
|
|
449
|
-
throw this.#
|
|
470
|
+
throw this.#o.unregister(n), e;
|
|
450
471
|
}
|
|
451
472
|
let a = await Promise.race([r, new Promise((n, r) => setTimeout(() => r(new c(e)), t))]);
|
|
452
|
-
if (this.#
|
|
473
|
+
if (this.#o.unregister(n), a.err) throw a.err;
|
|
453
474
|
return a.data;
|
|
454
475
|
}
|
|
455
476
|
on(e, t) {
|
|
456
477
|
switch (e) {
|
|
457
478
|
case "textMessage":
|
|
458
|
-
this.#
|
|
479
|
+
this.#u.push(t);
|
|
459
480
|
break;
|
|
460
481
|
case "clientEnter":
|
|
461
|
-
this.#
|
|
482
|
+
this.#d.push(t);
|
|
462
483
|
break;
|
|
463
484
|
case "clientLeave":
|
|
464
|
-
this.#
|
|
485
|
+
this.#f.push(t);
|
|
465
486
|
break;
|
|
466
487
|
case "clientMoved":
|
|
467
|
-
this.#
|
|
488
|
+
this.#p.push(t);
|
|
468
489
|
break;
|
|
469
490
|
case "poked":
|
|
470
|
-
this.#
|
|
491
|
+
this.#m.push(t);
|
|
471
492
|
break;
|
|
472
493
|
case "voiceData":
|
|
473
|
-
this.#
|
|
494
|
+
this.#h.push(t);
|
|
474
495
|
break;
|
|
475
496
|
case "connected":
|
|
476
|
-
this.#
|
|
497
|
+
this.#g.push(t);
|
|
477
498
|
break;
|
|
478
499
|
case "disconnected":
|
|
479
|
-
this.#
|
|
500
|
+
this.#_.push(t);
|
|
480
501
|
break;
|
|
481
502
|
case "kicked":
|
|
482
|
-
this.#
|
|
503
|
+
this.#v.push(t);
|
|
483
504
|
break;
|
|
484
505
|
}
|
|
485
506
|
return this;
|
|
486
507
|
}
|
|
487
508
|
useCommandMiddleware(...e) {
|
|
488
|
-
return this.#
|
|
509
|
+
return this.#y.push(...e), this.#x = this.#F(), this;
|
|
489
510
|
}
|
|
490
511
|
useEventMiddleware(...e) {
|
|
491
|
-
return this.#
|
|
512
|
+
return this.#b.push(...e), this.#S = this.#I(), this;
|
|
492
513
|
}
|
|
493
514
|
clientID() {
|
|
494
515
|
return this.clid;
|
|
495
516
|
}
|
|
496
517
|
channelID() {
|
|
497
|
-
return this.#
|
|
518
|
+
return this.#c.get(this.clid)?.channelID ?? 0n;
|
|
498
519
|
}
|
|
499
520
|
sendVoice(e, t) {
|
|
500
521
|
this.handler.sendVoicePacket(e, t);
|
|
501
522
|
}
|
|
502
523
|
async fileTransferInitUpload(e, t, n, r, i = !1) {
|
|
503
|
-
let [a, s] = this.#
|
|
524
|
+
let [a, s] = this.#s.register(), c = I(e, t, n, r, a, i);
|
|
504
525
|
try {
|
|
505
526
|
await this.execCommand(c, 1e4);
|
|
506
527
|
} catch (e) {
|
|
507
|
-
throw this.#
|
|
528
|
+
throw this.#s.unregister(a), e;
|
|
508
529
|
}
|
|
509
530
|
let l = await Promise.race([s, new Promise((e, t) => setTimeout(() => t(new g()), 1e4))]);
|
|
510
|
-
if (this.#
|
|
531
|
+
if (this.#s.unregister(a), "size" in l) throw new o("unexpected download response");
|
|
511
532
|
if ("status" in l) {
|
|
512
533
|
let e = l;
|
|
513
534
|
throw new o(`${e.message} (status=${e.status})`);
|
|
@@ -515,14 +536,14 @@ var ce = class e {
|
|
|
515
536
|
return l;
|
|
516
537
|
}
|
|
517
538
|
async fileTransferInitDownload(e, t, n) {
|
|
518
|
-
let [r, i] = this.#
|
|
539
|
+
let [r, i] = this.#s.register(), a = L(e, t, n, r);
|
|
519
540
|
try {
|
|
520
541
|
await this.execCommand(a, 1e4);
|
|
521
542
|
} catch (e) {
|
|
522
|
-
throw this.#
|
|
543
|
+
throw this.#s.unregister(r), e;
|
|
523
544
|
}
|
|
524
545
|
let s = await Promise.race([i, new Promise((e, t) => setTimeout(() => t(new g()), 1e4))]);
|
|
525
|
-
if (this.#
|
|
546
|
+
if (this.#s.unregister(r), "seekPosition" in s) throw new o("unexpected upload response");
|
|
526
547
|
if ("status" in s) {
|
|
527
548
|
let e = s;
|
|
528
549
|
throw new o(`${e.message} (status=${e.status})`);
|
|
@@ -530,22 +551,22 @@ var ce = class e {
|
|
|
530
551
|
return s;
|
|
531
552
|
}
|
|
532
553
|
uploadFileData(e, t, n) {
|
|
533
|
-
return
|
|
554
|
+
return P(e, t, n);
|
|
534
555
|
}
|
|
535
556
|
downloadFileData(e, t, n) {
|
|
536
|
-
return
|
|
557
|
+
return F(e, t, n);
|
|
537
558
|
}
|
|
538
559
|
_markConnected() {
|
|
539
|
-
this.#
|
|
540
|
-
for (let e of this.#
|
|
541
|
-
this.#
|
|
542
|
-
let e = this.#
|
|
560
|
+
this.#i = n.Connected;
|
|
561
|
+
for (let e of this.#l) e();
|
|
562
|
+
this.#l = [];
|
|
563
|
+
let e = this.#g.slice();
|
|
543
564
|
for (let t of e) setImmediate(() => t());
|
|
544
565
|
}
|
|
545
|
-
#
|
|
546
|
-
this.handler.close(), this.crypt = new v(this.#e), this.handler = new x(this.crypt, this.logger), this.handler.onPacket = (e) => this.#
|
|
566
|
+
#C() {
|
|
567
|
+
this.handler.close(), this.crypt = new v(this.#e), this.handler = new x(this.crypt, this.logger), this.handler.onPacket = (e) => this.#T(e), this.handler.onClosed = (e) => this.#P(e), this.#o.reset(), this.#s.reset(), this.#c.clear(), this.clid = 0, this.#x = this.#F();
|
|
547
568
|
}
|
|
548
|
-
async #
|
|
569
|
+
async #w() {
|
|
549
570
|
let e = this.#t.includes(":") ? this.#t : `${this.#t}:9987`;
|
|
550
571
|
try {
|
|
551
572
|
return (await this.#n.resolve(this.#t))[0]?.addr ?? e;
|
|
@@ -553,24 +574,24 @@ var ce = class e {
|
|
|
553
574
|
return e;
|
|
554
575
|
}
|
|
555
576
|
}
|
|
556
|
-
#w(e) {
|
|
557
|
-
this.#T(e);
|
|
558
|
-
}
|
|
559
577
|
#T(e) {
|
|
578
|
+
this.#E(e);
|
|
579
|
+
}
|
|
580
|
+
#E(e) {
|
|
560
581
|
let t = e.typeFlagged & 15;
|
|
561
582
|
if (t === 8) {
|
|
562
|
-
let t =
|
|
583
|
+
let t = te(this.crypt, e.data);
|
|
563
584
|
t && this.handler.sendPacket(b.Init1, t, 0);
|
|
564
585
|
return;
|
|
565
586
|
}
|
|
566
587
|
if ((t === 0 || t === 1) && e.data.length > 5) {
|
|
567
|
-
this.#
|
|
588
|
+
this.#D(e.data);
|
|
568
589
|
return;
|
|
569
590
|
}
|
|
570
|
-
(t === 2 || t === 3) && e.data.length > 0 && this.#
|
|
591
|
+
(t === 2 || t === 3) && e.data.length > 0 && this.#O(Buffer.from(e.data).toString("utf8"));
|
|
571
592
|
}
|
|
572
|
-
#
|
|
573
|
-
if (this.#
|
|
593
|
+
#D(e) {
|
|
594
|
+
if (this.#h.length === 0) return;
|
|
574
595
|
let t = new DataView(e.buffer, e.byteOffset, e.byteLength).getUint16(2, !1);
|
|
575
596
|
if (t === this.clid) return;
|
|
576
597
|
let n = {
|
|
@@ -578,36 +599,36 @@ var ce = class e {
|
|
|
578
599
|
codec: e[4],
|
|
579
600
|
data: e.subarray(5)
|
|
580
601
|
};
|
|
581
|
-
for (let e of this.#
|
|
602
|
+
for (let e of this.#h) setImmediate(() => e(n));
|
|
582
603
|
}
|
|
583
|
-
#
|
|
604
|
+
#O(e) {
|
|
584
605
|
if (!e) return;
|
|
585
606
|
let t = e.split(/[\n\0]/);
|
|
586
607
|
for (let e of t) {
|
|
587
608
|
let t = e.replace(/\r$/, "");
|
|
588
|
-
if (t) for (let e of
|
|
609
|
+
if (t) for (let e of Q(t)) this.#k(e);
|
|
589
610
|
}
|
|
590
611
|
}
|
|
591
|
-
#
|
|
592
|
-
let t =
|
|
612
|
+
#k(e) {
|
|
613
|
+
let t = E(e);
|
|
593
614
|
if (!(!t || !t.name)) {
|
|
594
615
|
if (t.name.startsWith("notify")) {
|
|
595
|
-
let e =
|
|
596
|
-
this.#
|
|
616
|
+
let e = ne(t, this.clid, this.#c, this.nickname);
|
|
617
|
+
this.#j(e, t.params);
|
|
597
618
|
return;
|
|
598
619
|
}
|
|
599
620
|
switch (t.name) {
|
|
600
621
|
case "clientinitiv":
|
|
601
|
-
|
|
622
|
+
B(this, t.params);
|
|
602
623
|
break;
|
|
603
624
|
case "initivexpand2":
|
|
604
|
-
|
|
625
|
+
V(this, t.params);
|
|
605
626
|
break;
|
|
606
627
|
case "initserver":
|
|
607
|
-
|
|
628
|
+
H(this, t.params);
|
|
608
629
|
break;
|
|
609
630
|
case "error":
|
|
610
|
-
this.#
|
|
631
|
+
this.#A(t.params);
|
|
611
632
|
break;
|
|
612
633
|
default: {
|
|
613
634
|
let e = t.params;
|
|
@@ -618,91 +639,91 @@ var ce = class e {
|
|
|
618
639
|
...t.params
|
|
619
640
|
};
|
|
620
641
|
}
|
|
621
|
-
this.#
|
|
642
|
+
this.#o.buffer(e);
|
|
622
643
|
break;
|
|
623
644
|
}
|
|
624
645
|
}
|
|
625
646
|
}
|
|
626
647
|
}
|
|
627
|
-
#
|
|
628
|
-
let { err: t, rc: n } =
|
|
629
|
-
n === null ? this.#
|
|
648
|
+
#A(e) {
|
|
649
|
+
let { err: t, rc: n } = A(e);
|
|
650
|
+
n === null ? this.#o.discardBuffer() : this.#o.resolve(n, t), (e.id ?? "0") === "3329" && setImmediate(() => this.disconnect().catch(() => {}));
|
|
630
651
|
}
|
|
631
|
-
#
|
|
652
|
+
#j(e, t) {
|
|
632
653
|
switch (e.kind) {
|
|
633
654
|
case "clientEnter": {
|
|
634
655
|
let t = e.info;
|
|
635
|
-
t.id !== 0 &&
|
|
656
|
+
t.id !== 0 && Z(this.nickname, t.nickname) && (this.clid = t.id, this.handler.setClientID(t.id), this.#o.signalWelcomeComplete()), this.#M("clientEnter", t);
|
|
636
657
|
break;
|
|
637
658
|
}
|
|
638
659
|
case "clientLeave":
|
|
639
|
-
if (this.#
|
|
660
|
+
if (this.#M("clientLeave", e.event), e.isSelf && (e.event.reasonID === 4 || e.event.reasonID === 5)) {
|
|
640
661
|
let t = e.event.reasonMsg;
|
|
641
|
-
for (let e of this.#
|
|
662
|
+
for (let e of this.#v) setImmediate(() => e(t));
|
|
642
663
|
}
|
|
643
664
|
break;
|
|
644
665
|
case "clientMoved":
|
|
645
|
-
this.#
|
|
666
|
+
this.#M("clientMoved", e.event);
|
|
646
667
|
break;
|
|
647
668
|
case "textMessage":
|
|
648
|
-
this.#
|
|
669
|
+
this.#M("textMessage", e.message);
|
|
649
670
|
break;
|
|
650
671
|
case "poked":
|
|
651
|
-
this.#
|
|
672
|
+
this.#M("poked", e.event);
|
|
652
673
|
break;
|
|
653
674
|
case "startUpload":
|
|
654
|
-
this.#
|
|
675
|
+
this.#s.notify(e.info.clientFileTransferID, e.info);
|
|
655
676
|
break;
|
|
656
677
|
case "startDownload":
|
|
657
|
-
this.#
|
|
678
|
+
this.#s.notify(e.info.clientFileTransferID, e.info);
|
|
658
679
|
break;
|
|
659
680
|
case "fileTransferStatus":
|
|
660
|
-
this.#
|
|
681
|
+
this.#s.notify(e.info.clientFileTransferID, e.info);
|
|
661
682
|
break;
|
|
662
683
|
}
|
|
663
684
|
}
|
|
664
|
-
#j(e, t) {
|
|
665
|
-
this.#x(t);
|
|
666
|
-
}
|
|
667
685
|
#M(e, t) {
|
|
686
|
+
this.#S(t);
|
|
687
|
+
}
|
|
688
|
+
#N(e, t) {
|
|
668
689
|
switch (e) {
|
|
669
690
|
case "textMessage":
|
|
670
|
-
for (let e of this.#
|
|
691
|
+
for (let e of this.#u) setImmediate(() => e(t));
|
|
671
692
|
break;
|
|
672
693
|
case "clientEnter":
|
|
673
|
-
for (let e of this.#
|
|
694
|
+
for (let e of this.#d) setImmediate(() => e(t));
|
|
674
695
|
break;
|
|
675
696
|
case "clientLeave":
|
|
676
|
-
for (let e of this.#
|
|
697
|
+
for (let e of this.#f) setImmediate(() => e(t));
|
|
677
698
|
break;
|
|
678
699
|
case "clientMoved":
|
|
679
|
-
for (let e of this.#
|
|
700
|
+
for (let e of this.#p) setImmediate(() => e(t));
|
|
680
701
|
break;
|
|
681
702
|
case "poked":
|
|
682
|
-
for (let e of this.#
|
|
703
|
+
for (let e of this.#m) setImmediate(() => e(t));
|
|
683
704
|
break;
|
|
684
705
|
}
|
|
685
706
|
}
|
|
686
|
-
#
|
|
687
|
-
if (this.#
|
|
688
|
-
this.#
|
|
689
|
-
let t = this.#
|
|
707
|
+
#P(e) {
|
|
708
|
+
if (this.#i === n.Disconnected) return;
|
|
709
|
+
this.#i = n.Disconnected;
|
|
710
|
+
let t = this.#_.slice();
|
|
690
711
|
for (let n of t) setImmediate(() => n(e ?? void 0));
|
|
691
712
|
}
|
|
692
|
-
#
|
|
693
|
-
return
|
|
713
|
+
#F() {
|
|
714
|
+
return R(this.#y, async (e) => {
|
|
694
715
|
this.handler.sendPacket(b.Command, Buffer.from(e), 0);
|
|
695
716
|
});
|
|
696
717
|
}
|
|
697
|
-
#
|
|
698
|
-
return
|
|
699
|
-
typeof e == "object" && e && "invokerName" in e && "message" in e && "targetMode" in e ? this.#
|
|
718
|
+
#I() {
|
|
719
|
+
return z(this.#b, (e) => {
|
|
720
|
+
typeof e == "object" && e && "invokerName" in e && "message" in e && "targetMode" in e ? this.#N("textMessage", e) : typeof e == "object" && e && "invokerName" in e && "message" in e && !("targetMode" in e) ? this.#N("poked", e) : typeof e == "object" && e && "id" in e && "uid" in e ? this.#N("clientEnter", e) : typeof e == "object" && e && "id" in e && "reasonID" in e && "targetChannelID" in e ? this.#N("clientMoved", e) : typeof e == "object" && e && "id" in e && "reasonID" in e && this.#N("clientLeave", e);
|
|
700
721
|
});
|
|
701
722
|
}
|
|
702
723
|
};
|
|
703
724
|
//#endregion
|
|
704
725
|
//#region src/api.ts
|
|
705
|
-
async function
|
|
726
|
+
async function $(e, t, n, r) {
|
|
706
727
|
let i = C("sendtextmessage", [
|
|
707
728
|
["targetmode", String(t)],
|
|
708
729
|
["target", String(n)],
|
|
@@ -710,22 +731,22 @@ async function ue(e, t, n, r) {
|
|
|
710
731
|
]);
|
|
711
732
|
await e.sendCommandNoWait(i);
|
|
712
733
|
}
|
|
713
|
-
async function
|
|
734
|
+
async function me(e, t, n, r = "") {
|
|
714
735
|
let i = [["clid", String(t)], ["cid", String(n)]];
|
|
715
736
|
r && i.push(["cpw", r]);
|
|
716
737
|
let a = C("clientmove", i);
|
|
717
738
|
await e.execCommand(a, 1e4);
|
|
718
739
|
}
|
|
719
|
-
async function
|
|
740
|
+
async function he(e, t, n) {
|
|
720
741
|
let r = C("clientpoke", [["clid", String(t)], ["msg", n]]);
|
|
721
742
|
await e.execCommand(r, 1e4);
|
|
722
743
|
}
|
|
723
|
-
async function
|
|
744
|
+
async function ge(e, t) {
|
|
724
745
|
let n = (await e.execCommandWithResponse(`clientinfo clid=${t}`, 5e3))[0];
|
|
725
746
|
if (!n) throw Error(`no data returned for client ${t}`);
|
|
726
747
|
return n;
|
|
727
748
|
}
|
|
728
|
-
async function
|
|
749
|
+
async function _e(e) {
|
|
729
750
|
return (await e.execCommandWithResponse("channellist", 5e3)).map((e) => ({
|
|
730
751
|
id: BigInt(e.cid ?? "0"),
|
|
731
752
|
parentID: BigInt(e.pid ?? "0"),
|
|
@@ -733,7 +754,7 @@ async function me(e) {
|
|
|
733
754
|
description: ""
|
|
734
755
|
}));
|
|
735
756
|
}
|
|
736
|
-
async function
|
|
757
|
+
async function ve(e) {
|
|
737
758
|
return (await e.execCommandWithResponse("clientlist -uid -away -voice -groups", 5e3)).map((e) => {
|
|
738
759
|
let t = e.client_servergroups ?? "";
|
|
739
760
|
return {
|
|
@@ -746,7 +767,7 @@ async function he(e) {
|
|
|
746
767
|
};
|
|
747
768
|
});
|
|
748
769
|
}
|
|
749
|
-
async function
|
|
770
|
+
async function ye(e, t, n) {
|
|
750
771
|
if (n.length === 0) return;
|
|
751
772
|
let r = n.join("|"), i = w("ftdeletefile", {
|
|
752
773
|
cid: String(t),
|
|
@@ -756,6 +777,6 @@ async function ge(e, t, n) {
|
|
|
756
777
|
await e.execCommand(i, 1e4);
|
|
757
778
|
}
|
|
758
779
|
//#endregion
|
|
759
|
-
export { l as AlreadyConnectedError,
|
|
780
|
+
export { l as AlreadyConnectedError, pe as Client, n as ClientStatus, c as CommandTimeoutError, a as CryptoInitError, m as EAXTagMismatchError, _ as FakeSignatureMismatchError, o as FileTransferError, g as FileTransferTimeoutError, u as Identity, i as InvalidIdentityError, r as ServerError, h as TeamspeakError, me as clientMove, e as consoleLogger, N as dialFileTransfer, F as downloadFileData, ye as fileTransferDeleteFile, p as generateIdentity, ge as getClientInfo, s as getUidFromPublicKey, ee as identityFromString, _e as listChannels, ve as listClients, t as noopLogger, he as poke, $ as sendTextMessage, P as uploadFileData };
|
|
760
781
|
|
|
761
782
|
//# sourceMappingURL=index.mjs.map
|