teeworlds 2.5.3 → 2.5.5
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 +4 -3
- package/docs/documentation.md +3 -0
- package/index.js +24 -24
- package/lib/MsgPacker.js +46 -55
- package/lib/MsgUnpacker.js +52 -53
- package/lib/UUIDManager.js +44 -50
- package/lib/client.js +761 -845
- package/lib/client.ts +124 -214
- package/lib/components/game.js +103 -143
- package/lib/components/game.ts +12 -13
- package/lib/components/movement.js +74 -82
- package/lib/components/rcon.js +91 -0
- package/lib/components/rcon.ts +114 -0
- package/lib/components/snapshot.js +143 -258
- package/lib/components/snapshot.ts +68 -100
- package/lib/enums_types/protocol.js +13 -0
- package/lib/enums_types/protocol.ts +145 -0
- package/lib/enums_types/types.d.ts +236 -0
- package/lib/huffman.js +186 -192
- package/lib/snapshot.js +598 -610
- package/lib/snapshot.ts +36 -38
- package/package.json +4 -3
- package/tsconfig.json +1 -1
- package/lib/snapshots.d.ts +0 -233
package/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# Teeworlds Client
|
|
2
2
|
Library to connect a bot to a Teeworlds server.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
# Links
|
|
5
|
+
https://github.com/swarfeya/teeworlds-library-ts/tree/main
|
|
5
6
|
https://www.npmjs.com/package/teeworlds
|
|
6
7
|
|
|
7
8
|
# Documentation
|
|
8
|
-
You can find an documentation to what most components do in the [docs/documentation.md](https://
|
|
9
|
-
You can also find a few examples inside of the [docs/examples](https://
|
|
9
|
+
You can find an documentation to what most components do in the [docs/documentation.md](https://github.com/swarfeya/teeworlds-library-ts/blob/main/docs/documentation.md).
|
|
10
|
+
You can also find a few examples inside of the [docs/examples](https://github.com/swarfeya/teeworlds-library-ts/tree/main/docs/examples) directory.
|
|
10
11
|
|
|
11
12
|
# Projects using this library
|
|
12
13
|
Note: If you have or know any projects running using this library, please contact me so i can add them, or PR them yourself.
|
package/docs/documentation.md
CHANGED
|
@@ -365,4 +365,7 @@ You can find some of the examples in the [docs/examples](docs/examples/) folder.
|
|
|
365
365
|
*Note:* If you have or know any projects running using this library, please contact me so i can add them, or PR them yourself.
|
|
366
366
|
|
|
367
367
|
* A discord which is bridging all discord messages and ingame messages (currently closed source): https://discord.gg/MSYcjYvU6e
|
|
368
|
+
* DDNet / Teeworlds Chat Client, no game, just chatting by kiocode: https://github.com/k-i-o/CChat.TW
|
|
369
|
+
* https://github.com/vitorblue007/DDnet-chatbot
|
|
370
|
+
* https://github.com/Siraxa/DDNetSpectate/tree/master
|
|
368
371
|
|
package/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Client = void 0;
|
|
18
|
-
var client_1 = require("./lib/client");
|
|
19
|
-
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
|
|
20
|
-
__exportStar(require("./lib/MsgPacker"), exports);
|
|
21
|
-
__exportStar(require("./lib/MsgUnpacker"), exports);
|
|
22
|
-
__exportStar(require("./lib/snapshot"), exports);
|
|
23
|
-
__exportStar(require("./lib/huffman"), exports);
|
|
24
|
-
__exportStar(require("./lib/UUIDManager"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Client = void 0;
|
|
18
|
+
var client_1 = require("./lib/client");
|
|
19
|
+
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_1.Client; } });
|
|
20
|
+
__exportStar(require("./lib/MsgPacker"), exports);
|
|
21
|
+
__exportStar(require("./lib/MsgUnpacker"), exports);
|
|
22
|
+
__exportStar(require("./lib/snapshot"), exports);
|
|
23
|
+
__exportStar(require("./lib/huffman"), exports);
|
|
24
|
+
__exportStar(require("./lib/UUIDManager"), exports);
|
package/lib/MsgPacker.js
CHANGED
|
@@ -1,55 +1,46 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MsgPacker = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
this.result = Buffer.from([2 * msg + (sys ? 1 : 0)]);
|
|
7
|
-
this.sys = sys;
|
|
8
|
-
this.flag = flag;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
this.result = Buffer.concat([this.result, Buffer.from(str), Buffer.from([0x00])]);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
this.result = Buffer.concat([this.result, buffer]);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
var result = [];
|
|
18
|
-
var pDst = (i >> 25) & 0x40;
|
|
19
|
-
var i = i ^ (i >> 31);
|
|
20
|
-
pDst |= i & 0x3f;
|
|
21
|
-
i >>= 6;
|
|
22
|
-
if (i) {
|
|
23
|
-
pDst |= 0x80;
|
|
24
|
-
result.push(pDst);
|
|
25
|
-
while (true) {
|
|
26
|
-
pDst++;
|
|
27
|
-
pDst = i & (0x7f);
|
|
28
|
-
i >>= 7;
|
|
29
|
-
pDst |= (Number(i != 0)) << 7;
|
|
30
|
-
result.push(pDst);
|
|
31
|
-
if (!i)
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else
|
|
36
|
-
result.push(pDst);
|
|
37
|
-
this.result = Buffer.concat([this.result, Buffer.from(result)]);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
get: function () {
|
|
48
|
-
return this.result;
|
|
49
|
-
},
|
|
50
|
-
enumerable: false,
|
|
51
|
-
configurable: true
|
|
52
|
-
});
|
|
53
|
-
return MsgPacker;
|
|
54
|
-
}());
|
|
55
|
-
exports.MsgPacker = MsgPacker;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MsgPacker = void 0;
|
|
4
|
+
class MsgPacker {
|
|
5
|
+
constructor(msg, sys, flag) {
|
|
6
|
+
this.result = Buffer.from([2 * msg + (sys ? 1 : 0)]);
|
|
7
|
+
this.sys = sys;
|
|
8
|
+
this.flag = flag;
|
|
9
|
+
}
|
|
10
|
+
AddString(str) {
|
|
11
|
+
this.result = Buffer.concat([this.result, Buffer.from(str), Buffer.from([0x00])]);
|
|
12
|
+
}
|
|
13
|
+
AddBuffer(buffer) {
|
|
14
|
+
this.result = Buffer.concat([this.result, buffer]);
|
|
15
|
+
}
|
|
16
|
+
AddInt(i) {
|
|
17
|
+
var result = [];
|
|
18
|
+
var pDst = (i >> 25) & 0x40;
|
|
19
|
+
var i = i ^ (i >> 31);
|
|
20
|
+
pDst |= i & 0x3f;
|
|
21
|
+
i >>= 6;
|
|
22
|
+
if (i) {
|
|
23
|
+
pDst |= 0x80;
|
|
24
|
+
result.push(pDst);
|
|
25
|
+
while (true) {
|
|
26
|
+
pDst++;
|
|
27
|
+
pDst = i & (0x7f);
|
|
28
|
+
i >>= 7;
|
|
29
|
+
pDst |= (Number(i != 0)) << 7;
|
|
30
|
+
result.push(pDst);
|
|
31
|
+
if (!i)
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else
|
|
36
|
+
result.push(pDst);
|
|
37
|
+
this.result = Buffer.concat([this.result, Buffer.from(result)]);
|
|
38
|
+
}
|
|
39
|
+
get size() {
|
|
40
|
+
return this.result.byteLength;
|
|
41
|
+
}
|
|
42
|
+
get buffer() {
|
|
43
|
+
return this.result;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.MsgPacker = MsgPacker;
|
package/lib/MsgUnpacker.js
CHANGED
|
@@ -1,53 +1,52 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MsgUnpacker =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
srcIndex
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.remaining = pSrc;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// let unpacked;
|
|
31
|
-
// if (!_unpacked) {
|
|
32
|
-
|
|
33
|
-
this.remaining = unpacked.remaining;
|
|
34
|
-
// } else {
|
|
35
|
-
// unpacked = {result: this.remaining[0]};
|
|
36
|
-
// this.remaining = this.remaining.slice(1);
|
|
37
|
-
// }
|
|
38
|
-
return unpacked.result;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
this.remaining = unpacked.remaining;
|
|
43
|
-
return unpacked.result;
|
|
44
|
-
}
|
|
45
|
-
/** @param size - size in bytes */
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this.remaining = this.remaining.slice(size);
|
|
49
|
-
return unpacked;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
exports.MsgUnpacker = MsgUnpacker;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MsgUnpacker = void 0;
|
|
4
|
+
exports.unpackInt = unpackInt;
|
|
5
|
+
exports.unpackString = unpackString;
|
|
6
|
+
const decoder = new TextDecoder('utf-8');
|
|
7
|
+
function unpackInt(pSrc) {
|
|
8
|
+
var srcIndex = 0;
|
|
9
|
+
const sign = ((pSrc[srcIndex] >> 6) & 1);
|
|
10
|
+
var result = (pSrc[srcIndex] & 63);
|
|
11
|
+
while (srcIndex <= 4) {
|
|
12
|
+
if ((pSrc[srcIndex] & 128) === 0)
|
|
13
|
+
break;
|
|
14
|
+
srcIndex++;
|
|
15
|
+
result |= ((pSrc[srcIndex] & 127)) << (6 + 7 * (srcIndex - 1));
|
|
16
|
+
}
|
|
17
|
+
result ^= -sign;
|
|
18
|
+
return { result, remaining: pSrc.slice(srcIndex + 1) };
|
|
19
|
+
}
|
|
20
|
+
function unpackString(pSrc) {
|
|
21
|
+
var result = pSrc.slice(0, pSrc.indexOf(0));
|
|
22
|
+
pSrc = pSrc.slice(pSrc.indexOf(0) + 1, pSrc.length);
|
|
23
|
+
return { result: decoder.decode(new Uint8Array(result)), remaining: pSrc };
|
|
24
|
+
}
|
|
25
|
+
class MsgUnpacker {
|
|
26
|
+
constructor(pSrc) {
|
|
27
|
+
this.remaining = pSrc;
|
|
28
|
+
}
|
|
29
|
+
unpackInt() {
|
|
30
|
+
// let unpacked;
|
|
31
|
+
// if (!_unpacked) {
|
|
32
|
+
let unpacked = unpackInt(this.remaining);
|
|
33
|
+
this.remaining = unpacked.remaining;
|
|
34
|
+
// } else {
|
|
35
|
+
// unpacked = {result: this.remaining[0]};
|
|
36
|
+
// this.remaining = this.remaining.slice(1);
|
|
37
|
+
// }
|
|
38
|
+
return unpacked.result;
|
|
39
|
+
}
|
|
40
|
+
unpackString() {
|
|
41
|
+
let unpacked = unpackString(this.remaining);
|
|
42
|
+
this.remaining = unpacked.remaining;
|
|
43
|
+
return unpacked.result;
|
|
44
|
+
}
|
|
45
|
+
/** @param size - size in bytes */
|
|
46
|
+
unpackRaw(size) {
|
|
47
|
+
let unpacked = this.remaining.slice(0, size);
|
|
48
|
+
this.remaining = this.remaining.slice(size);
|
|
49
|
+
return unpacked;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.MsgUnpacker = MsgUnpacker;
|
package/lib/UUIDManager.js
CHANGED
|
@@ -1,50 +1,44 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UUIDManager = exports.createTwMD5Hash = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
.update(Buffer.from([0xe0, 0x5d, 0xda, 0xaa, 0xc4, 0xe6, 0x4c, 0xfb, 0xb6, 0x42, 0x5d, 0x48, 0xe8, 0x0c, 0x00, 0x29]))
|
|
8
|
-
.update(name)
|
|
9
|
-
.digest();
|
|
10
|
-
hash[6] &= 0x0f;
|
|
11
|
-
hash[6] |= 0x30;
|
|
12
|
-
hash[8] &= 0x3f;
|
|
13
|
-
hash[8] |= 0x80;
|
|
14
|
-
return hash;
|
|
15
|
-
};
|
|
16
|
-
exports.createTwMD5Hash = createTwMD5Hash;
|
|
17
|
-
// [{name: string, hash: Buffer}, ..]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
type_id: type_id
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
return UUIDManager;
|
|
49
|
-
}());
|
|
50
|
-
exports.UUIDManager = UUIDManager;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UUIDManager = exports.createTwMD5Hash = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const createTwMD5Hash = (name) => {
|
|
6
|
+
let hash = (0, crypto_1.createHash)("md5")
|
|
7
|
+
.update(Buffer.from([0xe0, 0x5d, 0xda, 0xaa, 0xc4, 0xe6, 0x4c, 0xfb, 0xb6, 0x42, 0x5d, 0x48, 0xe8, 0x0c, 0x00, 0x29]))
|
|
8
|
+
.update(name)
|
|
9
|
+
.digest();
|
|
10
|
+
hash[6] &= 0x0f;
|
|
11
|
+
hash[6] |= 0x30;
|
|
12
|
+
hash[8] &= 0x3f;
|
|
13
|
+
hash[8] |= 0x80;
|
|
14
|
+
return hash;
|
|
15
|
+
};
|
|
16
|
+
exports.createTwMD5Hash = createTwMD5Hash;
|
|
17
|
+
// [{name: string, hash: Buffer}, ..]
|
|
18
|
+
class UUIDManager {
|
|
19
|
+
constructor(pOffset = 65536, pSnapshot = false) {
|
|
20
|
+
this.uuids = [];
|
|
21
|
+
this.offset = pOffset;
|
|
22
|
+
this.snapshot = pSnapshot;
|
|
23
|
+
}
|
|
24
|
+
LookupUUID(hash) {
|
|
25
|
+
return this.uuids.find(a => a.hash.compare(hash) == 0);
|
|
26
|
+
}
|
|
27
|
+
LookupName(name) {
|
|
28
|
+
return this.uuids.find(a => a.name === name);
|
|
29
|
+
}
|
|
30
|
+
LookupType(ID) {
|
|
31
|
+
if (!this.snapshot) {
|
|
32
|
+
return this.uuids[ID - this.offset];
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return this.uuids.find(a => a.type_id == ID);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
RegisterName(name, type_id = this.offset - this.uuids.length) {
|
|
39
|
+
this.uuids.push({
|
|
40
|
+
name, hash: (0, exports.createTwMD5Hash)(name), type_id
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.UUIDManager = UUIDManager;
|