mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-27 00:53:55 -07:00
More web stuff (#5055)
* Add Response.gamesOfuser * Cleanup and confirm all
This commit is contained in:
parent
f04702fdd1
commit
291c535edb
12 changed files with 71 additions and 24 deletions
|
|
@ -38,4 +38,8 @@ export default class SessionService {
|
||||||
static getUserInfo(userName: string): void {
|
static getUserInfo(userName: string): void {
|
||||||
SessionCommands.getUserInfo(userName);
|
SessionCommands.getUserInfo(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getUserGames(userName: string): void {
|
||||||
|
SessionCommands.getGamesOfUser(userName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import { SessionPersistence } from '../../persistence';
|
||||||
|
|
||||||
import { disconnect, login, updateStatus } from './';
|
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 { userName, token } = options as unknown as AccountActivationParams;
|
||||||
|
|
||||||
const accountActivationConfig = {
|
const accountActivationConfig = {
|
||||||
|
|
@ -5,7 +5,7 @@ import webClient from '../../WebClient';
|
||||||
import { SessionPersistence } from '../../persistence';
|
import { SessionPersistence } from '../../persistence';
|
||||||
import { disconnect, updateStatus } from './';
|
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 { userName, email } = options as unknown as ForgotPasswordChallengeParams;
|
||||||
|
|
||||||
const forgotPasswordChallengeConfig = {
|
const forgotPasswordChallengeConfig = {
|
||||||
|
|
@ -7,7 +7,7 @@ import { hashPassword } from '../../utils';
|
||||||
|
|
||||||
import { disconnect, updateStatus } from '.';
|
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 { userName, token, newPassword } = options as unknown as ForgotPasswordResetParams;
|
||||||
|
|
||||||
const forgotPasswordResetConfig: any = {
|
const forgotPasswordResetConfig: any = {
|
||||||
29
webclient/src/websocket/commands/session/getGamesOfUser.ts
Normal file
29
webclient/src/websocket/commands/session/getGamesOfUser.ts
Normal file
|
|
@ -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');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
export * from './activateAccount';
|
export * from './activate';
|
||||||
export * from './addToList';
|
export * from './addToList';
|
||||||
export * from './connect';
|
export * from './connect';
|
||||||
export * from './disconnect';
|
export * from './disconnect';
|
||||||
|
|
@ -9,8 +9,8 @@ export * from './login';
|
||||||
export * from './register';
|
export * from './register';
|
||||||
export * from './removeFromList';
|
export * from './removeFromList';
|
||||||
export * from './requestPasswordSalt';
|
export * from './requestPasswordSalt';
|
||||||
export * from './resetPassword';
|
export * from './forgotPasswordRequest';
|
||||||
export * from './resetPasswordChallenge'
|
export * from './forgotPasswordChallenge'
|
||||||
export * from './resetPasswordRequest';
|
export * from './resetPasswordRequest';
|
||||||
export * from './updateStatus';
|
export * from './updateStatus';
|
||||||
export * from './accountPassword';
|
export * from './accountPassword';
|
||||||
|
|
@ -18,3 +18,5 @@ export * from './accountEdit';
|
||||||
export * from './accountImage';
|
export * from './accountImage';
|
||||||
export * from './message';
|
export * from './message';
|
||||||
export * from './getUserInfo';
|
export * from './getUserInfo';
|
||||||
|
export * from './getGamesOfUser';
|
||||||
|
export * from './ping';
|
||||||
|
|
|
||||||
12
webclient/src/websocket/commands/session/ping.ts
Normal file
12
webclient/src/websocket/commands/session/ping.ts
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -5,10 +5,10 @@ import webClient from '../../WebClient';
|
||||||
import { SessionPersistence } from '../../persistence';
|
import { SessionPersistence } from '../../persistence';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
activateAccount,
|
activate,
|
||||||
disconnect,
|
disconnect,
|
||||||
login,
|
login,
|
||||||
resetPassword,
|
forgotPasswordRequest,
|
||||||
updateStatus
|
updateStatus
|
||||||
} from './';
|
} from './';
|
||||||
|
|
||||||
|
|
@ -33,12 +33,12 @@ export function requestPasswordSalt(options: WebSocketConnectOptions): void {
|
||||||
|
|
||||||
switch (options.reason) {
|
switch (options.reason) {
|
||||||
case WebSocketConnectReason.ACTIVATE_ACCOUNT: {
|
case WebSocketConnectReason.ACTIVATE_ACCOUNT: {
|
||||||
activateAccount(options, passwordSalt);
|
activate(options, passwordSalt);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WebSocketConnectReason.PASSWORD_RESET: {
|
case WebSocketConnectReason.PASSWORD_RESET: {
|
||||||
resetPassword(options, passwordSalt);
|
forgotPasswordRequest(options, passwordSalt);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -319,14 +319,14 @@ describe.skip('SessionEvents', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update stat/info and activate account', () => {
|
it('should update stat/info and activate account', () => {
|
||||||
jest.spyOn(SessionCommands, 'activateAccount').mockImplementation(() => {});
|
jest.spyOn(SessionCommands, 'activate').mockImplementation(() => {});
|
||||||
|
|
||||||
webClient.options.reason = WebSocketConnectReason.ACTIVATE_ACCOUNT;
|
webClient.options.reason = WebSocketConnectReason.ACTIVATE_ACCOUNT;
|
||||||
|
|
||||||
event(data);
|
event(data);
|
||||||
|
|
||||||
expect(SessionPersistence.updateInfo).toHaveBeenCalledWith(data.serverName, data.serverVersion);
|
expect(SessionPersistence.updateInfo).toHaveBeenCalledWith(data.serverName, data.serverVersion);
|
||||||
expect(SessionCommands.activateAccount).toHaveBeenCalled();
|
expect(SessionCommands.activate).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should disconnect if protocolVersion mismatched', () => {
|
it('should disconnect if protocolVersion mismatched', () => {
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ import { StatusEnum, WebSocketConnectReason } from 'types';
|
||||||
|
|
||||||
import webClient from '../../WebClient';
|
import webClient from '../../WebClient';
|
||||||
import {
|
import {
|
||||||
activateAccount,
|
activate,
|
||||||
disconnect,
|
disconnect,
|
||||||
login,
|
login,
|
||||||
register,
|
register,
|
||||||
requestPasswordSalt,
|
requestPasswordSalt,
|
||||||
resetPassword,
|
forgotPasswordChallenge,
|
||||||
resetPasswordChallenge,
|
forgotPasswordRequest,
|
||||||
resetPasswordRequest,
|
resetPasswordRequest,
|
||||||
updateStatus,
|
updateStatus,
|
||||||
} from '../../commands/session';
|
} from '../../commands/session';
|
||||||
|
|
@ -44,20 +44,20 @@ export function serverIdentification(info: ServerIdentificationData) {
|
||||||
if (getPasswordSalt) {
|
if (getPasswordSalt) {
|
||||||
requestPasswordSalt(options);
|
requestPasswordSalt(options);
|
||||||
} else {
|
} else {
|
||||||
activateAccount(options);
|
activate(options);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WebSocketConnectReason.PASSWORD_RESET_REQUEST:
|
case WebSocketConnectReason.PASSWORD_RESET_REQUEST:
|
||||||
resetPasswordRequest(options);
|
resetPasswordRequest(options);
|
||||||
break;
|
break;
|
||||||
case WebSocketConnectReason.PASSWORD_RESET_CHALLENGE:
|
case WebSocketConnectReason.PASSWORD_RESET_CHALLENGE:
|
||||||
resetPasswordChallenge(options);
|
forgotPasswordChallenge(options);
|
||||||
break;
|
break;
|
||||||
case WebSocketConnectReason.PASSWORD_RESET:
|
case WebSocketConnectReason.PASSWORD_RESET:
|
||||||
if (getPasswordSalt) {
|
if (getPasswordSalt) {
|
||||||
requestPasswordSalt(options);
|
requestPasswordSalt(options);
|
||||||
} else {
|
} else {
|
||||||
resetPassword(options);
|
forgotPasswordRequest(options);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -164,4 +164,8 @@ export class SessionPersistence {
|
||||||
static getUserInfo(userInfo: string) {
|
static getUserInfo(userInfo: string) {
|
||||||
console.log('getUserInfo');
|
console.log('getUserInfo');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getGamesOfUser(userName: string, response: any): void {
|
||||||
|
console.log('getGamesOfUser');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import protobuf from 'protobufjs';
|
||||||
import { RoomEvents, SessionEvents } from '../events';
|
import { RoomEvents, SessionEvents } from '../events';
|
||||||
import { SessionPersistence } from '../persistence';
|
import { SessionPersistence } from '../persistence';
|
||||||
import { WebClient } from '../WebClient';
|
import { WebClient } from '../WebClient';
|
||||||
|
import { SessionCommands } from 'websocket';
|
||||||
import ProtoFiles from '../../proto-files.json';
|
import ProtoFiles from '../../proto-files.json';
|
||||||
|
|
||||||
export interface ProtobufEvents {
|
export interface ProtobufEvents {
|
||||||
|
|
@ -75,11 +75,7 @@ export class ProtobufService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public sendKeepAliveCommand(pingReceived: Function) {
|
public sendKeepAliveCommand(pingReceived: Function) {
|
||||||
const command = this.controller.SessionCommand.create({
|
SessionCommands.ping(pingReceived);
|
||||||
'.Command_Ping.ext': this.controller.Command_Ping.create()
|
|
||||||
});
|
|
||||||
|
|
||||||
this.sendSessionCommand(command, pingReceived);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public handleMessageEvent({ data }: MessageEvent): void {
|
public handleMessageEvent({ data }: MessageEvent): void {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue