forked from clusterio/clusterio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages_instance.ts
945 lines (789 loc) · 24.9 KB
/
messages_instance.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
import { Type, Static } from "@sinclair/typebox";
import PlayerStats from "./PlayerStats";
import { JsonString, StringEnum, jsonArray, plainJson } from "./composites";
import { InstanceConfig } from "../config";
import type { IControllerUser } from "./User";
import type { MessageRequest } from "./messages_core";
import { CollectorResultSerialized } from "../prometheus";
export const InstanceStatus = StringEnum([
"unknown",
"unassigned",
"stopped",
"starting",
"running",
"stopping",
"creating_save",
"exporting_data",
"deleted",
]);
/**
* Current status of the instance. One of:
* - `unknown`: Instance is assigned to a host but this host is currently
* not connected to the contreller.
* - `unassigned`: Instance is not assigned to a a host and exists only on
* the controller.
* - `stopped`: Instance is stopped.
* - `starting`: Instance is in the process of starting up.
* - `running`: Instance is running normally.
* - `stopping`: Instance is in the process of stopping.
* - `creating_save`: Instance is in the process of creating a save.
* - `exporting_data`: Instance is in the process of exporting game data.
* - `deleted`: Instance has been deleted.
*/
export type InstanceStatus = Static<typeof InstanceStatus>;
export class InstanceDetails {
constructor(
public name: string,
public id: number,
public assignedHost: number | undefined,
public gamePort: number | undefined,
public status: InstanceStatus,
/** Millisecond Unix timestamp this entry was last updated at */
public updatedAtMs = 0,
) { }
static jsonSchema = Type.Object({
"name": Type.String(),
"id": Type.Integer(),
"assignedHost": Type.Optional(Type.Integer()),
"gamePort": Type.Optional(Type.Integer()),
"status": StringEnum([
"unknown", "unassigned", "stopped", "starting", "running", "stopping",
"creating_save", "exporting_data", "deleted",
]),
"updatedAtMs": Type.Optional(Type.Number()),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(
json.name,
json.id,
json.assignedHost,
json.gamePort,
json.status,
json.updatedAtMs,
);
}
get isDeleted() {
return this.status === "deleted";
}
}
export class InstanceDetailsGetRequest {
declare ["constructor"]: typeof InstanceDetailsGetRequest;
static type = "request" as const;
static src = "control" as const;
static dst = "controller" as const;
static permission = "core.instance.get" as const;
constructor(
public instanceId: number,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId);
}
static Response = InstanceDetails;
}
export class InstanceDetailsListRequest {
declare ["constructor"]: typeof InstanceDetailsListRequest;
static type = "request" as const;
static src = "control" as const;
static dst = "controller" as const;
static permission = "core.instance.list" as const;
static Response = jsonArray(InstanceDetails);
};
export class InstanceDetailsUpdatesEvent {
declare ["constructor"]: typeof InstanceDetailsUpdatesEvent;
static type = "event" as const;
static src = "controller" as const;
static dst = "control" as const;
static permission = "core.instance.subscribe" as const;
constructor(
public updates: InstanceDetails[],
) { }
static jsonSchema = Type.Object({
"updates": Type.Array(InstanceDetails.jsonSchema),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.updates.map(update => InstanceDetails.fromJSON(update)));
}
};
export class InstanceCreateRequest {
declare ["constructor"]: typeof InstanceCreateRequest;
static type = "request" as const;
static src = "control" as const;
static dst = "controller" as const;
static permission = "core.instance.create" as const;
constructor(
public config: Static<typeof InstanceConfig.jsonSchema>,
) { }
static jsonSchema = Type.Object({
"config": InstanceConfig.jsonSchema,
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.config);
}
}
export class InstanceConfigGetRequest {
declare ["constructor"]: typeof InstanceConfigGetRequest;
static type = "request" as const;
static src = "control" as const;
static dst = "controller" as const;
static permission = "core.instance.get_config" as const;
static Response = plainJson(InstanceConfig.jsonSchema);
constructor(
public instanceId: number,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId);
}
}
export class InstanceConfigSetFieldRequest {
declare ["constructor"]: typeof InstanceConfigSetFieldRequest;
static type = "request" as const;
static src = "control" as const;
static dst = "controller" as const;
static permission = "core.instance.update_config" as const;
constructor(
public instanceId: number,
public field: string,
public value: string,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
"field": Type.String(),
"value": Type.String(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId, json.field, json.value);
}
}
export class InstanceConfigSetPropRequest {
declare ["constructor"]: typeof InstanceConfigSetPropRequest;
static type = "request" as const;
static src = "control" as const;
static dst = "controller" as const;
static permission = "core.instance.update_config" as const;
constructor(
public instanceId: number,
public field: string,
public prop: string,
public value?: unknown,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
"field": Type.String(),
"prop": Type.String(),
"value": Type.Optional(Type.Unknown()),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId, json.field, json.prop, json.value);
}
}
export class InstanceAssignRequest {
declare ["constructor"]: typeof InstanceAssignRequest;
static type = "request" as const;
static src = "control" as const;
static dst = "controller" as const;
static permission = "core.instance.assign" as const;
constructor(
public instanceId: number,
public hostId?: number,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Number(),
"hostId": Type.Optional(Type.Number()),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId, json.hostId);
}
}
export class InstanceMetricsRequest {
declare ["constructor"]: typeof InstanceMetricsRequest;
static type = "request" as const;
static src = "host" as const;
static dst = "instance" as const;
static Response = class Response { // TODO: Use JSON class pattern in Prometheus
constructor(
public results: CollectorResultSerialized[],
) { }
static jsonSchema = Type.Object({
"results": Type.Array(CollectorResultSerialized),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.results);
}
};
}
export class InstanceStartRequest {
declare ["constructor"]: typeof InstanceStartRequest;
static type = "request" as const;
static src = ["control", "controller"] as const;
static dst = "instance" as const;
static permission = "core.instance.start" as const;
constructor(
public save?: string,
) { }
static jsonSchema = Type.Object({
"save": Type.Optional(Type.String()),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.save);
}
}
export class SaveDetails {
constructor(
public instanceId: number,
public type: "file" | "directory" | "special",
public name: string,
public size: number,
public mtimeMs: number,
public loaded: boolean,
public loadByDefault: boolean,
/** Millisecond Unix timestamp this entry was last updated at */
public updatedAtMs: number,
public isDeleted: boolean,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
"type": StringEnum(["file", "directory", "special"]),
"name": Type.String(),
"size": Type.Integer(),
"mtimeMs": Type.Number(),
"loaded": Type.Boolean(),
"loadByDefault": Type.Boolean(),
"updatedAtMs": Type.Number(),
"isDeleted": Type.Boolean(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(
json.instanceId,
json.type,
json.name,
json.size,
json.mtimeMs,
json.loaded,
json.loadByDefault,
json.updatedAtMs,
json.isDeleted,
);
}
/** Concatenation of instance id and name forming a unique string for this save */
get id() {
return `${this.instanceId}/${this.name}`;
}
/**
* Compare this save with another save.
* @param other - save to compare with.
* @returns true if this save is identical to the provided save
*/
equals(other: SaveDetails) {
// Note that updatedAtMs is not included in the equality check because
// instances send the whole list of saves with updatedAtMs set to zero
// to the controller whenever any save changes and this equals check
// is used to filter whether a save was updated.
return (
this.instanceId === other.instanceId
&& this.type === other.type
&& this.name === other.name
&& this.size === other.size
&& this.mtimeMs === other.mtimeMs
&& this.loaded === other.loaded
&& this.loadByDefault === other.loadByDefault
&& this.isDeleted === other.isDeleted
);
}
}
export class InstanceSaveDetailsListRequest {
declare ["constructor"]: typeof InstanceSaveDetailsListRequest;
static type = "request" as const;
static src = ["control", "host"] as const;
static dst = ["controller", "instance"] as const;
static permission = "core.instance.save.list" as const;
static Response = jsonArray(SaveDetails);
}
export class InstanceSaveDetailsUpdatesEvent {
declare ["constructor"]: typeof InstanceSaveDetailsUpdatesEvent;
static type = "event" as const;
static src = ["instance", "host", "controller"] as const;
static dst = ["controller", "control"] as const;
static permission = "core.instance.save.list.subscribe" as const;
constructor(
public updates: SaveDetails[],
/**
* Present if this update was sent by a host and updates contains all
* saves of the given instance.
*/
public instanceId?: number,
) { }
static jsonSchema = Type.Object({
"updates": Type.Array(SaveDetails.jsonSchema),
"instanceId": Type.Optional(Type.Integer()),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.updates.map(i => SaveDetails.fromJSON(i)), json.instanceId);
}
}
export class InstanceCreateSaveRequest {
declare ["constructor"]: typeof InstanceCreateSaveRequest;
static type = "request" as const;
static src = ["control", "controller"] as const;
static dst = "instance" as const;
static permission = "core.instance.save.create" as const;
constructor(
public name: string,
public seed?: number,
public mapGenSettings?: object,
public mapSettings?: object,
) { }
static jsonSchema = Type.Object({
"name": Type.String(),
"seed": Type.Optional(Type.Integer()),
"mapGenSettings": Type.Optional(Type.Object({})),
"mapSettings": Type.Optional(Type.Object({})),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.name, json.seed, json.mapGenSettings, json.mapSettings);
}
}
export class InstanceRenameSaveRequest {
declare ["constructor"]: typeof InstanceRenameSaveRequest;
static type = "request" as const;
static src = ["control", "controller"] as const;
static dst = ["controller", "host"] as const;
static permission = "core.instance.save.rename" as const;
constructor(
public instanceId: number,
public oldName: string,
public newName: string,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
"oldName": Type.String(),
"newName": Type.String(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId, json.oldName, json.newName);
}
}
export class InstanceCopySaveRequest {
declare ["constructor"]: typeof InstanceCopySaveRequest;
static type = "request" as const;
static src = ["control", "controller"] as const;
static dst = ["controller", "host"] as const;
static permission = "core.instance.save.copy" as const;
constructor(
public instanceId: number,
public source: string,
public destination: string,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
"source": Type.String(),
"destination": Type.String(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId, json.source, json.destination);
}
}
export class InstanceDeleteSaveRequest {
declare ["constructor"]: typeof InstanceDeleteSaveRequest;
static type = "request" as const;
static src = ["control", "controller"] as const;
static dst = ["controller", "host"] as const;
static permission = "core.instance.save.delete" as const;
constructor(
public instanceId: number,
public name: string,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
"name": Type.String(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId, json.name);
}
}
export class InstanceDownloadSaveRequest {
declare ["constructor"]: typeof InstanceDownloadSaveRequest;
static type = "request" as const;
static src = ["control", "controller"] as const;
static dst = "controller" as const;
static permission = "core.instance.save.download" as const;
constructor(
public instanceId: number,
public name: string,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
"name": Type.String(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId, json.name);
}
static Response = JsonString;
}
export class InstanceTransferSaveRequest {
declare ["constructor"]: typeof InstanceTransferSaveRequest;
static type = "request" as const;
static src = ["control", "controller"] as const;
static dst = ["controller", "host"] as const;
static permission(user: IControllerUser, message: MessageRequest) {
user.checkPermission("core.instance.save.transfer");
if (typeof message.data === "object" && message.data !== null) {
const data = message.data as { copy: boolean, sourceName: string, targetName: string };
if (data.copy) {
user.checkPermission("core.instance.save.copy");
} else if (data.sourceName !== data.targetName) {
user.checkPermission("core.instance.save.rename");
}
}
}
constructor(
public sourceInstanceId: number,
public sourceName: string,
public targetInstanceId: number,
public targetName: string,
public copy: boolean,
) { }
static jsonSchema = Type.Object({
"sourceInstanceId": Type.Number(),
"sourceName": Type.String(),
"targetInstanceId": Type.Number(),
"targetName": Type.String(),
"copy": Type.Boolean(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(
json.sourceInstanceId, json.sourceName, json.targetInstanceId, json.targetName, json.copy
);
}
static Response = JsonString;
}
export class InstancePullSaveRequest {
declare ["constructor"]: typeof InstancePullSaveRequest;
static type = "request" as const;
static src = "controller" as const;
static dst = "host" as const;
constructor(
public instanceId: number,
public streamId: string,
public name: string,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
"streamId": Type.String(),
"name": Type.String(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId, json.streamId, json.name);
}
static Response = JsonString;
}
export class InstancePushSaveRequest {
declare ["constructor"]: typeof InstancePushSaveRequest;
static type = "request" as const;
static src = "controller" as const;
static dst = "host" as const;
constructor(
public instanceId: number,
public streamId: string,
public name: string,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
"streamId": Type.String(),
"name": Type.String(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId, json.streamId, json.name);
}
}
export class InstanceLoadScenarioRequest {
declare ["constructor"]: typeof InstanceLoadScenarioRequest;
static type = "request" as const;
static src = ["control", "controller"] as const;
static dst = "instance" as const;
static permission = "core.instance.load_scenario" as const;
constructor(
public scenario: string,
public seed?: number,
public mapGenSettings?: object,
public mapSettings?: object,
) { }
static jsonSchema = Type.Object({
"scenario": Type.String(),
"seed": Type.Optional(Type.Integer()),
"mapGenSettings": Type.Optional(Type.Object({})),
"mapSettings": Type.Optional(Type.Object({})),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.scenario, json.seed, json.mapGenSettings, json.mapSettings);
}
}
export class InstanceExportDataRequest {
declare ["constructor"]: typeof InstanceExportDataRequest;
static type = "request" as const;
static src = ["control", "controller"] as const;
static dst = "instance" as const;
static permission = "core.instance.export_data" as const;
}
export class InstanceExtractPlayersRequest {
declare ["constructor"]: typeof InstanceExtractPlayersRequest;
static type = "request" as const;
static src = ["control", "controller"] as const;
static dst = "instance" as const;
static permission = "core.instance.extract_players" as const;
}
export class InstanceStopRequest {
declare ["constructor"]: typeof InstanceStopRequest;
static type = "request" as const;
static src = ["control", "controller"] as const;
static dst = "instance" as const;
static permission = "core.instance.stop" as const;
}
export class InstanceKillRequest {
declare ["constructor"]: typeof InstanceKillRequest;
static type = "request" as const;
static src = ["control", "controller"] as const;
static dst = "instance" as const;
static permission = "core.instance.kill" as const;
}
export class InstanceDeleteRequest {
declare ["constructor"]: typeof InstanceDeleteRequest;
static type = "request" as const;
static src = "control" as const;
static dst = "controller" as const;
static permission = "core.instance.delete" as const;
constructor(
public instanceId: number,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId);
}
}
export class InstanceDeleteInternalRequest {
declare ["constructor"]: typeof InstanceDeleteInternalRequest;
static type = "request" as const;
static src = "controller" as const;
static dst = "host" as const;
constructor(
public instanceId: number,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId);
}
}
export class InstanceSendRconRequest {
declare ["constructor"]: typeof InstanceSendRconRequest;
static type = "request" as const;
static src = ["control", "controller"] as const;
static dst = "instance" as const;
static permission = "core.instance.send_rcon" as const;
constructor(
public command: string,
) { }
static jsonSchema = Type.Object({
"command": Type.String(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.command);
}
static Response = JsonString;
}
export class HostInstanceUpdate {
constructor(
public config: Static<typeof InstanceConfig.jsonSchema>,
public status: InstanceStatus,
public gamePort: undefined | number,
) { }
static jsonSchema = Type.Object({
"config": InstanceConfig.jsonSchema,
"status": StringEnum([
"stopped", "starting", "running", "stopping", "creating_save", "exporting_data",
]),
"gamePort": Type.Optional(Type.Number()),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.config, json.status, json.gamePort);
}
}
export class InstancesUpdateRequest {
declare ["constructor"]: typeof InstancesUpdateRequest;
static type = "request" as const;
static src = "host" as const;
static dst = "controller" as const;
constructor(
public instances: HostInstanceUpdate[],
) { }
static jsonSchema = Type.Array(HostInstanceUpdate.jsonSchema);
toJSON() {
return this.instances;
}
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.map(i => HostInstanceUpdate.fromJSON(i)));
}
}
export class InstanceAssignInternalRequest {
declare ["constructor"]: typeof InstanceAssignInternalRequest;
static type = "request" as const;
static src = "controller" as const;
static dst = "host" as const;
constructor(
public instanceId: number,
public config: Static<typeof InstanceConfig.jsonSchema>,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
"config": InstanceConfig.jsonSchema,
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId, json.config);
}
}
export class InstanceUnassignInternalRequest {
declare ["constructor"]: typeof InstanceUnassignInternalRequest;
static type = "request" as const;
static src = "controller" as const;
static dst = "host" as const;
constructor(
public instanceId: number,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId);
}
}
export class InstanceInitialisedEvent {
declare ["constructor"]: typeof InstanceInitialisedEvent;
static type = "event" as const;
static src = "instance" as const;
static dst = "host" as const;
constructor(
public plugins: Record<string, string>,
) { }
static jsonSchema = Type.Object({
"plugins": Type.Record(Type.String(), Type.String()),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.plugins);
}
}
export class InstanceStatusChangedEvent {
declare ["constructor"]: typeof InstanceStatusChangedEvent;
static type = "event" as const;
static src = ["instance", "host"] as const;
static dst = "controller" as const;
constructor(
public instanceId: number,
public status: InstanceStatus,
public gamePort?: number,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
"status": StringEnum([
"stopped", "starting", "running", "stopping", "creating_save", "exporting_data",
]),
"gamePort": Type.Optional(Type.Integer()),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId, json.status, json.gamePort);
}
}
export class InstanceDetailsChangedEvent {
declare ["constructor"]: typeof InstanceDetailsChangedEvent;
static type = "event" as const;
static src = "instance" as const;
static dst = "controller" as const;
constructor(
public details: InstanceDetails,
) { }
static jsonSchema = InstanceDetails.jsonSchema;
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(InstanceDetails.fromJSON(json));
}
}
export class InstanceBanlistUpdateEvent {
declare ["constructor"]: typeof InstanceBanlistUpdateEvent;
static type = "event" as const;
static src = "controller" as const;
static dst = "instance" as const;
constructor(
public name: string,
public banned: boolean,
public reason: string,
) { }
static jsonSchema = Type.Object({
"name": Type.String(),
"banned": Type.Boolean(),
"reason": Type.String(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.name, json.banned, json.reason);
}
}
export class InstanceAdminlistUpdateEvent {
declare ["constructor"]: typeof InstanceAdminlistUpdateEvent;
static type = "event" as const;
static src = "controller" as const;
static dst = "instance" as const;
constructor(
public name: string,
public admin: boolean,
) { }
static jsonSchema = Type.Object({
"name": Type.String(),
"admin": Type.Boolean(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.name, json.admin);
}
}
export class InstanceWhitelistUpdateEvent {
declare ["constructor"]: typeof InstanceWhitelistUpdateEvent;
static type = "event" as const;
static src = "controller" as const;
static dst = "instance" as const;
constructor(
public name: string,
public whitelisted: boolean,
) { }
static jsonSchema = Type.Object({
"name": Type.String(),
"whitelisted": Type.Boolean(),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.name, json.whitelisted);
}
}
export class InstancePlayerUpdateEvent {
declare ["constructor"]: typeof InstancePlayerUpdateEvent;
static type = "event" as const;
static src = "instance" as const;
static dst = "controller" as const;
constructor(
public type: "join" | "leave" | "import",
public name: string,
public stats: PlayerStats,
public reason?: string,
) { }
static jsonSchema = Type.Object({
"type": StringEnum(["join", "leave", "import"]),
"name": Type.String(),
"reason": Type.Optional(Type.String()),
"stats": Type.Unsafe<object>(PlayerStats.jsonSchema),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.type, json.name, PlayerStats.fromJSON(json.stats), json.reason);
}
}