Initial implementation completion and refactor (#6806)
Some checks failed
Build Desktop / Configure (push) Has been cancelled
Build Docker Image / amd64 & arm64 (push) Has been cancelled
Build Web / React (Node 16) (push) Has been cancelled
Build Web / React (Node lts/*) (push) Has been cancelled
Build Desktop / Debian 11 (push) Has been cancelled
Build Desktop / Debian 13 (push) Has been cancelled
Build Desktop / Debian 12 (push) Has been cancelled
Build Desktop / Fedora 43 (push) Has been cancelled
Build Desktop / Fedora 42 (push) Has been cancelled
Build Desktop / Servatrice_Debian 11 (push) Has been cancelled
Build Desktop / Ubuntu 24.04 (push) Has been cancelled
Build Desktop / Ubuntu 26.04 (push) Has been cancelled
Build Desktop / Ubuntu 22.04 (push) Has been cancelled
Build Desktop / Arch (push) Has been cancelled
Build Desktop / macOS 14 (push) Has been cancelled
Build Desktop / macOS 15 (push) Has been cancelled
Build Desktop / macOS 13 Intel (push) Has been cancelled
Build Desktop / macOS 15 Debug (push) Has been cancelled
Build Desktop / Windows 10 (push) Has been cancelled

This commit is contained in:
Jeremy Letto 2026-04-11 22:51:10 -05:00 committed by GitHub
parent 2e10b2f5d5
commit 8cc65b8967
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
76 changed files with 897 additions and 890 deletions

View file

@ -1,4 +1,4 @@
import { WebSocketConnectOptions } from 'types';
import { DeckList, DeckStorageTreeItem, ReplayMatch, WebSocketConnectOptions } from 'types';
import { Types } from './server.types';
export const Actions = {
@ -210,4 +210,33 @@ export const Actions = {
type: Types.WARN_USER,
userName,
}),
grantReplayAccess: (replayId: number, moderatorName: string) => ({
type: Types.GRANT_REPLAY_ACCESS,
replayId,
moderatorName,
}),
forceActivateUser: (usernameToActivate: string, moderatorName: string) => ({
type: Types.FORCE_ACTIVATE_USER,
usernameToActivate,
moderatorName,
}),
getAdminNotes: (userName: string, notes: string) => ({
type: Types.GET_ADMIN_NOTES,
userName,
notes,
}),
updateAdminNotes: (userName: string, notes: string) => ({
type: Types.UPDATE_ADMIN_NOTES,
userName,
notes,
}),
replayList: (matchList: ReplayMatch[]) => ({ type: Types.REPLAY_LIST, matchList }),
replayAdded: (matchInfo: ReplayMatch) => ({ type: Types.REPLAY_ADDED, matchInfo }),
replayModifyMatch: (gameId: number, doNotHide: boolean) => ({ type: Types.REPLAY_MODIFY_MATCH, gameId, doNotHide }),
replayDeleteMatch: (gameId: number) => ({ type: Types.REPLAY_DELETE_MATCH, gameId }),
backendDecks: (deckList: DeckList) => ({ type: Types.BACKEND_DECKS, deckList }),
deckNewDir: (path: string, dirName: string) => ({ type: Types.DECK_NEW_DIR, path, dirName }),
deckDelDir: (path: string) => ({ type: Types.DECK_DEL_DIR, path }),
deckUpload: (path: string, treeItem: DeckStorageTreeItem) => ({ type: Types.DECK_UPLOAD, path, treeItem }),
deckDelete: (deckId: number) => ({ type: Types.DECK_DELETE, deckId }),
}

View file

@ -1,7 +1,7 @@
import { reset } from 'redux-form';
import { Actions } from './server.actions';
import { store } from 'store';
import { WebSocketConnectOptions } from 'types';
import { DeckList, DeckStorageTreeItem, ReplayMatch, WebSocketConnectOptions } from 'types';
export const Dispatch = {
initialized: () => {
@ -177,4 +177,43 @@ export const Dispatch = {
warnUser: (userName) => {
store.dispatch(Actions.warnUser(userName))
},
grantReplayAccess: (replayId: number, moderatorName: string) => {
store.dispatch(Actions.grantReplayAccess(replayId, moderatorName));
},
forceActivateUser: (usernameToActivate: string, moderatorName: string) => {
store.dispatch(Actions.forceActivateUser(usernameToActivate, moderatorName));
},
getAdminNotes: (userName: string, notes: string) => {
store.dispatch(Actions.getAdminNotes(userName, notes));
},
updateAdminNotes: (userName: string, notes: string) => {
store.dispatch(Actions.updateAdminNotes(userName, notes));
},
replayList: (matchList: ReplayMatch[]) => {
store.dispatch(Actions.replayList(matchList));
},
replayAdded: (matchInfo: ReplayMatch) => {
store.dispatch(Actions.replayAdded(matchInfo));
},
replayModifyMatch: (gameId: number, doNotHide: boolean) => {
store.dispatch(Actions.replayModifyMatch(gameId, doNotHide));
},
replayDeleteMatch: (gameId: number) => {
store.dispatch(Actions.replayDeleteMatch(gameId));
},
backendDecks: (deckList: DeckList) => {
store.dispatch(Actions.backendDecks(deckList));
},
deckNewDir: (path: string, dirName: string) => {
store.dispatch(Actions.deckNewDir(path, dirName));
},
deckDelDir: (path: string) => {
store.dispatch(Actions.deckDelDir(path));
},
deckUpload: (path: string, treeItem: DeckStorageTreeItem) => {
store.dispatch(Actions.deckUpload(path, treeItem));
},
deckDelete: (deckId: number) => {
store.dispatch(Actions.deckDelete(deckId));
},
}

View file

@ -1,4 +1,6 @@
import { WarnHistoryItem, BanHistoryItem, LogItem, SortBy, User, UserSortField, WebSocketConnectOptions, WarnListItem } from 'types';
import {
WarnHistoryItem, BanHistoryItem, DeckList, LogItem, ReplayMatch, SortBy, User, UserSortField, WebSocketConnectOptions, WarnListItem
} from 'types';
import { NotifyUserData, ServerShutdownData, UserMessageData } from 'websocket/events/session/interfaces';
export interface ServerConnectParams {
@ -67,6 +69,9 @@ export interface ServerState {
};
warnListOptions: WarnListItem[];
warnUser: string;
adminNotes: { [userName: string]: string };
replays: ReplayMatch[];
backendDecks: DeckList | null;
}
export interface ServerStateStatus {

View file

@ -1,10 +1,60 @@
import { SortDirection, StatusEnum, UserLevelFlag, UserSortField } from 'types';
import { DeckStorageFolder, DeckStorageTreeItem, SortDirection, StatusEnum, UserLevelFlag, UserSortField } from 'types';
import { SortUtil } from '../common';
import { ServerState } from './server.interfaces'
import { Types } from './server.types';
function splitPath(path: string): string[] {
return path ? path.split('/') : [];
}
function insertAtPath(folder: DeckStorageFolder, pathSegments: string[], item: DeckStorageTreeItem): DeckStorageFolder {
if (pathSegments.length === 0 || (pathSegments.length === 1 && pathSegments[0] === '')) {
return { items: [...folder.items, item] };
}
const [head, ...tail] = pathSegments;
const match = folder.items.find(child => child.name === head && child.folder);
if (match) {
return {
items: folder.items.map(child =>
child === match
? { ...child, folder: insertAtPath(child.folder!, tail, item) }
: child
),
};
}
const created: DeckStorageTreeItem = { id: 0, name: head, file: null, folder: insertAtPath({ items: [] }, tail, item) };
return { items: [...folder.items, created] };
}
function removeById(folder: DeckStorageFolder, id: number): DeckStorageFolder {
return {
items: folder.items
.filter(item => item.id !== id)
.map(item =>
item.folder ? { ...item, folder: removeById(item.folder, id) } : item
),
};
}
function removeByPath(folder: DeckStorageFolder, pathSegments: string[]): DeckStorageFolder {
if (pathSegments.length === 0 || (pathSegments.length === 1 && pathSegments[0] === '')) {
return folder;
}
const [head, ...tail] = pathSegments;
if (tail.length === 0) {
return { items: folder.items.filter(item => !(item.name === head && item.folder !== null)) };
}
return {
items: folder.items.map(item =>
item.name === head && item.folder
? { ...item, folder: removeByPath(item.folder, tail) }
: item
),
};
}
const initialState: ServerState = {
initialized: false,
buddyList: [],
@ -40,6 +90,9 @@ const initialState: ServerState = {
warnHistory: {},
warnListOptions: [],
warnUser: '',
adminNotes: {},
replays: [],
backendDecks: null,
};
export const serverReducer = (state = initialState, action: any) => {
@ -247,7 +300,7 @@ export const serverReducer = (state = initialState, action: any) => {
messages: {
...state.messages,
[userName]: [
...state.messages[userName],
...(state.messages[userName] ?? []),
action.messageData,
],
}
@ -328,6 +381,17 @@ export const serverReducer = (state = initialState, action: any) => {
warnUser: userName,
};
}
case Types.GET_ADMIN_NOTES:
case Types.UPDATE_ADMIN_NOTES: {
const { userName, notes } = action;
return {
...state,
adminNotes: {
...state.adminNotes,
[userName]: notes,
}
};
}
case Types.ADJUST_MOD: {
const { userName, shouldBeMod, shouldBeJudge } = action;
@ -346,6 +410,71 @@ export const serverReducer = (state = initialState, action: any) => {
})
};
}
case Types.REPLAY_LIST: {
return { ...state, replays: [...action.matchList] };
}
case Types.REPLAY_ADDED: {
return { ...state, replays: [...state.replays, action.matchInfo] };
}
case Types.REPLAY_MODIFY_MATCH: {
return {
...state,
replays: state.replays.map(r =>
r.gameId === action.gameId ? { ...r, doNotHide: action.doNotHide } : r
),
};
}
case Types.REPLAY_DELETE_MATCH: {
return { ...state, replays: state.replays.filter(r => r.gameId !== action.gameId) };
}
case Types.BACKEND_DECKS: {
return { ...state, backendDecks: action.deckList };
}
case Types.DECK_UPLOAD: {
if (!state.backendDecks) {
return state;
}
return {
...state,
backendDecks: {
root: insertAtPath(state.backendDecks.root, splitPath(action.path), action.treeItem),
},
};
}
case Types.DECK_DELETE: {
if (!state.backendDecks) {
return state;
}
return {
...state,
backendDecks: {
root: removeById(state.backendDecks.root, action.deckId),
},
};
}
case Types.DECK_NEW_DIR: {
if (!state.backendDecks) {
return state;
}
const newFolder: DeckStorageTreeItem = { id: 0, name: action.dirName, file: null, folder: { items: [] } };
return {
...state,
backendDecks: {
root: insertAtPath(state.backendDecks.root, splitPath(action.path), newFolder),
},
};
}
case Types.DECK_DEL_DIR: {
if (!state.backendDecks) {
return state;
}
return {
...state,
backendDecks: {
root: removeByPath(state.backendDecks.root, splitPath(action.path)),
},
};
}
default:
return state;
}

View file

@ -16,5 +16,7 @@ export const Selectors = {
getUsers: ({ server }: State) => server.users,
getLogs: ({ server }: State) => server.logs,
getBuddyList: ({ server }: State) => server.buddyList,
getIgnoreList: ({ server }: State) => server.ignoreList
getIgnoreList: ({ server }: State) => server.ignoreList,
getReplays: ({ server }: State) => server.replays,
getBackendDecks: ({ server }: State) => server.backendDecks,
}

View file

@ -54,4 +54,19 @@ export const Types = {
WARN_HISTORY: '[Server] Warn History',
WARN_LIST_OPTIONS: '[Server] Warn List Options',
WARN_USER: '[Server] Warn User',
GRANT_REPLAY_ACCESS: '[Server] Grant Replay Access',
FORCE_ACTIVATE_USER: '[Server] Force Activate User',
GET_ADMIN_NOTES: '[Server] Get Admin Notes',
UPDATE_ADMIN_NOTES: '[Server] Update Admin Notes',
// Replay
REPLAY_LIST: '[Server] Replay List',
REPLAY_ADDED: '[Server] Replay Added',
REPLAY_MODIFY_MATCH: '[Server] Replay Modify Match',
REPLAY_DELETE_MATCH: '[Server] Replay Delete Match',
// Deck Storage
BACKEND_DECKS: '[Server] Backend Decks',
DECK_NEW_DIR: '[Server] Deck New Dir',
DECK_DEL_DIR: '[Server] Deck Del Dir',
DECK_UPLOAD: '[Server] Deck Upload',
DECK_DELETE: '[Server] Deck Delete',
};