add missing requests/responses

This commit is contained in:
seavor 2026-04-16 01:28:42 -05:00
parent f0c3581d26
commit 4b5f66d497
27 changed files with 382 additions and 10 deletions

View file

@ -29,4 +29,7 @@ export const request: IWebClientRequest = {
get moderator() {
return WebClient.instance.request.moderator;
},
get game() {
return WebClient.instance.request.game;
},
};

View file

@ -0,0 +1,142 @@
import type { IGameRequest } from '@app/websocket';
import { GameCommands } from '@app/websocket';
import { Data } from '@app/types';
export class GameRequestImpl implements IGameRequest {
leaveGame(gameId: number): void {
GameCommands.leaveGame(gameId);
}
kickFromGame(gameId: number, params: Data.KickFromGameParams): void {
GameCommands.kickFromGame(gameId, params);
}
gameSay(gameId: number, params: Data.GameSayParams): void {
GameCommands.gameSay(gameId, params);
}
readyStart(gameId: number, params: Data.ReadyStartParams): void {
GameCommands.readyStart(gameId, params);
}
concede(gameId: number): void {
GameCommands.concede(gameId);
}
unconcede(gameId: number): void {
GameCommands.unconcede(gameId);
}
judge(gameId: number, targetId: number, innerGameCommand: Data.GameCommand): void {
GameCommands.judge(gameId, targetId, innerGameCommand);
}
nextTurn(gameId: number): void {
GameCommands.nextTurn(gameId);
}
setActivePhase(gameId: number, params: Data.SetActivePhaseParams): void {
GameCommands.setActivePhase(gameId, params);
}
reverseTurn(gameId: number): void {
GameCommands.reverseTurn(gameId);
}
moveCard(gameId: number, params: Data.MoveCardParams): void {
GameCommands.moveCard(gameId, params);
}
flipCard(gameId: number, params: Data.FlipCardParams): void {
GameCommands.flipCard(gameId, params);
}
attachCard(gameId: number, params: Data.AttachCardParams): void {
GameCommands.attachCard(gameId, params);
}
createToken(gameId: number, params: Data.CreateTokenParams): void {
GameCommands.createToken(gameId, params);
}
setCardAttr(gameId: number, params: Data.SetCardAttrParams): void {
GameCommands.setCardAttr(gameId, params);
}
setCardCounter(gameId: number, params: Data.SetCardCounterParams): void {
GameCommands.setCardCounter(gameId, params);
}
incCardCounter(gameId: number, params: Data.IncCardCounterParams): void {
GameCommands.incCardCounter(gameId, params);
}
drawCards(gameId: number, params: Data.DrawCardsParams): void {
GameCommands.drawCards(gameId, params);
}
undoDraw(gameId: number): void {
GameCommands.undoDraw(gameId);
}
createArrow(gameId: number, params: Data.CreateArrowParams): void {
GameCommands.createArrow(gameId, params);
}
deleteArrow(gameId: number, params: Data.DeleteArrowParams): void {
GameCommands.deleteArrow(gameId, params);
}
createCounter(gameId: number, params: Data.CreateCounterParams): void {
GameCommands.createCounter(gameId, params);
}
setCounter(gameId: number, params: Data.SetCounterParams): void {
GameCommands.setCounter(gameId, params);
}
incCounter(gameId: number, params: Data.IncCounterParams): void {
GameCommands.incCounter(gameId, params);
}
delCounter(gameId: number, params: Data.DelCounterParams): void {
GameCommands.delCounter(gameId, params);
}
shuffle(gameId: number, params: Data.ShuffleParams): void {
GameCommands.shuffle(gameId, params);
}
dumpZone(gameId: number, params: Data.DumpZoneParams): void {
GameCommands.dumpZone(gameId, params);
}
revealCards(gameId: number, params: Data.RevealCardsParams): void {
GameCommands.revealCards(gameId, params);
}
changeZoneProperties(gameId: number, params: Data.ChangeZonePropertiesParams): void {
GameCommands.changeZoneProperties(gameId, params);
}
deckSelect(gameId: number, params: Data.DeckSelectParams): void {
GameCommands.deckSelect(gameId, params);
}
setSideboardPlan(gameId: number, params: Data.SetSideboardPlanParams): void {
GameCommands.setSideboardPlan(gameId, params);
}
setSideboardLock(gameId: number, params: Data.SetSideboardLockParams): void {
GameCommands.setSideboardLock(gameId, params);
}
mulligan(gameId: number, params: Data.MulliganParams): void {
GameCommands.mulligan(gameId, params);
}
rollDie(gameId: number, params: Data.RollDieParams): void {
GameCommands.rollDie(gameId, params);
}
}

