Initial implementation completion and refactor

This commit is contained in:
seavor 2026-04-11 21:18:10 -05:00
parent e977f123ce
commit f0bf865646
76 changed files with 897 additions and 890 deletions

View file

@ -1,29 +1,13 @@
import webClient from '../../WebClient';
import { BackendService } from '../../services/BackendService';
import { ModeratorPersistence } from '../../persistence';
export function banFromServer(minutes: number, userName?: string, address?: string, reason?: string,
visibleReason?: string, clientid?: string, removeMessages?: number): void {
const command = webClient.protobuf.controller.Command_BanFromServer.create({
BackendService.sendModeratorCommand('Command_BanFromServer', {
minutes, userName, address, reason, visibleReason, clientid, removeMessages
});
const sc = webClient.protobuf.controller.ModeratorCommand.create({ '.Command_BanFromServer.ext': command });
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
const { responseCode } = raw;
let error: string;
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
ModeratorPersistence.banFromServer(userName);
return;
default:
error = 'Failed to ban user.';
break;
}
if (error) {
console.error(responseCode, error);
}
}, {
onSuccess: () => {
ModeratorPersistence.banFromServer(userName);
},
});
}

View file

@ -0,0 +1,10 @@
import { BackendService } from '../../services/BackendService';
import { ModeratorPersistence } from '../../persistence';
export function forceActivateUser(usernameToActivate: string, moderatorName: string): void {
BackendService.sendModeratorCommand('Command_ForceActivateUser', { usernameToActivate, moderatorName }, {
onSuccess: () => {
ModeratorPersistence.forceActivateUser(usernameToActivate, moderatorName);
},
});
}

View file

@ -0,0 +1,11 @@
import { BackendService } from '../../services/BackendService';
import { ModeratorPersistence } from '../../persistence';
export function getAdminNotes(userName: string): void {
BackendService.sendModeratorCommand('Command_GetAdminNotes', { userName }, {
responseName: 'Response_GetAdminNotes',
onSuccess: (response) => {
ModeratorPersistence.getAdminNotes(userName, response.notes);
},
});
}

View file

@ -1,27 +1,11 @@
import webClient from '../../WebClient';
import { BackendService } from '../../services/BackendService';
import { ModeratorPersistence } from '../../persistence';
export function getBanHistory(userName: string): void {
const command = webClient.protobuf.controller.Command_GetBanHistory.create({ userName });
const sc = webClient.protobuf.controller.ModeratorCommand.create({ '.Command_GetBanHistory.ext': command });
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
const { responseCode } = raw;
let error: string;
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
const { banList } = raw['.Response_BanHistory.ext'];
ModeratorPersistence.banHistory(userName, banList);
return;
default:
error = 'Failed to get ban history.';
break;
}
if (error) {
console.error(responseCode, error);
}
BackendService.sendModeratorCommand('Command_GetBanHistory', { userName }, {
responseName: 'Response_BanHistory',
onSuccess: (response) => {
ModeratorPersistence.banHistory(userName, response.banList);
},
});
}

View file

@ -1,27 +1,11 @@
import webClient from '../../WebClient';
import { BackendService } from '../../services/BackendService';
import { ModeratorPersistence } from '../../persistence';
export function getWarnHistory(userName: string): void {
const command = webClient.protobuf.controller.Command_GetWarnHistory.create({ userName });
const sc = webClient.protobuf.controller.ModeratorCommand.create({ '.Command_GetWarnHistory.ext': command });
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
const { responseCode } = raw;
let error: string;
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
const { warnList } = raw['.Response_WarnHistory.ext'];
ModeratorPersistence.warnHistory(userName, warnList);
return;
default:
error = 'Failed to get warn history.';
break;
}
if (error) {
console.error(responseCode, error);
}
BackendService.sendModeratorCommand('Command_GetWarnHistory', { userName }, {
responseName: 'Response_WarnHistory',
onSuccess: (response) => {
ModeratorPersistence.warnHistory(userName, response.warnList);
},
});
}

View file

