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.
- package/dist/client.d.ts +22 -0
- package/dist/client.js +77 -0
- package/dist/constants.d.ts +4 -0
- package/{src/constants.ts → dist/constants.js} +1 -1
- package/dist/custom-event-emitter.d.ts +7 -0
- package/dist/custom-event-emitter.js +16 -0
- package/dist/index.d.ts +4592 -0
- package/dist/index.esm.js +16502 -0
- package/{src/index.ts → dist/index.js} +1 -1
- package/dist/models/commands.d.ts +116 -0
- package/{src/models/commands.ts → dist/models/commands.js} +17 -102
- package/dist/models/discord.d.ts +76 -0
- package/{src/models/discord.ts → dist/models/discord.js} +15 -62
- package/dist/models/events.d.ts +419 -0
- package/{src/models/events.ts → dist/models/events.js} +89 -354
- package/dist/models/index.js +8 -0
- package/dist/models/models.d.ts +1137 -0
- package/{src/models/models.ts → dist/models/models.js} +200 -799
- package/dist/models/packets.d.ts +144 -0
- package/{src/models/packets.ts → dist/models/packets.js} +26 -126
- package/dist/models/pushes.d.ts +122 -0
- package/{src/models/pushes.ts → dist/models/pushes.js} +24 -96
- package/dist/models/requests.d.ts +1694 -0
- package/{src/models/requests.ts → dist/models/requests.js} +323 -1469
- package/dist/models/responses.d.ts +799 -0
- package/{src/models/responses.ts → dist/models/responses.js} +161 -669
- package/dist/scraper.d.ts +2 -0
- package/dist/scraper.js +87 -0
- package/dist/state-manager.d.ts +50 -0
- package/dist/state-manager.js +196 -0
- package/dist/tournament-assistant-client.d.ts +114 -0
- package/dist/tournament-assistant-client.js +1170 -0
- package/package.json +8 -2
- package/rollup.config.mjs +0 -16
- package/scripts/esbuild.mjs +0 -24
- package/scripts/fixImports.mjs +0 -44
- package/src/client.ts +0 -101
- package/src/custom-event-emitter.ts +0 -21
- package/src/scraper.ts +0 -137
- package/src/state-manager.ts +0 -308
- package/src/tournament-assistant-client.ts +0 -1553
- package/tsconfig.json +0 -27
- /package/{src/models/index.ts → dist/models/index.d.ts} +0 -0
|
@@ -0,0 +1,1170 @@
|
|
|
1
|
+
import { Client } from "./client.js";
|
|
2
|
+
import { CustomEventEmitter } from "./custom-event-emitter.js";
|
|
3
|
+
import { v4 as uuidv4 } from "uuid";
|
|
4
|
+
import { StateManager } from "./state-manager.js";
|
|
5
|
+
import { Response_ResponseType, } from "./models/responses.js";
|
|
6
|
+
import { versionCode } from "./constants.js";
|
|
7
|
+
import WebSocket from "ws";
|
|
8
|
+
// Created by Moon on 6/12/2022
|
|
9
|
+
export * from "./scraper.js";
|
|
10
|
+
export * from "./models/models.js";
|
|
11
|
+
export class TAClient extends CustomEventEmitter {
|
|
12
|
+
stateManager;
|
|
13
|
+
client;
|
|
14
|
+
token = "";
|
|
15
|
+
shouldHeartbeat = false;
|
|
16
|
+
heartbeatInterval;
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
this.stateManager = new StateManager();
|
|
20
|
+
}
|
|
21
|
+
// --- State helpers --- //
|
|
22
|
+
get isConnected() {
|
|
23
|
+
return this.client?.isConnected ?? false;
|
|
24
|
+
}
|
|
25
|
+
get isConnecting() {
|
|
26
|
+
return this.client?.readyState === WebSocket.CONNECTING;
|
|
27
|
+
}
|
|
28
|
+
// --- Actions --- //
|
|
29
|
+
async connect(serverAddress, port) {
|
|
30
|
+
this.shouldHeartbeat = true;
|
|
31
|
+
this.client = new Client(serverAddress, port, this.token);
|
|
32
|
+
this.client.on("packetReceived", this.handlePacket);
|
|
33
|
+
this.client.on("disconnectedFromServer", () => {
|
|
34
|
+
clearInterval(this.heartbeatInterval);
|
|
35
|
+
console.info("Disconnected from server!");
|
|
36
|
+
this.emit("disconnectedFromServer", {});
|
|
37
|
+
});
|
|
38
|
+
this.client.on("failedToConnectToServer", () => {
|
|
39
|
+
console.error("Failed to connect to server!");
|
|
40
|
+
this.emit("failedToConnectToServer", {});
|
|
41
|
+
});
|
|
42
|
+
this.emit("connectingToServer", {});
|
|
43
|
+
// Create a promise that resolves when connected to the server
|
|
44
|
+
const connectPromise = new Promise((resolve, reject) => {
|
|
45
|
+
const onConnectedToServer = async () => {
|
|
46
|
+
const response = await this.sendRequest({
|
|
47
|
+
type: {
|
|
48
|
+
oneofKind: "connect",
|
|
49
|
+
connect: {
|
|
50
|
+
clientVersion: versionCode,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
if (this.shouldHeartbeat) {
|
|
55
|
+
this.heartbeatInterval = setInterval(() => {
|
|
56
|
+
this.client?.send({
|
|
57
|
+
token: this.token,
|
|
58
|
+
from: this.stateManager.getSelfGuid(),
|
|
59
|
+
id: uuidv4(),
|
|
60
|
+
packet: {
|
|
61
|
+
oneofKind: "command",
|
|
62
|
+
command: {
|
|
63
|
+
type: {
|
|
64
|
+
oneofKind: "heartbeat",
|
|
65
|
+
heartbeat: true,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}, 10000);
|
|
71
|
+
}
|
|
72
|
+
this.client?.removeListener("connectedToServer", onConnectedToServer);
|
|
73
|
+
clearTimeout(timeout);
|
|
74
|
+
if (response.length <= 0) {
|
|
75
|
+
reject("Server timed out");
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
resolve(response[0].response);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
// Return what we have after 5 seconds
|
|
82
|
+
const createTimeout = (time) => {
|
|
83
|
+
return setTimeout(() => {
|
|
84
|
+
this.client?.removeListener("connectedToServer", onConnectedToServer);
|
|
85
|
+
reject("Server timed out");
|
|
86
|
+
}, time);
|
|
87
|
+
};
|
|
88
|
+
const timeout = createTimeout(30000);
|
|
89
|
+
this.client?.on("connectedToServer", onConnectedToServer);
|
|
90
|
+
});
|
|
91
|
+
this.client.connect();
|
|
92
|
+
return connectPromise;
|
|
93
|
+
}
|
|
94
|
+
disconnect() {
|
|
95
|
+
this.shouldHeartbeat = false;
|
|
96
|
+
console.info(`Disconnecting from server!`);
|
|
97
|
+
this.client?.disconnect();
|
|
98
|
+
}
|
|
99
|
+
setAuthToken(token) {
|
|
100
|
+
this.token = token;
|
|
101
|
+
this.client?.setToken(token);
|
|
102
|
+
}
|
|
103
|
+
forwardToUsers(packet, to) {
|
|
104
|
+
this.client?.send({
|
|
105
|
+
token: "",
|
|
106
|
+
from: packet.from,
|
|
107
|
+
id: packet.id,
|
|
108
|
+
packet: {
|
|
109
|
+
oneofKind: "forwardingPacket",
|
|
110
|
+
forwardingPacket: {
|
|
111
|
+
forwardTo: to,
|
|
112
|
+
packet,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
sendCommand(command, to) {
|
|
118
|
+
const packet = {
|
|
119
|
+
token: this.token,
|
|
120
|
+
from: this.stateManager.getSelfGuid(),
|
|
121
|
+
id: uuidv4(),
|
|
122
|
+
packet: {
|
|
123
|
+
oneofKind: "command",
|
|
124
|
+
command,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
this.forwardToUsers(packet, to);
|
|
128
|
+
}
|
|
129
|
+
async sendRequest(request, to) {
|
|
130
|
+
const packet = {
|
|
131
|
+
token: "",
|
|
132
|
+
from: this.stateManager.getSelfGuid(),
|
|
133
|
+
id: uuidv4(),
|
|
134
|
+
packet: {
|
|
135
|
+
oneofKind: "request",
|
|
136
|
+
request,
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
const responseDictionary = [];
|
|
140
|
+
// Create a promise that resolves when all responses are received
|
|
141
|
+
const responsesPromise = new Promise((resolve) => {
|
|
142
|
+
const addListeners = () => {
|
|
143
|
+
this.on("responseReceived", onResponseReceived);
|
|
144
|
+
this.on("authorizationRequestedFromServer", onAuthorizationRequested);
|
|
145
|
+
this.on("authorizedWithServer", onAuthroizedWithServer);
|
|
146
|
+
};
|
|
147
|
+
const removeListeners = () => {
|
|
148
|
+
this.removeListener("responseReceived", onResponseReceived);
|
|
149
|
+
this.removeListener("authorizationRequestedFromServer", onAuthorizationRequested);
|
|
150
|
+
this.removeListener("authorizedWithServer", onAuthroizedWithServer);
|
|
151
|
+
};
|
|
152
|
+
// Check that we got responses from all expected users
|
|
153
|
+
const checkResponses = () => {
|
|
154
|
+
const responseUsers = responseDictionary.map((x) => x.userId);
|
|
155
|
+
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
|
|
156
|
+
if (responseUsers.length !== expectedUsers.length) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const sortedArr1 = responseUsers.slice().sort();
|
|
160
|
+
const sortedArr2 = expectedUsers.slice().sort();
|
|
161
|
+
for (let i = 0; i < sortedArr1.length; i++) {
|
|
162
|
+
if (sortedArr1[i] !== sortedArr2[i]) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// All responses are received, clean up and resolve
|
|
167
|
+
removeListeners();
|
|
168
|
+
clearTimeout(timeout);
|
|
169
|
+
resolve(responseDictionary);
|
|
170
|
+
};
|
|
171
|
+
// Add to the dictionary when the response is to this packet, and from an expected user
|
|
172
|
+
const onResponseReceived = (response) => {
|
|
173
|
+
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
|
|
174
|
+
if (response.response.respondingToPacketId === packet.id &&
|
|
175
|
+
expectedUsers.includes(response.userId)) {
|
|
176
|
+
responseDictionary.push({
|
|
177
|
+
userId: response.userId,
|
|
178
|
+
response: response.response,
|
|
179
|
+
});
|
|
180
|
+
checkResponses();
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
// Return what we have after 5 seconds
|
|
184
|
+
const createTimeout = (time) => {
|
|
185
|
+
return setTimeout(() => {
|
|
186
|
+
removeListeners();
|
|
187
|
+
resolve(responseDictionary);
|
|
188
|
+
}, time);
|
|
189
|
+
};
|
|
190
|
+
const timeout = createTimeout(30000);
|
|
191
|
+
// If authorization is requested, we're assuming an external application will handle
|
|
192
|
+
// resetting the auth token, so we'll extend the timeout by 30 seconds and try again
|
|
193
|
+
// if a successful auth is noticed
|
|
194
|
+
const onAuthorizationRequested = () => {
|
|
195
|
+
clearTimeout(timeout);
|
|
196
|
+
createTimeout(30000);
|
|
197
|
+
};
|
|
198
|
+
// Retry on successful authorization
|
|
199
|
+
const onAuthroizedWithServer = () => {
|
|
200
|
+
sendRequest();
|
|
201
|
+
};
|
|
202
|
+
addListeners();
|
|
203
|
+
});
|
|
204
|
+
// Assume forwardToUsers emits the 'responseReceived' event asynchronously
|
|
205
|
+
const sendRequest = () => {
|
|
206
|
+
if (to) {
|
|
207
|
+
this.forwardToUsers(packet, to);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
this.client?.send(packet, to);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
sendRequest();
|
|
214
|
+
return responsesPromise;
|
|
215
|
+
}
|
|
216
|
+
async sendResponse(response, to) {
|
|
217
|
+
const packet = {
|
|
218
|
+
token: this.token,
|
|
219
|
+
from: this.stateManager.getSelfGuid(),
|
|
220
|
+
id: uuidv4(),
|
|
221
|
+
packet: {
|
|
222
|
+
oneofKind: "response",
|
|
223
|
+
response,
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
if (to) {
|
|
227
|
+
this.forwardToUsers(packet, to);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
this.client?.send(packet, to);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// --- Commands --- //
|
|
234
|
+
playSong = (gameplayParameters, userIds) => {
|
|
235
|
+
this.sendCommand({
|
|
236
|
+
type: {
|
|
237
|
+
oneofKind: "playSong",
|
|
238
|
+
playSong: {
|
|
239
|
+
gameplayParameters,
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
}, userIds);
|
|
243
|
+
};
|
|
244
|
+
returnToMenu = (userIds) => {
|
|
245
|
+
this.sendCommand({
|
|
246
|
+
type: {
|
|
247
|
+
oneofKind: "returnToMenu",
|
|
248
|
+
returnToMenu: true,
|
|
249
|
+
},
|
|
250
|
+
}, userIds);
|
|
251
|
+
};
|
|
252
|
+
showLoadedImage = (userIds) => {
|
|
253
|
+
this.sendCommand({
|
|
254
|
+
type: {
|
|
255
|
+
oneofKind: "streamSyncShowImage",
|
|
256
|
+
streamSyncShowImage: true,
|
|
257
|
+
},
|
|
258
|
+
}, userIds);
|
|
259
|
+
};
|
|
260
|
+
delayTestFinished = (userIds) => {
|
|
261
|
+
this.sendCommand({
|
|
262
|
+
type: {
|
|
263
|
+
oneofKind: "delayTestFinish",
|
|
264
|
+
delayTestFinish: true,
|
|
265
|
+
},
|
|
266
|
+
}, userIds);
|
|
267
|
+
};
|
|
268
|
+
// --- Requests --- //
|
|
269
|
+
joinTournament = async (tournamentId) => {
|
|
270
|
+
const response = await this.sendRequest({
|
|
271
|
+
type: {
|
|
272
|
+
oneofKind: "join",
|
|
273
|
+
join: {
|
|
274
|
+
tournamentId,
|
|
275
|
+
password: "",
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
if (response.length <= 0) {
|
|
280
|
+
throw new Error("Server timed out");
|
|
281
|
+
}
|
|
282
|
+
return response[0].response;
|
|
283
|
+
};
|
|
284
|
+
getLeaderboard = async (tournamentId, qualifierId, mapId) => {
|
|
285
|
+
const response = await this.sendRequest({
|
|
286
|
+
type: {
|
|
287
|
+
oneofKind: "qualifierScores",
|
|
288
|
+
qualifierScores: {
|
|
289
|
+
tournamentId: tournamentId,
|
|
290
|
+
eventId: qualifierId,
|
|
291
|
+
mapId,
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
if (response.length <= 0) {
|
|
296
|
+
throw new Error("Server timed out");
|
|
297
|
+
}
|
|
298
|
+
return response[0].response;
|
|
299
|
+
};
|
|
300
|
+
loadSong = async (levelId, userIds) => {
|
|
301
|
+
const response = await this.sendRequest({
|
|
302
|
+
type: {
|
|
303
|
+
oneofKind: "loadSong",
|
|
304
|
+
loadSong: {
|
|
305
|
+
levelId,
|
|
306
|
+
customHostUrl: ""
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
}, userIds);
|
|
310
|
+
if (response.length <= 0) {
|
|
311
|
+
throw new Error("Server timed out, or no users responded");
|
|
312
|
+
}
|
|
313
|
+
return response;
|
|
314
|
+
};
|
|
315
|
+
loadImage = async (bitmap, userIds) => {
|
|
316
|
+
const response = await this.sendRequest({
|
|
317
|
+
type: {
|
|
318
|
+
oneofKind: "preloadImageForStreamSync",
|
|
319
|
+
preloadImageForStreamSync: {
|
|
320
|
+
fileId: uuidv4(),
|
|
321
|
+
data: bitmap,
|
|
322
|
+
compressed: false
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
}, userIds);
|
|
326
|
+
if (response.length <= 0) {
|
|
327
|
+
throw new Error("Server timed out, or no users responded");
|
|
328
|
+
}
|
|
329
|
+
return response;
|
|
330
|
+
};
|
|
331
|
+
// --- Packet Handler --- //
|
|
332
|
+
handlePacket = (packet) => {
|
|
333
|
+
this.stateManager.handlePacket(packet);
|
|
334
|
+
// if (packet.packet.oneofKind !== "acknowledgement") {
|
|
335
|
+
// const send: Packet = {
|
|
336
|
+
// token: this.token,
|
|
337
|
+
// from: this.stateManager.getSelfGuid(),
|
|
338
|
+
// id: uuidv4(),
|
|
339
|
+
// packet: {
|
|
340
|
+
// oneofKind: "acknowledgement",
|
|
341
|
+
// acknowledgement: {
|
|
342
|
+
// packetId: packet.id,
|
|
343
|
+
// type: Acknowledgement_AcknowledgementType.MessageReceived,
|
|
344
|
+
// },
|
|
345
|
+
// },
|
|
346
|
+
// };
|
|
347
|
+
// this.client?.send(send);
|
|
348
|
+
// }
|
|
349
|
+
if (packet.packet.oneofKind === "command") {
|
|
350
|
+
const command = packet.packet.command;
|
|
351
|
+
if (command.type.oneofKind === 'discordAuthorize') {
|
|
352
|
+
this.emit("authorizationRequestedFromServer", command.type.discordAuthorize);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
else if (packet.packet.oneofKind === 'request') {
|
|
356
|
+
const request = packet.packet.request;
|
|
357
|
+
if (request.type.oneofKind === 'loadSong') {
|
|
358
|
+
this.emit("loadSongRequested", [packet.id, packet.from, request.type.loadSong]);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
else if (packet.packet.oneofKind === "response") {
|
|
362
|
+
const response = packet.packet.response;
|
|
363
|
+
this.emit("responseReceived", {
|
|
364
|
+
userId: packet.from,
|
|
365
|
+
response: response,
|
|
366
|
+
});
|
|
367
|
+
if (response.details.oneofKind === "connect") {
|
|
368
|
+
const connect = response.details.connect;
|
|
369
|
+
if (response.type === Response_ResponseType.Success) {
|
|
370
|
+
console.info(`Successfully connected to server!`);
|
|
371
|
+
this.emit("connectedToServer", connect);
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
console.error(`Failed to connect to server. Message: ${connect.message}`);
|
|
375
|
+
this.emit("failedToConnectToServer", {});
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
else if (response.details.oneofKind === "join") {
|
|
379
|
+
const join = response.details.join;
|
|
380
|
+
if (response.type === Response_ResponseType.Success) {
|
|
381
|
+
console.info(`Successfully joined tournament!`);
|
|
382
|
+
this.emit("joinedTournament", {});
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
console.error(`Failed to join server. Message: ${join.message}`);
|
|
386
|
+
this.emit("failedToJoinTournament", {});
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
else if (response.details.oneofKind === "createTournament") {
|
|
390
|
+
const createTournament = response.details.createTournament;
|
|
391
|
+
if (response.type === Response_ResponseType.Success) {
|
|
392
|
+
console.info(`Successfully created tournament!`);
|
|
393
|
+
this.emit("createdTournament", {});
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
console.error(`Failed to create tournament. Message: ${createTournament.message}`);
|
|
397
|
+
this.emit("failedToCreateTournament", {});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
else if (response.details.oneofKind === "updateTournament") {
|
|
401
|
+
const updateTournament = response.details.updateTournament;
|
|
402
|
+
if (response.type === Response_ResponseType.Success) {
|
|
403
|
+
console.info(`Successfully modified tournament!`);
|
|
404
|
+
this.emit("updatedTournament", {});
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
console.error(`Failed update tournament. Message: ${updateTournament.message}`);
|
|
408
|
+
this.emit("failedToUpdateTournament", {});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
else if (response.details.oneofKind === "deleteTournament") {
|
|
412
|
+
const deleteTournament = response.details.deleteTournament;
|
|
413
|
+
if (response.type === Response_ResponseType.Success) {
|
|
414
|
+
console.info(`Successfully deleted tournament!`);
|
|
415
|
+
this.emit("deletedTournament", {});
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
console.error(`Failed to delete tournament. Message: ${deleteTournament.message}`);
|
|
419
|
+
this.emit("failedToDeleteTournament", {});
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
else if (response.details.oneofKind === "createMatch") {
|
|
423
|
+
const createMatch = response.details.createMatch;
|
|
424
|
+
if (response.type === Response_ResponseType.Success) {
|
|
425
|
+
console.info(`Successfully created match!`);
|
|
426
|
+
this.emit("createdMatch", {});
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
console.error(`Failed to create Match. Message: ${createMatch.message}`);
|
|
430
|
+
this.emit("failedToCreateMatch", {});
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
else if (response.details.oneofKind === "updateMatch") {
|
|
434
|
+
const updateMatch = response.details.updateMatch;
|
|
435
|
+
if (response.type === Response_ResponseType.Success) {
|
|
436
|
+
console.info(`Successfully modified match!`);
|
|
437
|
+
this.emit("updatedMatch", {});
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
console.error(`Failed update Match. Message: ${updateMatch.message}`);
|
|
441
|
+
this.emit("failedToUpdateMatch", {});
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
else if (response.details.oneofKind === "deleteMatch") {
|
|
445
|
+
const deleteMatch = response.details.deleteMatch;
|
|
446
|
+
if (response.type === Response_ResponseType.Success) {
|
|
447
|
+
console.info(`Successfully deleted match!`);
|
|
448
|
+
this.emit("deletedMatch", {});
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
console.error(`Failed to delete Match. Message: ${deleteMatch.message}`);
|
|
452
|
+
this.emit("failedToDeleteMatch", {});
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
else if (response.details.oneofKind === "createQualifierEvent") {
|
|
456
|
+
const createQualifierEvent = response.details.createQualifierEvent;
|
|
457
|
+
if (response.type === Response_ResponseType.Success) {
|
|
458
|
+
console.info(`Successfully created qualifier!`);
|
|
459
|
+
this.emit("createdQualifier", {});
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
console.error(`Failed to create qualifier. Message: ${createQualifierEvent.message}`);
|
|
463
|
+
this.emit("failedToCreateQualifier", {});
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
else if (response.details.oneofKind === "updateQualifierEvent") {
|
|
467
|
+
const modifyQualifier = response.details.updateQualifierEvent;
|
|
468
|
+
if (response.type === Response_ResponseType.Success) {
|
|
469
|
+
console.info(`Successfully modified qualifier!`);
|
|
470
|
+
this.emit("updatedQualifier", {});
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
console.error(`Failed to update qualifier. Message: ${modifyQualifier.message}`);
|
|
474
|
+
this.emit("failedToUpdateQualifier", {});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
else if (response.details.oneofKind === "deleteQualifierEvent") {
|
|
478
|
+
const deleteQualifierEvent = response.details.deleteQualifierEvent;
|
|
479
|
+
if (response.type === Response_ResponseType.Success) {
|
|
480
|
+
console.info(`Successfully deleted qualifier!`);
|
|
481
|
+
this.emit("deletedQualifier", {});
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
console.error(`Failed to delete qualifier. Message: ${deleteQualifierEvent.message}`);
|
|
485
|
+
this.emit("failedToDeleteQualifier", {});
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
else if (packet.packet.oneofKind === "push") {
|
|
490
|
+
const push = packet.packet.push;
|
|
491
|
+
if (push.data.oneofKind === "discordAuthorized") {
|
|
492
|
+
if (push.data.discordAuthorized.success) {
|
|
493
|
+
this.emit("authorizedWithServer", push.data.discordAuthorized.token);
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
this.emit("failedToAuthorizeWithServer", {});
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
else if (push.data.oneofKind === "songFinished") {
|
|
500
|
+
this.emit("songFinished", push.data.songFinished);
|
|
501
|
+
}
|
|
502
|
+
else if (push.data.oneofKind === "realtimeScore") {
|
|
503
|
+
this.emit("realtimeScore", push.data.realtimeScore);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
// --- State Actions --- //
|
|
508
|
+
updateUser = async (tournamentId, user) => {
|
|
509
|
+
const response = await this.sendRequest({
|
|
510
|
+
type: {
|
|
511
|
+
oneofKind: "updateUser",
|
|
512
|
+
updateUser: {
|
|
513
|
+
tournamentId,
|
|
514
|
+
user,
|
|
515
|
+
},
|
|
516
|
+
},
|
|
517
|
+
});
|
|
518
|
+
if (response.length <= 0) {
|
|
519
|
+
throw new Error("Server timed out");
|
|
520
|
+
}
|
|
521
|
+
return response[0].response;
|
|
522
|
+
};
|
|
523
|
+
createMatch = async (tournamentId, match) => {
|
|
524
|
+
const response = await this.sendRequest({
|
|
525
|
+
type: {
|
|
526
|
+
oneofKind: "createMatch",
|
|
527
|
+
createMatch: {
|
|
528
|
+
tournamentId,
|
|
529
|
+
match,
|
|
530
|
+
},
|
|
531
|
+
},
|
|
532
|
+
});
|
|
533
|
+
// Checking oneOfKind here helps typescript identify what type of response it is
|
|
534
|
+
if (response.length <= 0) {
|
|
535
|
+
throw new Error("Server timed out");
|
|
536
|
+
}
|
|
537
|
+
return response[0].response;
|
|
538
|
+
};
|
|
539
|
+
addUserToMatch = async (tournamentId, matchId, userId) => {
|
|
540
|
+
const response = await this.sendRequest({
|
|
541
|
+
type: {
|
|
542
|
+
oneofKind: "addUserToMatch",
|
|
543
|
+
addUserToMatch: {
|
|
544
|
+
tournamentId,
|
|
545
|
+
matchId,
|
|
546
|
+
userId
|
|
547
|
+
},
|
|
548
|
+
},
|
|
549
|
+
});
|
|
550
|
+
if (response.length <= 0) {
|
|
551
|
+
throw new Error("Server timed out");
|
|
552
|
+
}
|
|
553
|
+
return response[0].response;
|
|
554
|
+
};
|
|
555
|
+
removeUserFromMatch = async (tournamentId, matchId, userId) => {
|
|
556
|
+
const response = await this.sendRequest({
|
|
557
|
+
type: {
|
|
558
|
+
oneofKind: "removeUserFromMatch",
|
|
559
|
+
removeUserFromMatch: {
|
|
560
|
+
tournamentId,
|
|
561
|
+
matchId,
|
|
562
|
+
userId
|
|
563
|
+
},
|
|
564
|
+
},
|
|
565
|
+
});
|
|
566
|
+
if (response.length <= 0) {
|
|
567
|
+
throw new Error("Server timed out");
|
|
568
|
+
}
|
|
569
|
+
return response[0].response;
|
|
570
|
+
};
|
|
571
|
+
setMatchLeader = async (tournamentId, matchId, userId) => {
|
|
572
|
+
const response = await this.sendRequest({
|
|
573
|
+
type: {
|
|
574
|
+
oneofKind: "setMatchLeader",
|
|
575
|
+
setMatchLeader: {
|
|
576
|
+
tournamentId,
|
|
577
|
+
matchId,
|
|
578
|
+
userId
|
|
579
|
+
},
|
|
580
|
+
},
|
|
581
|
+
});
|
|
582
|
+
if (response.length <= 0) {
|
|
583
|
+
throw new Error("Server timed out");
|
|
584
|
+
}
|
|
585
|
+
return response[0].response;
|
|
586
|
+
};
|
|
587
|
+
setMatchMap = async (tournamentId, matchId, map) => {
|
|
588
|
+
const response = await this.sendRequest({
|
|
589
|
+
type: {
|
|
590
|
+
oneofKind: "setMatchMap",
|
|
591
|
+
setMatchMap: {
|
|
592
|
+
tournamentId,
|
|
593
|
+
matchId,
|
|
594
|
+
map
|
|
595
|
+
},
|
|
596
|
+
},
|
|
597
|
+
});
|
|
598
|
+
if (response.length <= 0) {
|
|
599
|
+
throw new Error("Server timed out");
|
|
600
|
+
}
|
|
601
|
+
return response[0].response;
|
|
602
|
+
};
|
|
603
|
+
deleteMatch = async (tournamentId, matchId) => {
|
|
604
|
+
const response = await this.sendRequest({
|
|
605
|
+
type: {
|
|
606
|
+
oneofKind: "deleteMatch",
|
|
607
|
+
deleteMatch: {
|
|
608
|
+
tournamentId,
|
|
609
|
+
matchId,
|
|
610
|
+
},
|
|
611
|
+
},
|
|
612
|
+
});
|
|
613
|
+
if (response.length <= 0) {
|
|
614
|
+
throw new Error("Server timed out");
|
|
615
|
+
}
|
|
616
|
+
return response[0].response;
|
|
617
|
+
};
|
|
618
|
+
createQualifierEvent = async (tournamentId, event) => {
|
|
619
|
+
const response = await this.sendRequest({
|
|
620
|
+
type: {
|
|
621
|
+
oneofKind: "createQualifierEvent",
|
|
622
|
+
createQualifierEvent: {
|
|
623
|
+
tournamentId,
|
|
624
|
+
event,
|
|
625
|
+
},
|
|
626
|
+
},
|
|
627
|
+
});
|
|
628
|
+
if (response.length <= 0) {
|
|
629
|
+
throw new Error("Server timed out");
|
|
630
|
+
}
|
|
631
|
+
return response[0].response;
|
|
632
|
+
};
|
|
633
|
+
setQualifierName = async (tournamentId, qualifierId, qualifierName) => {
|
|
634
|
+
const response = await this.sendRequest({
|
|
635
|
+
type: {
|
|
636
|
+
oneofKind: "setQualifierName",
|
|
637
|
+
setQualifierName: {
|
|
638
|
+
tournamentId,
|
|
639
|
+
qualifierId,
|
|
640
|
+
qualifierName
|
|
641
|
+
},
|
|
642
|
+
},
|
|
643
|
+
});
|
|
644
|
+
if (response.length <= 0) {
|
|
645
|
+
throw new Error("Server timed out");
|
|
646
|
+
}
|
|
647
|
+
return response[0].response;
|
|
648
|
+
};
|
|
649
|
+
setQualifierImage = async (tournamentId, qualifierId, qualifierImage) => {
|
|
650
|
+
const response = await this.sendRequest({
|
|
651
|
+
type: {
|
|
652
|
+
oneofKind: "setQualifierImage",
|
|
653
|
+
setQualifierImage: {
|
|
654
|
+
tournamentId,
|
|
655
|
+
qualifierId,
|
|
656
|
+
qualifierImage
|
|
657
|
+
},
|
|
658
|
+
},
|
|
659
|
+
});
|
|
660
|
+
if (response.length <= 0) {
|
|
661
|
+
throw new Error("Server timed out");
|
|
662
|
+
}
|
|
663
|
+
return response[0].response;
|
|
664
|
+
};
|
|
665
|
+
setQualifierInfoChannel = async (tournamentId, qualifierId, infoChannel) => {
|
|
666
|
+
const response = await this.sendRequest({
|
|
667
|
+
type: {
|
|
668
|
+
oneofKind: "setQualifierInfoChannel",
|
|
669
|
+
setQualifierInfoChannel: {
|
|
670
|
+
tournamentId,
|
|
671
|
+
qualifierId,
|
|
672
|
+
infoChannel
|
|
673
|
+
},
|
|
674
|
+
},
|
|
675
|
+
});
|
|
676
|
+
if (response.length <= 0) {
|
|
677
|
+
throw new Error("Server timed out");
|
|
678
|
+
}
|
|
679
|
+
return response[0].response;
|
|
680
|
+
};
|
|
681
|
+
setQualifierFlags = async (tournamentId, qualifierId, qualifierFlags) => {
|
|
682
|
+
const response = await this.sendRequest({
|
|
683
|
+
type: {
|
|
684
|
+
oneofKind: "setQualifierFlags",
|
|
685
|
+
setQualifierFlags: {
|
|
686
|
+
tournamentId,
|
|
687
|
+
qualifierId,
|
|
688
|
+
qualifierFlags
|
|
689
|
+
},
|
|
690
|
+
},
|
|
691
|
+
});
|
|
692
|
+
if (response.length <= 0) {
|
|
693
|
+
throw new Error("Server timed out");
|
|
694
|
+
}
|
|
695
|
+
return response[0].response;
|
|
696
|
+
};
|
|
697
|
+
setQualifierLeaderboardSort = async (tournamentId, qualifierId, qualifierLeaderboardSort) => {
|
|
698
|
+
const response = await this.sendRequest({
|
|
699
|
+
type: {
|
|
700
|
+
oneofKind: "setQualifierLeaderboardSort",
|
|
701
|
+
setQualifierLeaderboardSort: {
|
|
702
|
+
tournamentId,
|
|
703
|
+
qualifierId,
|
|
704
|
+
qualifierLeaderboardSort
|
|
705
|
+
},
|
|
706
|
+
},
|
|
707
|
+
});
|
|
708
|
+
if (response.length <= 0) {
|
|
709
|
+
throw new Error("Server timed out");
|
|
710
|
+
}
|
|
711
|
+
return response[0].response;
|
|
712
|
+
};
|
|
713
|
+
addQualifierMap = async (tournamentId, qualifierId, map) => {
|
|
714
|
+
const response = await this.sendRequest({
|
|
715
|
+
type: {
|
|
716
|
+
oneofKind: "addQualifierMap",
|
|
717
|
+
addQualifierMap: {
|
|
718
|
+
tournamentId,
|
|
719
|
+
qualifierId,
|
|
720
|
+
map
|
|
721
|
+
},
|
|
722
|
+
},
|
|
723
|
+
});
|
|
724
|
+
if (response.length <= 0) {
|
|
725
|
+
throw new Error("Server timed out");
|
|
726
|
+
}
|
|
727
|
+
return response[0].response;
|
|
728
|
+
};
|
|
729
|
+
updateQualifierMap = async (tournamentId, qualifierId, map) => {
|
|
730
|
+
const response = await this.sendRequest({
|
|
731
|
+
type: {
|
|
732
|
+
oneofKind: "updateQualifierMap",
|
|
733
|
+
updateQualifierMap: {
|
|
734
|
+
tournamentId,
|
|
735
|
+
qualifierId,
|
|
736
|
+
map
|
|
737
|
+
},
|
|
738
|
+
},
|
|
739
|
+
});
|
|
740
|
+
if (response.length <= 0) {
|
|
741
|
+
throw new Error("Server timed out");
|
|
742
|
+
}
|
|
743
|
+
return response[0].response;
|
|
744
|
+
};
|
|
745
|
+
removeQualifierMap = async (tournamentId, qualifierId, mapId) => {
|
|
746
|
+
const response = await this.sendRequest({
|
|
747
|
+
type: {
|
|
748
|
+
oneofKind: "removeQualifierMap",
|
|
749
|
+
removeQualifierMap: {
|
|
750
|
+
tournamentId,
|
|
751
|
+
qualifierId,
|
|
752
|
+
mapId
|
|
753
|
+
},
|
|
754
|
+
},
|
|
755
|
+
});
|
|
756
|
+
if (response.length <= 0) {
|
|
757
|
+
throw new Error("Server timed out");
|
|
758
|
+
}
|
|
759
|
+
return response[0].response;
|
|
760
|
+
};
|
|
761
|
+
deleteQualifierEvent = async (tournamentId, qualifierId) => {
|
|
762
|
+
const response = await this.sendRequest({
|
|
763
|
+
type: {
|
|
764
|
+
oneofKind: "deleteQualifierEvent",
|
|
765
|
+
deleteQualifierEvent: {
|
|
766
|
+
tournamentId,
|
|
767
|
+
qualifierId,
|
|
768
|
+
},
|
|
769
|
+
},
|
|
770
|
+
});
|
|
771
|
+
if (response.length <= 0) {
|
|
772
|
+
throw new Error("Server timed out");
|
|
773
|
+
}
|
|
774
|
+
return response[0].response;
|
|
775
|
+
};
|
|
776
|
+
addAuthorizedUser = async (tournamentId, discordId, permissionFlags) => {
|
|
777
|
+
const response = await this.sendRequest({
|
|
778
|
+
type: {
|
|
779
|
+
oneofKind: "addAuthorizedUser",
|
|
780
|
+
addAuthorizedUser: {
|
|
781
|
+
tournamentId,
|
|
782
|
+
discordId,
|
|
783
|
+
permissionFlags
|
|
784
|
+
},
|
|
785
|
+
},
|
|
786
|
+
});
|
|
787
|
+
if (response.length <= 0) {
|
|
788
|
+
throw new Error("Server timed out");
|
|
789
|
+
}
|
|
790
|
+
return response[0].response;
|
|
791
|
+
};
|
|
792
|
+
removeAuthorizedUser = async (tournamentId, discordId) => {
|
|
793
|
+
const response = await this.sendRequest({
|
|
794
|
+
type: {
|
|
795
|
+
oneofKind: "removeAuthorizedUser",
|
|
796
|
+
removeAuthorizedUser: {
|
|
797
|
+
tournamentId,
|
|
798
|
+
discordId
|
|
799
|
+
},
|
|
800
|
+
},
|
|
801
|
+
});
|
|
802
|
+
if (response.length <= 0) {
|
|
803
|
+
throw new Error("Server timed out");
|
|
804
|
+
}
|
|
805
|
+
return response[0].response;
|
|
806
|
+
};
|
|
807
|
+
getAuthorizedUsers = async (tournamentId) => {
|
|
808
|
+
const response = await this.sendRequest({
|
|
809
|
+
type: {
|
|
810
|
+
oneofKind: "getAuthorizedUsers",
|
|
811
|
+
getAuthorizedUsers: {
|
|
812
|
+
tournamentId,
|
|
813
|
+
},
|
|
814
|
+
},
|
|
815
|
+
});
|
|
816
|
+
if (response.length <= 0) {
|
|
817
|
+
throw new Error("Server timed out");
|
|
818
|
+
}
|
|
819
|
+
return response[0].response;
|
|
820
|
+
};
|
|
821
|
+
getDiscordInfo = async (tournamentId, discordId) => {
|
|
822
|
+
const response = await this.sendRequest({
|
|
823
|
+
type: {
|
|
824
|
+
oneofKind: "getDiscordInfo",
|
|
825
|
+
getDiscordInfo: {
|
|
826
|
+
tournamentId,
|
|
827
|
+
discordId
|
|
828
|
+
},
|
|
829
|
+
},
|
|
830
|
+
});
|
|
831
|
+
if (response.length <= 0) {
|
|
832
|
+
throw new Error("Server timed out");
|
|
833
|
+
}
|
|
834
|
+
return response[0].response;
|
|
835
|
+
};
|
|
836
|
+
createTournament = async (tournament) => {
|
|
837
|
+
const response = await this.sendRequest({
|
|
838
|
+
type: {
|
|
839
|
+
oneofKind: "createTournament",
|
|
840
|
+
createTournament: {
|
|
841
|
+
tournament,
|
|
842
|
+
},
|
|
843
|
+
},
|
|
844
|
+
});
|
|
845
|
+
if (response.length <= 0) {
|
|
846
|
+
throw new Error("Server timed out");
|
|
847
|
+
}
|
|
848
|
+
return response[0].response;
|
|
849
|
+
};
|
|
850
|
+
setTournamentName = async (tournamentId, tournamentName) => {
|
|
851
|
+
const response = await this.sendRequest({
|
|
852
|
+
type: {
|
|
853
|
+
oneofKind: "setTournamentName",
|
|
854
|
+
setTournamentName: {
|
|
855
|
+
tournamentId,
|
|
856
|
+
tournamentName
|
|
857
|
+
},
|
|
858
|
+
},
|
|
859
|
+
});
|
|
860
|
+
if (response.length <= 0) {
|
|
861
|
+
throw new Error("Server timed out");
|
|
862
|
+
}
|
|
863
|
+
return response[0].response;
|
|
864
|
+
};
|
|
865
|
+
setTournamentImage = async (tournamentId, tournamentImage) => {
|
|
866
|
+
const response = await this.sendRequest({
|
|
867
|
+
type: {
|
|
868
|
+
oneofKind: "setTournamentImage",
|
|
869
|
+
setTournamentImage: {
|
|
870
|
+
tournamentId,
|
|
871
|
+
tournamentImage
|
|
872
|
+
},
|
|
873
|
+
},
|
|
874
|
+
});
|
|
875
|
+
if (response.length <= 0) {
|
|
876
|
+
throw new Error("Server timed out");
|
|
877
|
+
}
|
|
878
|
+
return response[0].response;
|
|
879
|
+
};
|
|
880
|
+
setTournamentEnableTeams = async (tournamentId, enableTeams) => {
|
|
881
|
+
const response = await this.sendRequest({
|
|
882
|
+
type: {
|
|
883
|
+
oneofKind: "setTournamentEnableTeams",
|
|
884
|
+
setTournamentEnableTeams: {
|
|
885
|
+
tournamentId,
|
|
886
|
+
enableTeams
|
|
887
|
+
},
|
|
888
|
+
},
|
|
889
|
+
});
|
|
890
|
+
if (response.length <= 0) {
|
|
891
|
+
throw new Error("Server timed out");
|
|
892
|
+
}
|
|
893
|
+
return response[0].response;
|
|
894
|
+
};
|
|
895
|
+
setTournamentEnablePools = async (tournamentId, enablePools) => {
|
|
896
|
+
const response = await this.sendRequest({
|
|
897
|
+
type: {
|
|
898
|
+
oneofKind: "setTournamentEnablePools",
|
|
899
|
+
setTournamentEnablePools: {
|
|
900
|
+
tournamentId,
|
|
901
|
+
enablePools
|
|
902
|
+
},
|
|
903
|
+
},
|
|
904
|
+
});
|
|
905
|
+
if (response.length <= 0) {
|
|
906
|
+
throw new Error("Server timed out");
|
|
907
|
+
}
|
|
908
|
+
return response[0].response;
|
|
909
|
+
};
|
|
910
|
+
setTournamentShowTournamentButton = async (tournamentId, showTournamentButton) => {
|
|
911
|
+
const response = await this.sendRequest({
|
|
912
|
+
type: {
|
|
913
|
+
oneofKind: "setTournamentShowTournamentButton",
|
|
914
|
+
setTournamentShowTournamentButton: {
|
|
915
|
+
tournamentId,
|
|
916
|
+
showTournamentButton
|
|
917
|
+
},
|
|
918
|
+
},
|
|
919
|
+
});
|
|
920
|
+
if (response.length <= 0) {
|
|
921
|
+
throw new Error("Server timed out");
|
|
922
|
+
}
|
|
923
|
+
return response[0].response;
|
|
924
|
+
};
|
|
925
|
+
setTournamentShowQualifierButton = async (tournamentId, showQualifierButton) => {
|
|
926
|
+
const response = await this.sendRequest({
|
|
927
|
+
type: {
|
|
928
|
+
oneofKind: "setTournamentShowQualifierButton",
|
|
929
|
+
setTournamentShowQualifierButton: {
|
|
930
|
+
tournamentId,
|
|
931
|
+
showQualifierButton
|
|
932
|
+
},
|
|
933
|
+
},
|
|
934
|
+
});
|
|
935
|
+
if (response.length <= 0) {
|
|
936
|
+
throw new Error("Server timed out");
|
|
937
|
+
}
|
|
938
|
+
return response[0].response;
|
|
939
|
+
};
|
|
940
|
+
setTournamentAllowUnauthorizedView = async (tournamentId, allowUnauthorizedView) => {
|
|
941
|
+
const response = await this.sendRequest({
|
|
942
|
+
type: {
|
|
943
|
+
oneofKind: "setTournamentAllowUnauthorizedView",
|
|
944
|
+
setTournamentAllowUnauthorizedView: {
|
|
945
|
+
tournamentId,
|
|
946
|
+
allowUnauthorizedView
|
|
947
|
+
},
|
|
948
|
+
},
|
|
949
|
+
});
|
|
950
|
+
if (response.length <= 0) {
|
|
951
|
+
throw new Error("Server timed out");
|
|
952
|
+
}
|
|
953
|
+
return response[0].response;
|
|
954
|
+
};
|
|
955
|
+
setTournamentScoreUpdateFrequency = async (tournamentId, scoreUpdateFrequency) => {
|
|
956
|
+
const response = await this.sendRequest({
|
|
957
|
+
type: {
|
|
958
|
+
oneofKind: "setTournamentScoreUpdateFrequency",
|
|
959
|
+
setTournamentScoreUpdateFrequency: {
|
|
960
|
+
tournamentId,
|
|
961
|
+
scoreUpdateFrequency
|
|
962
|
+
},
|
|
963
|
+
},
|
|
964
|
+
});
|
|
965
|
+
if (response.length <= 0) {
|
|
966
|
+
throw new Error("Server timed out");
|
|
967
|
+
}
|
|
968
|
+
return response[0].response;
|
|
969
|
+
};
|
|
970
|
+
setTournamentBannedMods = async (tournamentId, bannedMods) => {
|
|
971
|
+
const response = await this.sendRequest({
|
|
972
|
+
type: {
|
|
973
|
+
oneofKind: 'setTournamentBannedMods',
|
|
974
|
+
setTournamentBannedMods: {
|
|
975
|
+
tournamentId,
|
|
976
|
+
bannedMods
|
|
977
|
+
},
|
|
978
|
+
},
|
|
979
|
+
});
|
|
980
|
+
if (response.length <= 0) {
|
|
981
|
+
throw new Error("Server timed out");
|
|
982
|
+
}
|
|
983
|
+
return response[0].response;
|
|
984
|
+
};
|
|
985
|
+
addTournamentTeam = async (tournamentId, team) => {
|
|
986
|
+
const response = await this.sendRequest({
|
|
987
|
+
type: {
|
|
988
|
+
oneofKind: "addTournamentTeam",
|
|
989
|
+
addTournamentTeam: {
|
|
990
|
+
tournamentId,
|
|
991
|
+
team
|
|
992
|
+
},
|
|
993
|
+
},
|
|
994
|
+
});
|
|
995
|
+
if (response.length <= 0) {
|
|
996
|
+
throw new Error("Server timed out");
|
|
997
|
+
}
|
|
998
|
+
return response[0].response;
|
|
999
|
+
};
|
|
1000
|
+
setTournamentTeamName = async (tournamentId, teamId, teamName) => {
|
|
1001
|
+
const response = await this.sendRequest({
|
|
1002
|
+
type: {
|
|
1003
|
+
oneofKind: "setTournamentTeamName",
|
|
1004
|
+
setTournamentTeamName: {
|
|
1005
|
+
tournamentId,
|
|
1006
|
+
teamId,
|
|
1007
|
+
teamName
|
|
1008
|
+
},
|
|
1009
|
+
},
|
|
1010
|
+
});
|
|
1011
|
+
if (response.length <= 0) {
|
|
1012
|
+
throw new Error("Server timed out");
|
|
1013
|
+
}
|
|
1014
|
+
return response[0].response;
|
|
1015
|
+
};
|
|
1016
|
+
setTournamentTeamImage = async (tournamentId, teamId, teamImage) => {
|
|
1017
|
+
const response = await this.sendRequest({
|
|
1018
|
+
type: {
|
|
1019
|
+
oneofKind: "setTournamentTeamImage",
|
|
1020
|
+
setTournamentTeamImage: {
|
|
1021
|
+
tournamentId,
|
|
1022
|
+
teamId,
|
|
1023
|
+
teamImage
|
|
1024
|
+
},
|
|
1025
|
+
},
|
|
1026
|
+
});
|
|
1027
|
+
if (response.length <= 0) {
|
|
1028
|
+
throw new Error("Server timed out");
|
|
1029
|
+
}
|
|
1030
|
+
return response[0].response;
|
|
1031
|
+
};
|
|
1032
|
+
removeTournamentTeam = async (tournamentId, teamId) => {
|
|
1033
|
+
const response = await this.sendRequest({
|
|
1034
|
+
type: {
|
|
1035
|
+
oneofKind: "removeTournamentTeam",
|
|
1036
|
+
removeTournamentTeam: {
|
|
1037
|
+
tournamentId,
|
|
1038
|
+
teamId
|
|
1039
|
+
},
|
|
1040
|
+
},
|
|
1041
|
+
});
|
|
1042
|
+
if (response.length <= 0) {
|
|
1043
|
+
throw new Error("Server timed out");
|
|
1044
|
+
}
|
|
1045
|
+
return response[0].response;
|
|
1046
|
+
};
|
|
1047
|
+
addTournamentPool = async (tournamentId, pool) => {
|
|
1048
|
+
const response = await this.sendRequest({
|
|
1049
|
+
type: {
|
|
1050
|
+
oneofKind: "addTournamentPool",
|
|
1051
|
+
addTournamentPool: {
|
|
1052
|
+
tournamentId,
|
|
1053
|
+
pool
|
|
1054
|
+
},
|
|
1055
|
+
},
|
|
1056
|
+
});
|
|
1057
|
+
if (response.length <= 0) {
|
|
1058
|
+
throw new Error("Server timed out");
|
|
1059
|
+
}
|
|
1060
|
+
return response[0].response;
|
|
1061
|
+
};
|
|
1062
|
+
setTournamentPoolName = async (tournamentId, poolId, poolName) => {
|
|
1063
|
+
const response = await this.sendRequest({
|
|
1064
|
+
type: {
|
|
1065
|
+
oneofKind: "setTournamentPoolName",
|
|
1066
|
+
setTournamentPoolName: {
|
|
1067
|
+
tournamentId,
|
|
1068
|
+
poolId,
|
|
1069
|
+
poolName
|
|
1070
|
+
},
|
|
1071
|
+
},
|
|
1072
|
+
});
|
|
1073
|
+
if (response.length <= 0) {
|
|
1074
|
+
throw new Error("Server timed out");
|
|
1075
|
+
}
|
|
1076
|
+
return response[0].response;
|
|
1077
|
+
};
|
|
1078
|
+
addTournamentPoolMap = async (tournamentId, poolId, map) => {
|
|
1079
|
+
const response = await this.sendRequest({
|
|
1080
|
+
type: {
|
|
1081
|
+
oneofKind: "addTournamentPoolMap",
|
|
1082
|
+
addTournamentPoolMap: {
|
|
1083
|
+
tournamentId,
|
|
1084
|
+
poolId,
|
|
1085
|
+
map
|
|
1086
|
+
},
|
|
1087
|
+
},
|
|
1088
|
+
});
|
|
1089
|
+
if (response.length <= 0) {
|
|
1090
|
+
throw new Error("Server timed out");
|
|
1091
|
+
}
|
|
1092
|
+
return response[0].response;
|
|
1093
|
+
};
|
|
1094
|
+
updateTournamentPoolMap = async (tournamentId, poolId, map) => {
|
|
1095
|
+
const response = await this.sendRequest({
|
|
1096
|
+
type: {
|
|
1097
|
+
oneofKind: "updateTournamentPoolMap",
|
|
1098
|
+
updateTournamentPoolMap: {
|
|
1099
|
+
tournamentId,
|
|
1100
|
+
poolId,
|
|
1101
|
+
map
|
|
1102
|
+
},
|
|
1103
|
+
},
|
|
1104
|
+
});
|
|
1105
|
+
if (response.length <= 0) {
|
|
1106
|
+
throw new Error("Server timed out");
|
|
1107
|
+
}
|
|
1108
|
+
return response[0].response;
|
|
1109
|
+
};
|
|
1110
|
+
removeTournamentPoolMap = async (tournamentId, poolId, mapId) => {
|
|
1111
|
+
const response = await this.sendRequest({
|
|
1112
|
+
type: {
|
|
1113
|
+
oneofKind: "removeTournamentPoolMap",
|
|
1114
|
+
removeTournamentPoolMap: {
|
|
1115
|
+
tournamentId,
|
|
1116
|
+
poolId,
|
|
1117
|
+
mapId
|
|
1118
|
+
},
|
|
1119
|
+
},
|
|
1120
|
+
});
|
|
1121
|
+
if (response.length <= 0) {
|
|
1122
|
+
throw new Error("Server timed out");
|
|
1123
|
+
}
|
|
1124
|
+
return response[0].response;
|
|
1125
|
+
};
|
|
1126
|
+
removeTournamentPool = async (tournamentId, poolId) => {
|
|
1127
|
+
const response = await this.sendRequest({
|
|
1128
|
+
type: {
|
|
1129
|
+
oneofKind: "removeTournamentPool",
|
|
1130
|
+
removeTournamentPool: {
|
|
1131
|
+
tournamentId,
|
|
1132
|
+
poolId
|
|
1133
|
+
},
|
|
1134
|
+
},
|
|
1135
|
+
});
|
|
1136
|
+
if (response.length <= 0) {
|
|
1137
|
+
throw new Error("Server timed out");
|
|
1138
|
+
}
|
|
1139
|
+
return response[0].response;
|
|
1140
|
+
};
|
|
1141
|
+
deleteTournament = async (tournamentId) => {
|
|
1142
|
+
const response = await this.sendRequest({
|
|
1143
|
+
type: {
|
|
1144
|
+
oneofKind: "deleteTournament",
|
|
1145
|
+
deleteTournament: {
|
|
1146
|
+
tournamentId,
|
|
1147
|
+
},
|
|
1148
|
+
},
|
|
1149
|
+
});
|
|
1150
|
+
if (response.length <= 0) {
|
|
1151
|
+
throw new Error("Server timed out");
|
|
1152
|
+
}
|
|
1153
|
+
return response[0].response;
|
|
1154
|
+
};
|
|
1155
|
+
addServer = async (server, authToken) => {
|
|
1156
|
+
const response = await this.sendRequest({
|
|
1157
|
+
type: {
|
|
1158
|
+
oneofKind: "addServer",
|
|
1159
|
+
addServer: {
|
|
1160
|
+
server,
|
|
1161
|
+
authToken: authToken ?? "",
|
|
1162
|
+
},
|
|
1163
|
+
},
|
|
1164
|
+
});
|
|
1165
|
+
if (response.length <= 0) {
|
|
1166
|
+
throw new Error("Server timed out");
|
|
1167
|
+
}
|
|
1168
|
+
return response[0].response;
|
|
1169
|
+
};
|
|
1170
|
+
}
|