moons-ta-client 1.0.2 → 1.0.4

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.
Files changed (43) hide show
  1. package/dist/client.d.ts +22 -0
  2. package/dist/client.js +77 -0
  3. package/dist/constants.d.ts +4 -0
  4. package/{src/constants.ts → dist/constants.js} +1 -1
  5. package/dist/custom-event-emitter.d.ts +7 -0
  6. package/dist/custom-event-emitter.js +16 -0
  7. package/dist/index.d.ts +4592 -0
  8. package/dist/index.esm.js +16502 -0
  9. package/{src/index.ts → dist/index.js} +1 -1
  10. package/dist/models/commands.d.ts +116 -0
  11. package/{src/models/commands.ts → dist/models/commands.js} +17 -102
  12. package/dist/models/discord.d.ts +76 -0
  13. package/{src/models/discord.ts → dist/models/discord.js} +15 -62
  14. package/dist/models/events.d.ts +419 -0
  15. package/{src/models/events.ts → dist/models/events.js} +89 -354
  16. package/dist/models/index.js +8 -0
  17. package/dist/models/models.d.ts +1137 -0
  18. package/{src/models/models.ts → dist/models/models.js} +200 -799
  19. package/dist/models/packets.d.ts +144 -0
  20. package/{src/models/packets.ts → dist/models/packets.js} +26 -126
  21. package/dist/models/pushes.d.ts +122 -0
  22. package/{src/models/pushes.ts → dist/models/pushes.js} +24 -96
  23. package/dist/models/requests.d.ts +1694 -0
  24. package/{src/models/requests.ts → dist/models/requests.js} +323 -1469
  25. package/dist/models/responses.d.ts +799 -0
  26. package/{src/models/responses.ts → dist/models/responses.js} +161 -669
  27. package/dist/scraper.d.ts +2 -0
  28. package/dist/scraper.js +87 -0
  29. package/dist/state-manager.d.ts +50 -0
  30. package/dist/state-manager.js +196 -0
  31. package/dist/tournament-assistant-client.d.ts +114 -0
  32. package/dist/tournament-assistant-client.js +1170 -0
  33. package/package.json +8 -2
  34. package/rollup.config.mjs +0 -16
  35. package/scripts/esbuild.mjs +0 -24
  36. package/scripts/fixImports.mjs +0 -44
  37. package/src/client.ts +0 -101
  38. package/src/custom-event-emitter.ts +0 -21
  39. package/src/scraper.ts +0 -137
  40. package/src/state-manager.ts +0 -308
  41. package/src/tournament-assistant-client.ts +0 -1553
  42. package/tsconfig.json +0 -27
  43. /package/{src/models/index.ts → dist/models/index.d.ts} +0 -0