View file

@ -41,4 +41,12 @@ export class SessionRequestImpl implements ISessionRequest {
getUserGames(userName: string): void {
SessionCommands.getGamesOfUser(userName);
}
deckDownload(deckId: number): void {
SessionCommands.deckDownload(deckId);
}
replayDownload(replayId: number): void {
SessionCommands.replayDownload(replayId);
}
}

View file

@ -3,20 +3,18 @@ import type { IWebClientRequest } from '@app/websocket';
import { AuthenticationRequestImpl } from './AuthenticationRequestImpl';
import { SessionRequestImpl } from './SessionRequestImpl';
import { RoomsRequestImpl } from './RoomsRequestImpl';
import { GameRequestImpl } from './GameRequestImpl';
import { AdminRequestImpl } from './AdminRequestImpl';
import { ModeratorRequestImpl } from './ModeratorRequestImpl';
export { AuthenticationRequestImpl } from './AuthenticationRequestImpl';
export { SessionRequestImpl } from './SessionRequestImpl';
export { RoomsRequestImpl } from './RoomsRequestImpl';
export { AdminRequestImpl } from './AdminRequestImpl';
export { ModeratorRequestImpl } from './ModeratorRequestImpl';
export { AuthenticationRequestImpl, SessionRequestImpl, RoomsRequestImpl, GameRequestImpl, AdminRequestImpl, ModeratorRequestImpl };
export function createWebClientRequest(): IWebClientRequest {
return {
authentication: new AuthenticationRequestImpl(),
session: new SessionRequestImpl(),
rooms: new RoomsRequestImpl(),
game: new GameRequestImpl(),
admin: new AdminRequestImpl(),
moderator: new ModeratorRequestImpl(),
};

View file

@ -229,4 +229,12 @@ export class SessionResponseImpl implements ISessionResponse {
replayDeleteMatch(gameId: number): void {
ServerDispatch.replayDeleteMatch(gameId);
}
downloadServerDeck(deckId: number, response: Data.Response_DeckDownload): void {
ServerDispatch.deckDownloaded(deckId, response.deck);
}
replayDownloaded(replayId: number, response: Data.Response_ReplayDownload): void {
ServerDispatch.replayDownloaded(replayId, response.replayData);
}
}

View file

@ -6,11 +6,7 @@ import { GameResponseImpl } from './GameResponseImpl';
import { AdminResponseImpl } from './AdminResponseImpl';
import { ModeratorResponseImpl } from './ModeratorResponseImpl';
export { SessionResponseImpl } from './SessionResponseImpl';
export { RoomResponseImpl } from './RoomResponseImpl';
export { GameResponseImpl } from './GameResponseImpl';
export { AdminResponseImpl } from './AdminResponseImpl';
export { ModeratorResponseImpl } from './ModeratorResponseImpl';
export { SessionResponseImpl, RoomResponseImpl, GameResponseImpl, AdminResponseImpl, ModeratorResponseImpl };
export function createWebClientResponse(): IWebClientResponse {
return {

View file

@ -174,6 +174,8 @@ export function makeServerState(overrides: Partial<ServerState> = {}): ServerSta
adminNotes: {},
replays: {},
backendDecks: null,
downloadedDeck: null,
downloadedReplay: null,
gamesOfUser: {},
registrationError: null,
...overrides,

View file

@ -351,6 +351,21 @@ describe('Actions', () => {
expect(Actions.deckDelete({ deckId: 42 })).toEqual({ type: Types.DECK_DELETE, payload: { deckId: 42 } });
});
it('deckDownloaded', () => {
expect(Actions.deckDownloaded({ deckId: 42, deck: '<xml>' })).toEqual({
type: Types.DECK_DOWNLOADED,
payload: { deckId: 42, deck: '<xml>' },
});
});
it('replayDownloaded', () => {
const replayData = new Uint8Array([1, 2, 3]);
expect(Actions.replayDownloaded({ replayId: 99, replayData })).toEqual({
type: Types.REPLAY_DOWNLOADED,
payload: { replayId: 99, replayData },
});
});
it('gamesOfUser', () => {
const response = create(Data.Response_GetGamesOfUserSchema, { roomList: [], gameList: [] });
const action = Actions.gamesOfUser({ userName: 'alice', response });

View file

@ -388,6 +388,17 @@ describe('Dispatch', () => {
expect(mockDispatch).toHaveBeenCalledWith(Actions.deckDelete({ deckId: 42 }));
});
it('deckDownloaded dispatches correctly', () => {
Dispatch.deckDownloaded(42, '<deck-xml>');
expect(mockDispatch).toHaveBeenCalledWith(Actions.deckDownloaded({ deckId: 42, deck: '<deck-xml>' }));
});
it('replayDownloaded dispatches correctly', () => {
const data = new Uint8Array([1, 2, 3]);
Dispatch.replayDownloaded(99, data);
expect(mockDispatch).toHaveBeenCalledWith(Actions.replayDownloaded({ replayId: 99, replayData: data }));
});
it('gamesOfUser dispatches correctly', () => {
const response = create(Data.Response_GetGamesOfUserSchema, { roomList: [], gameList: [] });
Dispatch.gamesOfUser('alice', response);

View file

@ -207,6 +207,12 @@ export const Dispatch = {
deckDelete: (deckId: number) => {
store.dispatch(Actions.deckDelete({ deckId }));
},
deckDownloaded: (deckId: number, deck: string) => {
store.dispatch(Actions.deckDownloaded({ deckId, deck }));
},
replayDownloaded: (replayId: number, replayData: Uint8Array) => {
store.dispatch(Actions.replayDownloaded({ replayId, replayData }));
},
gamesOfUser: (userName: string, response: Data.Response_GetGamesOfUser) => {
store.dispatch(Actions.gamesOfUser({ userName, response }));
},

View file

@ -34,6 +34,8 @@ export interface ServerState {
/** Replays keyed by gameId for O(1) lookup/update. */
replays: { [gameId: number]: Data.ServerInfo_ReplayMatch };
backendDecks: Data.Response_DeckList | null;
downloadedDeck: { deckId: number; deck: string } | null;
downloadedReplay: { replayId: number; replayData: Uint8Array } | null;
gamesOfUser: { [userName: string]: Enriched.Game[] };
registrationError: string | null;
}

View file

@ -624,6 +624,25 @@ describe('Deck Storage', () => {
const result = serverReducer(state, Actions.deckDelDir({ path: 'parent/child' }));
expect(result.backendDecks!.root!.items[0].folder!.items).toHaveLength(0);
});
it('DECK_DOWNLOADED → sets downloadedDeck', () => {
const state = makeServerState();
const result = serverReducer(state, Actions.deckDownloaded({ deckId: 42, deck: '<deck-xml>' }));
expect(result.downloadedDeck).toEqual({ deckId: 42, deck: '<deck-xml>' });
});
it('DECK_DOWNLOADED → overwrites previous download', () => {
const state = makeServerState({ downloadedDeck: { deckId: 1, deck: 'old' } });
const result = serverReducer(state, Actions.deckDownloaded({ deckId: 2, deck: 'new' }));
expect(result.downloadedDeck).toEqual({ deckId: 2, deck: 'new' });
});
it('REPLAY_DOWNLOADED → sets downloadedReplay', () => {
const state = makeServerState();
const data = new Uint8Array([1, 2, 3]);
const result = serverReducer(state, Actions.replayDownloaded({ replayId: 99, replayData: data }));
expect(result.downloadedReplay).toEqual({ replayId: 99, replayData: data });
});
});
// ── GAMES_OF_USER ─────────────────────────────────────────────────────────────

View file

@ -102,6 +102,8 @@ const initialState: ServerState = {
adminNotes: {},
replays: {},
backendDecks: null,
downloadedDeck: null,
downloadedReplay: null,
gamesOfUser: {},
registrationError: null,
};
@ -341,6 +343,14 @@ export const serverSlice = createSlice({
});
},
deckDownloaded: (state, action: PayloadAction<{ deckId: number; deck: string }>) => {
state.downloadedDeck = action.payload;
},
replayDownloaded: (state, action: PayloadAction<{ replayId: number; replayData: Uint8Array }>) => {
state.downloadedReplay = action.payload;
},
gamesOfUser: (state, action: PayloadAction<{ userName: string; response: Data.Response_GetGamesOfUser }>) => {
const { userName, response } = action.payload;
const gametypeMap = normalizeGametypeMap(

View file

@ -133,6 +133,18 @@ describe('Selectors', () => {
expect(Selectors.getBackendDecks(rootState(state))).toBeNull();
});
it('getDownloadedDeck → returns downloadedDeck', () => {
const downloadedDeck = { deckId: 42, deck: '<xml>' };
const state = makeServerState({ downloadedDeck });
expect(Selectors.getDownloadedDeck(rootState(state))).toEqual(downloadedDeck);
});
it('getDownloadedReplay → returns downloadedReplay', () => {
const downloadedReplay = { replayId: 99, replayData: new Uint8Array([1, 2, 3]) };
const state = makeServerState({ downloadedReplay });
expect(Selectors.getDownloadedReplay(rootState(state))).toEqual(downloadedReplay);
});
it('getRegistrationError → returns registrationError', () => {
const state = makeServerState({ registrationError: 'bad input' });
expect(Selectors.getRegistrationError(rootState(state))).toBe('bad input');

View file

@ -39,6 +39,8 @@ export const Selectors = {
),
getLogs: ({ server }: State) => server.logs,
getBackendDecks: ({ server }: State) => server.backendDecks,
getDownloadedDeck: ({ server }: State) => server.downloadedDeck,
getDownloadedReplay: ({ server }: State) => server.downloadedReplay,
getRegistrationError: ({ server }: State) => server.registrationError,
getSortUsersBy: ({ server }: State) => server.sortUsersBy,

View file

@ -73,6 +73,8 @@ export const Types = {
DECK_DEL_DIR: a.deckDelDir.type,
DECK_UPLOAD: a.deckUpload.type,
DECK_DELETE: a.deckDelete.type,
DECK_DOWNLOADED: a.deckDownloaded.type,
REPLAY_DOWNLOADED: a.replayDownloaded.type,
// User games
GAMES_OF_USER: a.gamesOfUser.type,
} as const;

View file

@ -73,6 +73,8 @@ export function makeSessionPersistenceMock() {
replayAdded: vi.fn(),
replayModifyMatch: vi.fn(),
replayDeleteMatch: vi.fn(),
downloadServerDeck: vi.fn(),
replayDownloaded: vi.fn(),
resetPasswordChallenge: vi.fn(),
resetPassword: vi.fn(),
resetPasswordFailed: vi.fn(),

View file

@ -34,6 +34,7 @@ import { nextTurn } from './nextTurn';
import { readyStart } from './readyStart';
import { revealCards } from './revealCards';
import { reverseTurn } from './reverseTurn';
import { rollDie } from './rollDie';
import { setActivePhase } from './setActivePhase';
import { setCardAttr } from './setCardAttr';
import { setCardCounter } from './setCardCounter';
@ -262,6 +263,13 @@ describe('Game commands — delegate to WebClient.instance.protobuf.sendGameComm
expect(WebClient.instance.protobuf.sendGameCommand).toHaveBeenCalledWith(gameId, Data.Command_Unconcede_ext, expect.any(Object));
});
it('rollDie sends Command_RollDie', () => {
rollDie(gameId, { sides: 6, count: 2 });
expect(WebClient.instance.protobuf.sendGameCommand).toHaveBeenCalledWith(
gameId, Data.Command_RollDie_ext, expect.objectContaining({ sides: 6, count: 2 })
);
});
it('judge sends Command_Judge with targetId and wrapped gameCommand array', () => {
const targetId = 3;
const innerCmd = create(Data.GameCommandSchema);

View file

@ -31,3 +31,4 @@ export { deckSelect } from './deckSelect';
export { setSideboardPlan } from './setSideboardPlan';
export { setSideboardLock } from './setSideboardLock';
export { mulligan } from './mulligan';
export { rollDie } from './rollDie';

View file

@ -0,0 +1,8 @@
import { create } from '@bufbuild/protobuf';
import { WebClient } from '../../WebClient';
import { Data } from '@app/types';
export function rollDie(gameId: number, params: Data.RollDieParams): void {
WebClient.instance.protobuf.sendGameCommand(gameId, Data.Command_RollDie_ext, create(Data.Command_RollDieSchema, params));
}

View file

@ -0,0 +1,17 @@
import { create } from '@bufbuild/protobuf';
import { WebClient } from '../../WebClient';
import { Data } from '@app/types';
export function deckDownload(deckId: number): void {
WebClient.instance.protobuf.sendSessionCommand(
Data.Command_DeckDownload_ext,
create(Data.Command_DeckDownloadSchema, { deckId }),
{
responseExt: Data.Response_DeckDownload_ext,
onSuccess: (response) => {
WebClient.instance.response.session.downloadServerDeck(deckId, response);
},
}
);
}

View file

@ -6,6 +6,7 @@ export * from './addToList';
export * from './connect';
export * from './deckDel';
export * from './deckDelDir';
export * from './deckDownload';
export * from './deckList';
export * from './deckNewDir';
export * from './deckUpload';
@ -24,6 +25,7 @@ export * from './ping';
export * from './register';
export * from './removeFromList';
export * from './replayDeleteMatch';
export * from './replayDownload';
export * from './replayGetCode';
export * from './replayList';
export * from './replayModifyMatch';

View file

@ -0,0 +1,17 @@
import { create } from '@bufbuild/protobuf';
import { WebClient } from '../../WebClient';
import { Data } from '@app/types';
export function replayDownload(replayId: number): void {
WebClient.instance.protobuf.sendSessionCommand(
Data.Command_ReplayDownload_ext,
create(Data.Command_ReplayDownloadSchema, { replayId }),
{
responseExt: Data.Response_ReplayDownload_ext,
onSuccess: (response) => {
WebClient.instance.response.session.replayDownloaded(replayId, response);
},
}
);
}

View file

@ -27,6 +27,7 @@ import { accountImage } from './accountImage';
import { accountPassword } from './accountPassword';
import { deckDel } from './deckDel';
import { deckDelDir } from './deckDelDir';
import { deckDownload } from './deckDownload';
import { deckList } from './deckList';
import { deckNewDir } from './deckNewDir';
import { deckUpload } from './deckUpload';
@ -39,6 +40,7 @@ import { listUsers } from './listUsers';
import { message } from './message';
import { ping } from './ping';
import { replayDeleteMatch } from './replayDeleteMatch';
import { replayDownload } from './replayDownload';
import { replayList } from './replayList';
import { replayModifyMatch } from './replayModifyMatch';
import { addToList, addToBuddyList, addToIgnoreList } from './addToList';
@ -450,3 +452,39 @@ describe('replaySubmitCode', () => {
expect(onError).toHaveBeenCalledWith(404);
});
});
describe('deckDownload', () => {
it('sends Command_DeckDownload', () => {
deckDownload(42);
expect(WebClient.instance.protobuf.sendSessionCommand).toHaveBeenCalledWith(
Data.Command_DeckDownload_ext,
expect.objectContaining({ deckId: 42 }),
expect.objectContaining({ responseExt: Data.Response_DeckDownload_ext })
);
});
it('calls downloadServerDeck on success', () => {
deckDownload(42);
const resp = { deck: 'deck-content' };
invokeOnSuccess(resp, { responseCode: 0 });
expect(WebClient.instance.response.session.downloadServerDeck).toHaveBeenCalledWith(42, resp);
});
});
describe('replayDownload', () => {
it('sends Command_ReplayDownload', () => {
replayDownload(99);
expect(WebClient.instance.protobuf.sendSessionCommand).toHaveBeenCalledWith(
Data.Command_ReplayDownload_ext,
expect.objectContaining({ replayId: 99 }),
expect.objectContaining({ responseExt: Data.Response_ReplayDownload_ext })
);
});
it('calls replayDownloaded on success', () => {
replayDownload(99);
const resp = { replayData: new Uint8Array([1, 2, 3]) };
invokeOnSuccess(resp, { responseCode: 0 });
expect(WebClient.instance.response.session.replayDownloaded).toHaveBeenCalledWith(99, resp);
});
});

View file

@ -22,6 +22,8 @@ export interface ISessionRequest {
sendDirectMessage(userName: string, message: string): void;
getUserInfo(userName: string): void;
getUserGames(userName: string): void;
deckDownload(deckId: number): void;
replayDownload(replayId: number): void;
}
export interface IRoomsRequest {
@ -54,10 +56,48 @@ export interface IModeratorRequest {
warnUser(userName: string, reason: string, clientid?: string, removeMessages?: number): void;
}
export interface IGameRequest {
leaveGame(gameId: number): void;
kickFromGame(gameId: number, params: Data.KickFromGameParams): void;
gameSay(gameId: number, params: Data.GameSayParams): void;
readyStart(gameId: number, params: Data.ReadyStartParams): void;
concede(gameId: number): void;
unconcede(gameId: number): void;
judge(gameId: number, targetId: number, innerGameCommand: Data.GameCommand): void;
nextTurn(gameId: number): void;
setActivePhase(gameId: number, params: Data.SetActivePhaseParams): void;
reverseTurn(gameId: number): void;
moveCard(gameId: number, params: Data.MoveCardParams): void;
flipCard(gameId: number, params: Data.FlipCardParams): void;
attachCard(gameId: number, params: Data.AttachCardParams): void;
createToken(gameId: number, params: Data.CreateTokenParams): void;
setCardAttr(gameId: number, params: Data.SetCardAttrParams): void;
setCardCounter(gameId: number, params: Data.SetCardCounterParams): void;
incCardCounter(gameId: number, params: Data.IncCardCounterParams): void;
drawCards(gameId: number, params: Data.DrawCardsParams): void;
undoDraw(gameId: number): void;
createArrow(gameId: number, params: Data.CreateArrowParams): void;
deleteArrow(gameId: number, params: Data.DeleteArrowParams): void;
createCounter(gameId: number, params: Data.CreateCounterParams): void;
setCounter(gameId: number, params: Data.SetCounterParams): void;
incCounter(gameId: number, params: Data.IncCounterParams): void;
delCounter(gameId: number, params: Data.DelCounterParams): void;
shuffle(gameId: number, params: Data.ShuffleParams): void;
dumpZone(gameId: number, params: Data.DumpZoneParams): void;
revealCards(gameId: number, params: Data.RevealCardsParams): void;
changeZoneProperties(gameId: number, params: Data.ChangeZonePropertiesParams): void;
deckSelect(gameId: number, params: Data.DeckSelectParams): void;
setSideboardPlan(gameId: number, params: Data.SetSideboardPlanParams): void;
setSideboardLock(gameId: number, params: Data.SetSideboardLockParams): void;
mulligan(gameId: number, params: Data.MulliganParams): void;
rollDie(gameId: number, params: Data.RollDieParams): void;
}
export interface IWebClientRequest {
authentication: IAuthenticationRequest;
session: ISessionRequest;
rooms: IRoomsRequest;
game: IGameRequest;
admin: IAdminRequest;
moderator: IModeratorRequest;
}

View file

@ -50,12 +50,14 @@ export interface ISessionResponse {
deleteServerDeck(deckId: number): void;
updateServerDecks(deckList: Data.Response_DeckList): void;
uploadServerDeck(path: string, treeItem: Data.ServerInfo_DeckStorage_TreeItem): void;
downloadServerDeck(deckId: number, response: Data.Response_DeckDownload): void;
createServerDeckDir(path: string, dirName: string): void;
deleteServerDeckDir(path: string): void;
replayList(matchList: Data.ServerInfo_ReplayMatch[]): void;
replayAdded(matchInfo: Data.ServerInfo_ReplayMatch): void;
replayModifyMatch(gameId: number, doNotHide: boolean): void;
replayDeleteMatch(gameId: number): void;
replayDownloaded(replayId: number, response: Data.Response_ReplayDownload): void;
}
export interface IRoomResponse {

View file

@ -11,6 +11,7 @@ export type {
IAuthenticationRequest,
ISessionRequest,
IRoomsRequest,
IGameRequest,
IAdminRequest,
IModeratorRequest,
IWebClientRequest,