mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-12 15:49:28 -08:00
Add types for Moderator commands (#5084)
* Add types for Moderator commands * Support User Priv Level & userLevel
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Log, SortBy, User, UserSortField, WebSocketConnectOptions } from 'types';
|
import { LogItem, SortBy, User, UserSortField, WebSocketConnectOptions } from 'types';
|
||||||
|
|
||||||
export interface ServerConnectParams {
|
export interface ServerConnectParams {
|
||||||
host: string;
|
host: string;
|
||||||
@@ -63,9 +63,9 @@ export interface ServerStateInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ServerStateLogs {
|
export interface ServerStateLogs {
|
||||||
room: Log[];
|
room: LogItem[];
|
||||||
game: Log[];
|
game: LogItem[];
|
||||||
chat: Log[];
|
chat: LogItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ServerStateSortUsersBy extends SortBy {
|
export interface ServerStateSortUsersBy extends SortBy {
|
||||||
|
|||||||
@@ -15,3 +15,4 @@ export * from './languages';
|
|||||||
export * from './logs';
|
export * from './logs';
|
||||||
export * from './session';
|
export * from './session';
|
||||||
export * from './deckList';
|
export * from './deckList';
|
||||||
|
export * from './moderator';
|
||||||
|
|||||||
21
webclient/src/types/moderator.ts
Normal file
21
webclient/src/types/moderator.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
export interface BanHistoryItem {
|
||||||
|
adminId: string;
|
||||||
|
adminName: string;
|
||||||
|
banTime: string;
|
||||||
|
banLength: string;
|
||||||
|
banReason: string;
|
||||||
|
visibleReason: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WarnHistoryItem {
|
||||||
|
userName: string;
|
||||||
|
adminName: string;
|
||||||
|
reason: string;
|
||||||
|
timeOf: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WarnListItem {
|
||||||
|
warning: string;
|
||||||
|
userName: string;
|
||||||
|
userClientid: string;
|
||||||
|
}
|
||||||
@@ -109,7 +109,7 @@ export const KnownHosts = {
|
|||||||
[KnownHost.TETRARCH]: { port: 443, host: 'mtg.tetrarch.co/servatrice' },
|
[KnownHost.TETRARCH]: { port: 443, host: 'mtg.tetrarch.co/servatrice' },
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Log {
|
export interface LogItem {
|
||||||
message: string;
|
message: string;
|
||||||
senderId: string;
|
senderId: string;
|
||||||
senderIp: string;
|
senderIp: string;
|
||||||
@@ -121,7 +121,7 @@ export interface Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface LogGroups {
|
export interface LogGroups {
|
||||||
room: Log[];
|
room: LogItem[];
|
||||||
game: Log[];
|
game: LogItem[];
|
||||||
chat: Log[];
|
chat: LogItem[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,17 @@
|
|||||||
export interface User {
|
export interface User {
|
||||||
accountageSecs: number;
|
accountageSecs: number;
|
||||||
name: string;
|
name: string;
|
||||||
privlevel: UserAccessLevel;
|
privlevel: UserPrivLevel;
|
||||||
userLevel: UserPrivLevel;
|
userLevel: number;
|
||||||
realName?: string;
|
realName?: string;
|
||||||
country?: string;
|
country?: string;
|
||||||
avatarBmp?: Uint8Array;
|
avatarBmp?: Uint8Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum UserAccessLevel {
|
|
||||||
'NONE'
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum UserPrivLevel {
|
export enum UserPrivLevel {
|
||||||
'unknown 1',
|
NONE = 0,
|
||||||
'unknown 2',
|
VIP = 1,
|
||||||
'unknown 3',
|
DONOR = 2
|
||||||
'unknown 4'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum UserSortField {
|
export enum UserSortField {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export function getBanHistory(userName: string): void {
|
|||||||
switch (responseCode) {
|
switch (responseCode) {
|
||||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||||
const { banList } = raw['.Response_BanHistory.ext'];
|
const { banList } = raw['.Response_BanHistory.ext'];
|
||||||
ModeratorPersistence.banHistory(banList);
|
ModeratorPersistence.banHistory(userName, banList);
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
error = 'Failed to get ban history.';
|
error = 'Failed to get ban history.';
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export function getWarnHistory(userName: string): void {
|
|||||||
switch (responseCode) {
|
switch (responseCode) {
|
||||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||||
const { warnList } = raw['.Response_WarnHistory.ext'];
|
const { warnList } = raw['.Response_WarnHistory.ext'];
|
||||||
ModeratorPersistence.warnHistory(warnList);
|
ModeratorPersistence.warnHistory(userName, warnList);
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
error = 'Failed to get warn history.';
|
error = 'Failed to get warn history.';
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import webClient from '../../WebClient';
|
|||||||
import { ModeratorPersistence } from '../../persistence';
|
import { ModeratorPersistence } from '../../persistence';
|
||||||
|
|
||||||
export function warnUser(userName: string, reason: string, clientid?: string, removeMessage?: boolean): void {
|
export function warnUser(userName: string, reason: string, clientid?: string, removeMessage?: boolean): void {
|
||||||
const command = webClient.protobuf.controller.Command_BanFromServer.create({ userName, reason, clientid, removeMessage });
|
const command = webClient.protobuf.controller.Command_WarnUser.create({ userName, reason, clientid, removeMessage });
|
||||||
const sc = webClient.protobuf.controller.ModeratorCommand.create({ '.Command_WarnUser.ext': command });
|
const sc = webClient.protobuf.controller.ModeratorCommand.create({ '.Command_WarnUser.ext': command });
|
||||||
|
|
||||||
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
|
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
|
||||||
|
|||||||
@@ -1,30 +1,30 @@
|
|||||||
import { ServerDispatch } from 'store';
|
import { ServerDispatch } from 'store';
|
||||||
import { Log } from 'types';
|
import { BanHistoryItem, LogItem, WarnHistoryItem, WarnListItem } from 'types';
|
||||||
|
|
||||||
import NormalizeService from '../utils/NormalizeService';
|
import NormalizeService from '../utils/NormalizeService';
|
||||||
|
|
||||||
export class ModeratorPersistence {
|
export class ModeratorPersistence {
|
||||||
static banFromServer(userName: any) {
|
static banFromServer(userName: string): void {
|
||||||
console.log(userName);
|
console.log(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static banHistory(banHistory: any) {
|
static banHistory(userName: string, banHistory: BanHistoryItem[]): void {
|
||||||
console.log(banHistory);
|
console.log(userName, banHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
static viewLogs(logs: Log[]) {
|
static viewLogs(logs: LogItem[]): void {
|
||||||
ServerDispatch.viewLogs(NormalizeService.normalizeLogs(logs));
|
ServerDispatch.viewLogs(NormalizeService.normalizeLogs(logs));
|
||||||
}
|
}
|
||||||
|
|
||||||
static warnHistory(warnList: any) {
|
static warnHistory(userName: string, warnHistory: WarnHistoryItem[]): void {
|
||||||
|
console.log(userName, warnHistory);
|
||||||
|
}
|
||||||
|
|
||||||
|
static warnList(warnList: WarnListItem[]): void {
|
||||||
console.log(warnList);
|
console.log(warnList);
|
||||||
}
|
}
|
||||||
|
|
||||||
static warnList(warning: any) {
|
static warnUser(userName: string): void {
|
||||||
console.log(warning);
|
|
||||||
}
|
|
||||||
|
|
||||||
static warnUser(userName: any) {
|
|
||||||
console.log(userName);
|
console.log(userName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Game, GametypeMap, Log, LogGroups, Message, Room } from 'types';
|
import { Game, GametypeMap, LogItem, LogGroups, Message, Room } from 'types';
|
||||||
|
|
||||||
export default class NormalizeService {
|
export default class NormalizeService {
|
||||||
// Flatten room gameTypes into map object
|
// Flatten room gameTypes into map object
|
||||||
@@ -26,7 +26,7 @@ export default class NormalizeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Flatten logs[] into object mapped by targetType (room, game, chat)
|
// Flatten logs[] into object mapped by targetType (room, game, chat)
|
||||||
static normalizeLogs(logs: Log[]): LogGroups {
|
static normalizeLogs(logs: LogItem[]): LogGroups {
|
||||||
return logs.reduce((obj, log) => {
|
return logs.reduce((obj, log) => {
|
||||||
const { targetType } = log;
|
const { targetType } = log;
|
||||||
obj[targetType] = obj[targetType] || [];
|
obj[targetType] = obj[targetType] || [];
|
||||||
|
|||||||
Reference in New Issue
Block a user