@@ -1,1553 +0,0 @@
1
- import { Client } from "./client.js";
2
- import { CustomEventEmitter } from "./custom-event-emitter.js";
3
- import { v4 as uuidv4 } from "uuid";
4
- import {
5
- User,
6
- Match,
7
- QualifierEvent,
8
- CoreServer,
9
- Tournament,
10
- GameplayParameters,
11
- Map,
12
- QualifierEvent_EventSettings,
13
- QualifierEvent_LeaderboardSort,
14
- Tournament_TournamentSettings_Team,
15
- Tournament_TournamentSettings_Pool,
16
- Permissions,
17
- } from "./models/models.js";
18
- import { Packet } from "./models/packets.js";
19
- import { StateManager } from "./state-manager.js";
20
- import {
21
- Response,
22
- Response_Connect,
23
- Response_ResponseType,
24
- } from "./models/responses.js";
25
- import { Request, Request_LoadSong } from "./models/requests.js";
26
- import { Command } from "./models/commands.js";
27
- import { versionCode } from "./constants.js";
28
- import { Channel, Push_SongFinished } from "./models/index.js";
29
- import WebSocket from "ws";
30
-
31
- // Created by Moon on 6/12/2022
32
-
33
- export * from "./scraper.js";
34
- export * from "./models/models.js";
35
-
36
- export type ResponseFromUser = { userId: string; response: Response };
37
-
38
- type TAClientEvents = {
39
- connectedToServer: Response_Connect;
40
- connectingToServer: {};
41
- failedToConnectToServer: {};
42
- disconnectedFromServer: {};
43
-
44
- authorizationRequestedFromServer: string;
45
- authorizedWithServer: string;
46
- failedToAuthorizeWithServer: {};
47
-
48
- loadSongRequested: [string, string, Request_LoadSong];
49
-
50
- songFinished: Push_SongFinished;
51
-
52
- responseReceived: ResponseFromUser;
53
-
54
- joinedTournament: {};
55
- failedToJoinTournament: {};
56
-
57
- createdTournament: {};
58
- updatedTournament: {};
59
- deletedTournament: {};
60
- failedToCreateTournament: {};
61
- failedToUpdateTournament: {};
62
- failedToDeleteTournament: {};
63
-
64
- createdMatch: {};
65
- updatedMatch: {};
66
- deletedMatch: {};
67
- failedToCreateMatch: {};
68
- failedToUpdateMatch: {};
69
- failedToDeleteMatch: {};
70
-
71
- createdQualifier: {};
72
- updatedQualifier: {};
73
- deletedQualifier: {};
74
- failedToCreateQualifier: {};
75
- failedToUpdateQualifier: {};
76
- failedToDeleteQualifier: {};
77
- };
78
-
79
- export class TAClient extends CustomEventEmitter<TAClientEvents> {
80
- public stateManager: StateManager;
81
-
82
- private client?: Client;
83
- private token = "";
84
-
85
- private shouldHeartbeat = false;
86
- private heartbeatInterval: NodeJS.Timeout | undefined;
87
-
88
- constructor() {
89
- super();
90
- this.stateManager = new StateManager();
91
- }
92
-
93
- // --- State helpers --- //
94
- public get isConnected() {
95
- return this.client?.isConnected ?? false;
96
- }
97
-
98
- public get isConnecting() {
99
- return this.client?.readyState === WebSocket.CONNECTING;
100
- }
101
-
102
- // --- Actions --- //
103
- public async connect(serverAddress: string, port: string) {
104
- this.shouldHeartbeat = true;
105
-
106
- this.client = new Client(serverAddress, port, this.token);
107
-
108
- this.client.on("packetReceived", this.handlePacket);
109
-
110
- this.client.on("disconnectedFromServer", () => {
111
- clearInterval(this.heartbeatInterval!);
112
-
113
- console.info("Disconnected from server!");
114
- this.emit("disconnectedFromServer", {});
115
- });
116
-
117
- this.client.on("failedToConnectToServer", () => {
118
- console.error("Failed to connect to server!");
119
- this.emit("failedToConnectToServer", {});
120
- });
121
-
122
- this.emit("connectingToServer", {});
123
-
124
- // Create a promise that resolves when connected to the server
125
- const connectPromise = new Promise<Response>((resolve, reject) => {
126
- const onConnectedToServer = async () => {
127
- const response = await this.sendRequest({
128
- type: {
129
- oneofKind: "connect",
130
- connect: {
131
- clientVersion: versionCode,
132
- },
133
- },
134
- });
135
-
136
- if (this.shouldHeartbeat) {
137
- this.heartbeatInterval = setInterval(() => {
138
- this.client?.send({
139
- token: this.token,
140
- from: this.stateManager.getSelfGuid(),
141
- id: uuidv4(),
142
- packet: {
143
- oneofKind: "command",
144
- command: {
145
- type: {
146
- oneofKind: "heartbeat",
147
- heartbeat: true,
148
- },
149
- },
150
- },
151
- });
152
- }, 10000);
153
- }
154
-
155
- this.client?.removeListener("connectedToServer", onConnectedToServer);
156
-
157
- clearTimeout(timeout);
158
-
159
- if (response.length <= 0) {
160
- reject("Server timed out");
161
- } else {
162
- resolve(response[0].response);
163
- }
164
- };
165
-
166
- // Return what we have after 5 seconds
167
- const createTimeout = (time: number) => {
168
- return setTimeout(() => {
169
- this.client?.removeListener("connectedToServer", onConnectedToServer);
170
- reject("Server timed out");
171
- }, time);
172
- };
173
-
174
- const timeout = createTimeout(30000);
175
-
176
- this.client?.on("connectedToServer", onConnectedToServer);
177
- });
178
-
179
- this.client.connect();
180
-
181
- return connectPromise;
182
- }
183
-
184
- public disconnect() {
185
- this.shouldHeartbeat = false;
186
-
187
- console.info(`Disconnecting from server!`);
188
- this.client?.disconnect();
189
- }
190
-
191
- public setAuthToken(token: string) {
192
- this.token = token;
193
- this.client?.setToken(token);
194
- }
195
-
196
- private forwardToUsers(packet: Packet, to: string[]) {
197
- this.client?.send({
198
- token: "", // Overridden in this.send()
199
- from: packet.from,
200
- id: packet.id,
201
- packet: {
202
- oneofKind: "forwardingPacket",
203
- forwardingPacket: {
204
- forwardTo: to,
205
- packet,
206
- },
207
- },
208
- });
209
- }
210
-
211
- private sendCommand(command: Command, to: string[]) {
212
- const packet: Packet = {
213
- token: this.token,
214
- from: this.stateManager.getSelfGuid(),
215
- id: uuidv4(),
216
- packet: {
217
- oneofKind: "command",
218
- command,
219
- },
220
- };
221
-
222
- this.forwardToUsers(packet, to);
223
- }
224
-
225
- private async sendRequest(
226
- request: Request,
227
- to?: string[]
228
- ): Promise<ResponseFromUser[]> {
229
- const packet: Packet = {
230
- token: "", // Overridden in this.send()
231
- from: this.stateManager.getSelfGuid(),
232
- id: uuidv4(),
233
- packet: {
234
- oneofKind: "request",
235
- request,
236
- },
237
- };
238
-
239
- const responseDictionary: ResponseFromUser[] = [];
240
-
241
- // Create a promise that resolves when all responses are received
242
- const responsesPromise = new Promise<ResponseFromUser[]>((resolve) => {
243
- const addListeners = () => {
244
- this.on("responseReceived", onResponseReceived);
245
- this.on("authorizationRequestedFromServer", onAuthorizationRequested);
246
- this.on("authorizedWithServer", onAuthroizedWithServer);
247
- };
248
-
249
- const removeListeners = () => {
250
- this.removeListener("responseReceived", onResponseReceived);
251
- this.removeListener(
252
- "authorizationRequestedFromServer",
253
- onAuthorizationRequested
254
- );
255
- this.removeListener("authorizedWithServer", onAuthroizedWithServer);
256
- };
257
-
258
- // Check that we got responses from all expected users
259
- const checkResponses = () => {
260
- const responseUsers = responseDictionary.map((x) => x.userId);
261
- const expectedUsers = to ?? ["00000000-0000-0000-0000-000000000000"]; // If we didn't forward this to any users, we should expect a response from the server
262
-
263
- if (responseUsers.length !== expectedUsers.length) {
264
- return;
265
- }
266
-
267
- const sortedArr1 = responseUsers.slice().sort();
268
- const sortedArr2 = expectedUsers.slice().sort();
269
-
270
- for (let i = 0; i < sortedArr1.length; i++) {
271
- if (sortedArr1[i] !== sortedArr2[i]) {
272
- return;
273
- }
274
- }
275
-
276
- // All responses are received, clean up and resolve
277
- removeListeners();
278
- clearTimeout(timeout);
279
- resolve(responseDictionary);
280
- };
281
-
282
- // Add to the dictionary when the response is to this packet, and from an expected user
283
- const onResponseReceived = (response: ResponseFromUser) => {
284
- const expectedUsers = to ?? ["00000000-0000-0000-0000-000000000000"]; // If we didn't forward this to any users, we should expect a response from the server
285
-
286
- if (
287
- response.response.respondingToPacketId === packet.id &&
288
- expectedUsers.includes(response.userId)
289
- ) {
290
- responseDictionary.push({
291
- userId: response.userId,
292
- response: response.response,
293
- });
294
-
295
- checkResponses();
296
- }
297
- };
298
-
299
- // Return what we have after 5 seconds
300
- const createTimeout = (time: number) => {
301
- return setTimeout(() => {
302
- removeListeners();
303
- resolve(responseDictionary);
304
- }, time);
305
- };
306
-
307
- const timeout = createTimeout(30000);
308
-
309
- // If authorization is requested, we're assuming an external application will handle
310
- // resetting the auth token, so we'll extend the timeout by 30 seconds and try again
311
- // if a successful auth is noticed
312
- const onAuthorizationRequested = () => {
313
- clearTimeout(timeout);
314
- createTimeout(30000);
315
- };
316
-
317
- // Retry on successful authorization
318
- const onAuthroizedWithServer = () => {
319
- sendRequest();
320
- };
321
-
322
- addListeners();
323
- });
324
-
325
- // Assume forwardToUsers emits the 'responseReceived' event asynchronously
326
- const sendRequest = () => {
327
- if (to) {
328
- this.forwardToUsers(packet, to);
329
- } else {
330
- this.client?.send(packet, to);
331
- }
332
- };
333
-
334
- sendRequest();
335
-
336
- return responsesPromise;
337
- }
338
-
339
- public async sendResponse(response: Response, to?: string[]) {
340
- const packet: Packet = {
341
- token: this.token,
342
- from: this.stateManager.getSelfGuid(),
343
- id: uuidv4(),
344
- packet: {
345
- oneofKind: "response",
346
- response,
347
- },
348
- };
349
-
350
- if (to) {
351
- this.forwardToUsers(packet, to);
352
- } else {
353
- this.client?.send(packet, to);
354
- }
355
- }
356
-
357
- // --- Commands --- //
358
- public playSong = (gameplayParameters: GameplayParameters, userIds: string[]) => {
359
- this.sendCommand({
360
- type: {
361
- oneofKind: "playSong",
362
- playSong: {
363
- gameplayParameters,
364
- },
365
- },
366
- }, userIds);
367
- };
368
-
369
- public returnToMenu = (userIds: string[]) => {
370
- this.sendCommand({
371
- type: {
372
- oneofKind: "returnToMenu",
373
- returnToMenu: true,
374
- },
375
- }, userIds);
376
- };
377
-
378
- public showLoadedImage = (userIds: string[]) => {
379
- this.sendCommand({
380
- type: {
381
- oneofKind: "streamSyncShowImage",
382
- streamSyncShowImage: true,
383
- },
384
- }, userIds);
385
- };
386
-
387
- public delayTestFinished = (userIds: string[]) => {
388
- this.sendCommand({
389
- type: {
390
- oneofKind: "delayTestFinish",
391
- delayTestFinish: true,
392
- },
393
- }, userIds);
394
- };
395
-
396
- // --- Requests --- //
397
- public joinTournament = async (tournamentId: string) => {
398
- const response = await this.sendRequest({
399
- type: {
400
- oneofKind: "join",
401
- join: {
402
- tournamentId,
403
- password: "",
404
- },
405
- },
406
- });
407
-
408
- if (response.length <= 0) {
409
- throw new Error("Server timed out");
410
- }
411
-
412
- return response[0].response;
413
- };
414
-
415
- public getLeaderboard = async (tournamentId: string, qualifierId: string, mapId: string) => {
416
- const response = await this.sendRequest({
417
- type: {
418
- oneofKind: "qualifierScores",
419
- qualifierScores: {
420
- tournamentId: tournamentId,
421
- eventId: qualifierId,
422
- mapId,
423
- },
424
- },
425
- });
426
-
427
- if (response.length <= 0) {
428
- throw new Error("Server timed out");
429
- }
430
-
431
- return response[0].response;
432
- };
433
-
434
- public loadSong = async (levelId: string, userIds: string[]) => {
435
- const response = await this.sendRequest({
436
- type: {
437
- oneofKind: "loadSong",
438
- loadSong: {
439
- levelId,
440
- customHostUrl: ""
441
- },
442
- },
443
- }, userIds);
444
-
445
- if (response.length <= 0) {
446
- throw new Error("Server timed out, or no users responded");
447
- }
448
-
449
- return response;
450
- };
451
-
452
- public loadImage = async (bitmap: Uint8Array, userIds: string[]) => {
453
- const response = await this.sendRequest({
454
- type: {
455
- oneofKind: "preloadImageForStreamSync",
456
- preloadImageForStreamSync: {
457
- fileId: uuidv4(),
458
- data: bitmap,
459
- compressed: false
460
- },
461
- },
462
- }, userIds);
463
-
464
- if (response.length <= 0) {
465
- throw new Error("Server timed out, or no users responded");
466
- }
467
-
468
- return response;
469
- };
470
-
471
- // --- Packet Handler --- //
472
- private handlePacket = (packet: Packet) => {
473
- this.stateManager.handlePacket(packet);
474
-
475
- // if (packet.packet.oneofKind !== "acknowledgement") {
476
- // const send: Packet = {
477
- // token: this.token,
478
- // from: this.stateManager.getSelfGuid(),
479
- // id: uuidv4(),
480
- // packet: {
481
- // oneofKind: "acknowledgement",
482
- // acknowledgement: {
483
- // packetId: packet.id,
484
- // type: Acknowledgement_AcknowledgementType.MessageReceived,
485
- // },
486
- // },
487
- // };
488
-
489
- // this.client?.send(send);
490
- // }
491
-
492
- if (packet.packet.oneofKind === "command") {
493
- const command = packet.packet.command;
494
-
495
- if (command.type.oneofKind === 'discordAuthorize') {
496
- this.emit(
497
- "authorizationRequestedFromServer",
498
- command.type.discordAuthorize
499
- );
500
- }
501
- } else if (packet.packet.oneofKind === 'request') {
502
- const request = packet.packet.request;
503
-
504
- if (request.type.oneofKind === 'loadSong') {
505
- this.emit("loadSongRequested", [packet.id, packet.from, request.type.loadSong]);
506
- }
507
- } else if (packet.packet.oneofKind === "response") {
508
- const response = packet.packet.response;
509
-
510
- this.emit("responseReceived", {
511
- userId: packet.from,
512
- response: response,
513
- });
514
-
515
- if (response.details.oneofKind === "connect") {
516
- const connect = response.details.connect;
517
-
518
- if (response.type === Response_ResponseType.Success) {
519
- console.info(`Successfully connected to server!`);
520
- this.emit("connectedToServer", connect);
521
- } else {
522
- console.error(
523
- `Failed to connect to server. Message: ${connect.message}`
524
- );
525
- this.emit("failedToConnectToServer", {});
526
- }
527
- } else if (response.details.oneofKind === "join") {
528
- const join = response.details.join;
529
-
530
- if (response.type === Response_ResponseType.Success) {
531
- console.info(`Successfully joined tournament!`);
532
- this.emit("joinedTournament", {});
533
- } else {
534
- console.error(`Failed to join server. Message: ${join.message}`);
535
- this.emit("failedToJoinTournament", {});
536
- }
537
- } else if (response.details.oneofKind === "createTournament") {
538
- const createTournament = response.details.createTournament;
539
-
540
- if (response.type === Response_ResponseType.Success) {
541
- console.info(`Successfully created tournament!`);
542
- this.emit("createdTournament", {});
543
- } else {
544
- console.error(
545
- `Failed to create tournament. Message: ${createTournament.message}`
546
- );
547
- this.emit("failedToCreateTournament", {});
548
- }
549
- } else if (response.details.oneofKind === "updateTournament") {
550
- const updateTournament = response.details.updateTournament;
551
-
552
- if (response.type === Response_ResponseType.Success) {
553
- console.info(`Successfully modified tournament!`);
554
- this.emit("updatedTournament", {});
555
- } else {
556
- console.error(
557
- `Failed update tournament. Message: ${updateTournament.message}`
558
- );
559
- this.emit("failedToUpdateTournament", {});
560
- }
561
- } else if (response.details.oneofKind === "deleteTournament") {
562
- const deleteTournament = response.details.deleteTournament;
563
-
564
- if (response.type === Response_ResponseType.Success) {
565
- console.info(`Successfully deleted tournament!`);
566
- this.emit("deletedTournament", {});
567
- } else {
568
- console.error(
569
- `Failed to delete tournament. Message: ${deleteTournament.message}`
570
- );
571
- this.emit("failedToDeleteTournament", {});
572
- }
573
- } else if (response.details.oneofKind === "createMatch") {
574
- const createMatch = response.details.createMatch;
575
-
576
- if (response.type === Response_ResponseType.Success) {
577
- console.info(`Successfully created match!`);
578
- this.emit("createdMatch", {});
579
- } else {
580
- console.error(
581
- `Failed to create Match. Message: ${createMatch.message}`
582
- );
583
- this.emit("failedToCreateMatch", {});
584
- }
585
- } else if (response.details.oneofKind === "updateMatch") {
586
- const updateMatch = response.details.updateMatch;
587
-
588
- if (response.type === Response_ResponseType.Success) {
589
- console.info(`Successfully modified match!`);
590
- this.emit("updatedMatch", {});
591
- } else {
592
- console.error(`Failed update Match. Message: ${updateMatch.message}`);
593
- this.emit("failedToUpdateMatch", {});
594
- }
595
- } else if (response.details.oneofKind === "deleteMatch") {
596
- const deleteMatch = response.details.deleteMatch;
597
-
598
- if (response.type === Response_ResponseType.Success) {
599
- console.info(`Successfully deleted match!`);
600
- this.emit("deletedMatch", {});
601
- } else {
602
- console.error(
603
- `Failed to delete Match. Message: ${deleteMatch.message}`
604
- );
605
- this.emit("failedToDeleteMatch", {});
606
- }
607
- } else if (response.details.oneofKind === "createQualifierEvent") {
608
- const createQualifierEvent = response.details.createQualifierEvent;
609
-
610
- if (response.type === Response_ResponseType.Success) {
611
- console.info(`Successfully created qualifier!`);
612
- this.emit("createdQualifier", {});
613
- } else {
614
- console.error(
615
- `Failed to create qualifier. Message: ${createQualifierEvent.message}`
616
- );
617
- this.emit("failedToCreateQualifier", {});
618
- }
619
- } else if (response.details.oneofKind === "updateQualifierEvent") {
620
- const modifyQualifier = response.details.updateQualifierEvent;
621
-
622
- if (response.type === Response_ResponseType.Success) {
623
- console.info(`Successfully modified qualifier!`);
624
- this.emit("updatedQualifier", {});
625
- } else {
626
- console.error(
627
- `Failed to update qualifier. Message: ${modifyQualifier.message}`
628
- );
629
- this.emit("failedToUpdateQualifier", {});
630
- }
631
- } else if (response.details.oneofKind === "deleteQualifierEvent") {
632
- const deleteQualifierEvent = response.details.deleteQualifierEvent;
633
-
634
- if (response.type === Response_ResponseType.Success) {
635
- console.info(`Successfully deleted qualifier!`);
636
- this.emit("deletedQualifier", {});
637
- } else {
638
- console.error(
639
- `Failed to delete qualifier. Message: ${deleteQualifierEvent.message}`
640
- );
641
- this.emit("failedToDeleteQualifier", {});
642
- }
643
- }
644
- } else if (packet.packet.oneofKind === "push") {
645
- const push = packet.packet.push;
646
-
647
- if (push.data.oneofKind === "discordAuthorized") {
648
- if (push.data.discordAuthorized.success) {
649
- this.emit("authorizedWithServer", push.data.discordAuthorized.token);
650
- } else {
651
- this.emit("failedToAuthorizeWithServer", {});
652
- }
653
- }
654
- else if (push.data.oneofKind === "songFinished") {
655
- this.emit("songFinished", push.data.songFinished);
656
- }
657
- }
658
- };
659
-
660
- // --- State Actions --- //
661
- public updateUser = async (tournamentId: string, user: User) => {
662
- const response = await this.sendRequest({
663
- type: {
664
- oneofKind: "updateUser",
665
- updateUser: {
666
- tournamentId,
667
- user,
668
- },
669
- },
670
- });
671
-
672
- if (response.length <= 0) {
673
- throw new Error("Server timed out");
674
- }
675
-
676
- return response[0].response;
677
- };
678
-
679
- public createMatch = async (tournamentId: string, match: Match) => {
680
- const response = await this.sendRequest({
681
- type: {
682
- oneofKind: "createMatch",
683
- createMatch: {
684
- tournamentId,
685
- match,
686
- },
687
- },
688
- });
689
-
690
- // Checking oneOfKind here helps typescript identify what type of response it is
691
- if (response.length <= 0) {
692
- throw new Error("Server timed out");
693
- }
694
-
695
- return response[0].response;
696
- };
697
-
698
-
699
- public addUserToMatch = async (tournamentId: string, matchId: string, userId: string) => {
700
- const response = await this.sendRequest({
701
- type: {
702
- oneofKind: "addUserToMatch",
703
- addUserToMatch: {
704
- tournamentId,
705
- matchId,
706
- userId
707
- },
708
- },
709
- });
710
-
711
- if (response.length <= 0) {
712
- throw new Error("Server timed out");
713
- }
714
-
715
- return response[0].response;
716
- };
717
-
718
- public removeUserFromMatch = async (tournamentId: string, matchId: string, userId: string) => {
719
- const response = await this.sendRequest({
720
- type: {
721
- oneofKind: "removeUserFromMatch",
722
- removeUserFromMatch: {
723
- tournamentId,
724
- matchId,
725
- userId
726
- },
727
- },
728
- });
729
-
730
- if (response.length <= 0) {
731
- throw new Error("Server timed out");
732
- }
733
-
734
- return response[0].response;
735
- };
736
-
737
- public setMatchLeader = async (tournamentId: string, matchId: string, userId: string) => {
738
- const response = await this.sendRequest({
739
- type: {
740
- oneofKind: "setMatchLeader",
741
- setMatchLeader: {
742
- tournamentId,
743
- matchId,
744
- userId
745
- },
746
- },
747
- });
748
-
749
- if (response.length <= 0) {
750
- throw new Error("Server timed out");
751
- }
752
-
753
- return response[0].response;
754
- };
755
-
756
- public setMatchMap = async (tournamentId: string, matchId: string, map: Map) => {
757
- const response = await this.sendRequest({
758
- type: {
759
- oneofKind: "setMatchMap",
760
- setMatchMap: {
761
- tournamentId,
762
- matchId,
763
- map
764
- },
765
- },
766
- });
767
-
768
- if (response.length <= 0) {
769
- throw new Error("Server timed out");
770
- }
771
-
772
- return response[0].response;
773
- };
774
-
775
- public deleteMatch = async (tournamentId: string, matchId: string) => {
776
- const response = await this.sendRequest({
777
- type: {
778
- oneofKind: "deleteMatch",
779
- deleteMatch: {
780
- tournamentId,
781
- matchId,
782
- },
783
- },
784
- });
785
-
786
- if (response.length <= 0) {
787
- throw new Error("Server timed out");
788
- }
789
-
790
- return response[0].response;
791
- };
792
-
793
- public createQualifierEvent = async (
794
- tournamentId: string,
795
- event: QualifierEvent
796
- ) => {
797
- const response = await this.sendRequest({
798
- type: {
799
- oneofKind: "createQualifierEvent",
800
- createQualifierEvent: {
801
- tournamentId,
802
- event,
803
- },
804
- },
805
- });
806
-
807
- if (response.length <= 0) {
808
- throw new Error("Server timed out");
809
- }
810
-
811
- return response[0].response;
812
- };
813
-
814
- public setQualifierName = async (
815
- tournamentId: string,
816
- qualifierId: string,
817
- qualifierName: string
818
- ) => {
819
- const response = await this.sendRequest({
820
- type: {
821
- oneofKind: "setQualifierName",
822
- setQualifierName: {
823
- tournamentId,
824
- qualifierId,
825
- qualifierName
826
- },
827
- },
828
- });
829
-
830
- if (response.length <= 0) {
831
- throw new Error("Server timed out");
832
- }
833
-
834
- return response[0].response;
835
- };
836
-
837
- public setQualifierImage = async (
838
- tournamentId: string,
839
- qualifierId: string,
840
- qualifierImage: Uint8Array
841
- ) => {
842
- const response = await this.sendRequest({
843
- type: {
844
- oneofKind: "setQualifierImage",
845
- setQualifierImage: {
846
- tournamentId,
847
- qualifierId,
848
- qualifierImage
849
- },
850
- },
851
- });
852
-
853
- if (response.length <= 0) {
854
- throw new Error("Server timed out");
855
- }
856
-
857
- return response[0].response;
858
- };
859
-
860
- public setQualifierInfoChannel = async (
861
- tournamentId: string,
862
- qualifierId: string,
863
- infoChannel: Channel
864
- ) => {
865
- const response = await this.sendRequest({
866
- type: {
867
- oneofKind: "setQualifierInfoChannel",
868
- setQualifierInfoChannel: {
869
- tournamentId,
870
- qualifierId,
871
- infoChannel
872
- },
873
- },
874
- });
875
-
876
- if (response.length <= 0) {
877
- throw new Error("Server timed out");
878
- }
879
-
880
- return response[0].response;
881
- };
882
-
883
- public setQualifierFlags = async (
884
- tournamentId: string,
885
- qualifierId: string,
886
- qualifierFlags: QualifierEvent_EventSettings
887
- ) => {
888
- const response = await this.sendRequest({
889
- type: {
890
- oneofKind: "setQualifierFlags",
891
- setQualifierFlags: {
892
- tournamentId,
893
- qualifierId,
894
- qualifierFlags
895
- },
896
- },
897
- });
898
-
899
- if (response.length <= 0) {
900
- throw new Error("Server timed out");
901
- }
902
-
903
- return response[0].response;
904
- };
905
-
906
- public setQualifierLeaderboardSort = async (
907
- tournamentId: string,
908
- qualifierId: string,
909
- qualifierLeaderboardSort: QualifierEvent_LeaderboardSort
910
- ) => {
911
- const response = await this.sendRequest({
912
- type: {
913
- oneofKind: "setQualifierLeaderboardSort",
914
- setQualifierLeaderboardSort: {
915
- tournamentId,
916
- qualifierId,
917
- qualifierLeaderboardSort
918
- },
919
- },
920
- });
921
-
922
- if (response.length <= 0) {
923
- throw new Error("Server timed out");
924
- }
925
-
926
- return response[0].response;
927
- };
928
-
929
- public addQualifierMap = async (
930
- tournamentId: string,
931
- qualifierId: string,
932
- map: Map
933
- ) => {
934
- const response = await this.sendRequest({
935
- type: {
936
- oneofKind: "addQualifierMap",
937
- addQualifierMap: {
938
- tournamentId,
939
- qualifierId,
940
- map
941
- },
942
- },
943
- });
944
-
945
- if (response.length <= 0) {
946
- throw new Error("Server timed out");
947
- }
948
-
949
- return response[0].response;
950
- };
951
-
952
- public updateQualifierMap = async (
953
- tournamentId: string,
954
- qualifierId: string,
955
- map: Map
956
- ) => {
957
- const response = await this.sendRequest({
958
- type: {
959
- oneofKind: "updateQualifierMap",
960
- updateQualifierMap: {
961
- tournamentId,
962
- qualifierId,
963
- map
964
- },
965
- },
966
- });
967
-
968
- if (response.length <= 0) {
969
- throw new Error("Server timed out");
970
- }
971
-
972
- return response[0].response;
973
- };
974
-
975
- public removeQualifierMap = async (
976
- tournamentId: string,
977
- qualifierId: string,
978
- mapId: string
979
- ) => {
980
- const response = await this.sendRequest({
981
- type: {
982
- oneofKind: "removeQualifierMap",
983
- removeQualifierMap: {
984
- tournamentId,
985
- qualifierId,
986
- mapId
987
- },
988
- },
989
- });
990
-
991
- if (response.length <= 0) {
992
- throw new Error("Server timed out");
993
- }
994
-
995
- return response[0].response;
996
- };
997
-
998
- public deleteQualifierEvent = async (
999
- tournamentId: string,
1000
- qualifierId: string
1001
- ) => {
1002
- const response = await this.sendRequest({
1003
- type: {
1004
- oneofKind: "deleteQualifierEvent",
1005
- deleteQualifierEvent: {
1006
- tournamentId,
1007
- qualifierId,
1008
- },
1009
- },
1010
- });
1011
-
1012
- if (response.length <= 0) {
1013
- throw new Error("Server timed out");
1014
- }
1015
-
1016
- return response[0].response;
1017
- };
1018
-
1019
- public addAuthorizedUser = async (tournamentId: string, discordId: string, permissionFlags: Permissions) => {
1020
- const response = await this.sendRequest({
1021
- type: {
1022
- oneofKind: "addAuthorizedUser",
1023
- addAuthorizedUser: {
1024
- tournamentId,
1025
- discordId,
1026
- permissionFlags
1027
- },
1028
- },
1029
- });
1030
-
1031
- if (response.length <= 0) {
1032
- throw new Error("Server timed out");
1033
- }
1034
-
1035
- return response[0].response;
1036
- };
1037
-
1038
- public removeAuthorizedUser = async (tournamentId: string, discordId: string) => {
1039
- const response = await this.sendRequest({
1040
- type: {
1041
- oneofKind: "removeAuthorizedUser",
1042
- removeAuthorizedUser: {
1043
- tournamentId,
1044
- discordId
1045
- },
1046
- },
1047
- });
1048
-
1049
- if (response.length <= 0) {
1050
- throw new Error("Server timed out");
1051
- }
1052
-
1053
- return response[0].response;
1054
- };
1055
-
1056
- public getAuthorizedUsers = async (tournamentId: string) => {
1057
- const response = await this.sendRequest({
1058
- type: {
1059
- oneofKind: "getAuthorizedUsers",
1060
- getAuthorizedUsers: {
1061
- tournamentId,
1062
- },
1063
- },
1064
- });
1065
-
1066
- if (response.length <= 0) {
1067
- throw new Error("Server timed out");
1068
- }
1069
-
1070
- return response[0].response;
1071
- };
1072
-
1073
- public getDiscordInfo = async (tournamentId: string, discordId: string) => {
1074
- const response = await this.sendRequest({
1075
- type: {
1076
- oneofKind: "getDiscordInfo",
1077
- getDiscordInfo: {
1078
- tournamentId,
1079
- discordId
1080
- },
1081
- },
1082
- });
1083
-
1084
- if (response.length <= 0) {
1085
- throw new Error("Server timed out");
1086
- }
1087
-
1088
- return response[0].response;
1089
- };
1090
-
1091
- public createTournament = async (tournament: Tournament) => {
1092
- const response = await this.sendRequest({
1093
- type: {
1094
- oneofKind: "createTournament",
1095
- createTournament: {
1096
- tournament,
1097
- },
1098
- },
1099
- });
1100
-
1101
- if (response.length <= 0) {
1102
- throw new Error("Server timed out");
1103
- }
1104
-
1105
- return response[0].response;
1106
- };
1107
-
1108
- public setTournamentName = async (
1109
- tournamentId: string,
1110
- tournamentName: string
1111
- ) => {
1112
- const response = await this.sendRequest({
1113
- type: {
1114
- oneofKind: "setTournamentName",
1115
- setTournamentName: {
1116
- tournamentId,
1117
- tournamentName
1118
- },
1119
- },
1120
- });
1121
-
1122
- if (response.length <= 0) {
1123
- throw new Error("Server timed out");
1124
- }
1125
-
1126
- return response[0].response;
1127
- };
1128
-
1129
- public setTournamentImage = async (
1130
- tournamentId: string,
1131
- tournamentImage: Uint8Array
1132
- ) => {
1133
- const response = await this.sendRequest({
1134
- type: {
1135
- oneofKind: "setTournamentImage",
1136
- setTournamentImage: {
1137
- tournamentId,
1138
- tournamentImage
1139
- },
1140
- },
1141
- });
1142
-
1143
- if (response.length <= 0) {
1144
- throw new Error("Server timed out");
1145
- }
1146
-
1147
- return response[0].response;
1148
- };
1149
-
1150
- public setTournamentEnableTeams = async (
1151
- tournamentId: string,
1152
- enableTeams: boolean
1153
- ) => {
1154
- const response = await this.sendRequest({
1155
- type: {
1156
- oneofKind: "setTournamentEnableTeams",
1157
- setTournamentEnableTeams: {
1158
- tournamentId,
1159
- enableTeams
1160
- },
1161
- },
1162
- });
1163
-
1164
- if (response.length <= 0) {
1165
- throw new Error("Server timed out");
1166
- }
1167
-
1168
- return response[0].response;
1169
- };
1170
-
1171
- public setTournamentEnablePools = async (
1172
- tournamentId: string,
1173
- enablePools: boolean
1174
- ) => {
1175
- const response = await this.sendRequest({
1176
- type: {
1177
- oneofKind: "setTournamentEnablePools",
1178
- setTournamentEnablePools: {
1179
- tournamentId,
1180
- enablePools
1181
- },
1182
- },
1183
- });
1184
-
1185
- if (response.length <= 0) {
1186
- throw new Error("Server timed out");
1187
- }
1188
-
1189
- return response[0].response;
1190
- };
1191
-
1192
- public setTournamentShowTournamentButton = async (
1193
- tournamentId: string,
1194
- showTournamentButton: boolean
1195
- ) => {
1196
- const response = await this.sendRequest({
1197
- type: {
1198
- oneofKind: "setTournamentShowTournamentButton",
1199
- setTournamentShowTournamentButton: {
1200
- tournamentId,
1201
- showTournamentButton
1202
- },
1203
- },
1204
- });
1205
-
1206
- if (response.length <= 0) {
1207
- throw new Error("Server timed out");
1208
- }
1209
-
1210
- return response[0].response;
1211
- };
1212
-
1213
- public setTournamentShowQualifierButton = async (
1214
- tournamentId: string,
1215
- showQualifierButton: boolean
1216
- ) => {
1217
- const response = await this.sendRequest({
1218
- type: {
1219
- oneofKind: "setTournamentShowQualifierButton",
1220
- setTournamentShowQualifierButton: {
1221
- tournamentId,
1222
- showQualifierButton
1223
- },
1224
- },
1225
- });
1226
-
1227
- if (response.length <= 0) {
1228
- throw new Error("Server timed out");
1229
- }
1230
-
1231
- return response[0].response;
1232
- };
1233
-
1234
- public setTournamentAllowUnauthorizedView = async (
1235
- tournamentId: string,
1236
- allowUnauthorizedView: boolean
1237
- ) => {
1238
- const response = await this.sendRequest({
1239
- type: {
1240
- oneofKind: "setTournamentAllowUnauthorizedView",
1241
- setTournamentAllowUnauthorizedView: {
1242
- tournamentId,
1243
- allowUnauthorizedView
1244
- },
1245
- },
1246
- });
1247
-
1248
- if (response.length <= 0) {
1249
- throw new Error("Server timed out");
1250
- }
1251
-
1252
- return response[0].response;
1253
- };
1254
-
1255
- public setTournamentScoreUpdateFrequency = async (
1256
- tournamentId: string,
1257
- scoreUpdateFrequency: number
1258
- ) => {
1259
- const response = await this.sendRequest({
1260
- type: {
1261
- oneofKind: "setTournamentScoreUpdateFrequency",
1262
- setTournamentScoreUpdateFrequency: {
1263
- tournamentId,
1264
- scoreUpdateFrequency
1265
- },
1266
- },
1267
- });
1268
-
1269
- if (response.length <= 0) {
1270
- throw new Error("Server timed out");
1271
- }
1272
-
1273
- return response[0].response;
1274
- };
1275
-
1276
- public setTournamentBannedMods = async (
1277
- tournamentId: string,
1278
- bannedMods: string[]
1279
- ) => {
1280
- const response = await this.sendRequest({
1281
- type: {
1282
- oneofKind: 'setTournamentBannedMods',
1283
- setTournamentBannedMods: {
1284
- tournamentId,
1285
- bannedMods
1286
- },
1287
- },
1288
- });
1289
-
1290
- if (response.length <= 0) {
1291
- throw new Error("Server timed out");
1292
- }
1293
-
1294
- return response[0].response;
1295
- };
1296
-
1297
- public addTournamentTeam = async (
1298
- tournamentId: string,
1299
- team: Tournament_TournamentSettings_Team
1300
- ) => {
1301
- const response = await this.sendRequest({
1302
- type: {
1303
- oneofKind: "addTournamentTeam",
1304
- addTournamentTeam: {
1305
- tournamentId,
1306
- team
1307
- },
1308
- },
1309
- });
1310
-
1311
- if (response.length <= 0) {
1312
- throw new Error("Server timed out");
1313
- }
1314
-
1315
- return response[0].response;
1316
- };
1317
-
1318
- public setTournamentTeamName = async (
1319
- tournamentId: string,
1320
- teamId: string,
1321
- teamName: string
1322
- ) => {
1323
- const response = await this.sendRequest({
1324
- type: {
1325
- oneofKind: "setTournamentTeamName",
1326
- setTournamentTeamName: {
1327
- tournamentId,
1328
- teamId,
1329
- teamName
1330
- },
1331
- },
1332
- });
1333
-
1334
- if (response.length <= 0) {
1335
- throw new Error("Server timed out");
1336
- }
1337
-
1338
- return response[0].response;
1339
- };
1340
-
1341
- public setTournamentTeamImage = async (
1342
- tournamentId: string,
1343
- teamId: string,
1344
- teamImage: Uint8Array
1345
- ) => {
1346
- const response = await this.sendRequest({
1347
- type: {
1348
- oneofKind: "setTournamentTeamImage",
1349
- setTournamentTeamImage: {
1350
- tournamentId,
1351
- teamId,
1352
- teamImage
1353
- },
1354
- },
1355
- });
1356
-
1357
- if (response.length <= 0) {
1358
- throw new Error("Server timed out");
1359
- }
1360
-
1361
- return response[0].response;
1362
- };
1363
-
1364
- public removeTournamentTeam = async (
1365
- tournamentId: string,
1366
- teamId: string
1367
- ) => {
1368
- const response = await this.sendRequest({
1369
- type: {
1370
- oneofKind: "removeTournamentTeam",
1371
- removeTournamentTeam: {
1372
- tournamentId,
1373
- teamId
1374
- },
1375
- },
1376
- });
1377
-
1378
- if (response.length <= 0) {
1379
- throw new Error("Server timed out");
1380
- }
1381
-
1382
- return response[0].response;
1383
- };
1384
-
1385
- public addTournamentPool = async (
1386
- tournamentId: string,
1387
- pool: Tournament_TournamentSettings_Pool
1388
- ) => {
1389
- const response = await this.sendRequest({
1390
- type: {
1391
- oneofKind: "addTournamentPool",
1392
- addTournamentPool: {
1393
- tournamentId,
1394
- pool
1395
- },
1396
- },
1397
- });
1398
-
1399
- if (response.length <= 0) {
1400
- throw new Error("Server timed out");
1401
- }
1402
-
1403
- return response[0].response;
1404
- };
1405
-
1406
- public setTournamentPoolName = async (
1407
- tournamentId: string,
1408
- poolId: string,
1409
- poolName: string
1410
- ) => {
1411
- const response = await this.sendRequest({
1412
- type: {
1413
- oneofKind: "setTournamentPoolName",
1414
- setTournamentPoolName: {
1415
- tournamentId,
1416
- poolId,
1417
- poolName
1418
- },
1419
- },
1420
- });
1421
-
1422
- if (response.length <= 0) {
1423
- throw new Error("Server timed out");
1424
- }
1425
-
1426
- return response[0].response;
1427
- };
1428
-
1429
- public addTournamentPoolMap = async (
1430
- tournamentId: string,
1431
- poolId: string,
1432
- map: Map
1433
- ) => {
1434
- const response = await this.sendRequest({
1435
- type: {
1436
- oneofKind: "addTournamentPoolMap",
1437
- addTournamentPoolMap: {
1438
- tournamentId,
1439
- poolId,
1440
- map
1441
- },
1442
- },
1443
- });
1444
-
1445
- if (response.length <= 0) {
1446
- throw new Error("Server timed out");
1447
- }
1448
-
1449
- return response[0].response;
1450
- };
1451
-
1452
- public updateTournamentPoolMap = async (
1453
- tournamentId: string,
1454
- poolId: string,
1455
- map: Map
1456
- ) => {
1457
- const response = await this.sendRequest({
1458
- type: {
1459
- oneofKind: "updateTournamentPoolMap",
1460
- updateTournamentPoolMap: {
1461
- tournamentId,
1462
- poolId,
1463
- map
1464
- },
1465
- },
1466
- });
1467
-
1468
- if (response.length <= 0) {
1469
- throw new Error("Server timed out");
1470
- }
1471
-
1472
- return response[0].response;
1473
- };
1474
-
1475
- public removeTournamentPoolMap = async (
1476
- tournamentId: string,
1477
- poolId: string,
1478
- mapId: string
1479
- ) => {
1480
- const response = await this.sendRequest({
1481
- type: {
1482
- oneofKind: "removeTournamentPoolMap",
1483
- removeTournamentPoolMap: {
1484
- tournamentId,
1485
- poolId,
1486
- mapId
1487
- },
1488
- },
1489
- });
1490
-
1491
- if (response.length <= 0) {
1492
- throw new Error("Server timed out");
1493
- }
1494
-
1495
- return response[0].response;
1496
- };
1497
-
1498
- public removeTournamentPool = async (
1499
- tournamentId: string,
1500
- poolId: string
1501
- ) => {
1502
- const response = await this.sendRequest({
1503
- type: {
1504
- oneofKind: "removeTournamentPool",
1505
- removeTournamentPool: {
1506
- tournamentId,
1507
- poolId
1508
- },
1509
- },
1510
- });
1511
-
1512
- if (response.length <= 0) {
1513
- throw new Error("Server timed out");
1514
- }
1515
-
1516
- return response[0].response;
1517
- };
1518
-
1519
- public deleteTournament = async (tournamentId: string) => {
1520
- const response = await this.sendRequest({
1521
- type: {
1522
- oneofKind: "deleteTournament",
1523
- deleteTournament: {
1524
- tournamentId,
1525
- },
1526
- },
1527
- });
1528
-
1529
- if (response.length <= 0) {
1530
- throw new Error("Server timed out");
1531
- }
1532
-
1533
- return response[0].response;
1534
- };
1535
-
1536
- public addServer = async (server: CoreServer, authToken?: string) => {
1537
- const response = await this.sendRequest({
1538
- type: {
1539
- oneofKind: "addServer",
1540
- addServer: {
1541
- server,
1542
- authToken: authToken ?? "",
1543
- },
1544
- },
1545
- });
1546
-
1547
- if (response.length <= 0) {
1548
- throw new Error("Server timed out");
1549
- }
1550
-
1551
- return response[0].response;
1552
- };
1553
- }