diff --git a/webclient/src/api/SessionService.tsx b/webclient/src/api/SessionService.tsx index c1fbeddbd..1ecab0743 100644 --- a/webclient/src/api/SessionService.tsx +++ b/webclient/src/api/SessionService.tsx @@ -38,4 +38,8 @@ export default class SessionService { static getUserInfo(userName: string): void { SessionCommands.getUserInfo(userName); } + + static getUserGames(userName: string): void { + SessionCommands.getGamesOfUser(userName); + } } diff --git a/webclient/src/websocket/commands/session/activateAccount.ts b/webclient/src/websocket/commands/session/activate.ts similarity index 91% rename from webclient/src/websocket/commands/session/activateAccount.ts rename to webclient/src/websocket/commands/session/activate.ts index 1bf5118b6..1f45369f5 100644 --- a/webclient/src/websocket/commands/session/activateAccount.ts +++ b/webclient/src/websocket/commands/session/activate.ts @@ -6,7 +6,7 @@ import { SessionPersistence } from '../../persistence'; import { disconnect, login, updateStatus } from './'; -export function activateAccount(options: WebSocketConnectOptions, passwordSalt?: string): void { +export function activate(options: WebSocketConnectOptions, passwordSalt?: string): void { const { userName, token } = options as unknown as AccountActivationParams; const accountActivationConfig = { diff --git a/webclient/src/websocket/commands/session/resetPasswordChallenge.ts b/webclient/src/websocket/commands/session/forgotPasswordChallenge.ts similarity index 93% rename from webclient/src/websocket/commands/session/resetPasswordChallenge.ts rename to webclient/src/websocket/commands/session/forgotPasswordChallenge.ts index 39298b36d..40c248f35 100644 --- a/webclient/src/websocket/commands/session/resetPasswordChallenge.ts +++ b/webclient/src/websocket/commands/session/forgotPasswordChallenge.ts @@ -5,7 +5,7 @@ import webClient from '../../WebClient'; import { SessionPersistence } from '../../persistence'; import { disconnect, updateStatus } from './'; -export function resetPasswordChallenge(options: WebSocketConnectOptions): void { +export function forgotPasswordChallenge(options: WebSocketConnectOptions): void { const { userName, email } = options as unknown as ForgotPasswordChallengeParams; const forgotPasswordChallengeConfig = { diff --git a/webclient/src/websocket/commands/session/resetPassword.ts b/webclient/src/websocket/commands/session/forgotPasswordRequest.ts similarity index 92% rename from webclient/src/websocket/commands/session/resetPassword.ts rename to webclient/src/websocket/commands/session/forgotPasswordRequest.ts index a3c7092ff..5e5cc7d5e 100644 --- a/webclient/src/websocket/commands/session/resetPassword.ts +++ b/webclient/src/websocket/commands/session/forgotPasswordRequest.ts @@ -7,7 +7,7 @@ import { hashPassword } from '../../utils'; import { disconnect, updateStatus } from '.'; -export function resetPassword(options: WebSocketConnectOptions, passwordSalt?: string): void { +export function forgotPasswordRequest(options: WebSocketConnectOptions, passwordSalt?: string): void { const { userName, token, newPassword } = options as unknown as ForgotPasswordResetParams; const forgotPasswordResetConfig: any = { diff --git a/webclient/src/websocket/commands/session/getGamesOfUser.ts b/webclient/src/websocket/commands/session/getGamesOfUser.ts new file mode 100644 index 000000000..88f73a0f7 --- /dev/null +++ b/webclient/src/websocket/commands/session/getGamesOfUser.ts @@ -0,0 +1,29 @@ +import webClient from '../../WebClient'; +import { SessionPersistence } from '../../persistence'; + +export function getGamesOfUser(userName: string): void { + const command = webClient.protobuf.controller.Command_GetGamesOfUser.create({ userName }); + + const sc = webClient.protobuf.controller.SessionCommand.create({ + '.Command_GetGamesOfUser.ext': command + }); + + webClient.protobuf.sendSessionCommand(sc, raw => { + const { responseCode } = raw; + const response = raw['.Response_GetGamesOfUser.ext']; + + switch (responseCode) { + case webClient.protobuf.controller.Response.ResponseCode.RespOk: + SessionPersistence.getGamesOfUser(userName, response); + break; + case webClient.protobuf.controller.Response.ResponseCode.RespFunctionNotAllowed: + console.log('Not allowed'); + break; + case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword: + console.log('Wrong password'); + break; + default: + console.log('Failed to update information'); + } + }); +} diff --git a/webclient/src/websocket/commands/session/index.ts b/webclient/src/websocket/commands/session/index.ts index 16e34ee7c..24bb7183f 100644 --- a/webclient/src/websocket/commands/session/index.ts +++ b/webclient/src/websocket/commands/session/index.ts @@ -1,4 +1,4 @@ -export * from './activateAccount'; +export * from './activate'; export * from './addToList'; export * from './connect'; export * from './disconnect'; @@ -9,8 +9,8 @@ export * from './login'; export * from './register'; export * from './removeFromList'; export * from './requestPasswordSalt'; -export * from './resetPassword'; -export * from './resetPasswordChallenge' +export * from './forgotPasswordRequest'; +export * from './forgotPasswordChallenge' export * from './resetPasswordRequest'; export * from './updateStatus'; export * from './accountPassword'; @@ -18,3 +18,5 @@ export * from './accountEdit'; export * from './accountImage'; export * from './message'; export * from './getUserInfo'; +export * from './getGamesOfUser'; +export * from './ping'; diff --git a/webclient/src/websocket/commands/session/ping.ts b/webclient/src/websocket/commands/session/ping.ts new file mode 100644 index 000000000..642f45f62 --- /dev/null +++ b/webclient/src/websocket/commands/session/ping.ts @@ -0,0 +1,12 @@ +import webClient from '../../WebClient'; +import { SessionPersistence } from '../../persistence'; + +export function ping(pingReceived: Function): void { + const command = webClient.protobuf.controller.Command_Ping.create(); + + const sc = webClient.protobuf.controller.SessionCommand.create({ + '.Command_Ping.ext': command + }); + + webClient.protobuf.sendSessionCommand(sc, pingReceived); +} diff --git a/webclient/src/websocket/commands/session/requestPasswordSalt.ts b/webclient/src/websocket/commands/session/requestPasswordSalt.ts index f9f2d3640..667190bda 100644 --- a/webclient/src/websocket/commands/session/requestPasswordSalt.ts +++ b/webclient/src/websocket/commands/session/requestPasswordSalt.ts @@ -5,10 +5,10 @@ import webClient from '../../WebClient'; import { SessionPersistence } from '../../persistence'; import { - activateAccount, + activate, disconnect, login, - resetPassword, + forgotPasswordRequest, updateStatus } from './'; @@ -33,12 +33,12 @@ export function requestPasswordSalt(options: WebSocketConnectOptions): void { switch (options.reason) { case WebSocketConnectReason.ACTIVATE_ACCOUNT: { - activateAccount(options, passwordSalt); + activate(options, passwordSalt); break; } case WebSocketConnectReason.PASSWORD_RESET: { - resetPassword(options, passwordSalt); + forgotPasswordRequest(options, passwordSalt); break; } diff --git a/webclient/src/websocket/events/session/SessionEvents.spec.ts b/webclient/src/websocket/events/session/SessionEvents.spec.ts index 0153bd468..37c1d8c9e 100644 --- a/webclient/src/websocket/events/session/SessionEvents.spec.ts +++ b/webclient/src/websocket/events/session/SessionEvents.spec.ts @@ -319,14 +319,14 @@ describe.skip('SessionEvents', () => { }); it('should update stat/info and activate account', () => { - jest.spyOn(SessionCommands, 'activateAccount').mockImplementation(() => {}); + jest.spyOn(SessionCommands, 'activate').mockImplementation(() => {}); webClient.options.reason = WebSocketConnectReason.ACTIVATE_ACCOUNT; event(data); expect(SessionPersistence.updateInfo).toHaveBeenCalledWith(data.serverName, data.serverVersion); - expect(SessionCommands.activateAccount).toHaveBeenCalled(); + expect(SessionCommands.activate).toHaveBeenCalled(); }); it('should disconnect if protocolVersion mismatched', () => { diff --git a/webclient/src/websocket/events/session/serverIdentification.ts b/webclient/src/websocket/events/session/serverIdentification.ts index 716fa601f..6673533f2 100644 --- a/webclient/src/websocket/events/session/serverIdentification.ts +++ b/webclient/src/websocket/events/session/serverIdentification.ts @@ -2,13 +2,13 @@ import { StatusEnum, WebSocketConnectReason } from 'types'; import webClient from '../../WebClient'; import { - activateAccount, + activate, disconnect, login, register, requestPasswordSalt, - resetPassword, - resetPasswordChallenge, + forgotPasswordChallenge, + forgotPasswordRequest, resetPasswordRequest, updateStatus, } from '../../commands/session'; @@ -44,20 +44,20 @@ export function serverIdentification(info: ServerIdentificationData) { if (getPasswordSalt) { requestPasswordSalt(options); } else { - activateAccount(options); + activate(options); } break; case WebSocketConnectReason.PASSWORD_RESET_REQUEST: resetPasswordRequest(options); break; case WebSocketConnectReason.PASSWORD_RESET_CHALLENGE: - resetPasswordChallenge(options); + forgotPasswordChallenge(options); break; case WebSocketConnectReason.PASSWORD_RESET: if (getPasswordSalt) { requestPasswordSalt(options); } else { - resetPassword(options); + forgotPasswordRequest(options); } break; default: diff --git a/webclient/src/websocket/persistence/SessionPersistence.ts b/webclient/src/websocket/persistence/SessionPersistence.ts index 81e77458d..0e1fc18d9 100644 --- a/webclient/src/websocket/persistence/SessionPersistence.ts +++ b/webclient/src/websocket/persistence/SessionPersistence.ts @@ -164,4 +164,8 @@ export class SessionPersistence { static getUserInfo(userInfo: string) { console.log('getUserInfo'); } + + static getGamesOfUser(userName: string, response: any): void { + console.log('getGamesOfUser'); + } } diff --git a/webclient/src/websocket/services/ProtobufService.ts b/webclient/src/websocket/services/ProtobufService.ts index 6dda2fba9..4a7f80d4e 100644 --- a/webclient/src/websocket/services/ProtobufService.ts +++ b/webclient/src/websocket/services/ProtobufService.ts @@ -3,7 +3,7 @@ import protobuf from 'protobufjs'; import { RoomEvents, SessionEvents } from '../events'; import { SessionPersistence } from '../persistence'; import { WebClient } from '../WebClient'; - +import { SessionCommands } from 'websocket'; import ProtoFiles from '../../proto-files.json'; export interface ProtobufEvents { @@ -75,11 +75,7 @@ export class ProtobufService { } public sendKeepAliveCommand(pingReceived: Function) { - const command = this.controller.SessionCommand.create({ - '.Command_Ping.ext': this.controller.Command_Ping.create() - }); - - this.sendSessionCommand(command, pingReceived); + SessionCommands.ping(pingReceived); } public handleMessageEvent({ data }: MessageEvent): void {