@ -1,27 +1,11 @@
import webClient from '../../WebClient';
import { BackendService } from '../../services/BackendService';
import { ModeratorPersistence } from '../../persistence';
export function getWarnList(modName: string, userName: string, userClientid: string): void {
const command = webClient.protobuf.controller.Command_GetWarnList.create({ modName, userName, userClientid });
const sc = webClient.protobuf.controller.ModeratorCommand.create({ '.Command_GetWarnList.ext': command });
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
const { responseCode } = raw;
let error: string;
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
const { warning } = raw['.Response_WarnList.ext'];
ModeratorPersistence.warnListOptions(warning);
return;
default:
error = 'Failed to get warn list.';
break;
}
if (error) {
console.error(responseCode, error);
}
BackendService.sendModeratorCommand('Command_GetWarnList', { modName, userName, userClientid }, {
responseName: 'Response_WarnList',
onSuccess: (response) => {
ModeratorPersistence.warnListOptions(response.warning);
},
});
}

View file

@ -0,0 +1,10 @@
import { BackendService } from '../../services/BackendService';
import { ModeratorPersistence } from '../../persistence';
export function grantReplayAccess(replayId: number, moderatorName: string): void {
BackendService.sendModeratorCommand('Command_GrantReplayAccess', { replayId, moderatorName }, {
onSuccess: () => {
ModeratorPersistence.grantReplayAccess(replayId, moderatorName);
},
});
}

View file

@ -1,6 +1,10 @@
export * from './banFromServer';
export * from './forceActivateUser';
export * from './getAdminNotes';
export * from './getBanHistory';
export * from './getWarnHistory';
export * from './getWarnList';
export * from './grantReplayAccess';
export * from './updateAdminNotes';
export * from './viewLogHistory';
export * from './warnUser';

View file

@ -0,0 +1,10 @@
import { BackendService } from '../../services/BackendService';
import { ModeratorPersistence } from '../../persistence';
export function updateAdminNotes(userName: string, notes: string): void {
BackendService.sendModeratorCommand('Command_UpdateAdminNotes', { userName, notes }, {
onSuccess: () => {
ModeratorPersistence.updateAdminNotes(userName, notes);
},
});
}

View file

@ -1,28 +1,12 @@
import webClient from '../../WebClient';
import { BackendService } from '../../services/BackendService';
import { ModeratorPersistence } from '../../persistence';
import { LogFilters } from 'types';
export function viewLogHistory(filters: LogFilters): void {
const command = webClient.protobuf.controller.Command_ViewLogHistory.create(filters);
const sc = webClient.protobuf.controller.ModeratorCommand.create({ '.Command_ViewLogHistory.ext': command });
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
const { responseCode } = raw;
let error: string;
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
const { logMessage } = raw['.Response_ViewLogHistory.ext'];
ModeratorPersistence.viewLogs(logMessage)
return;
default:
error = 'Failed to retrieve log history.';
break;
}
if (error) {
console.error(responseCode, error);
}
BackendService.sendModeratorCommand('Command_ViewLogHistory', filters, {
responseName: 'Response_ViewLogHistory',
onSuccess: (response) => {
ModeratorPersistence.viewLogs(response.logMessage);
},
});
}

View file

@ -1,26 +1,10 @@
import webClient from '../../WebClient';
import { BackendService } from '../../services/BackendService';
import { ModeratorPersistence } from '../../persistence';
export function warnUser(userName: string, reason: string, clientid?: string, removeMessage?: boolean): void {
const command = webClient.protobuf.controller.Command_WarnUser.create({ userName, reason, clientid, removeMessage });
const sc = webClient.protobuf.controller.ModeratorCommand.create({ '.Command_WarnUser.ext': command });
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
const { responseCode } = raw;
let error: string;
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
ModeratorPersistence.warnUser(userName);
return;
default:
error = 'Failed to warn user.';
break;
}
if (error) {
console.error(responseCode, error);
}
export function warnUser(userName: string, reason: string, clientid?: string, removeMessages?: number): void {
BackendService.sendModeratorCommand('Command_WarnUser', { userName, reason, clientid, removeMessages }, {
onSuccess: () => {
ModeratorPersistence.warnUser(userName);
},
});
}