@erlcjs/core 1.0.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 +111 -0
- package/dist/index.d.mts +1218 -0
- package/dist/index.d.ts +1218 -0
- package/dist/index.js +1324 -0
- package/dist/index.mjs +1277 -0
- package/package.json +38 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1324 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Base: () => Base,
|
|
24
|
+
Client: () => Client18,
|
|
25
|
+
CommandLog: () => CommandLog,
|
|
26
|
+
CommandLogManager: () => CommandLogManager,
|
|
27
|
+
CommandManager: () => CommandManager,
|
|
28
|
+
ERLCEvents: () => ERLCEvents,
|
|
29
|
+
EmergencyCall: () => EmergencyCall,
|
|
30
|
+
EmergencyCallManager: () => EmergencyCallManager,
|
|
31
|
+
InvalidServerKeyError: () => InvalidServerKeyError,
|
|
32
|
+
KillLog: () => KillLog,
|
|
33
|
+
KillLogManager: () => KillLogManager,
|
|
34
|
+
ModCall: () => ModCall,
|
|
35
|
+
ModCallManager: () => ModCallManager,
|
|
36
|
+
Player: () => Player,
|
|
37
|
+
PlayerManager: () => PlayerManager,
|
|
38
|
+
RestManager: () => RestManager,
|
|
39
|
+
Server: () => Server,
|
|
40
|
+
ServerManager: () => ServerManager,
|
|
41
|
+
Vehicle: () => Vehicle,
|
|
42
|
+
VehicleManager: () => VehicleManager,
|
|
43
|
+
WebhookServer: () => WebhookServer
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(index_exports);
|
|
46
|
+
|
|
47
|
+
// src/client/client.ts
|
|
48
|
+
var import_node_events = require("events");
|
|
49
|
+
|
|
50
|
+
// src/errors/index.ts
|
|
51
|
+
var InvalidServerKeyError = class extends Error {
|
|
52
|
+
/**
|
|
53
|
+
* Creates an instance of InvalidServerKeyError.
|
|
54
|
+
* @param message - The error message. Defaults to 'Invalid Server API Key.'.
|
|
55
|
+
*/
|
|
56
|
+
constructor(message = "Invalid Server API Key.") {
|
|
57
|
+
super(message);
|
|
58
|
+
this.name = "InvalidServerKeyError";
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/rest/manager.ts
|
|
63
|
+
var RestManager = class {
|
|
64
|
+
/**
|
|
65
|
+
* Creates an instance of RestManager.
|
|
66
|
+
* @param options - The ClientOptions configuration.
|
|
67
|
+
*/
|
|
68
|
+
constructor(options) {
|
|
69
|
+
this.options = options;
|
|
70
|
+
}
|
|
71
|
+
options;
|
|
72
|
+
queue = [];
|
|
73
|
+
processing = false;
|
|
74
|
+
rateLimitReset = 0;
|
|
75
|
+
baseUrl = "https://api.erlc.gg";
|
|
76
|
+
/**
|
|
77
|
+
* Enqueues and sends an HTTP request to the ER:LC API.
|
|
78
|
+
* @param method - The HTTP method to use ('GET' or 'POST').
|
|
79
|
+
* @param endpoint - The API endpoint path.
|
|
80
|
+
* @param body - The optional request body payload.
|
|
81
|
+
* @returns A promise resolving to the API response data.
|
|
82
|
+
* @throws {@link InvalidServerKeyError} if the server API key is invalid (403).
|
|
83
|
+
* @throws Error - for other HTTP error codes.
|
|
84
|
+
*/
|
|
85
|
+
async request(method, endpoint, body) {
|
|
86
|
+
console.log(method, endpoint, body);
|
|
87
|
+
return new Promise((resolve, reject) => {
|
|
88
|
+
this.queue.push(async () => {
|
|
89
|
+
try {
|
|
90
|
+
if (Date.now() < this.rateLimitReset) {
|
|
91
|
+
const waitTime = this.rateLimitReset - Date.now();
|
|
92
|
+
await new Promise((res) => setTimeout(res, waitTime));
|
|
93
|
+
}
|
|
94
|
+
const response = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
95
|
+
method,
|
|
96
|
+
headers: {
|
|
97
|
+
"Server-Key": this.options.serverKey,
|
|
98
|
+
"Content-Type": "application/json",
|
|
99
|
+
...this.options.globalKey && { "Authorization": `Bearer ${this.options.globalKey}` }
|
|
100
|
+
},
|
|
101
|
+
body: body ? JSON.stringify(body) : void 0
|
|
102
|
+
});
|
|
103
|
+
const resetHeader = response.headers.get("x-ratelimit-reset");
|
|
104
|
+
if (resetHeader) {
|
|
105
|
+
this.rateLimitReset = Date.now() + parseInt(resetHeader) * 1e3;
|
|
106
|
+
}
|
|
107
|
+
if (response.status === 403) {
|
|
108
|
+
throw new InvalidServerKeyError();
|
|
109
|
+
}
|
|
110
|
+
if (response.status === 429) {
|
|
111
|
+
this.queue.unshift(() => this.request(method, endpoint, body).then(resolve).catch(reject));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (!response.ok) {
|
|
115
|
+
throw new Error(`[ERLC API Error] ${response.status}: ${response.statusText}`);
|
|
116
|
+
}
|
|
117
|
+
const data = await response.json();
|
|
118
|
+
resolve(data);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
reject(error);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
this.processQueue();
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Processes the request queue sequentially.
|
|
128
|
+
*/
|
|
129
|
+
async processQueue() {
|
|
130
|
+
if (this.processing) return;
|
|
131
|
+
this.processing = true;
|
|
132
|
+
while (this.queue.length > 0) {
|
|
133
|
+
const executeTask = this.queue.shift();
|
|
134
|
+
if (executeTask) await executeTask();
|
|
135
|
+
}
|
|
136
|
+
this.processing = false;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// src/structures/base.ts
|
|
141
|
+
var Base = class {
|
|
142
|
+
/**
|
|
143
|
+
* Creates an instance of the Base class.
|
|
144
|
+
* @param client - The ERLCApi client instance.
|
|
145
|
+
*/
|
|
146
|
+
constructor(client) {
|
|
147
|
+
this.client = client;
|
|
148
|
+
}
|
|
149
|
+
client;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// src/structures/server.ts
|
|
153
|
+
var Server = class extends Base {
|
|
154
|
+
/**
|
|
155
|
+
* The name of the server.
|
|
156
|
+
*/
|
|
157
|
+
name;
|
|
158
|
+
/**
|
|
159
|
+
* The UserId of the server owner.
|
|
160
|
+
*/
|
|
161
|
+
ownerId;
|
|
162
|
+
/**
|
|
163
|
+
* Array of UserIds of server co-owners.
|
|
164
|
+
*/
|
|
165
|
+
coOwnerIds;
|
|
166
|
+
/**
|
|
167
|
+
* The current number of players connected to the server.
|
|
168
|
+
*/
|
|
169
|
+
currentPlayers;
|
|
170
|
+
/**
|
|
171
|
+
* The maximum number of players allowed in the server.
|
|
172
|
+
*/
|
|
173
|
+
maxPlayers;
|
|
174
|
+
/**
|
|
175
|
+
* The join key of the server.
|
|
176
|
+
*/
|
|
177
|
+
joinKey;
|
|
178
|
+
/**
|
|
179
|
+
* Account verification requirements for joining.
|
|
180
|
+
*/
|
|
181
|
+
accVerifiedReq;
|
|
182
|
+
/**
|
|
183
|
+
* Whether team balance enforcement is enabled.
|
|
184
|
+
*/
|
|
185
|
+
teamBalance;
|
|
186
|
+
/**
|
|
187
|
+
* The queue of players waiting to join the server.
|
|
188
|
+
*/
|
|
189
|
+
queue;
|
|
190
|
+
/**
|
|
191
|
+
* Creates an instance of Server.
|
|
192
|
+
* @param client - The ERLCApi client.
|
|
193
|
+
* @param data - The raw server data to initialize.
|
|
194
|
+
*/
|
|
195
|
+
constructor(client, data) {
|
|
196
|
+
super(client);
|
|
197
|
+
this._patch(data);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Patches the Server instance with new raw data.
|
|
201
|
+
* @param data - The new raw server data.
|
|
202
|
+
* @returns This server instance.
|
|
203
|
+
*/
|
|
204
|
+
_patch(data) {
|
|
205
|
+
this.name = data.Name;
|
|
206
|
+
this.ownerId = data.OwnerId;
|
|
207
|
+
this.coOwnerIds = data.CoOwnerIds;
|
|
208
|
+
this.currentPlayers = data.CurrentPlayers;
|
|
209
|
+
this.maxPlayers = data.MaxPlayers;
|
|
210
|
+
this.joinKey = data.JoinKey;
|
|
211
|
+
this.accVerifiedReq = data.AccVerifiedReq;
|
|
212
|
+
this.teamBalance = data.TeamBalance;
|
|
213
|
+
this.queue = data.Queue ?? [];
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Compares the current server data with another raw data payload to check if it's identical.
|
|
218
|
+
* @param data - The raw server data to compare against.
|
|
219
|
+
* @returns True if the properties are identical, false otherwise.
|
|
220
|
+
*/
|
|
221
|
+
compare(data) {
|
|
222
|
+
return this.name === data.Name && this.ownerId === data.OwnerId && this.coOwnerIds === data.CoOwnerIds && this.currentPlayers === data.CurrentPlayers && this.maxPlayers === data.MaxPlayers && this.joinKey === data.JoinKey && this.accVerifiedReq === data.AccVerifiedReq && this.teamBalance === data.TeamBalance && this.queue === data.Queue;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Converts this Server instance back to its raw JSON structure.
|
|
226
|
+
* @returns The raw server data.
|
|
227
|
+
*/
|
|
228
|
+
toJSON() {
|
|
229
|
+
return {
|
|
230
|
+
Name: this.name,
|
|
231
|
+
OwnerId: this.ownerId,
|
|
232
|
+
CoOwnerIds: this.coOwnerIds,
|
|
233
|
+
CurrentPlayers: this.currentPlayers,
|
|
234
|
+
MaxPlayers: this.maxPlayers,
|
|
235
|
+
JoinKey: this.joinKey,
|
|
236
|
+
AccVerifiedReq: this.accVerifiedReq,
|
|
237
|
+
TeamBalance: this.teamBalance,
|
|
238
|
+
Queue: this.queue
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// src/managers/servermanager.ts
|
|
244
|
+
var ServerManager = class {
|
|
245
|
+
/**
|
|
246
|
+
* Creates an instance of ServerManager.
|
|
247
|
+
* @param client - The ERLCApi client.
|
|
248
|
+
*/
|
|
249
|
+
constructor(client) {
|
|
250
|
+
this.client = client;
|
|
251
|
+
}
|
|
252
|
+
client;
|
|
253
|
+
/**
|
|
254
|
+
* Cached Server structure instance, if fetched.
|
|
255
|
+
*/
|
|
256
|
+
cache;
|
|
257
|
+
/**
|
|
258
|
+
* Fetches current server information from the API.
|
|
259
|
+
* Patches the cache and emits event updates if there are changes.
|
|
260
|
+
* @returns A promise resolving to the raw server data from the API.
|
|
261
|
+
*/
|
|
262
|
+
async fetch() {
|
|
263
|
+
const rawServerData = await this.client.rest.request("GET", "/v2/server?Players=true&Vehicles=true&Staff=true&JoinLogs=true&Queue=true&KillLogs=true&CommandLogs=true&ModCalls=true&EmergencyCalls=true");
|
|
264
|
+
if (this.cache?.compare(rawServerData)) return rawServerData;
|
|
265
|
+
if (this.cache) {
|
|
266
|
+
const oldCache = new Server(this.client, this.cache.toJSON());
|
|
267
|
+
this.cache._patch(rawServerData);
|
|
268
|
+
this.client.emit("SERVER_UPDATE" /* serverUpdate */, oldCache, this.cache);
|
|
269
|
+
} else {
|
|
270
|
+
this.cache = new Server(this.client, rawServerData);
|
|
271
|
+
this.client.emit("SERVER_CREATE" /* serverCreate */, this.cache);
|
|
272
|
+
}
|
|
273
|
+
return rawServerData;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// src/structures/player.ts
|
|
278
|
+
var Player = class _Player extends Base {
|
|
279
|
+
/**
|
|
280
|
+
* The unique UserId of the player.
|
|
281
|
+
*/
|
|
282
|
+
id;
|
|
283
|
+
/**
|
|
284
|
+
* The Roblox username of the player.
|
|
285
|
+
*/
|
|
286
|
+
username;
|
|
287
|
+
/**
|
|
288
|
+
* The in-game team name the player is currently on.
|
|
289
|
+
*/
|
|
290
|
+
team;
|
|
291
|
+
/**
|
|
292
|
+
* The player's callsign, if assigned.
|
|
293
|
+
*/
|
|
294
|
+
callsign;
|
|
295
|
+
/**
|
|
296
|
+
* The current location coordinates and address of the player.
|
|
297
|
+
*/
|
|
298
|
+
location;
|
|
299
|
+
/**
|
|
300
|
+
* The player's server permission role.
|
|
301
|
+
*/
|
|
302
|
+
permission;
|
|
303
|
+
/**
|
|
304
|
+
* The player's current wanted star level.
|
|
305
|
+
*/
|
|
306
|
+
wantedLevel;
|
|
307
|
+
/**
|
|
308
|
+
* Creates an instance of Player.
|
|
309
|
+
* @param client - The ERLCApi client.
|
|
310
|
+
* @param data - The raw player data to initialize.
|
|
311
|
+
*/
|
|
312
|
+
constructor(client, data) {
|
|
313
|
+
super(client);
|
|
314
|
+
this._patch(data);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Patches/updates the player structure with new raw data.
|
|
318
|
+
* @param data - The new raw player data.
|
|
319
|
+
* @returns This player instance.
|
|
320
|
+
*/
|
|
321
|
+
_patch(data) {
|
|
322
|
+
const splitPlayer = data.Player.split(":");
|
|
323
|
+
this.id = Number(splitPlayer[1]);
|
|
324
|
+
this.username = splitPlayer[0];
|
|
325
|
+
this.team = data.Team;
|
|
326
|
+
this.callsign = data.Callsign;
|
|
327
|
+
this.location = {
|
|
328
|
+
x: data.Location.LocationX,
|
|
329
|
+
y: data.Location.LocationY,
|
|
330
|
+
postalCode: data.Location.PostalCode,
|
|
331
|
+
streetName: data.Location.StreetName,
|
|
332
|
+
buildingNumber: data.Location.BuildingNumber
|
|
333
|
+
};
|
|
334
|
+
this.permission = data.Permission ?? "Normal";
|
|
335
|
+
this.wantedLevel = data.WantedStars ?? 0;
|
|
336
|
+
return this;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Kicks the player from the game server.
|
|
340
|
+
* @param reason - The reason for kicking the player. Defaults to "Kicked by API".
|
|
341
|
+
* @returns A promise that resolves when the kick command is sent.
|
|
342
|
+
*/
|
|
343
|
+
async kick(reason = "Kicked by API") {
|
|
344
|
+
await this.client.commands.execute(`:kick ${this.username} ${reason}`);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Bans the player from the game server.
|
|
348
|
+
* @param reason - The reason for banning the player. Defaults to "Banned by API".
|
|
349
|
+
* @returns A promise that resolves when the ban command is sent.
|
|
350
|
+
*/
|
|
351
|
+
async ban(reason = "Banned by API") {
|
|
352
|
+
await this.client.commands.execute(`:ban ${this.username} ${reason}`);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Jails the player in the game server.
|
|
356
|
+
* @returns A promise that resolves when the jail command is sent.
|
|
357
|
+
*/
|
|
358
|
+
async jail() {
|
|
359
|
+
await this.client.commands.execute(`:jail ${this.username}`);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Heals the player in the game server.
|
|
363
|
+
* @returns A promise that resolves when the heal command is sent.
|
|
364
|
+
*/
|
|
365
|
+
async heal() {
|
|
366
|
+
await this.client.commands.execute(`:heal ${this.username}`);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Kills the player in-game.
|
|
370
|
+
* @returns A promise that resolves when the kill command is sent.
|
|
371
|
+
*/
|
|
372
|
+
async kill() {
|
|
373
|
+
await this.client.commands.execute(`:kill ${this.username}`);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Helpers the player in-game.
|
|
377
|
+
* @returns A promise that resolves when the helper command is sent.
|
|
378
|
+
*/
|
|
379
|
+
async helper() {
|
|
380
|
+
await this.client.commands.execute(`:helper ${this.username}`);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Unhelpers the player in-game.
|
|
384
|
+
* @returns A promise that resolves when the unhelper command is sent.
|
|
385
|
+
*/
|
|
386
|
+
async unhelper() {
|
|
387
|
+
await this.client.commands.execute(`:helper ${this.username}`);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Mods the player in-game.
|
|
391
|
+
* @returns A promise that resolves when the mod command is sent.
|
|
392
|
+
*/
|
|
393
|
+
async mod() {
|
|
394
|
+
await this.client.commands.execute(`:mod ${this.username}`);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Unmods the player in-game.
|
|
398
|
+
* @returns A promise that resolves when the unmod command is sent.
|
|
399
|
+
*/
|
|
400
|
+
async unmod() {
|
|
401
|
+
await this.client.commands.execute(`:unmod ${this.username}`);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Admins the player in-game.
|
|
405
|
+
* @returns A promise that resolves when the admin command is sent.
|
|
406
|
+
*/
|
|
407
|
+
async admin() {
|
|
408
|
+
await this.client.commands.execute(`:admin ${this.username}`);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Unadmins the player in-game.
|
|
412
|
+
* @returns A promise that resolves when the unadmin command is sent.
|
|
413
|
+
*/
|
|
414
|
+
async unadmin() {
|
|
415
|
+
await this.client.commands.execute(`:unadmin ${this.username}`);
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Teleports the player to another player.
|
|
419
|
+
* @param player - The player to teleport the player to.
|
|
420
|
+
* @returns A promise that resolves when the teleport command is sent.
|
|
421
|
+
*/
|
|
422
|
+
async tp(player) {
|
|
423
|
+
const playerId = player instanceof _Player ? player.id : player;
|
|
424
|
+
await this.client.commands.execute(`:tp ${this.username} ${playerId}`);
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Sends a private message to the player.
|
|
428
|
+
* @param text - The message body.
|
|
429
|
+
* @returns A promise that resolves when the message command is sent.
|
|
430
|
+
*/
|
|
431
|
+
async message(text) {
|
|
432
|
+
await this.client.commands.execute(`:pm ${this.username} ${text}`);
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Sends a private message to the player.
|
|
436
|
+
* @param text - The message body.
|
|
437
|
+
* @returns A promise that resolves when the message command is sent.
|
|
438
|
+
*/
|
|
439
|
+
async pm(text) {
|
|
440
|
+
await this.client.commands.execute(`:pm ${this.username} ${text}`);
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Converts this Player instance back into raw data structure.
|
|
444
|
+
* @returns The raw player data.
|
|
445
|
+
*/
|
|
446
|
+
toJSON() {
|
|
447
|
+
return {
|
|
448
|
+
Player: `${this.username}:${this.id}`,
|
|
449
|
+
Permission: this.permission,
|
|
450
|
+
Team: this.team,
|
|
451
|
+
Callsign: this.callsign,
|
|
452
|
+
WantedStars: this.wantedLevel,
|
|
453
|
+
Location: { LocationX: this.location.x, LocationY: this.location.y, PostalCode: this.location.postalCode, StreetName: this.location.streetName, BuildingNumber: this.location.buildingNumber }
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
// src/managers/playermanager.ts
|
|
459
|
+
var PlayerManager = class {
|
|
460
|
+
/**
|
|
461
|
+
* Creates an instance of PlayerManager.
|
|
462
|
+
* @param client - The ERLCApi client.
|
|
463
|
+
*/
|
|
464
|
+
constructor(client) {
|
|
465
|
+
this.client = client;
|
|
466
|
+
}
|
|
467
|
+
client;
|
|
468
|
+
/**
|
|
469
|
+
* Map cache of online Players, keyed by their UserId.
|
|
470
|
+
*/
|
|
471
|
+
cache = /* @__PURE__ */ new Map();
|
|
472
|
+
nameToId = /* @__PURE__ */ new Map();
|
|
473
|
+
/**
|
|
474
|
+
* Fetches all active players currently in the game server.
|
|
475
|
+
* Updates the player cache.
|
|
476
|
+
* @returns A promise resolving to a Map of active Players.
|
|
477
|
+
*/
|
|
478
|
+
async fetchAll() {
|
|
479
|
+
const rawServer = await this.client.rest.request("GET", "/v2/server?Players=true");
|
|
480
|
+
const rawPlayers = rawServer.Players ?? [];
|
|
481
|
+
return this.updateCache(rawPlayers);
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Re-synchronizes the cache with the raw player list from the API.
|
|
485
|
+
* Emits playerJoin, playerLeave, and playerUpdate events.
|
|
486
|
+
* @param rawPlayers - Raw player list payload.
|
|
487
|
+
* @returns The updated Player cache Map.
|
|
488
|
+
*/
|
|
489
|
+
updateCache(rawPlayers) {
|
|
490
|
+
const activeIds = /* @__PURE__ */ new Set();
|
|
491
|
+
const activeUsers = /* @__PURE__ */ new Set();
|
|
492
|
+
for (const rawData of rawPlayers) {
|
|
493
|
+
const userId = Number(rawData.Player.split(":")[1]);
|
|
494
|
+
const username = rawData.Player.split(":")[0];
|
|
495
|
+
activeIds.add(userId);
|
|
496
|
+
activeUsers.add(username);
|
|
497
|
+
this.nameToId.set(username, userId);
|
|
498
|
+
const cachedPlayer = this.cache.get(userId);
|
|
499
|
+
if (cachedPlayer) {
|
|
500
|
+
const oldPlayer = new Player(this.client, cachedPlayer.toJSON());
|
|
501
|
+
cachedPlayer._patch(rawData);
|
|
502
|
+
this.client.emit("PLAYER_UPDATE" /* playerUpdate */, oldPlayer, cachedPlayer);
|
|
503
|
+
} else {
|
|
504
|
+
const newPlayer = new Player(this.client, rawData);
|
|
505
|
+
this.cache.set(newPlayer.id, newPlayer);
|
|
506
|
+
this.client.emit("PLAYER_JOIN" /* playerJoin */, newPlayer);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
for (const cachedId of this.cache.keys()) {
|
|
510
|
+
if (!activeIds.has(cachedId)) {
|
|
511
|
+
this.client.emit("PLAYER_LEAVE" /* playerLeave */, this.cache.get(cachedId));
|
|
512
|
+
this.cache.delete(cachedId);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
for (const cachedUser of this.nameToId.keys()) {
|
|
516
|
+
if (!activeUsers.has(cachedUser)) this.nameToId.delete(cachedUser);
|
|
517
|
+
}
|
|
518
|
+
return this.cache;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Retrieves a player's UserId from their Roblox username.
|
|
522
|
+
* Attempts to resolve from cache first, otherwise triggers a fresh fetch.
|
|
523
|
+
* @param name - The Roblox username.
|
|
524
|
+
* @returns The UserId if resolved, otherwise undefined.
|
|
525
|
+
*/
|
|
526
|
+
getIdFromName(name) {
|
|
527
|
+
if (this.nameToId.has(name)) return this.nameToId.get(name);
|
|
528
|
+
this.fetchAll().then(() => {
|
|
529
|
+
return this.nameToId.get(name);
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
// src/managers/commandmanager.ts
|
|
535
|
+
var CommandManager = class {
|
|
536
|
+
/**
|
|
537
|
+
* Creates an instance of CommandManager.
|
|
538
|
+
* @param client - The ERLCApi client.
|
|
539
|
+
*/
|
|
540
|
+
constructor(client) {
|
|
541
|
+
this.client = client;
|
|
542
|
+
}
|
|
543
|
+
client;
|
|
544
|
+
/**
|
|
545
|
+
* Executes a server command via the ER:LC API.
|
|
546
|
+
* @param command - The full command string to execute (e.g. `:pm jamie hello`).
|
|
547
|
+
* @returns A promise resolving to the API response string status.
|
|
548
|
+
*/
|
|
549
|
+
async execute(command) {
|
|
550
|
+
const res = await this.client.rest.request("POST", "/v2/server/command", { command });
|
|
551
|
+
return res;
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
// src/gateway/webhookserver.ts
|
|
556
|
+
var import_node_http = require("http");
|
|
557
|
+
var WebhookServer = class {
|
|
558
|
+
/**
|
|
559
|
+
* Creates an instance of WebhookServer.
|
|
560
|
+
* @param client - The ERLCApi client.
|
|
561
|
+
*/
|
|
562
|
+
constructor(client) {
|
|
563
|
+
this.client = client;
|
|
564
|
+
this.server = (0, import_node_http.createServer)((req, res) => {
|
|
565
|
+
const configPath = this.client.options.webhook?.path || "/";
|
|
566
|
+
if (req.method === "POST" && req.url === configPath) {
|
|
567
|
+
let body = "";
|
|
568
|
+
req.on("data", (chunk) => body += chunk);
|
|
569
|
+
req.on("end", () => {
|
|
570
|
+
try {
|
|
571
|
+
const payload = JSON.parse(body);
|
|
572
|
+
this.handleGatewayEvent(payload);
|
|
573
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
574
|
+
res.end(JSON.stringify({ received: true }));
|
|
575
|
+
} catch (err) {
|
|
576
|
+
res.writeHead(400).end("Malformed Payload");
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
} else {
|
|
580
|
+
res.writeHead(404).end();
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
client;
|
|
585
|
+
server;
|
|
586
|
+
/**
|
|
587
|
+
* Starts listening for incoming webhook events.
|
|
588
|
+
*/
|
|
589
|
+
listen() {
|
|
590
|
+
const port = this.client.options.webhook?.port || 3e3;
|
|
591
|
+
this.server.listen(port, () => {
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Internally processes gateway event payload.
|
|
596
|
+
* @param payload - Raw JSON payload received.
|
|
597
|
+
*/
|
|
598
|
+
handleGatewayEvent(payload) {
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
// src/structures/vehicle.ts
|
|
603
|
+
var Vehicle = class extends Base {
|
|
604
|
+
/**
|
|
605
|
+
* The name/model of the vehicle.
|
|
606
|
+
*/
|
|
607
|
+
name;
|
|
608
|
+
/**
|
|
609
|
+
* The UserId of the vehicle owner.
|
|
610
|
+
*/
|
|
611
|
+
ownerId;
|
|
612
|
+
/**
|
|
613
|
+
* The username of the vehicle owner.
|
|
614
|
+
*/
|
|
615
|
+
ownerUsername;
|
|
616
|
+
/**
|
|
617
|
+
* The Player instance representing the owner, if they are currently online.
|
|
618
|
+
*/
|
|
619
|
+
owner;
|
|
620
|
+
/**
|
|
621
|
+
* The license plate text of the vehicle.
|
|
622
|
+
*/
|
|
623
|
+
plate;
|
|
624
|
+
/**
|
|
625
|
+
* The custom texture identifier, if any.
|
|
626
|
+
*/
|
|
627
|
+
texture;
|
|
628
|
+
/**
|
|
629
|
+
* The hexadecimal color code of the vehicle.
|
|
630
|
+
*/
|
|
631
|
+
colorHex;
|
|
632
|
+
/**
|
|
633
|
+
* The user-friendly color name of the vehicle.
|
|
634
|
+
*/
|
|
635
|
+
colorName;
|
|
636
|
+
/**
|
|
637
|
+
* Creates an instance of Vehicle.
|
|
638
|
+
* @param client - The ERLCApi client.
|
|
639
|
+
* @param data - The raw vehicle data to initialize.
|
|
640
|
+
*/
|
|
641
|
+
constructor(client, data) {
|
|
642
|
+
super(client);
|
|
643
|
+
this._patch(data);
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Patches the Vehicle structure with new raw data.
|
|
647
|
+
* @param data - The new raw vehicle data.
|
|
648
|
+
* @returns This vehicle instance.
|
|
649
|
+
*/
|
|
650
|
+
_patch(data) {
|
|
651
|
+
this.name = data.Name;
|
|
652
|
+
this.ownerUsername = data.Owner;
|
|
653
|
+
this.ownerId = this.client.players.getIdFromName(this.ownerUsername);
|
|
654
|
+
this.owner = this.client.players.cache.get(this.ownerId);
|
|
655
|
+
this.plate = data.Plate;
|
|
656
|
+
this.texture = data.Texture;
|
|
657
|
+
this.colorHex = data.ColorHex;
|
|
658
|
+
this.colorName = data.ColorName;
|
|
659
|
+
return this;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Converts this Vehicle instance to raw JSON representation.
|
|
663
|
+
* @returns The raw vehicle data.
|
|
664
|
+
*/
|
|
665
|
+
toJSON() {
|
|
666
|
+
return {
|
|
667
|
+
Name: this.name,
|
|
668
|
+
Owner: this.ownerUsername,
|
|
669
|
+
Plate: this.plate,
|
|
670
|
+
ColorHex: this.colorHex,
|
|
671
|
+
Texture: this.texture,
|
|
672
|
+
ColorName: this.colorName
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
// src/managers/vehiclemanager.ts
|
|
678
|
+
var VehicleManager = class {
|
|
679
|
+
/**
|
|
680
|
+
* Creates an instance of VehicleManager.
|
|
681
|
+
* @param client - The ERLCApi client.
|
|
682
|
+
*/
|
|
683
|
+
constructor(client) {
|
|
684
|
+
this.client = client;
|
|
685
|
+
}
|
|
686
|
+
client;
|
|
687
|
+
/**
|
|
688
|
+
* Map cache of spawned vehicles in the server, keyed by their license plate.
|
|
689
|
+
*/
|
|
690
|
+
cache = /* @__PURE__ */ new Map();
|
|
691
|
+
/**
|
|
692
|
+
* Fetches all active vehicles currently spawned in the game server.
|
|
693
|
+
* Updates the vehicle cache.
|
|
694
|
+
* @returns A promise resolving to a Map of active Vehicles.
|
|
695
|
+
*/
|
|
696
|
+
async fetchAll() {
|
|
697
|
+
const rawServer = await this.client.rest.request("GET", "/v2/server?Vehicles=true");
|
|
698
|
+
const rawVehicles = rawServer.Vehicles ?? [];
|
|
699
|
+
return this.updateCache(rawVehicles);
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Re-synchronizes the cache with the raw vehicle list from the API.
|
|
703
|
+
* Emits vehicleAdd, vehicleRemove, and vehicleUpdate events.
|
|
704
|
+
* @param rawVehicles - Raw vehicle list payload.
|
|
705
|
+
* @returns The updated Vehicle cache Map.
|
|
706
|
+
*/
|
|
707
|
+
updateCache(rawVehicles) {
|
|
708
|
+
const activePlates = /* @__PURE__ */ new Set();
|
|
709
|
+
for (const rawData of rawVehicles) {
|
|
710
|
+
const plate = rawData.Plate;
|
|
711
|
+
activePlates.add(plate);
|
|
712
|
+
const cachedVehicle = this.cache.get(plate);
|
|
713
|
+
if (cachedVehicle) {
|
|
714
|
+
const oldVehicle = new Vehicle(this.client, cachedVehicle.toJSON());
|
|
715
|
+
cachedVehicle._patch(rawData);
|
|
716
|
+
this.client.emit("VEHICLE_UPDATE" /* vehicleUpdate */, oldVehicle, cachedVehicle);
|
|
717
|
+
} else {
|
|
718
|
+
const newVehicle = new Vehicle(this.client, rawData);
|
|
719
|
+
this.cache.set(newVehicle.plate, newVehicle);
|
|
720
|
+
this.client.emit("VEHICLE_ADD" /* vehicleAdd */, newVehicle);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
for (const cachedPlate of this.cache.keys()) {
|
|
724
|
+
if (!activePlates.has(cachedPlate)) {
|
|
725
|
+
this.client.emit("VEHICLE_REMOVE" /* vehicleRemove */, this.cache.get(cachedPlate));
|
|
726
|
+
this.cache.delete(cachedPlate);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
return this.cache;
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
// src/structures/commandlog.ts
|
|
734
|
+
var CommandLog = class extends Base {
|
|
735
|
+
/**
|
|
736
|
+
* The player instance representing who ran the command.
|
|
737
|
+
*/
|
|
738
|
+
player;
|
|
739
|
+
/**
|
|
740
|
+
* The UserId of the player who ran the command.
|
|
741
|
+
*/
|
|
742
|
+
playerId;
|
|
743
|
+
/**
|
|
744
|
+
* The username of the player who ran the command.
|
|
745
|
+
*/
|
|
746
|
+
playerUsername;
|
|
747
|
+
/**
|
|
748
|
+
* Unix timestamp of when the command was run.
|
|
749
|
+
*/
|
|
750
|
+
timestamp;
|
|
751
|
+
/**
|
|
752
|
+
* The full command string executed.
|
|
753
|
+
*/
|
|
754
|
+
command;
|
|
755
|
+
/**
|
|
756
|
+
* Creates an instance of CommandLog.
|
|
757
|
+
* @param client - The ERLCApi client.
|
|
758
|
+
* @param data - The raw command log data to initialize.
|
|
759
|
+
*/
|
|
760
|
+
constructor(client, data) {
|
|
761
|
+
super(client);
|
|
762
|
+
this._patch(data);
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Patches the CommandLog structure with new raw data.
|
|
766
|
+
* @param data - The new raw command log data.
|
|
767
|
+
* @returns This command log instance.
|
|
768
|
+
*/
|
|
769
|
+
_patch(data) {
|
|
770
|
+
const splitPlayer = data.Player.split(":");
|
|
771
|
+
this.playerId = Number(splitPlayer[1]);
|
|
772
|
+
this.playerUsername = splitPlayer[0];
|
|
773
|
+
this.player = this.client.players.cache.get(this.playerId);
|
|
774
|
+
this.command = data.Command;
|
|
775
|
+
this.timestamp = data.Timestamp;
|
|
776
|
+
return this;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Converts this CommandLog instance to raw JSON representation.
|
|
780
|
+
* @returns The raw command log data.
|
|
781
|
+
*/
|
|
782
|
+
toJSON() {
|
|
783
|
+
return {
|
|
784
|
+
Player: `${this.playerUsername}:${this.playerId}`,
|
|
785
|
+
Timestamp: this.timestamp,
|
|
786
|
+
Command: this.command
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
// src/managers/commandlogmanager.ts
|
|
792
|
+
var CommandLogManager = class {
|
|
793
|
+
/**
|
|
794
|
+
* Creates an instance of CommandLogManager.
|
|
795
|
+
* @param client - The ERLCApi client.
|
|
796
|
+
*/
|
|
797
|
+
constructor(client) {
|
|
798
|
+
this.client = client;
|
|
799
|
+
}
|
|
800
|
+
client;
|
|
801
|
+
/**
|
|
802
|
+
* Map cache of logged commands, keyed by a composite `Player:Timestamp` key.
|
|
803
|
+
*/
|
|
804
|
+
cache = /* @__PURE__ */ new Map();
|
|
805
|
+
/**
|
|
806
|
+
* Fetches all command logs from the game server.
|
|
807
|
+
* Updates the command log cache.
|
|
808
|
+
* @returns A promise resolving to a Map of CommandLogs.
|
|
809
|
+
*/
|
|
810
|
+
async fetchAll() {
|
|
811
|
+
const rawServer = await this.client.rest.request("GET", "/v2/server?CommandLogs=true");
|
|
812
|
+
const rawCommands = rawServer.CommandLogs ?? [];
|
|
813
|
+
return this.updateCache(rawCommands);
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Re-synchronizes the cache with the raw command logs.
|
|
817
|
+
* Emits command event for new logs.
|
|
818
|
+
* @param rawCommands - Raw command logs payload.
|
|
819
|
+
* @returns The updated CommandLog cache Map.
|
|
820
|
+
*/
|
|
821
|
+
updateCache(rawCommands) {
|
|
822
|
+
for (const rawData of rawCommands) {
|
|
823
|
+
const key = `${rawData.Player}:${rawData.Timestamp}`;
|
|
824
|
+
const cachedPlayer = this.cache.get(key);
|
|
825
|
+
if (!cachedPlayer) {
|
|
826
|
+
const newCommand = new CommandLog(this.client, rawData);
|
|
827
|
+
this.cache.set(key, newCommand);
|
|
828
|
+
this.client.emit("COMMAND" /* command */, newCommand);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return this.cache;
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
// src/structures/emergencycall.ts
|
|
836
|
+
var EmergencyCall = class extends Base {
|
|
837
|
+
/**
|
|
838
|
+
* The Player instance representing the caller.
|
|
839
|
+
*/
|
|
840
|
+
caller;
|
|
841
|
+
/**
|
|
842
|
+
* The UserId of the player who made the emergency call.
|
|
843
|
+
*/
|
|
844
|
+
callerId;
|
|
845
|
+
/**
|
|
846
|
+
* The team associated with the emergency call (e.g., "Police", "Fire").
|
|
847
|
+
*/
|
|
848
|
+
team;
|
|
849
|
+
/**
|
|
850
|
+
* Array of UserIds of responders assigned to this call.
|
|
851
|
+
*/
|
|
852
|
+
playerIds;
|
|
853
|
+
/**
|
|
854
|
+
* Array of Player instances of active responders assigned to this call.
|
|
855
|
+
*/
|
|
856
|
+
players;
|
|
857
|
+
/**
|
|
858
|
+
* The game position coordinates [x, y] of the call.
|
|
859
|
+
*/
|
|
860
|
+
position;
|
|
861
|
+
/**
|
|
862
|
+
* Unix timestamp of when the call was started.
|
|
863
|
+
*/
|
|
864
|
+
startedAt;
|
|
865
|
+
/**
|
|
866
|
+
* The unique call number.
|
|
867
|
+
*/
|
|
868
|
+
callNumber;
|
|
869
|
+
/**
|
|
870
|
+
* The description text of the emergency call.
|
|
871
|
+
*/
|
|
872
|
+
description;
|
|
873
|
+
/**
|
|
874
|
+
* Positional description of where the call was made.
|
|
875
|
+
*/
|
|
876
|
+
positionDescriptor;
|
|
877
|
+
/**
|
|
878
|
+
* Creates an instance of EmergencyCall.
|
|
879
|
+
* @param client - The ERLCApi client.
|
|
880
|
+
* @param data - The raw emergency call data to initialize.
|
|
881
|
+
*/
|
|
882
|
+
constructor(client, data) {
|
|
883
|
+
super(client);
|
|
884
|
+
this._patch(data);
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Patches the EmergencyCall structure with new raw data.
|
|
888
|
+
* @param data - The new raw emergency call data.
|
|
889
|
+
* @returns This emergency call instance.
|
|
890
|
+
*/
|
|
891
|
+
_patch(data) {
|
|
892
|
+
this.callerId = data.Caller;
|
|
893
|
+
this.caller = this.client.players.cache.get(this.callerId);
|
|
894
|
+
this.team = data.Team;
|
|
895
|
+
this.playerIds = data.Players;
|
|
896
|
+
this.players = [];
|
|
897
|
+
for (const playerId of data.Players) {
|
|
898
|
+
const player = this.client.players.cache.get(playerId);
|
|
899
|
+
if (player) this.players.push(player);
|
|
900
|
+
}
|
|
901
|
+
this.position = data.Position;
|
|
902
|
+
this.startedAt = data.StartedAt;
|
|
903
|
+
this.callNumber = data.CallNumber;
|
|
904
|
+
this.description = data.Description;
|
|
905
|
+
this.positionDescriptor = data.PositionDescriptor;
|
|
906
|
+
return this;
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* Converts this EmergencyCall instance to raw JSON representation.
|
|
910
|
+
* @returns The raw emergency call data.
|
|
911
|
+
*/
|
|
912
|
+
toJSON() {
|
|
913
|
+
return {
|
|
914
|
+
Caller: this.callerId,
|
|
915
|
+
Team: this.team,
|
|
916
|
+
Players: this.playerIds,
|
|
917
|
+
Position: this.position,
|
|
918
|
+
StartedAt: this.startedAt,
|
|
919
|
+
CallNumber: this.callNumber,
|
|
920
|
+
Description: this.description,
|
|
921
|
+
PositionDescriptor: this.positionDescriptor
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
};
|
|
925
|
+
|
|
926
|
+
// src/managers/emergencycallmanager.ts
|
|
927
|
+
var EmergencyCallManager = class {
|
|
928
|
+
/**
|
|
929
|
+
* Creates an instance of EmergencyCallManager.
|
|
930
|
+
* @param client - The ERLCApi client.
|
|
931
|
+
*/
|
|
932
|
+
constructor(client) {
|
|
933
|
+
this.client = client;
|
|
934
|
+
}
|
|
935
|
+
client;
|
|
936
|
+
/**
|
|
937
|
+
* Map cache of active emergency calls, keyed by call number.
|
|
938
|
+
*/
|
|
939
|
+
cache = /* @__PURE__ */ new Map();
|
|
940
|
+
/**
|
|
941
|
+
* Fetches all active emergency calls from the game server.
|
|
942
|
+
* Updates the emergency call cache.
|
|
943
|
+
* @returns A promise resolving to a Map of active EmergencyCalls.
|
|
944
|
+
*/
|
|
945
|
+
async fetchAll() {
|
|
946
|
+
const rawServer = await this.client.rest.request("GET", "/v2/server?EmergencyCalls=true");
|
|
947
|
+
const rawEmergencyCalls = rawServer.EmergencyCalls ?? [];
|
|
948
|
+
return this.updateCache(rawEmergencyCalls);
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Re-synchronizes the cache with the raw emergency calls payload.
|
|
952
|
+
* Emits emergencyCallAdd, emergencyCallRemove, and emergencyCallUpdate events.
|
|
953
|
+
* @param rawCalls - Raw active emergency calls payload.
|
|
954
|
+
* @returns The updated EmergencyCall cache Map.
|
|
955
|
+
*/
|
|
956
|
+
updateCache(rawCalls) {
|
|
957
|
+
const activeCalls = /* @__PURE__ */ new Set();
|
|
958
|
+
for (const rawData of rawCalls) {
|
|
959
|
+
const callNum = rawData.CallNumber;
|
|
960
|
+
activeCalls.add(callNum);
|
|
961
|
+
const cachedCall = this.cache.get(callNum);
|
|
962
|
+
if (cachedCall) {
|
|
963
|
+
const oldCall = new EmergencyCall(this.client, cachedCall.toJSON());
|
|
964
|
+
cachedCall._patch(rawData);
|
|
965
|
+
this.client.emit("EMERGENCY_CALL_UPDATE" /* emergencyCallUpdate */, oldCall, cachedCall);
|
|
966
|
+
} else {
|
|
967
|
+
const newCall = new EmergencyCall(this.client, rawData);
|
|
968
|
+
this.cache.set(newCall.callNumber, newCall);
|
|
969
|
+
this.client.emit("EMERGENCY_CALL_ADD" /* emergencyCallAdd */, newCall);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
for (const cachedCall of this.cache.keys()) {
|
|
973
|
+
if (!activeCalls.has(cachedCall)) {
|
|
974
|
+
this.client.emit("EMERGENCY_CALL_REMOVE" /* emergencyCallRemove */, this.cache.get(cachedCall));
|
|
975
|
+
this.cache.delete(cachedCall);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
return this.cache;
|
|
979
|
+
}
|
|
980
|
+
};
|
|
981
|
+
|
|
982
|
+
// src/structures/killlog.ts
|
|
983
|
+
var KillLog = class extends Base {
|
|
984
|
+
/**
|
|
985
|
+
* The Player instance representing the player who was killed.
|
|
986
|
+
*/
|
|
987
|
+
killed;
|
|
988
|
+
/**
|
|
989
|
+
* The UserId of the player who was killed.
|
|
990
|
+
*/
|
|
991
|
+
killedId;
|
|
992
|
+
/**
|
|
993
|
+
* The Roblox username of the player who was killed.
|
|
994
|
+
*/
|
|
995
|
+
killedUsername;
|
|
996
|
+
/**
|
|
997
|
+
* The Player instance representing the player who did the killing.
|
|
998
|
+
*/
|
|
999
|
+
killer;
|
|
1000
|
+
/**
|
|
1001
|
+
* The UserId of the player who did the killing.
|
|
1002
|
+
*/
|
|
1003
|
+
killerId;
|
|
1004
|
+
/**
|
|
1005
|
+
* The Roblox username of the player who did the killing.
|
|
1006
|
+
*/
|
|
1007
|
+
killerUsername;
|
|
1008
|
+
/**
|
|
1009
|
+
* Unix timestamp of when the kill occurred.
|
|
1010
|
+
*/
|
|
1011
|
+
timestamp;
|
|
1012
|
+
/**
|
|
1013
|
+
* Creates an instance of KillLog.
|
|
1014
|
+
* @param client - The ERLCApi client.
|
|
1015
|
+
* @param data - The raw kill log data.
|
|
1016
|
+
*/
|
|
1017
|
+
constructor(client, data) {
|
|
1018
|
+
super(client);
|
|
1019
|
+
this._patch(data);
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* Patches the KillLog structure with new raw data.
|
|
1023
|
+
* @param data - The new raw kill log data.
|
|
1024
|
+
* @returns This kill log instance.
|
|
1025
|
+
*/
|
|
1026
|
+
_patch(data) {
|
|
1027
|
+
const splitKilled = data.Killed.split(":");
|
|
1028
|
+
const splitKiller = data.Killer.split(":");
|
|
1029
|
+
this.killedId = Number(splitKilled[1]);
|
|
1030
|
+
this.killedUsername = splitKilled[0];
|
|
1031
|
+
this.killed = this.client.players.cache.get(this.killedId);
|
|
1032
|
+
this.killerId = Number(splitKiller[1]);
|
|
1033
|
+
this.killerUsername = splitKiller[0];
|
|
1034
|
+
this.killer = this.client.players.cache.get(this.killerId);
|
|
1035
|
+
this.timestamp = data.Timestamp;
|
|
1036
|
+
return this;
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Converts this KillLog instance to raw JSON representation.
|
|
1040
|
+
* @returns The raw kill log data.
|
|
1041
|
+
*/
|
|
1042
|
+
toJSON() {
|
|
1043
|
+
return {
|
|
1044
|
+
Killed: `${this.killedUsername}:${this.killedId}`,
|
|
1045
|
+
Killer: `${this.killerUsername}:${this.killerId}`,
|
|
1046
|
+
Timestamp: this.timestamp
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
// src/managers/killlogmanager.ts
|
|
1052
|
+
var KillLogManager = class {
|
|
1053
|
+
/**
|
|
1054
|
+
* Creates an instance of KillLogManager.
|
|
1055
|
+
* @param client - The ERLCApi client.
|
|
1056
|
+
*/
|
|
1057
|
+
constructor(client) {
|
|
1058
|
+
this.client = client;
|
|
1059
|
+
}
|
|
1060
|
+
client;
|
|
1061
|
+
/**
|
|
1062
|
+
* Map cache of logged kills, keyed by a composite `Killer:Killed:Timestamp` key.
|
|
1063
|
+
*/
|
|
1064
|
+
cache = /* @__PURE__ */ new Map();
|
|
1065
|
+
/**
|
|
1066
|
+
* Fetches all kill logs from the game server.
|
|
1067
|
+
* Updates the kill log cache.
|
|
1068
|
+
* @returns A promise resolving to a Map of KillLogs.
|
|
1069
|
+
*/
|
|
1070
|
+
async fetchAll() {
|
|
1071
|
+
const rawServer = await this.client.rest.request("GET", "/v2/server?KillLogs=true");
|
|
1072
|
+
const rawKillLogs = rawServer.KillLogs ?? [];
|
|
1073
|
+
return this.updateCache(rawKillLogs);
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Re-synchronizes the cache with the raw kill logs.
|
|
1077
|
+
* Emits a kill event for new logs.
|
|
1078
|
+
* @param rawCommands - Raw kill logs payload.
|
|
1079
|
+
* @returns The updated KillLog cache Map.
|
|
1080
|
+
*/
|
|
1081
|
+
updateCache(rawCommands) {
|
|
1082
|
+
for (const rawData of rawCommands) {
|
|
1083
|
+
const key = `${rawData.Killer}:${rawData.Killed}:${rawData.Timestamp}`;
|
|
1084
|
+
const cachedPlayer = this.cache.get(key);
|
|
1085
|
+
if (!cachedPlayer) {
|
|
1086
|
+
const newKill = new KillLog(this.client, rawData);
|
|
1087
|
+
this.cache.set(key, newKill);
|
|
1088
|
+
this.client.emit("KILL" /* kill */, newKill);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
return this.cache;
|
|
1092
|
+
}
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
// src/structures/modcall.ts
|
|
1096
|
+
var ModCall = class extends Base {
|
|
1097
|
+
/**
|
|
1098
|
+
* The Player instance representing the caller.
|
|
1099
|
+
*/
|
|
1100
|
+
caller;
|
|
1101
|
+
/**
|
|
1102
|
+
* The UserId of the player who made the moderator call.
|
|
1103
|
+
*/
|
|
1104
|
+
callerId;
|
|
1105
|
+
/**
|
|
1106
|
+
* The Roblox username of the caller.
|
|
1107
|
+
*/
|
|
1108
|
+
callerUsername;
|
|
1109
|
+
/**
|
|
1110
|
+
* Unix timestamp of the moderator call.
|
|
1111
|
+
*/
|
|
1112
|
+
timestamp;
|
|
1113
|
+
/**
|
|
1114
|
+
* The Player instance representing the moderator who responded, if any.
|
|
1115
|
+
*/
|
|
1116
|
+
moderator;
|
|
1117
|
+
/**
|
|
1118
|
+
* The UserId of the moderator who responded, if any.
|
|
1119
|
+
*/
|
|
1120
|
+
moderatorId;
|
|
1121
|
+
/**
|
|
1122
|
+
* The Roblox username of the moderator who responded, if any.
|
|
1123
|
+
*/
|
|
1124
|
+
moderatorUsername;
|
|
1125
|
+
/**
|
|
1126
|
+
* Creates an instance of ModCall.
|
|
1127
|
+
* @param client - The ERLCApi client.
|
|
1128
|
+
* @param data - The raw moderator call data.
|
|
1129
|
+
*/
|
|
1130
|
+
constructor(client, data) {
|
|
1131
|
+
super(client);
|
|
1132
|
+
this._patch(data);
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* Patches the ModCall structure with new raw data.
|
|
1136
|
+
* @param data - The new raw moderator call data.
|
|
1137
|
+
* @returns This moderator call instance.
|
|
1138
|
+
*/
|
|
1139
|
+
_patch(data) {
|
|
1140
|
+
const splitCaller = data.Caller.split(":");
|
|
1141
|
+
this.callerId = Number(splitCaller[1]);
|
|
1142
|
+
this.callerUsername = splitCaller[0];
|
|
1143
|
+
this.caller = this.client.players.cache.get(this.callerId);
|
|
1144
|
+
if (data.Moderator) {
|
|
1145
|
+
const splitModerator = data.Moderator.split(":");
|
|
1146
|
+
this.moderatorId = Number(splitModerator[1]);
|
|
1147
|
+
this.moderatorUsername = splitModerator[0];
|
|
1148
|
+
this.moderator = this.client.players.cache.get(this.moderatorId);
|
|
1149
|
+
}
|
|
1150
|
+
this.timestamp = data.Timestamp;
|
|
1151
|
+
return this;
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Converts this ModCall instance to raw JSON representation.
|
|
1155
|
+
* @returns The raw moderator call data.
|
|
1156
|
+
*/
|
|
1157
|
+
toJSON() {
|
|
1158
|
+
if (this.moderatorId) return {
|
|
1159
|
+
Caller: `${this.callerUsername}:${this.callerId}`,
|
|
1160
|
+
Timestamp: this.timestamp,
|
|
1161
|
+
Moderator: `${this.moderatorUsername}:${this.moderatorId}`
|
|
1162
|
+
};
|
|
1163
|
+
return {
|
|
1164
|
+
Caller: `${this.callerUsername}:${this.callerId}`,
|
|
1165
|
+
Timestamp: this.timestamp
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
|
|
1170
|
+
// src/managers/modcallmanager.ts
|
|
1171
|
+
var ModCallManager = class {
|
|
1172
|
+
/**
|
|
1173
|
+
* Creates an instance of ModCallManager.
|
|
1174
|
+
* @param client - The ERLCApi client.
|
|
1175
|
+
*/
|
|
1176
|
+
constructor(client) {
|
|
1177
|
+
this.client = client;
|
|
1178
|
+
}
|
|
1179
|
+
client;
|
|
1180
|
+
/**
|
|
1181
|
+
* Map cache of logged moderator calls, keyed by a composite `Caller:Timestamp` key.
|
|
1182
|
+
*/
|
|
1183
|
+
cache = /* @__PURE__ */ new Map();
|
|
1184
|
+
/**
|
|
1185
|
+
* Fetches all moderator calls from the game server.
|
|
1186
|
+
* Updates the moderator call cache.
|
|
1187
|
+
* @returns A promise resolving to a Map of ModCalls.
|
|
1188
|
+
*/
|
|
1189
|
+
async fetchAll() {
|
|
1190
|
+
const rawServer = await this.client.rest.request("GET", "/v2/server?ModCalls=true");
|
|
1191
|
+
const rawModCalls = rawServer.ModCalls ?? [];
|
|
1192
|
+
return this.updateCache(rawModCalls);
|
|
1193
|
+
}
|
|
1194
|
+
/**
|
|
1195
|
+
* Re-synchronizes the cache with the raw moderator calls.
|
|
1196
|
+
* Emits a modCall event for new calls.
|
|
1197
|
+
* @param rawCommands - Raw moderator calls payload.
|
|
1198
|
+
* @returns The updated ModCall cache Map.
|
|
1199
|
+
*/
|
|
1200
|
+
updateCache(rawCommands) {
|
|
1201
|
+
for (const rawData of rawCommands) {
|
|
1202
|
+
const key = `${rawData.Caller}:${rawData.Timestamp}`;
|
|
1203
|
+
const cachedPlayer = this.cache.get(key);
|
|
1204
|
+
if (!cachedPlayer) {
|
|
1205
|
+
const newCall = new ModCall(this.client, rawData);
|
|
1206
|
+
this.cache.set(key, newCall);
|
|
1207
|
+
this.client.emit("MOD_CALL" /* modCall */, newCall);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
return this.cache;
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
|
|
1214
|
+
// src/client/client.ts
|
|
1215
|
+
var ERLCEvents = /* @__PURE__ */ ((ERLCEvents2) => {
|
|
1216
|
+
ERLCEvents2["poll"] = "POLL";
|
|
1217
|
+
ERLCEvents2["serverUpdate"] = "SERVER_UPDATE";
|
|
1218
|
+
ERLCEvents2["serverCreate"] = "SERVER_CREATE";
|
|
1219
|
+
ERLCEvents2["playerJoin"] = "PLAYER_JOIN";
|
|
1220
|
+
ERLCEvents2["playerUpdate"] = "PLAYER_UPDATE";
|
|
1221
|
+
ERLCEvents2["playerLeave"] = "PLAYER_LEAVE";
|
|
1222
|
+
ERLCEvents2["vehicleAdd"] = "VEHICLE_ADD";
|
|
1223
|
+
ERLCEvents2["vehicleRemove"] = "VEHICLE_REMOVE";
|
|
1224
|
+
ERLCEvents2["vehicleUpdate"] = "VEHICLE_UPDATE";
|
|
1225
|
+
ERLCEvents2["command"] = "COMMAND";
|
|
1226
|
+
ERLCEvents2["modCall"] = "MOD_CALL";
|
|
1227
|
+
ERLCEvents2["kill"] = "KILL";
|
|
1228
|
+
ERLCEvents2["emergencyCallAdd"] = "EMERGENCY_CALL_ADD";
|
|
1229
|
+
ERLCEvents2["emergencyCallRemove"] = "EMERGENCY_CALL_REMOVE";
|
|
1230
|
+
ERLCEvents2["emergencyCallUpdate"] = "EMERGENCY_CALL_UPDATE";
|
|
1231
|
+
return ERLCEvents2;
|
|
1232
|
+
})(ERLCEvents || {});
|
|
1233
|
+
var Client18 = class extends import_node_events.EventEmitter {
|
|
1234
|
+
/**
|
|
1235
|
+
* Creates an instance of Client.
|
|
1236
|
+
* @param options - The ClientOptions configuration.
|
|
1237
|
+
*/
|
|
1238
|
+
constructor(options) {
|
|
1239
|
+
super();
|
|
1240
|
+
this.options = options;
|
|
1241
|
+
this.rest = new RestManager(options);
|
|
1242
|
+
this.server = new ServerManager(this);
|
|
1243
|
+
this.players = new PlayerManager(this);
|
|
1244
|
+
this.commands = new CommandManager(this);
|
|
1245
|
+
this.vehicles = new VehicleManager(this);
|
|
1246
|
+
this.commandLogs = new CommandLogManager(this);
|
|
1247
|
+
this.emergencyCalls = new EmergencyCallManager(this);
|
|
1248
|
+
this.killLogs = new KillLogManager(this);
|
|
1249
|
+
this.modCalls = new ModCallManager(this);
|
|
1250
|
+
if (options.webhook?.enabled) {
|
|
1251
|
+
this.gateway = new WebhookServer(this);
|
|
1252
|
+
this.gateway.listen();
|
|
1253
|
+
}
|
|
1254
|
+
if (options.polling) {
|
|
1255
|
+
this.startPolling();
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
options;
|
|
1259
|
+
/** REST Manager for sending manual requests to the ER:LC API. */
|
|
1260
|
+
rest;
|
|
1261
|
+
/** Manager for fetching and caching general server configuration. */
|
|
1262
|
+
server;
|
|
1263
|
+
/** Manager for player caching, joining, and management actions. */
|
|
1264
|
+
players;
|
|
1265
|
+
/** Manager for executing server-side console commands. */
|
|
1266
|
+
commands;
|
|
1267
|
+
/** Manager for spawned vehicles cache and events. */
|
|
1268
|
+
vehicles;
|
|
1269
|
+
/** Manager for command execution log events. */
|
|
1270
|
+
commandLogs;
|
|
1271
|
+
/** Manager for active emergency calls. */
|
|
1272
|
+
emergencyCalls;
|
|
1273
|
+
/** Manager for kill logs. */
|
|
1274
|
+
killLogs;
|
|
1275
|
+
/** Manager for moderator call logs. */
|
|
1276
|
+
modCalls;
|
|
1277
|
+
/** Webhook Gateway server instance, if enabled. */
|
|
1278
|
+
gateway;
|
|
1279
|
+
/**
|
|
1280
|
+
* Starts the periodic api-polling loop if enabled.
|
|
1281
|
+
*/
|
|
1282
|
+
startPolling() {
|
|
1283
|
+
console.log("begin polling");
|
|
1284
|
+
setInterval(async () => {
|
|
1285
|
+
try {
|
|
1286
|
+
const server = await this.server.fetch();
|
|
1287
|
+
this.emit("POLL" /* poll */, server);
|
|
1288
|
+
console.log("fetch");
|
|
1289
|
+
if (server.Players) this.players.updateCache(server.Players);
|
|
1290
|
+
if (server.Vehicles) this.vehicles.updateCache(server.Vehicles);
|
|
1291
|
+
if (server.CommandLogs) this.commandLogs.updateCache(server.CommandLogs);
|
|
1292
|
+
if (server.EmergencyCalls) this.emergencyCalls.updateCache(server.EmergencyCalls);
|
|
1293
|
+
if (server.KillLogs) this.killLogs.updateCache(server.KillLogs);
|
|
1294
|
+
if (server.ModCalls) this.modCalls.updateCache(server.ModCalls);
|
|
1295
|
+
} catch (err) {
|
|
1296
|
+
this.emit("error", err);
|
|
1297
|
+
}
|
|
1298
|
+
}, 5e3);
|
|
1299
|
+
}
|
|
1300
|
+
};
|
|
1301
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1302
|
+
0 && (module.exports = {
|
|
1303
|
+
Base,
|
|
1304
|
+
Client,
|
|
1305
|
+
CommandLog,
|
|
1306
|
+
CommandLogManager,
|
|
1307
|
+
CommandManager,
|
|
1308
|
+
ERLCEvents,
|
|
1309
|
+
EmergencyCall,
|
|
1310
|
+
EmergencyCallManager,
|
|
1311
|
+
InvalidServerKeyError,
|
|
1312
|
+
KillLog,
|
|
1313
|
+
KillLogManager,
|
|
1314
|
+
ModCall,
|
|
1315
|
+
ModCallManager,
|
|
1316
|
+
Player,
|
|
1317
|
+
PlayerManager,
|
|
1318
|
+
RestManager,
|
|
1319
|
+
Server,
|
|
1320
|
+
ServerManager,
|
|
1321
|
+
Vehicle,
|
|
1322
|
+
VehicleManager,
|
|
1323
|
+
WebhookServer
|
|
1324
|
+
});
|