mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Admin persistence changes (#5086)
This commit is contained in:
parent
090a48515c
commit
b111f0921c
9 changed files with 148 additions and 10 deletions
|
|
@ -131,6 +131,12 @@ export const Actions = {
|
||||||
resetPasswordSuccess: () => ({
|
resetPasswordSuccess: () => ({
|
||||||
type: Types.RESET_PASSWORD_SUCCESS,
|
type: Types.RESET_PASSWORD_SUCCESS,
|
||||||
}),
|
}),
|
||||||
|
adjustMod: (userName, shouldBeMod, shouldBeJudge) => ({
|
||||||
|
type: Types.ADJUST_MOD,
|
||||||
|
userName,
|
||||||
|
shouldBeMod,
|
||||||
|
shouldBeJudge,
|
||||||
|
}),
|
||||||
reloadConfig: () => ({
|
reloadConfig: () => ({
|
||||||
type: Types.RELOAD_CONFIG,
|
type: Types.RELOAD_CONFIG,
|
||||||
}),
|
}),
|
||||||
|
|
@ -182,4 +188,26 @@ export const Actions = {
|
||||||
list,
|
list,
|
||||||
userName,
|
userName,
|
||||||
}),
|
}),
|
||||||
|
banFromServer: (userName) => ({
|
||||||
|
type: Types.BAN_FROM_SERVER,
|
||||||
|
userName,
|
||||||
|
}),
|
||||||
|
banHistory: (userName, banHistory) => ({
|
||||||
|
type: Types.BAN_HISTORY,
|
||||||
|
userName,
|
||||||
|
banHistory,
|
||||||
|
}),
|
||||||
|
warnHistory: (userName, warnHistory) => ({
|
||||||
|
type: Types.WARN_HISTORY,
|
||||||
|
userName,
|
||||||
|
warnHistory,
|
||||||
|
}),
|
||||||
|
warnListOptions: (warnList) => ({
|
||||||
|
type: Types.WARN_LIST_OPTIONS,
|
||||||
|
warnList,
|
||||||
|
}),
|
||||||
|
warnUser: (userName) => ({
|
||||||
|
type: Types.WARN_USER,
|
||||||
|
userName,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,9 @@ export const Dispatch = {
|
||||||
resetPasswordSuccess: () => {
|
resetPasswordSuccess: () => {
|
||||||
store.dispatch(Actions.resetPasswordSuccess());
|
store.dispatch(Actions.resetPasswordSuccess());
|
||||||
},
|
},
|
||||||
|
adjustMod: (userName, shouldBeMod, shouldBeJudge) => {
|
||||||
|
store.dispatch(Actions.adjustMod(userName, shouldBeMod, shouldBeJudge));
|
||||||
|
},
|
||||||
reloadConfig: () => {
|
reloadConfig: () => {
|
||||||
store.dispatch(Actions.reloadConfig());
|
store.dispatch(Actions.reloadConfig());
|
||||||
},
|
},
|
||||||
|
|
@ -159,4 +162,19 @@ export const Dispatch = {
|
||||||
removeFromList: (list, userName) => {
|
removeFromList: (list, userName) => {
|
||||||
store.dispatch(Actions.removeFromList(list, userName))
|
store.dispatch(Actions.removeFromList(list, userName))
|
||||||
},
|
},
|
||||||
|
banFromServer: (userName) => {
|
||||||
|
store.dispatch(Actions.banFromServer(userName));
|
||||||
|
},
|
||||||
|
banHistory: (userName, banHistory) => {
|
||||||
|
store.dispatch(Actions.banHistory(userName, banHistory))
|
||||||
|
},
|
||||||
|
warnHistory: (userName, warnHistory) => {
|
||||||
|
store.dispatch(Actions.warnHistory(userName, warnHistory))
|
||||||
|
},
|
||||||
|
warnListOptions: (warnList) => {
|
||||||
|
store.dispatch(Actions.warnListOptions(warnList))
|
||||||
|
},
|
||||||
|
warnUser: (userName) => {
|
||||||
|
store.dispatch(Actions.warnUser(userName))
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { LogItem, SortBy, User, UserSortField, WebSocketConnectOptions } from 'types';
|
import { WarnHistoryItem, BanHistoryItem, LogItem, SortBy, User, UserSortField, WebSocketConnectOptions, WarnListItem } from 'types';
|
||||||
import { NotifyUserData, ServerShutdownData, UserMessageData } from 'websocket/events/session/interfaces';
|
import { NotifyUserData, ServerShutdownData, UserMessageData } from 'websocket/events/session/interfaces';
|
||||||
|
|
||||||
export interface ServerConnectParams {
|
export interface ServerConnectParams {
|
||||||
|
|
@ -58,6 +58,15 @@ export interface ServerState {
|
||||||
}
|
}
|
||||||
notifications: NotifyUserData[];
|
notifications: NotifyUserData[];
|
||||||
serverShutdown: ServerShutdownData;
|
serverShutdown: ServerShutdownData;
|
||||||
|
banUser: string;
|
||||||
|
banHistory: {
|
||||||
|
[userName: string]: BanHistoryItem[];
|
||||||
|
};
|
||||||
|
warnHistory: {
|
||||||
|
[userName: string]: WarnHistoryItem[];
|
||||||
|
};
|
||||||
|
warnListOptions: WarnListItem[];
|
||||||
|
warnUser: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ServerStateStatus {
|
export interface ServerStateStatus {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { SortDirection, StatusEnum, UserSortField } from 'types';
|
import { SortDirection, StatusEnum, UserLevelFlag, UserSortField } from 'types';
|
||||||
|
|
||||||
import { SortUtil } from '../common';
|
import { SortUtil } from '../common';
|
||||||
|
|
||||||
|
|
@ -35,6 +35,11 @@ const initialState: ServerState = {
|
||||||
userInfo: {},
|
userInfo: {},
|
||||||
notifications: [],
|
notifications: [],
|
||||||
serverShutdown: null,
|
serverShutdown: null,
|
||||||
|
banUser: '',
|
||||||
|
banHistory: {},
|
||||||
|
warnHistory: {},
|
||||||
|
warnListOptions: [],
|
||||||
|
warnUser: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const serverReducer = (state = initialState, action: any) => {
|
export const serverReducer = (state = initialState, action: any) => {
|
||||||
|
|
@ -278,6 +283,69 @@ export const serverReducer = (state = initialState, action: any) => {
|
||||||
serverShutdown: data,
|
serverShutdown: data,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
case Types.BAN_FROM_SERVER: {
|
||||||
|
const { userName } = action;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
banUser: userName,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case Types.BAN_HISTORY: {
|
||||||
|
const { userName, banHistory } = action;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
banHistory: {
|
||||||
|
...state.banHistory,
|
||||||
|
[userName]: banHistory,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case Types.WARN_HISTORY: {
|
||||||
|
const { userName, warnHistory } = action;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
warnHistory: {
|
||||||
|
...state.warnHistory,
|
||||||
|
[userName]: warnHistory,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case Types.WARN_LIST_OPTIONS: {
|
||||||
|
const { warnList } = action;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
warnListOptions: warnList,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case Types.WARN_USER: {
|
||||||
|
const { userName } = action;
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
warnUser: userName,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case Types.ADJUST_MOD: {
|
||||||
|
const { userName, shouldBeMod, shouldBeJudge } = action;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
users: state.users.map((user) => {
|
||||||
|
if (user.name !== userName) {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
const judgeFlag = shouldBeJudge ? UserLevelFlag.IsJudge : UserLevelFlag.IsNothing;
|
||||||
|
const modFlag = shouldBeMod ? UserLevelFlag.IsModerator : UserLevelFlag.IsNothing;
|
||||||
|
return {
|
||||||
|
...user,
|
||||||
|
userLevel: user.userLevel & (judgeFlag | modFlag)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ export const Types = {
|
||||||
RESET_PASSWORD_FAILED: '[Server] Reset Password Failed',
|
RESET_PASSWORD_FAILED: '[Server] Reset Password Failed',
|
||||||
RESET_PASSWORD_CHALLENGE: '[Server] Reset Password Challenge',
|
RESET_PASSWORD_CHALLENGE: '[Server] Reset Password Challenge',
|
||||||
RESET_PASSWORD_SUCCESS: '[Server] Reset Password Success',
|
RESET_PASSWORD_SUCCESS: '[Server] Reset Password Success',
|
||||||
|
ADJUST_MOD: '[Server] Adjust Mod',
|
||||||
RELOAD_CONFIG: '[Server] Reload Config',
|
RELOAD_CONFIG: '[Server] Reload Config',
|
||||||
SHUTDOWN_SERVER: '[Server] Shutdown Server',
|
SHUTDOWN_SERVER: '[Server] Shutdown Server',
|
||||||
UPDATE_SERVER_MESSAGE: '[Server] Update Server Message',
|
UPDATE_SERVER_MESSAGE: '[Server] Update Server Message',
|
||||||
|
|
@ -48,4 +49,9 @@ export const Types = {
|
||||||
USER_MESSAGE: '[Server] User Message',
|
USER_MESSAGE: '[Server] User Message',
|
||||||
ADD_TO_LIST: '[Server] Add To List',
|
ADD_TO_LIST: '[Server] Add To List',
|
||||||
REMOVE_FROM_LIST: '[Server] Remove From List',
|
REMOVE_FROM_LIST: '[Server] Remove From List',
|
||||||
|
BAN_FROM_SERVER: '[Server] Ban From Server',
|
||||||
|
BAN_HISTORY: '[Server] Ban History',
|
||||||
|
WARN_HISTORY: '[Server] Warn History',
|
||||||
|
WARN_LIST_OPTIONS: '[Server] Warn List Options',
|
||||||
|
WARN_USER: '[Server] Warn User',
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,15 @@ export interface User {
|
||||||
avatarBmp?: Uint8Array;
|
avatarBmp?: Uint8Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum UserLevelFlag {
|
||||||
|
IsNothing = 0,
|
||||||
|
IsUser = 1,
|
||||||
|
IsRegistered = 2,
|
||||||
|
IsModerator = 4,
|
||||||
|
IsAdmin = 8,
|
||||||
|
IsJudge = 16,
|
||||||
|
}
|
||||||
|
|
||||||
export enum UserPrivLevel {
|
export enum UserPrivLevel {
|
||||||
NONE = 0,
|
NONE = 0,
|
||||||
VIP = 1,
|
VIP = 1,
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ export function getWarnList(modName: string, userName: string, userClientid: str
|
||||||
switch (responseCode) {
|
switch (responseCode) {
|
||||||
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
|
||||||
const { warning } = raw['.Response_WarnList.ext'];
|
const { warning } = raw['.Response_WarnList.ext'];
|
||||||
ModeratorPersistence.warnList(warning);
|
ModeratorPersistence.warnListOptions(warning);
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
error = 'Failed to get warn list.';
|
error = 'Failed to get warn list.';
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { ServerDispatch } from 'store';
|
||||||
|
|
||||||
export class AdminPersistence {
|
export class AdminPersistence {
|
||||||
static adjustMod(userName: string, shouldBeMod: boolean, shouldBeJudge: boolean) {
|
static adjustMod(userName: string, shouldBeMod: boolean, shouldBeJudge: boolean) {
|
||||||
console.log('adjustMod');
|
ServerDispatch.adjustMod(userName, shouldBeMod, shouldBeJudge)
|
||||||
}
|
}
|
||||||
|
|
||||||
static reloadConfig() {
|
static reloadConfig() {
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ import NormalizeService from '../utils/NormalizeService';
|
||||||
|
|
||||||
export class ModeratorPersistence {
|
export class ModeratorPersistence {
|
||||||
static banFromServer(userName: string): void {
|
static banFromServer(userName: string): void {
|
||||||
console.log(userName);
|
ServerDispatch.banFromServer(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static banHistory(userName: string, banHistory: BanHistoryItem[]): void {
|
static banHistory(userName: string, banHistory: BanHistoryItem[]): void {
|
||||||
console.log(userName, banHistory);
|
ServerDispatch.banHistory(userName, banHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
static viewLogs(logs: LogItem[]): void {
|
static viewLogs(logs: LogItem[]): void {
|
||||||
|
|
@ -17,14 +17,14 @@ export class ModeratorPersistence {
|
||||||
}
|
}
|
||||||
|
|
||||||
static warnHistory(userName: string, warnHistory: WarnHistoryItem[]): void {
|
static warnHistory(userName: string, warnHistory: WarnHistoryItem[]): void {
|
||||||
console.log(userName, warnHistory);
|
ServerDispatch.warnHistory(userName, warnHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
static warnList(warnList: WarnListItem[]): void {
|
static warnListOptions(warnList: WarnListItem[]): void {
|
||||||
console.log(warnList);
|
ServerDispatch.warnListOptions(warnList);
|
||||||
}
|
}
|
||||||
|
|
||||||
static warnUser(userName: string): void {
|
static warnUser(userName: string): void {
|
||||||
console.log(userName);
|
ServerDispatch.warnUser(userName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue