teeworlds 2.5.5 → 2.5.6
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/{index.ts → index.d.ts} +6 -6
- package/index.js +1 -0
- package/index.js.map +1 -0
- package/lib/MsgPacker.d.ts +11 -0
- package/lib/MsgPacker.js +1 -0
- package/lib/MsgPacker.js.map +1 -0
- package/lib/MsgUnpacker.d.ts +16 -0
- package/lib/MsgUnpacker.js +1 -0
- package/lib/MsgUnpacker.js.map +1 -0
- package/lib/UUIDManager.d.ts +27 -0
- package/lib/UUIDManager.js +1 -0
- package/lib/UUIDManager.js.map +1 -0
- package/lib/client.d.ts +135 -0
- package/lib/client.js +5 -4
- package/lib/client.js.map +1 -0
- package/lib/components/game.d.ts +32 -0
- package/lib/components/game.js +1 -0
- package/lib/components/game.js.map +1 -0
- package/lib/components/movement.d.ts +34 -0
- package/lib/components/movement.js +1 -0
- package/lib/components/movement.js.map +1 -0
- package/lib/components/rcon.d.ts +33 -0
- package/lib/components/rcon.js +1 -0
- package/lib/components/rcon.js.map +1 -0
- package/lib/components/snapshot.d.ts +59 -0
- package/lib/components/snapshot.js +1 -0
- package/lib/components/snapshot.js.map +1 -0
- package/lib/enums_types/protocol.d.ts +120 -0
- package/lib/enums_types/protocol.js +1 -0
- package/lib/enums_types/protocol.js.map +1 -0
- package/lib/huffman.d.ts +24 -0
- package/lib/huffman.js +1 -0
- package/lib/huffman.js.map +1 -0
- package/lib/snapshot.d.ts +49 -0
- package/lib/snapshot.js +1 -0
- package/lib/snapshot.js.map +1 -0
- package/package.json +21 -25
- package/docs/documentation.md +0 -371
- package/docs/examples/chat_bot.js +0 -25
- package/docs/examples/kill_on_freeze.js +0 -20
- package/lib/MsgPacker.ts +0 -45
- package/lib/MsgUnpacker.ts +0 -58
- package/lib/UUIDManager.ts +0 -45
- package/lib/client.ts +0 -947
- package/lib/components/game.ts +0 -133
- package/lib/components/movement.ts +0 -88
- package/lib/components/rcon.ts +0 -114
- package/lib/components/snapshot.ts +0 -187
- package/lib/enums_types/protocol.ts +0 -145
- package/lib/enums_types/types.d.ts +0 -236
- package/lib/huffman.ts +0 -226
- package/lib/snapshot.ts +0 -632
- package/tsconfig.json +0 -69
package/docs/documentation.md
DELETED
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
*version used for this documentation is 2.4.7. Versions below / above that possibly have other syntax.*
|
|
2
|
-
<!-- <details> <summary>Events</summary> -->
|
|
3
|
-
|
|
4
|
-
# Events
|
|
5
|
-
* [connected](#event-connected)
|
|
6
|
-
* [disconnect](#event-disconnect)
|
|
7
|
-
* [emote](#event-emote)
|
|
8
|
-
* [message](#event-chat-message)
|
|
9
|
-
* [broadcast](#event-broadcast-message)
|
|
10
|
-
* [motd](#event-motd-motto-of-the-day)
|
|
11
|
-
* [kill](#event-kill)
|
|
12
|
-
* [map_details](#ddnet-event-map-details)
|
|
13
|
-
* [capabilities](#ddnet-event-capabilities)
|
|
14
|
-
* [snapshot](#event-snapshot)
|
|
15
|
-
|
|
16
|
-
## Snapshot events
|
|
17
|
-
These events are accessable using client.SnapUnpacker.on("event", ..)
|
|
18
|
-
###### TODO: make this more clearer with examples
|
|
19
|
-
* common
|
|
20
|
-
* probably only exists to show for the type (x, y).
|
|
21
|
-
* explosion
|
|
22
|
-
* grenade explosion event
|
|
23
|
-
* spawn
|
|
24
|
-
* player spawn event
|
|
25
|
-
* hammerhit
|
|
26
|
-
* death
|
|
27
|
-
* player death event
|
|
28
|
-
* sound_global
|
|
29
|
-
* sound_world
|
|
30
|
-
* damage_indicator
|
|
31
|
-
|
|
32
|
-
### Event: Connected
|
|
33
|
-
This event will be fired as soon as the client is connected (specifically when it got 2 snapshot packets).
|
|
34
|
-
```
|
|
35
|
-
client.on("connect", () => console.log("Client connected!"));
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
### Event: Disconnect
|
|
39
|
-
This event will be fired as soon as the client is kicked. It will also return the reason.
|
|
40
|
-
```
|
|
41
|
-
client.on("disconnect", (reason: string) => console.log("Client disconnected. reason: " + reason));
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### Event: Emote
|
|
45
|
-
This event will be fired as soon as anybody on the server sends an emote (or possibly, depending on the server's implementation, only from players near you).
|
|
46
|
-
```
|
|
47
|
-
client.on("emote", (emote) => console.log(emote));
|
|
48
|
-
/*{
|
|
49
|
-
client_id: 0,
|
|
50
|
-
emoticon: 7,
|
|
51
|
-
author: { ClientInfo: { .. }, PlayerInfo: { .. } }
|
|
52
|
-
}*/
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### Event: Chat message
|
|
56
|
-
This event will be fired as soon as anybody on the server sends an chat message.
|
|
57
|
-
```
|
|
58
|
-
client.on("message", (message) => console.log(message));
|
|
59
|
-
/*{
|
|
60
|
-
team: 0,
|
|
61
|
-
client_id: 0,
|
|
62
|
-
message: 'Hello World!',
|
|
63
|
-
author: { ClientInfo: { .. }, PlayerInfo: { .. } }
|
|
64
|
-
}*/
|
|
65
|
-
|
|
66
|
-
// server messages also do not have an author attribute and will always have an client_id of -1.:
|
|
67
|
-
|
|
68
|
-
/*{
|
|
69
|
-
team: 0,
|
|
70
|
-
client_id: -1,
|
|
71
|
-
message: 'please visit DDNet.org or say /info and make sure to read our /rules'
|
|
72
|
-
}*/
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### Event: Broadcast message
|
|
76
|
-
This event will be fired as soon as your client receives an broadcast message.
|
|
77
|
-
```
|
|
78
|
-
client.on("broadcast", (message: string) => console.log(message));
|
|
79
|
-
// (f2 "broadcast Hello World!")
|
|
80
|
-
// Hello World!
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### Event: Motd (Motto of the day)
|
|
84
|
-
This event will be fired as soon as your client receives an motd message. Usually right after your client is connected.
|
|
85
|
-
```
|
|
86
|
-
client.on("broadcast", (message: string) => console.log(message));
|
|
87
|
-
// Testserver with DDraceNetwork Features!\nDon't forget to check server rules by using /rules!
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### Event: Kill
|
|
91
|
-
This event will be fired as soon as anybody on the server dies.
|
|
92
|
-
```
|
|
93
|
-
client.on("kill", (message) => console.log(message));
|
|
94
|
-
/*{
|
|
95
|
-
killer_id: 0,
|
|
96
|
-
victim_id: 0, // killer_id == victim_id, its a suicide
|
|
97
|
-
weapon: -2,
|
|
98
|
-
special_mode: 0,
|
|
99
|
-
victim: { ClientInfo: { .. }, PlayerInfo: { .. } },
|
|
100
|
-
killer: { ClientInfo: { .. }, PlayerInfo: { .. } }
|
|
101
|
-
}
|
|
102
|
-
}*/
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### DDNet Event: Map Details
|
|
106
|
-
This event will be fired when the client joins the server. This event only exists on ddnet-based servers.
|
|
107
|
-
```
|
|
108
|
-
client.on("map_details", (message) => console.log(message));
|
|
109
|
-
/*{
|
|
110
|
-
map_name: 'Firewatch',
|
|
111
|
-
map_sha256: <Buffer b7 17 80 52 1b 38 16 b3 8d 37 6b a8 84 c6 26 ef 48 db 93 7c 57 c1 8b e8 4b f9 7e e0 94 33 d6 f7>,
|
|
112
|
-
map_crc: 1834546968,
|
|
113
|
-
map_url: '' // empty, because official ddnet servers dont send their map url, only some non-ddnet servers (for example |*KoG*| servers) do.
|
|
114
|
-
}*/
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
### DDNet Event: Capabilities
|
|
118
|
-
This event will be fired when the client joins the server. This event only exists on ddnet-based servers.
|
|
119
|
-
```
|
|
120
|
-
client.on("capabilities", (message) => console.log(message));
|
|
121
|
-
/*{
|
|
122
|
-
ChatTimeoutCode: true,
|
|
123
|
-
AnyPlayerFlag: true,
|
|
124
|
-
PingEx: true,
|
|
125
|
-
AllowDummy: true,
|
|
126
|
-
SyncWeaponInput: true
|
|
127
|
-
}*/
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### Event: Snapshot
|
|
131
|
-
This event will be fired whenever the client receives an snapshot packet (which is up to 25 times per second!).
|
|
132
|
-
```
|
|
133
|
-
client.on("snapshot", (items) => console.log(items));
|
|
134
|
-
/* returns a list of all items that are being stored. */
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
<!-- </details> -->
|
|
139
|
-
|
|
140
|
-
# Game functions
|
|
141
|
-
|
|
142
|
-
accessable using client.game
|
|
143
|
-
methods:
|
|
144
|
-
* Say(message: string, team = false)
|
|
145
|
-
- sends the specified `message` in the chat.
|
|
146
|
-
* SetTeam(team: number)
|
|
147
|
-
- sets the client in a specific team (-1 spectator team, 0 team red/normal team, 1 team blue)
|
|
148
|
-
* SpectatorMode(SpectatorID: number)
|
|
149
|
-
- spectate a specific player id, if our client already in spectator mode
|
|
150
|
-
* ChangePlayerInfo(playerInfo: ClientInfo)
|
|
151
|
-
- changes the current player info (name, clan, etc.)
|
|
152
|
-
* Kill()
|
|
153
|
-
- kills the client
|
|
154
|
-
* Emote(emote: number)
|
|
155
|
-
- sends an emote
|
|
156
|
-
* Vote(vote: boolean)
|
|
157
|
-
- votes on an currently running vote
|
|
158
|
-
* CallVoteOption(Value: string, Reason: string)
|
|
159
|
-
- call an option vote (on ddnet servers, for example an map vote)
|
|
160
|
-
* CallVoteKick(PlayerID: string|number, Reason: string)
|
|
161
|
-
- sends kick vote for an specific player id
|
|
162
|
-
* CallVoteSpectate(PlayerID: string|number, Reason: string)
|
|
163
|
-
- sends vote to set an specific player into spectator mode
|
|
164
|
-
* (IsDDNetLegacy() -- unused, probably used to verify the client is running on ddnet?)
|
|
165
|
-
* Ping(): Promise\<number>
|
|
166
|
-
- pings the server and returns the latency in an Promise
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
# Snapshot
|
|
170
|
-
* Snapshots are used to deliver most of the information of players. You can access all objects using `client.SnapshotUnpacker.*`
|
|
171
|
-
* the SnapshotUnpacker is built with two methods per object:
|
|
172
|
-
* getObjX(id: number) - returns the object with the specified id.
|
|
173
|
-
* AllObjX - attribute, which returns all objects of the type in an array.
|
|
174
|
-
|
|
175
|
-
## Player/Character information
|
|
176
|
-
* [ClientInfo](#clientinfo)
|
|
177
|
-
* [PlayerInfo](#playerinfo)
|
|
178
|
-
* [Character](#character)
|
|
179
|
-
* [DDNetCharacter](#ddnetcharacter)
|
|
180
|
-
* [OwnID](#ownid)
|
|
181
|
-
|
|
182
|
-
<details><summary>other snapshot objects</summary>
|
|
183
|
-
|
|
184
|
-
* PlayerInput
|
|
185
|
-
* most servers probably dont use this
|
|
186
|
-
* Projectile
|
|
187
|
-
* Laser
|
|
188
|
-
* Pickup
|
|
189
|
-
* (Weapon Pickups)
|
|
190
|
-
* Flag
|
|
191
|
-
* Red/Blue Flag
|
|
192
|
-
* GameInfo
|
|
193
|
-
* GameData
|
|
194
|
-
* CharacterCore
|
|
195
|
-
* probably only used inside of the Character object and not sent by itself.
|
|
196
|
-
* [Character](#character)
|
|
197
|
-
* [PlayerInfo](#playerinfo)
|
|
198
|
-
* [ClientInfo](#clientinfo)
|
|
199
|
-
* SpectatorInfo
|
|
200
|
-
* MyOwnObject
|
|
201
|
-
* extended type by ddnet used for testing.
|
|
202
|
-
* [DDNetCharacter](#ddnetcharacter)
|
|
203
|
-
* extended type by ddnet
|
|
204
|
-
* ExGameInfo
|
|
205
|
-
* extended type by ddnet
|
|
206
|
-
* DDNetProjectile
|
|
207
|
-
* extended type by ddnet
|
|
208
|
-
* ExLaser
|
|
209
|
-
* extended type by ddnet
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
</details>
|
|
213
|
-
|
|
214
|
-
### ClientInfo
|
|
215
|
-
The ClientInfo Object (accessable using `client.SnapshotUnpacker.getObjClientInfo(player_id)` or `client.SnapshotUnpacker.AllObjClientInfo`) contains some of the essential client information. Example ClientInfo object:
|
|
216
|
-
```
|
|
217
|
-
{
|
|
218
|
-
name: 'Swarfey',
|
|
219
|
-
clan: '',
|
|
220
|
-
country: 276,
|
|
221
|
-
skin: 'coala_toptri',
|
|
222
|
-
use_custom_color: 0,
|
|
223
|
-
color_body: 4718592,
|
|
224
|
-
color_feet: 5046016,
|
|
225
|
-
**id: 0**
|
|
226
|
-
}
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
*The **ID** (player id) is essential for all player-specific informations.*
|
|
230
|
-
|
|
231
|
-
### PlayerInfo
|
|
232
|
-
The PlayerInfo Object (`client.SnapshotUnpacker.getObjPlayerInfo(player_id)` / `client.SnapshotUnpacker.AllObjPlayerInfo`) contains information like the ping,
|
|
233
|
-
Example PlayerInfo object:
|
|
234
|
-
```
|
|
235
|
-
{ local: 0, client_id: 0, team: 0, score: -901, latency: 0 }
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
*Note*: The Ping ("latency") will always be 0, if the scoreboard is not "opened". To open it, you can use client.movement.FlagScoreboard(true). If you do not need the information anymore, you can always "close" it by passing false as a paremeter.
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
### Character
|
|
242
|
-
The character includes information like the current position of the player
|
|
243
|
-
example client.SnapshotUnpacker.getObjCharacter(id):
|
|
244
|
-
```
|
|
245
|
-
{
|
|
246
|
-
character_core: {
|
|
247
|
-
tick: 247926,
|
|
248
|
-
x: 700,
|
|
249
|
-
y: 1201,
|
|
250
|
-
vel_x: 1,
|
|
251
|
-
vel_y: 0,
|
|
252
|
-
angle: 1032,
|
|
253
|
-
direction: 0,
|
|
254
|
-
jumped: 0,
|
|
255
|
-
hooked_player: -1,
|
|
256
|
-
hook_state: 0,
|
|
257
|
-
hook_tick: 6,
|
|
258
|
-
hook_x: 700,
|
|
259
|
-
hook_y: 1201,
|
|
260
|
-
hook_dx: -160,
|
|
261
|
-
hook_dy: -200
|
|
262
|
-
},
|
|
263
|
-
player_flags: 1,
|
|
264
|
-
health: 0,
|
|
265
|
-
armor: 0,
|
|
266
|
-
ammo_count: 0,
|
|
267
|
-
weapon: 1,
|
|
268
|
-
emote: 0,
|
|
269
|
-
attack_tick: 24714,
|
|
270
|
-
client_id: 0
|
|
271
|
-
}
|
|
272
|
-
```
|
|
273
|
-
*Note*: all coordinates differ from the one you see in the debug menu ingame. When ingame, it always is divided by 32.
|
|
274
|
-
|
|
275
|
-
### DDNetCharacter
|
|
276
|
-
example client.SnapshotUnpacker.getObjExDDNetCharacter(id):
|
|
277
|
-
```
|
|
278
|
-
{
|
|
279
|
-
m_Flags: 114688,
|
|
280
|
-
m_FreezeEnd: 255564,
|
|
281
|
-
m_Jumps: 2,
|
|
282
|
-
m_TeleCheckpoint: 0,
|
|
283
|
-
m_StrongWeakID: 1,
|
|
284
|
-
m_JumpedTotal: 0,
|
|
285
|
-
m_NinjaActivationTick: -500,
|
|
286
|
-
m_FreezeStart: 255415,
|
|
287
|
-
m_TargetX: 62,
|
|
288
|
-
m_TargetY: 352,
|
|
289
|
-
id: 0
|
|
290
|
-
}
|
|
291
|
-
```
|
|
292
|
-
### OwnID
|
|
293
|
-
returns your own client id. Useful if you need any of your own information.
|
|
294
|
-
|
|
295
|
-
# Movement
|
|
296
|
-
The movement component is accessable using `client.movement`.
|
|
297
|
-
* RunLeft()
|
|
298
|
-
* makes the client run left
|
|
299
|
-
* RunRight()
|
|
300
|
-
* makes the client run right
|
|
301
|
-
* RunStop()
|
|
302
|
-
* makes the client stop running (if he is)
|
|
303
|
-
* Jump(state?: boolean)
|
|
304
|
-
* makes the client Jump. if the parameter is false, the bot will stop holding jump.
|
|
305
|
-
* Fire()
|
|
306
|
-
* makes the client fire his weapon.
|
|
307
|
-
* Hook(state?: boolean)
|
|
308
|
-
* makes the client hook. if the state parameter is false, he will stop holding hook.
|
|
309
|
-
* NextWeapon()
|
|
310
|
-
* changes his current weapon to the next weapon.
|
|
311
|
-
* PrevWeapon()
|
|
312
|
-
* changes his current weapon to the previous weapon.
|
|
313
|
-
* SetAim(x: number, y: number)
|
|
314
|
-
* sets the aiming to the specified point.
|
|
315
|
-
* FlagPlaying(toggle = true)
|
|
316
|
-
* FlagInMenu(toggle = true)
|
|
317
|
-
* FlagChatting(toggle = true)
|
|
318
|
-
* adds a chat bubble to the bot.
|
|
319
|
-
* FlagScoreboard(toggle = true)
|
|
320
|
-
* useful if you also need the [latency of players](#playerinfo).
|
|
321
|
-
* FlagHookline(toggle = true)
|
|
322
|
-
* shows a hookline for the bot.
|
|
323
|
-
* Reset()
|
|
324
|
-
* resets all input back to default (0).
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
# Other useful things
|
|
328
|
-
* client.Disconnect() - disconnects the client.
|
|
329
|
-
* client.sendInput() - sends an input packet
|
|
330
|
-
* client.VoteOptionList - returns the whole vote list.
|
|
331
|
-
### You can also specify some options in the client constructor:
|
|
332
|
-
```
|
|
333
|
-
/*options: {
|
|
334
|
-
identity?: ClientInfo,
|
|
335
|
-
password?: string,
|
|
336
|
-
ddnet_version?: {version: number, release_version: string},
|
|
337
|
-
timeout?: number, // in ms
|
|
338
|
-
NET_VERSION?: string,
|
|
339
|
-
lightweight?: boolean // experimental, only sends keepalive's (sendinput has to be called manually)
|
|
340
|
-
}
|
|
341
|
-
*/
|
|
342
|
-
// client without options:
|
|
343
|
-
var client = new teeworlds.Client("127.0.0.1", 8303, "name");
|
|
344
|
-
// client with options:
|
|
345
|
-
var client = new teeworlds.Client("127.0.0.1", 8303, "name", {
|
|
346
|
-
identity: {
|
|
347
|
-
"name": "nameless bot",
|
|
348
|
-
"clan": "",
|
|
349
|
-
"skin": "eggp",
|
|
350
|
-
"use_custom_color": 0,
|
|
351
|
-
"color_body": 65408,
|
|
352
|
-
"color_feet": 65408,
|
|
353
|
-
"country": -1,
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
// will create a client with the name "nameless bot", skin eggp, etc.
|
|
357
|
-
|
|
358
|
-
client.connect();
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
# Examples
|
|
362
|
-
You can find some of the examples in the [docs/examples](docs/examples/) folder.
|
|
363
|
-
|
|
364
|
-
# Projects using this library
|
|
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
|
-
|
|
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
|
|
371
|
-
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
let teeworlds = require('teeworlds');
|
|
2
|
-
let client = new teeworlds.Client("127.0.0.1", 8303, "nameless bot");
|
|
3
|
-
|
|
4
|
-
client.on("connected", () => console.log("connected!"))
|
|
5
|
-
|
|
6
|
-
client.on("message", (msg) => {
|
|
7
|
-
console.log(msg.author?.ClientInfo?.name, msg.message)
|
|
8
|
-
if (msg.message.toLowerCase() == ";help") {
|
|
9
|
-
client.game.Say(`${msg.author?.ClientInfo?.name}: Commands: ;help, ;myskin, ;say, ;list`);
|
|
10
|
-
} else if (msg.message.toLowerCase() == ";myskin") {
|
|
11
|
-
client.game.Say(`${msg.author?.ClientInfo?.name}: Your skin: ${msg.author?.ClientInfo?.skin}`);
|
|
12
|
-
} else if (msg.message.toLowerCase().startsWith(";say ")) {
|
|
13
|
-
client.game.Say(msg.message.slice(";say ".length))
|
|
14
|
-
} else if (msg.message.toLowerCase() == ";list") {
|
|
15
|
-
let list = client.SnapshotUnpacker.AllObjClientInfo.map( a => a.name );
|
|
16
|
-
client.game.Say(list.join(", "));
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
client.connect();
|
|
21
|
-
|
|
22
|
-
process.on("SIGINT", () => {
|
|
23
|
-
client.Disconnect().then(() => process.exit(0)); // disconnect on ctrl + c
|
|
24
|
-
// process.exit()
|
|
25
|
-
})
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
let teeworlds = require('teeworlds');
|
|
2
|
-
let client = new teeworlds.Client("127.0.0.1", 8303, "nameless bot");
|
|
3
|
-
|
|
4
|
-
client.on("connected", () => console.log("connected!"))
|
|
5
|
-
|
|
6
|
-
client.on("snapshot", () => {
|
|
7
|
-
let myDDNetChar = client.SnapshotUnpacker.getObjExDDNetCharacter(client.SnapshotUnpacker.OwnID);
|
|
8
|
-
if (myDDNetChar == undefined)
|
|
9
|
-
return;
|
|
10
|
-
if (myDDNetChar.m_FreezeEnd != 0) {
|
|
11
|
-
client.game.Kill();
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
client.connect();
|
|
16
|
-
|
|
17
|
-
process.on("SIGINT", () => {
|
|
18
|
-
client.Disconnect().then(() => process.exit(0)); // disconnect on ctrl + c
|
|
19
|
-
// process.exit()
|
|
20
|
-
})
|
package/lib/MsgPacker.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export class MsgPacker {
|
|
2
|
-
result: Buffer;
|
|
3
|
-
sys: boolean;
|
|
4
|
-
flag: number;
|
|
5
|
-
constructor(msg: number, sys: boolean, flag: number) {
|
|
6
|
-
this.result = Buffer.from([2*msg + (sys ? 1 : 0)]);
|
|
7
|
-
this.sys = sys;
|
|
8
|
-
this.flag = flag;
|
|
9
|
-
}
|
|
10
|
-
AddString(str: string) {
|
|
11
|
-
this.result = Buffer.concat([this.result, Buffer.from(str), Buffer.from([0x00])])
|
|
12
|
-
}
|
|
13
|
-
AddBuffer(buffer: Buffer) {
|
|
14
|
-
this.result = Buffer.concat([this.result, buffer])
|
|
15
|
-
}
|
|
16
|
-
AddInt(i: number) {
|
|
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
|
-
} else
|
|
35
|
-
result.push(pDst)
|
|
36
|
-
|
|
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
|
-
}
|
package/lib/MsgUnpacker.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
const decoder = new TextDecoder('utf-8');
|
|
2
|
-
export function unpackInt(pSrc: Buffer): {result: number, remaining: Buffer} {
|
|
3
|
-
|
|
4
|
-
var srcIndex = 0;
|
|
5
|
-
const sign = ((pSrc[srcIndex] >> 6) & 1)
|
|
6
|
-
|
|
7
|
-
var result = (pSrc[srcIndex] & 0b0011_1111)
|
|
8
|
-
while (srcIndex <= 4) {
|
|
9
|
-
|
|
10
|
-
if ((pSrc[srcIndex] & 0b1000_0000) === 0)
|
|
11
|
-
break;
|
|
12
|
-
|
|
13
|
-
srcIndex++;
|
|
14
|
-
result |= ((pSrc[srcIndex] & 0b0111_1111)) << (6+7*(srcIndex-1))
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
result ^= -sign;
|
|
18
|
-
|
|
19
|
-
return {result, remaining: pSrc.slice(srcIndex+1)};
|
|
20
|
-
}
|
|
21
|
-
export function unpackString(pSrc: Buffer): {result: string, remaining: Buffer} {
|
|
22
|
-
var result = pSrc.slice(0, pSrc.indexOf(0))
|
|
23
|
-
pSrc = pSrc.slice(pSrc.indexOf(0) + 1, pSrc.length)
|
|
24
|
-
return {result: decoder.decode(new Uint8Array(result)), remaining: pSrc}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class MsgUnpacker {
|
|
28
|
-
remaining: Buffer;
|
|
29
|
-
constructor(pSrc: Buffer) {
|
|
30
|
-
this.remaining = pSrc;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
unpackInt(): number {
|
|
34
|
-
// let unpacked;
|
|
35
|
-
// if (!_unpacked) {
|
|
36
|
-
let unpacked = unpackInt(this.remaining);
|
|
37
|
-
this.remaining = unpacked.remaining;
|
|
38
|
-
// } else {
|
|
39
|
-
// unpacked = {result: this.remaining[0]};
|
|
40
|
-
// this.remaining = this.remaining.slice(1);
|
|
41
|
-
|
|
42
|
-
// }
|
|
43
|
-
return unpacked.result;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
unpackString(): string {
|
|
47
|
-
let unpacked = unpackString(this.remaining);
|
|
48
|
-
this.remaining = unpacked.remaining;
|
|
49
|
-
return unpacked.result;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** @param size - size in bytes */
|
|
53
|
-
unpackRaw(size: number): Buffer {
|
|
54
|
-
let unpacked = this.remaining.slice(0, size);
|
|
55
|
-
this.remaining = this.remaining.slice(size);
|
|
56
|
-
return unpacked;
|
|
57
|
-
}
|
|
58
|
-
}
|
package/lib/UUIDManager.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'crypto';
|
|
2
|
-
export const createTwMD5Hash = (name: string) => { // https://github.com/ddnet/ddnet/blob/6d9284adc1e0be4b5348447d857eae575e06e654/src/engine/shared/uuid_manager.cpp#L26
|
|
3
|
-
let hash = createHash("md5")
|
|
4
|
-
.update(Buffer.from([0xe0, 0x5d, 0xda, 0xaa, 0xc4, 0xe6, 0x4c, 0xfb, 0xb6, 0x42, 0x5d, 0x48, 0xe8, 0x0c, 0x00, 0x29]))
|
|
5
|
-
.update(name)
|
|
6
|
-
.digest()
|
|
7
|
-
hash[6] &= 0x0f;
|
|
8
|
-
hash[6] |= 0x30;
|
|
9
|
-
hash[8] &= 0x3f;
|
|
10
|
-
hash[8] |= 0x80;
|
|
11
|
-
return hash;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// [{name: string, hash: Buffer}, ..]
|
|
15
|
-
export class UUIDManager {
|
|
16
|
-
uuids: {name: string, hash: Buffer, type_id: number}[] = [];
|
|
17
|
-
offset: number;
|
|
18
|
-
snapshot: boolean; // snapshot uuids count the index from back (32767, 32766, ..), while normal uuids count with increasing type id (65536, 65537, 65538, ..)
|
|
19
|
-
constructor(pOffset = 65536, pSnapshot = false) {
|
|
20
|
-
this.offset = pOffset;
|
|
21
|
-
this.snapshot = pSnapshot;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
LookupUUID(hash: Buffer) {
|
|
25
|
-
return this.uuids.find( a => a.hash.compare(hash) == 0 );
|
|
26
|
-
}
|
|
27
|
-
LookupName(name: string) {
|
|
28
|
-
return this.uuids.find( a => a.name === name );
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
LookupType(ID: number) {
|
|
32
|
-
if (!this.snapshot) {
|
|
33
|
-
return this.uuids[ID - this.offset]
|
|
34
|
-
} else {
|
|
35
|
-
return this.uuids.find( a => a.type_id == ID);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
RegisterName(name: string, type_id = this.offset - this.uuids.length) {
|
|
39
|
-
this.uuids.push({
|
|
40
|
-
name, hash: createTwMD5Hash(name), type_id
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
}
|