mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-05 20:39:59 -08:00
Webatrice admin commands (#5051)
* Add AdminCommand.updateServerMessage * Add AdminCommand.shutdownServer * Add AdminCommand.reloadConfig * Cleanup * Add AdminCommand.adjustMod * Lint * Lint
This commit is contained in:
19
webclient/src/api/AdminService.tsx
Normal file
19
webclient/src/api/AdminService.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { AdminCommands } from 'websocket';
|
||||
|
||||
export default class AdminService {
|
||||
static adjustMod(userName: string, shouldBeMod?: boolean, shouldBeJudge?: boolean): void {
|
||||
AdminCommands.adjustMod(userName, shouldBeMod, shouldBeJudge);
|
||||
}
|
||||
|
||||
static reloadConfig(): void {
|
||||
AdminCommands.reloadConfig();
|
||||
}
|
||||
|
||||
static shutdownServer(reason: string, minutes: number): void {
|
||||
AdminCommands.shutdownServer(reason, minutes);
|
||||
}
|
||||
|
||||
static updateServerMessage(): void {
|
||||
AdminCommands.updateServerMessage();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export { default as AdminService } from './AdminService';
|
||||
export { default as AuthenticationService } from './AuthenticationService';
|
||||
export { default as ModeratorService } from './ModeratorService';
|
||||
export { default as RoomsService } from './RoomsService';
|
||||
|
||||
29
webclient/src/websocket/commands/admin/adjustMod.ts
Normal file
29
webclient/src/websocket/commands/admin/adjustMod.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import webClient from '../../WebClient';
|
||||
import { AdminPersistence } from '../../persistence';
|
||||
|
||||
export function adjustMod(userName: string, shouldBeMod?: boolean, shouldBeJudge?: boolean): void {
|
||||
const command = webClient.protobuf.controller.Command_AdjustMod.create({ userName, shouldBeMod, shouldBeJudge });
|
||||
|
||||
const sc = webClient.protobuf.controller.AdminCommand.create({
|
||||
'.Command_AdjustMod.ext': command
|
||||
});
|
||||
|
||||
webClient.protobuf.sendAdminCommand(sc, (raw) => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
let error: string;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
AdminPersistence.adjustMod(userName, shouldBeMod, shouldBeJudge);
|
||||
return;
|
||||
default:
|
||||
error = 'Failed to reload config.';
|
||||
break;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
console.error(responseCode, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
4
webclient/src/websocket/commands/admin/index.ts
Normal file
4
webclient/src/websocket/commands/admin/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './adjustMod';
|
||||
export * from './reloadConfig';
|
||||
export * from './shutdownServer';
|
||||
export * from './updateServerMessage';
|
||||
29
webclient/src/websocket/commands/admin/reloadConfig.ts
Normal file
29
webclient/src/websocket/commands/admin/reloadConfig.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import webClient from '../../WebClient';
|
||||
import { AdminPersistence } from '../../persistence';
|
||||
|
||||
export function reloadConfig(): void {
|
||||
const command = webClient.protobuf.controller.Command_ReloadConfig.create();
|
||||
|
||||
const sc = webClient.protobuf.controller.AdminCommand.create({
|
||||
'.Command_ReloadConfig.ext': command
|
||||
});
|
||||
|
||||
webClient.protobuf.sendAdminCommand(sc, (raw) => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
let error: string;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
AdminPersistence.reloadConfig();
|
||||
return;
|
||||
default:
|
||||
error = 'Failed to reload config.';
|
||||
break;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
console.error(responseCode, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
29
webclient/src/websocket/commands/admin/shutdownServer.ts
Normal file
29
webclient/src/websocket/commands/admin/shutdownServer.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import webClient from '../../WebClient';
|
||||
import { AdminPersistence } from '../../persistence';
|
||||
|
||||
export function shutdownServer(reason: string, minutes: number): void {
|
||||
const command = webClient.protobuf.controller.Command_ShutdownServer.create({ reason, minutes });
|
||||
|
||||
const sc = webClient.protobuf.controller.AdminCommand.create({
|
||||
'.Command_ShutdownServer.ext': command
|
||||
});
|
||||
|
||||
webClient.protobuf.sendAdminCommand(sc, (raw) => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
let error: string;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
AdminPersistence.shutdownServer();
|
||||
return;
|
||||
default:
|
||||
error = 'Failed to update server message.';
|
||||
break;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
console.error(responseCode, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import webClient from '../../WebClient';
|
||||
import { AdminPersistence } from '../../persistence';
|
||||
|
||||
export function updateServerMessage(): void {
|
||||
const command = webClient.protobuf.controller.Command_UpdateServerMessage.create();
|
||||
|
||||
const sc = webClient.protobuf.controller.AdminCommand.create({
|
||||
'.Command_UpdateServerMessage.ext': command
|
||||
});
|
||||
|
||||
webClient.protobuf.sendAdminCommand(sc, (raw) => {
|
||||
const { responseCode } = raw;
|
||||
|
||||
let error: string;
|
||||
|
||||
switch (responseCode) {
|
||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||
AdminPersistence.updateServerMessage();
|
||||
return;
|
||||
default:
|
||||
error = 'Failed to update server message.';
|
||||
break;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
console.error(responseCode, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export * as AdminCommands from './admin';
|
||||
export * as ModeratorCommands from './moderator';
|
||||
export * as RoomCommands from './room';
|
||||
export * as SessionCommands from './session';
|
||||
|
||||
17
webclient/src/websocket/persistence/AdminPresistence.ts
Normal file
17
webclient/src/websocket/persistence/AdminPresistence.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export class AdminPersistence {
|
||||
static adjustMod(userName: string, shouldBeMod: boolean, shouldBeJudge: boolean) {
|
||||
console.log('adjustMod');
|
||||
}
|
||||
|
||||
static reloadConfig() {
|
||||
console.log('reloadConfig');
|
||||
}
|
||||
|
||||
static shutdownServer() {
|
||||
console.log('shutdownServer');
|
||||
}
|
||||
|
||||
static updateServerMessage() {
|
||||
console.log('updateServerMessage');
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export { AdminPersistence } from './AdminPresistence';
|
||||
export { RoomPersistence } from './RoomPersistence';
|
||||
export { SessionPersistence } from './SessionPersistence';
|
||||
export { ModeratorPersistence } from './ModeratorPresistence';
|
||||
|
||||
@@ -55,6 +55,14 @@ export class ProtobufService {
|
||||
this.sendCommand(cmd, (raw) => callback && callback(raw));
|
||||
}
|
||||
|
||||
public sendAdminCommand(adminCmd: number, callback?: Function) {
|
||||
const cmd = this.controller.CommandContainer.create({
|
||||
'adminCommand': [adminCmd]
|
||||
});
|
||||
|
||||
this.sendCommand(cmd, (raw) => callback && callback(raw));
|
||||
}
|
||||
|
||||
public sendCommand(cmd: number, callback: Function) {
|
||||
this.cmdId++;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user