Add few more interfaces (#5063)

This commit is contained in:
Zach H 2024-06-25 01:00:45 -04:00 committed by GitHub
parent e261e16d99
commit 8687163cca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 359 additions and 90 deletions

View file

@ -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');
}
});
}

View file

@ -1,2 +1,4 @@
export * from './createGame';
export * from './joinGame';
export * from './leaveRoom';
export * from './roomSay';

View file

@ -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');
}
});
}

View file

@ -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');
}
});
}

View file

@ -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');
}
});
}

View file

@ -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');
}
});
}

View file

@ -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');
}
}
});
}

View file

@ -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');
}
});
}

View file

@ -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');
}
}
});
}

View file

@ -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();

View file

@ -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();
});
}

View file

@ -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
*/

View file

@ -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;
}

View file

@ -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();
});
}