From 8687163ccab3ac230879d774f97f493b6012a8d3 Mon Sep 17 00:00:00 2001 From: Zach H Date: Tue, 25 Jun 2024 01:00:45 -0400 Subject: [PATCH] Add few more interfaces (#5063) --- .../common/{SortUtil.tsx => SortUtil.ts} | 0 webclient/src/types/deckList.ts | 18 +++++++++ webclient/src/types/game.ts | 35 +++++++++++++++++ webclient/src/types/game.tsx | 12 ------ webclient/src/types/index.ts | 1 + .../src/types/{message.tsx => message.ts} | 0 webclient/src/types/{room.tsx => room.ts} | 0 webclient/src/types/{routes.tsx => routes.ts} | 0 webclient/src/types/{server.tsx => server.ts} | 0 webclient/src/types/{sort.tsx => sort.ts} | 0 webclient/src/types/{user.tsx => user.ts} | 0 .../commands/{index.tsx => index.ts} | 0 .../src/websocket/commands/room/createGame.ts | 21 ++++++++++ .../src/websocket/commands/room/index.ts | 2 + .../src/websocket/commands/room/joinGame.ts | 21 ++++++++++ .../src/websocket/commands/session/deckDel.ts | 19 +++++++++ .../websocket/commands/session/deckDelDir.ts | 19 +++++++++ .../commands/session/deckDownload.ts | 19 +++++++++ .../websocket/commands/session/deckList.ts | 22 +++++++++++ .../websocket/commands/session/deckNewDir.ts | 19 +++++++++ .../websocket/commands/session/deckUpload.ts | 23 +++++++++++ .../commands/session/forgotPasswordRequest.ts | 33 ++++++++-------- .../commands/session/forgotPasswordReset.ts | 39 +++++++++++++++++++ .../src/websocket/commands/session/index.ts | 33 +++++++++++----- .../commands/session/requestPasswordSalt.ts | 4 +- .../commands/session/resetPasswordRequest.ts | 38 ------------------ .../src/websocket/events/common/index.ts | 6 +++ .../playerPropertiesChanged.ts} | 4 +- webclient/src/websocket/events/index.ts | 1 + .../src/websocket/events/session/index.ts | 6 +-- .../events/session/serverIdentification.ts | 6 +-- .../websocket/persistence/RoomPersistence.ts | 8 ++++ .../persistence/SessionPersistence.ts | 29 +++++++++++++- .../src/websocket/services/ProtobufService.ts | 11 +++++- 34 files changed, 359 insertions(+), 90 deletions(-) rename webclient/src/store/common/{SortUtil.tsx => SortUtil.ts} (100%) create mode 100644 webclient/src/types/deckList.ts create mode 100644 webclient/src/types/game.ts delete mode 100644 webclient/src/types/game.tsx rename webclient/src/types/{message.tsx => message.ts} (100%) rename webclient/src/types/{room.tsx => room.ts} (100%) rename webclient/src/types/{routes.tsx => routes.ts} (100%) rename webclient/src/types/{server.tsx => server.ts} (100%) rename webclient/src/types/{sort.tsx => sort.ts} (100%) rename webclient/src/types/{user.tsx => user.ts} (100%) rename webclient/src/websocket/commands/{index.tsx => index.ts} (100%) create mode 100644 webclient/src/websocket/commands/room/createGame.ts create mode 100644 webclient/src/websocket/commands/room/joinGame.ts create mode 100644 webclient/src/websocket/commands/session/deckDel.ts create mode 100644 webclient/src/websocket/commands/session/deckDelDir.ts create mode 100644 webclient/src/websocket/commands/session/deckDownload.ts create mode 100644 webclient/src/websocket/commands/session/deckList.ts create mode 100644 webclient/src/websocket/commands/session/deckNewDir.ts create mode 100644 webclient/src/websocket/commands/session/deckUpload.ts create mode 100644 webclient/src/websocket/commands/session/forgotPasswordReset.ts delete mode 100644 webclient/src/websocket/commands/session/resetPasswordRequest.ts create mode 100644 webclient/src/websocket/events/common/index.ts rename webclient/src/websocket/events/{session/playerPropertiesChanges.ts => common/playerPropertiesChanged.ts} (50%) diff --git a/webclient/src/store/common/SortUtil.tsx b/webclient/src/store/common/SortUtil.ts similarity index 100% rename from webclient/src/store/common/SortUtil.tsx rename to webclient/src/store/common/SortUtil.ts diff --git a/webclient/src/types/deckList.ts b/webclient/src/types/deckList.ts new file mode 100644 index 000000000..18212079e --- /dev/null +++ b/webclient/src/types/deckList.ts @@ -0,0 +1,18 @@ +export interface DeckList { + root: DeckStorageFolder; +} + +export interface DeckStorageFolder { + items: DeckStorageTreeItem[]; +} + +export interface DeckStorageFile { + creationTime: number; +} + +export interface DeckStorageTreeItem { + id: number; + name: string; + file: DeckStorageFile; + folder: DeckStorageFolder; +} diff --git a/webclient/src/types/game.ts b/webclient/src/types/game.ts new file mode 100644 index 000000000..746c119e5 --- /dev/null +++ b/webclient/src/types/game.ts @@ -0,0 +1,35 @@ +export interface Game { + description: string; + gameId: number; + gameType: string; + gameTypes: string[]; + roomId: number; + started: boolean; +} + +export enum GameSortField { + START_TIME = 'startTime' +} + +export interface GameConfig { + description: string; + password: string; + maxPlayer: number; + onlyBuddies: boolean; + onlyRegistered: boolean; + spectatorsAllowed: boolean; + spectatorsNeedPassword: boolean; + spectatorsCanTalk: boolean; + spectatorsSeeEverything: boolean; + gameTypeIds: number[]; + joinAsJudge: boolean; + joinAsSpectator: boolean; +} + +export interface JoinGameParams { + gameId: number; + password: string; + spectator: boolean; + overrideRestrictions: boolean; + joinAsJudge: boolean; +} diff --git a/webclient/src/types/game.tsx b/webclient/src/types/game.tsx deleted file mode 100644 index 11e1934db..000000000 --- a/webclient/src/types/game.tsx +++ /dev/null @@ -1,12 +0,0 @@ -export interface Game { - description: string; - gameId: number; - gameType: string; - gameTypes: string[]; - roomId: number; - started: boolean; -} - -export enum GameSortField { - START_TIME = 'startTime' -} diff --git a/webclient/src/types/index.ts b/webclient/src/types/index.ts index 8a6147b83..59153999c 100644 --- a/webclient/src/types/index.ts +++ b/webclient/src/types/index.ts @@ -14,3 +14,4 @@ export * from './settings'; export * from './languages'; export * from './logs'; export * from './session'; +export * from './deckList'; diff --git a/webclient/src/types/message.tsx b/webclient/src/types/message.ts similarity index 100% rename from webclient/src/types/message.tsx rename to webclient/src/types/message.ts diff --git a/webclient/src/types/room.tsx b/webclient/src/types/room.ts similarity index 100% rename from webclient/src/types/room.tsx rename to webclient/src/types/room.ts diff --git a/webclient/src/types/routes.tsx b/webclient/src/types/routes.ts similarity index 100% rename from webclient/src/types/routes.tsx rename to webclient/src/types/routes.ts diff --git a/webclient/src/types/server.tsx b/webclient/src/types/server.ts similarity index 100% rename from webclient/src/types/server.tsx rename to webclient/src/types/server.ts diff --git a/webclient/src/types/sort.tsx b/webclient/src/types/sort.ts similarity index 100% rename from webclient/src/types/sort.tsx rename to webclient/src/types/sort.ts diff --git a/webclient/src/types/user.tsx b/webclient/src/types/user.ts similarity index 100% rename from webclient/src/types/user.tsx rename to webclient/src/types/user.ts diff --git a/webclient/src/websocket/commands/index.tsx b/webclient/src/websocket/commands/index.ts similarity index 100% rename from webclient/src/websocket/commands/index.tsx rename to webclient/src/websocket/commands/index.ts diff --git a/webclient/src/websocket/commands/room/createGame.ts b/webclient/src/websocket/commands/room/createGame.ts new file mode 100644 index 000000000..e5fd66f80 --- /dev/null +++ b/webclient/src/websocket/commands/room/createGame.ts @@ -0,0 +1,21 @@ +import { RoomPersistence } from '../../persistence'; +import webClient from '../../WebClient'; +import { GameConfig } from 'types'; + +export function createGame(roomId: number, gameConfig: GameConfig): void { + const command = webClient.protobuf.controller.Command_CreateGame.create(gameConfig); + const rc = webClient.protobuf.controller.RoomCommand.create({ '.Command_CreateGame.ext': command }); + + webClient.protobuf.sendRoomCommand(roomId, rc, (raw) => { + const { responseCode } = raw; + + switch (responseCode) { + case webClient.protobuf.controller.Response.ResponseCode.RespOk: + RoomPersistence.gameCreated(roomId); + break; + default: + console.log('Failed to do the thing'); + } + }); +} + diff --git a/webclient/src/websocket/commands/room/index.ts b/webclient/src/websocket/commands/room/index.ts index 36ab14d66..18235618c 100644 --- a/webclient/src/websocket/commands/room/index.ts +++ b/webclient/src/websocket/commands/room/index.ts @@ -1,2 +1,4 @@ +export * from './createGame'; +export * from './joinGame'; export * from './leaveRoom'; export * from './roomSay'; diff --git a/webclient/src/websocket/commands/room/joinGame.ts b/webclient/src/websocket/commands/room/joinGame.ts new file mode 100644 index 000000000..19a672924 --- /dev/null +++ b/webclient/src/websocket/commands/room/joinGame.ts @@ -0,0 +1,21 @@ +import { RoomPersistence } from '../../persistence'; +import webClient from '../../WebClient'; +import { GameConfig, JoinGameParams } from 'types'; + +export function joinGame(roomId: number, joinGameParams: JoinGameParams): void { + const command = webClient.protobuf.controller.Command_JoinGame.create(joinGameParams); + const rc = webClient.protobuf.controller.RoomCommand.create({ '.Command_JoinGame.ext': command }); + + webClient.protobuf.sendRoomCommand(roomId, rc, (raw) => { + const { responseCode } = raw; + + switch (responseCode) { + case webClient.protobuf.controller.Response.ResponseCode.RespOk: + RoomPersistence.joinedGame(roomId, joinGameParams.gameId); + break; + default: + console.log('Failed to do the thing'); + } + }); +} + diff --git a/webclient/src/websocket/commands/session/deckDel.ts b/webclient/src/websocket/commands/session/deckDel.ts new file mode 100644 index 000000000..c77d89aa3 --- /dev/null +++ b/webclient/src/websocket/commands/session/deckDel.ts @@ -0,0 +1,19 @@ +import webClient from '../../WebClient'; +import { SessionPersistence } from '../../persistence'; + +export function deckDel(deckId: number): void { + const command = webClient.protobuf.controller.Command_DeckDel.create({ deckId }); + const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_DeckDel.ext': command }); + + webClient.protobuf.sendSessionCommand(sc, raw => { + const { responseCode } = raw; + + switch (responseCode) { + case webClient.protobuf.controller.Response.ResponseCode.RespOk: + SessionPersistence.deckDelete(deckId); + break; + default: + console.log('Failed to do the thing'); + } + }); +} diff --git a/webclient/src/websocket/commands/session/deckDelDir.ts b/webclient/src/websocket/commands/session/deckDelDir.ts new file mode 100644 index 000000000..ff4b25ec3 --- /dev/null +++ b/webclient/src/websocket/commands/session/deckDelDir.ts @@ -0,0 +1,19 @@ +import webClient from '../../WebClient'; +import { SessionPersistence } from '../../persistence'; + +export function deckDelDir(path: string): void { + const command = webClient.protobuf.controller.Command_DeckDelDir.create({ path }); + const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_DeckDelDir.ext': command }); + + webClient.protobuf.sendSessionCommand(sc, raw => { + const { responseCode } = raw; + + switch (responseCode) { + case webClient.protobuf.controller.Response.ResponseCode.RespOk: + SessionPersistence.deckDeleteDir(path); + break; + default: + console.log('Failed to do the thing'); + } + }); +} diff --git a/webclient/src/websocket/commands/session/deckDownload.ts b/webclient/src/websocket/commands/session/deckDownload.ts new file mode 100644 index 000000000..a0c4bd461 --- /dev/null +++ b/webclient/src/websocket/commands/session/deckDownload.ts @@ -0,0 +1,19 @@ +import webClient from '../../WebClient'; +import { SessionPersistence } from '../../persistence'; + +export function deckDownload(deckId: number): void { + const command = webClient.protobuf.controller.Command_DeckDownload.create({ deckId }); + const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_DeckDownload.ext': command }); + + webClient.protobuf.sendSessionCommand(sc, raw => { + const { responseCode } = raw; + + switch (responseCode) { + case webClient.protobuf.controller.Response.ResponseCode.RespOk: + SessionPersistence.deckDownload(deckId); + break; + default: + console.log('Failed to do the thing'); + } + }); +} diff --git a/webclient/src/websocket/commands/session/deckList.ts b/webclient/src/websocket/commands/session/deckList.ts new file mode 100644 index 000000000..e84b8efb3 --- /dev/null +++ b/webclient/src/websocket/commands/session/deckList.ts @@ -0,0 +1,22 @@ +import webClient from '../../WebClient'; +import { SessionPersistence } from '../../persistence'; + +export function deckList(): void { + const command = webClient.protobuf.controller.Command_DeckList.create(); + const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_DeckList.ext': command }); + + webClient.protobuf.sendSessionCommand(sc, raw => { + const { responseCode } = raw; + const response = raw['.Response_DeckList.ext']; + + if (response) { + switch (responseCode) { + case webClient.protobuf.controller.Response.ResponseCode.RespOk: + SessionPersistence.deckList(response); + break; + default: + console.log('Failed to do the thing'); + } + } + }); +} diff --git a/webclient/src/websocket/commands/session/deckNewDir.ts b/webclient/src/websocket/commands/session/deckNewDir.ts new file mode 100644 index 000000000..b9bca6208 --- /dev/null +++ b/webclient/src/websocket/commands/session/deckNewDir.ts @@ -0,0 +1,19 @@ +import webClient from '../../WebClient'; +import { SessionPersistence } from '../../persistence'; + +export function deckNewDir(path: string, dirName: string): void { + const command = webClient.protobuf.controller.Command_DeckNewDir.create({ path, dirName }); + const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_DeckNewDir.ext': command }); + + webClient.protobuf.sendSessionCommand(sc, raw => { + const { responseCode } = raw; + + switch (responseCode) { + case webClient.protobuf.controller.Response.ResponseCode.RespOk: + SessionPersistence.deckNewDir(path, dirName); + break; + default: + console.log('Failed to do the thing'); + } + }); +} diff --git a/webclient/src/websocket/commands/session/deckUpload.ts b/webclient/src/websocket/commands/session/deckUpload.ts new file mode 100644 index 000000000..af526c8fc --- /dev/null +++ b/webclient/src/websocket/commands/session/deckUpload.ts @@ -0,0 +1,23 @@ +import webClient from '../../WebClient'; +import { SessionPersistence } from '../../persistence'; + +export function deckUpload(path: string, deckId: number, deckList: string): void { + const command = webClient.protobuf.controller.Command_DeckUpload.create({ path, deckId, deckList }); + const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_DeckUpload.ext': command }); + + webClient.protobuf.sendSessionCommand(sc, raw => { + const { responseCode } = raw; + const response = raw['.Response_DeckUpload.ext']; + + if (response) { + switch (responseCode) { + case webClient.protobuf.controller.Response.ResponseCode.RespOk: + SessionPersistence.deckUpload(response); + break; + default: + console.log('Failed to do the thing'); + } + } + + }); +} diff --git a/webclient/src/websocket/commands/session/forgotPasswordRequest.ts b/webclient/src/websocket/commands/session/forgotPasswordRequest.ts index 3e858ad41..5e5fe3bbd 100644 --- a/webclient/src/websocket/commands/session/forgotPasswordRequest.ts +++ b/webclient/src/websocket/commands/session/forgotPasswordRequest.ts @@ -1,34 +1,33 @@ -import { ForgotPasswordResetParams } from 'store'; +import { ForgotPasswordParams } from 'store'; import { StatusEnum, WebSocketConnectOptions } from 'types'; import webClient from '../../WebClient'; import { SessionPersistence } from '../../persistence'; -import { hashPassword } from '../../utils'; -import { disconnect, updateStatus } from '.'; +import { disconnect, updateStatus } from './'; -export function forgotPasswordRequest(options: WebSocketConnectOptions, passwordSalt?: string): void { - const { userName, token, newPassword } = options as unknown as ForgotPasswordResetParams; +export function forgotPasswordRequest(options: WebSocketConnectOptions): void { + const { userName } = options as unknown as ForgotPasswordParams; - const forgotPasswordResetConfig: any = { + const forgotPasswordConfig = { ...webClient.clientConfig, userName, - token, }; - if (passwordSalt) { - forgotPasswordResetConfig.hashedNewPassword = hashPassword(passwordSalt, newPassword); - } else { - forgotPasswordResetConfig.newPassword = newPassword; - } - - const command = webClient.protobuf.controller.Command_ForgotPasswordReset.create(forgotPasswordResetConfig); - const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ForgotPasswordReset.ext': command }); + const command = webClient.protobuf.controller.Command_ForgotPasswordRequest.create(forgotPasswordConfig); + const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ForgotPasswordRequest.ext': command }); webClient.protobuf.sendSessionCommand(sc, raw => { if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) { - updateStatus(StatusEnum.DISCONNECTED, null); - SessionPersistence.resetPasswordSuccess(); + const resp = raw['.Response_ForgotPasswordRequest.ext']; + + if (resp.challengeEmail) { + updateStatus(StatusEnum.DISCONNECTED, null); + SessionPersistence.resetPasswordChallenge(); + } else { + updateStatus(StatusEnum.DISCONNECTED, null); + SessionPersistence.resetPassword(); + } } else { updateStatus(StatusEnum.DISCONNECTED, null); SessionPersistence.resetPasswordFailed(); diff --git a/webclient/src/websocket/commands/session/forgotPasswordReset.ts b/webclient/src/websocket/commands/session/forgotPasswordReset.ts new file mode 100644 index 000000000..9312b71af --- /dev/null +++ b/webclient/src/websocket/commands/session/forgotPasswordReset.ts @@ -0,0 +1,39 @@ +import { ForgotPasswordResetParams } from 'store'; +import { StatusEnum, WebSocketConnectOptions } from 'types'; + +import webClient from '../../WebClient'; +import { SessionPersistence } from '../../persistence'; +import { hashPassword } from '../../utils'; + +import { disconnect, updateStatus } from '.'; + +export function forgotPasswordReset(options: WebSocketConnectOptions, passwordSalt?: string): void { + const { userName, token, newPassword } = options as unknown as ForgotPasswordResetParams; + + const forgotPasswordResetConfig: any = { + ...webClient.clientConfig, + userName, + token, + }; + + if (passwordSalt) { + forgotPasswordResetConfig.hashedNewPassword = hashPassword(passwordSalt, newPassword); + } else { + forgotPasswordResetConfig.newPassword = newPassword; + } + + const command = webClient.protobuf.controller.Command_ForgotPasswordReset.create(forgotPasswordResetConfig); + const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ForgotPasswordReset.ext': command }); + + webClient.protobuf.sendSessionCommand(sc, raw => { + if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) { + updateStatus(StatusEnum.DISCONNECTED, null); + SessionPersistence.resetPasswordSuccess(); + } else { + updateStatus(StatusEnum.DISCONNECTED, null); + SessionPersistence.resetPasswordFailed(); + } + + disconnect(); + }); +} diff --git a/webclient/src/websocket/commands/session/index.ts b/webclient/src/websocket/commands/session/index.ts index 24bb7183f..829a74b71 100644 --- a/webclient/src/websocket/commands/session/index.ts +++ b/webclient/src/websocket/commands/session/index.ts @@ -1,22 +1,35 @@ +export * from './accountEdit'; +export * from './accountImage'; +export * from './accountPassword'; export * from './activate'; export * from './addToList'; export * from './connect'; +export * from './deckDel'; +export * from './deckDelDir'; +export * from './deckDownload'; +export * from './deckList'; +export * from './deckNewDir'; +export * from './deckUpload'; export * from './disconnect'; +export * from './forgotPasswordChallenge' +export * from './forgotPasswordRequest'; +export * from './forgotPasswordReset'; +export * from './getGamesOfUser'; +export * from './getUserInfo'; export * from './joinRoom'; export * from './listRooms'; export * from './listUsers'; export * from './login'; +export * from './message'; +export * from './ping'; export * from './register'; export * from './removeFromList'; export * from './requestPasswordSalt'; -export * from './forgotPasswordRequest'; -export * from './forgotPasswordChallenge' -export * from './resetPasswordRequest'; export * from './updateStatus'; -export * from './accountPassword'; -export * from './accountEdit'; -export * from './accountImage'; -export * from './message'; -export * from './getUserInfo'; -export * from './getGamesOfUser'; -export * from './ping'; + +/** TODO + * REPLAY_DELETE_MATCH + * REPLAY_DOWNLOAD + * REPLAY_LIST + * REPLAY_MODIFY_MATCH + */ diff --git a/webclient/src/websocket/commands/session/requestPasswordSalt.ts b/webclient/src/websocket/commands/session/requestPasswordSalt.ts index 21ea27485..b7ab5ef92 100644 --- a/webclient/src/websocket/commands/session/requestPasswordSalt.ts +++ b/webclient/src/websocket/commands/session/requestPasswordSalt.ts @@ -8,7 +8,7 @@ import { activate, disconnect, login, - forgotPasswordRequest, + forgotPasswordReset, updateStatus } from './'; @@ -35,7 +35,7 @@ export function requestPasswordSalt(options: WebSocketConnectOptions): void { } case WebSocketConnectReason.PASSWORD_RESET: { - forgotPasswordRequest(options, passwordSalt); + forgotPasswordReset(options, passwordSalt); break; } diff --git a/webclient/src/websocket/commands/session/resetPasswordRequest.ts b/webclient/src/websocket/commands/session/resetPasswordRequest.ts deleted file mode 100644 index 800e8cc0d..000000000 --- a/webclient/src/websocket/commands/session/resetPasswordRequest.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { ForgotPasswordParams } from 'store'; -import { StatusEnum, WebSocketConnectOptions } from 'types'; - -import webClient from '../../WebClient'; -import { SessionPersistence } from '../../persistence'; - -import { disconnect, updateStatus } from './'; - -export function resetPasswordRequest(options: WebSocketConnectOptions): void { - const { userName } = options as unknown as ForgotPasswordParams; - - const forgotPasswordConfig = { - ...webClient.clientConfig, - userName, - }; - - const command = webClient.protobuf.controller.Command_ForgotPasswordRequest.create(forgotPasswordConfig); - const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ForgotPasswordRequest.ext': command }); - - webClient.protobuf.sendSessionCommand(sc, raw => { - if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) { - const resp = raw['.Response_ForgotPasswordRequest.ext']; - - if (resp.challengeEmail) { - updateStatus(StatusEnum.DISCONNECTED, null); - SessionPersistence.resetPasswordChallenge(); - } else { - updateStatus(StatusEnum.DISCONNECTED, null); - SessionPersistence.resetPassword(); - } - } else { - updateStatus(StatusEnum.DISCONNECTED, null); - SessionPersistence.resetPasswordFailed(); - } - - disconnect(); - }); -} diff --git a/webclient/src/websocket/events/common/index.ts b/webclient/src/websocket/events/common/index.ts new file mode 100644 index 000000000..77a325c1e --- /dev/null +++ b/webclient/src/websocket/events/common/index.ts @@ -0,0 +1,6 @@ +import { ProtobufEvents } from '../../services/ProtobufService'; +import { playerPropertiesChanged } from './playerPropertiesChanged'; + +export const CommonEvents: ProtobufEvents = { + '.Event_PlayerPropertiesChanged.ext': playerPropertiesChanged, +} diff --git a/webclient/src/websocket/events/session/playerPropertiesChanges.ts b/webclient/src/websocket/events/common/playerPropertiesChanged.ts similarity index 50% rename from webclient/src/websocket/events/session/playerPropertiesChanges.ts rename to webclient/src/websocket/events/common/playerPropertiesChanged.ts index 0f35b4ae3..557e57ac9 100644 --- a/webclient/src/websocket/events/session/playerPropertiesChanges.ts +++ b/webclient/src/websocket/events/common/playerPropertiesChanged.ts @@ -1,6 +1,6 @@ -import { PlayerGamePropertiesData } from './interfaces'; +import { PlayerGamePropertiesData } from '../session/interfaces'; import { SessionPersistence } from '../../persistence'; -export function playerPropertiesChanges(payload: PlayerGamePropertiesData): void { +export function playerPropertiesChanged(payload: PlayerGamePropertiesData): void { SessionPersistence.playerPropertiesChanged(payload); } diff --git a/webclient/src/websocket/events/index.ts b/webclient/src/websocket/events/index.ts index a5535a1cf..00d2e4629 100644 --- a/webclient/src/websocket/events/index.ts +++ b/webclient/src/websocket/events/index.ts @@ -1,2 +1,3 @@ +export * from './common'; export * from './room'; export * from './session'; diff --git a/webclient/src/websocket/events/session/index.ts b/webclient/src/websocket/events/session/index.ts index 400804f59..9fe7bb1da 100644 --- a/webclient/src/websocket/events/session/index.ts +++ b/webclient/src/websocket/events/session/index.ts @@ -3,7 +3,7 @@ import { addToList } from './addToList'; import { connectionClosed } from './connectionClosed'; import { listRooms } from './listRooms'; import { notifyUser } from './notifyUser'; -import { playerPropertiesChanges } from './playerPropertiesChanges'; +import { playerPropertiesChanged } from '../common/playerPropertiesChanged'; import { removeFromList } from './removeFromList'; import { serverIdentification } from './serverIdentification'; import { serverMessage } from './serverMessage'; @@ -19,9 +19,9 @@ export const SessionEvents: ProtobufEvents = { '.Event_GameJoined.ext': gameJoined, '.Event_ListRooms.ext': listRooms, '.Event_NotifyUser.ext': notifyUser, - '.Event_PlayerPropertiesChanges.ext': playerPropertiesChanges, '.Event_RemoveFromList.ext': removeFromList, - // '.Event_ReplayAdded.ext': () => {}, // TODO Eventually + '.Event_ReplayAdded.ext': () => console.log('Event_ReplayAdded'), + '.Event_ServerCompleteList.ext': () => console.log('Event_ServerCompleteList'), '.Event_ServerIdentification.ext': serverIdentification, '.Event_ServerMessage.ext': serverMessage, '.Event_ServerShutdown.ext': serverShutdown, diff --git a/webclient/src/websocket/events/session/serverIdentification.ts b/webclient/src/websocket/events/session/serverIdentification.ts index 24ae0ad0a..ce89e1f3c 100644 --- a/webclient/src/websocket/events/session/serverIdentification.ts +++ b/webclient/src/websocket/events/session/serverIdentification.ts @@ -9,7 +9,7 @@ import { requestPasswordSalt, forgotPasswordChallenge, forgotPasswordRequest, - resetPasswordRequest, + forgotPasswordReset, updateStatus, } from '../../commands/session'; import { generateSalt, passwordSaltSupported } from '../../utils'; @@ -48,7 +48,7 @@ export function serverIdentification(info: ServerIdentificationData): void { } break; case WebSocketConnectReason.PASSWORD_RESET_REQUEST: - resetPasswordRequest(options); + forgotPasswordRequest(options); break; case WebSocketConnectReason.PASSWORD_RESET_CHALLENGE: forgotPasswordChallenge(options); @@ -57,7 +57,7 @@ export function serverIdentification(info: ServerIdentificationData): void { if (getPasswordSalt) { requestPasswordSalt(options); } else { - forgotPasswordRequest(options); + forgotPasswordReset(options); } break; default: diff --git a/webclient/src/websocket/persistence/RoomPersistence.ts b/webclient/src/websocket/persistence/RoomPersistence.ts index 997ec20b1..9e664d9c5 100644 --- a/webclient/src/websocket/persistence/RoomPersistence.ts +++ b/webclient/src/websocket/persistence/RoomPersistence.ts @@ -52,4 +52,12 @@ export class RoomPersistence { static removeMessages(roomId: number, name: string, amount: number): void { console.log('removeMessages', roomId, name, amount); }; + + static gameCreated(roomId: number) { + console.log('gameCreated', roomId); + } + + static joinedGame(roomId: number, gameId: number) { + console.log('joinedGame', roomId, gameId); + } } diff --git a/webclient/src/websocket/persistence/SessionPersistence.ts b/webclient/src/websocket/persistence/SessionPersistence.ts index 9e803d4b8..cda905cf5 100644 --- a/webclient/src/websocket/persistence/SessionPersistence.ts +++ b/webclient/src/websocket/persistence/SessionPersistence.ts @@ -1,5 +1,5 @@ import { ServerDispatch } from 'store'; -import { StatusEnum, User, WebSocketConnectOptions } from 'types'; +import { DeckStorageTreeItem, StatusEnum, User, WebSocketConnectOptions } from 'types'; import { sanitizeHtml } from 'websocket/utils'; import { @@ -10,6 +10,7 @@ import { UserMessageData } from '../events/session/interfaces'; import NormalizeService from '../utils/NormalizeService'; +import { DeckList } from '../../types/deckList'; export class SessionPersistence { static initialized() { @@ -205,4 +206,30 @@ export class SessionPersistence { static removeFromList(list: string, userName: string): void { console.log('removeFromList', list, userName); } + + static deckDelete(deckId: number): void { + console.log('deckDelete', deckId); + } + + static deckDeleteDir(path: string): void { + console.log('deckDeleteDir', path); + } + + static deckDownload(deckId: number): void { + console.log('deckDownload', deckId); + } + + static deckList(deckList: DeckList): void { + console.log('deckList', deckList); + } + + static deckNewDir(path: string, dirName: string): void { + console.log('deckNewDir', path, dirName); + } + + static deckUpload(treeItem: DeckStorageTreeItem): void { + console.log('deckUpload', treeItem); + } } + + diff --git a/webclient/src/websocket/services/ProtobufService.ts b/webclient/src/websocket/services/ProtobufService.ts index 4a7f80d4e..8ade17513 100644 --- a/webclient/src/websocket/services/ProtobufService.ts +++ b/webclient/src/websocket/services/ProtobufService.ts @@ -1,6 +1,6 @@ import protobuf from 'protobufjs'; -import { RoomEvents, SessionEvents } from '../events'; +import { CommonEvents, RoomEvents, SessionEvents } from '../events'; import { SessionPersistence } from '../persistence'; import { WebClient } from '../WebClient'; import { SessionCommands } from 'websocket'; @@ -95,7 +95,10 @@ export class ProtobufService { this.processSessionEvent(msg.sessionEvent, msg); break; case this.controller.ServerMessage.MessageType.GAME_EVENT_CONTAINER: - // @TODO + console.log(msg); + break; + default: + console.log(msg); break; } } @@ -113,6 +116,10 @@ export class ProtobufService { } } + private processCommonEvent(response: any, raw: any) { + this.processEvent(response, CommonEvents, raw); + } + private processRoomEvent(response: any, raw: any) { this.processEvent(response, RoomEvents, raw); }