mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-09 15:54:47 -07:00
265 lines
6.8 KiB
TypeScript
265 lines
6.8 KiB
TypeScript
import { GameDispatch, ServerDispatch } from 'store';
|
|
import { DeckList, DeckStorageTreeItem, ReplayMatch, StatusEnum, User, WebSocketConnectOptions } from 'types';
|
|
import { GameEntry } from 'store/game/game.interfaces';
|
|
|
|
import { sanitizeHtml } from 'websocket/utils';
|
|
import {
|
|
GameJoinedData,
|
|
NotifyUserData,
|
|
PlayerGamePropertiesData,
|
|
ServerShutdownData,
|
|
UserMessageData
|
|
} from '../events/session/interfaces';
|
|
import NormalizeService from '../utils/NormalizeService';
|
|
|
|
export class SessionPersistence {
|
|
static initialized() {
|
|
ServerDispatch.initialized();
|
|
}
|
|
|
|
static clearStore() {
|
|
ServerDispatch.clearStore();
|
|
}
|
|
|
|
static loginSuccessful(options: WebSocketConnectOptions) {
|
|
ServerDispatch.loginSuccessful(options);
|
|
}
|
|
|
|
static loginFailed() {
|
|
ServerDispatch.loginFailed();
|
|
}
|
|
|
|
static connectionClosed(reason: number) {
|
|
ServerDispatch.connectionClosed(reason);
|
|
}
|
|
|
|
static connectionFailed() {
|
|
ServerDispatch.connectionFailed();
|
|
}
|
|
|
|
static testConnectionSuccessful() {
|
|
ServerDispatch.testConnectionSuccessful();
|
|
}
|
|
|
|
static testConnectionFailed() {
|
|
ServerDispatch.testConnectionFailed();
|
|
}
|
|
|
|
static updateBuddyList(buddyList) {
|
|
ServerDispatch.updateBuddyList(buddyList);
|
|
}
|
|
|
|
static addToBuddyList(user: User) {
|
|
ServerDispatch.addToBuddyList(user);
|
|
}
|
|
|
|
static removeFromBuddyList(userName: string) {
|
|
ServerDispatch.removeFromBuddyList(userName);
|
|
}
|
|
|
|
static updateIgnoreList(ignoreList) {
|
|
ServerDispatch.updateIgnoreList(ignoreList);
|
|
}
|
|
|
|
static addToIgnoreList(user: User) {
|
|
ServerDispatch.addToIgnoreList(user);
|
|
}
|
|
|
|
static removeFromIgnoreList(userName: string) {
|
|
ServerDispatch.removeFromIgnoreList(userName);
|
|
}
|
|
|
|
static updateInfo(name: string, version: string) {
|
|
ServerDispatch.updateInfo(name, version);
|
|
}
|
|
|
|
static updateStatus(state: number, description: string) {
|
|
ServerDispatch.updateStatus(state, description);
|
|
|
|
if (state === StatusEnum.DISCONNECTED) {
|
|
this.connectionClosed(state);
|
|
}
|
|
}
|
|
|
|
static updateUser(user: User) {
|
|
ServerDispatch.updateUser(user);
|
|
}
|
|
|
|
static updateUsers(users: User[]) {
|
|
ServerDispatch.updateUsers(users);
|
|
}
|
|
|
|
static userJoined(user: User) {
|
|
ServerDispatch.userJoined(user);
|
|
}
|
|
|
|
static userLeft(userName: string) {
|
|
ServerDispatch.userLeft(userName);
|
|
}
|
|
|
|
static serverMessage(message: string) {
|
|
ServerDispatch.serverMessage(sanitizeHtml(message));
|
|
}
|
|
|
|
static accountAwaitingActivation(options: WebSocketConnectOptions) {
|
|
ServerDispatch.accountAwaitingActivation(options);
|
|
}
|
|
|
|
static accountActivationSuccess() {
|
|
ServerDispatch.accountActivationSuccess();
|
|
}
|
|
|
|
static accountActivationFailed() {
|
|
ServerDispatch.accountActivationFailed();
|
|
}
|
|
|
|
static registrationRequiresEmail() {
|
|
ServerDispatch.registrationRequiresEmail();
|
|
}
|
|
|
|
static registrationSuccess() {
|
|
ServerDispatch.registrationSuccess();
|
|
}
|
|
|
|
static registrationFailed(reason: string, endTime?: number) {
|
|
const reasonMsg = endTime ? NormalizeService.normalizeBannedUserError(reason, endTime) : reason;
|
|
|
|
ServerDispatch.registrationFailed(reasonMsg);
|
|
}
|
|
|
|
static registrationEmailError(error: string) {
|
|
ServerDispatch.registrationEmailError(error);
|
|
}
|
|
|
|
static registrationPasswordError(error: string) {
|
|
ServerDispatch.registrationPasswordError(error);
|
|
}
|
|
|
|
static registrationUserNameError(error: string) {
|
|
ServerDispatch.registrationUserNameError(error);
|
|
}
|
|
|
|
static resetPasswordChallenge() {
|
|
ServerDispatch.resetPasswordChallenge();
|
|
}
|
|
|
|
static resetPassword() {
|
|
ServerDispatch.resetPassword();
|
|
}
|
|
|
|
static resetPasswordSuccess() {
|
|
ServerDispatch.resetPasswordSuccess();
|
|
}
|
|
|
|
static resetPasswordFailed() {
|
|
ServerDispatch.resetPasswordFailed();
|
|
}
|
|
|
|
static accountPasswordChange(): void {
|
|
ServerDispatch.accountPasswordChange();
|
|
}
|
|
|
|
static accountEditChanged(realName?: string, email?: string, country?: string): void {
|
|
ServerDispatch.accountEditChanged({ realName, email, country });
|
|
}
|
|
|
|
static accountImageChanged(avatarBmp: Uint8Array): void {
|
|
ServerDispatch.accountImageChanged({ avatarBmp });
|
|
}
|
|
|
|
static directMessageSent(userName: string, message: string): void {
|
|
ServerDispatch.directMessageSent(userName, message);
|
|
}
|
|
|
|
static getUserInfo(userInfo: User) {
|
|
ServerDispatch.getUserInfo(userInfo);
|
|
}
|
|
|
|
static getGamesOfUser(userName: string, response: any): void {
|
|
// Response_GetGamesOfUser contains a gameList field — log for now until game layer is complete
|
|
console.log('getGamesOfUser', userName, response);
|
|
}
|
|
|
|
static gameJoined(gameJoinedData: GameJoinedData): void {
|
|
const { gameInfo, hostId, playerId, spectator, judge } = gameJoinedData;
|
|
const gameEntry: GameEntry = {
|
|
gameId: gameInfo.gameId,
|
|
roomId: gameInfo.roomId,
|
|
description: gameInfo.description,
|
|
hostId,
|
|
localPlayerId: playerId,
|
|
spectator,
|
|
judge,
|
|
started: gameInfo.started,
|
|
activePlayerId: -1,
|
|
activePhase: -1,
|
|
secondsElapsed: 0,
|
|
reversed: false,
|
|
players: {},
|
|
messages: [],
|
|
};
|
|
GameDispatch.gameJoined(gameInfo.gameId, gameEntry);
|
|
}
|
|
|
|
static notifyUser(notification: NotifyUserData): void {
|
|
ServerDispatch.notifyUser(notification);
|
|
}
|
|
|
|
static playerPropertiesChanged(gameId: number, playerId: number, payload: PlayerGamePropertiesData): void {
|
|
GameDispatch.playerPropertiesChanged(gameId, playerId, payload);
|
|
}
|
|
|
|
static serverShutdown(data: ServerShutdownData): void {
|
|
ServerDispatch.serverShutdown(data);
|
|
}
|
|
|
|
static userMessage(messageData: UserMessageData): void {
|
|
ServerDispatch.userMessage(messageData);
|
|
}
|
|
|
|
static addToList(list: string, userName: string): void {
|
|
ServerDispatch.addToList(list, userName)
|
|
}
|
|
|
|
static removeFromList(list: string, userName: string): void {
|
|
ServerDispatch.removeFromList(list, userName);
|
|
}
|
|
|
|
static deleteServerDeck(deckId: number): void {
|
|
ServerDispatch.deckDelete(deckId);
|
|
}
|
|
|
|
static updateServerDecks(deckList: DeckList): void {
|
|
ServerDispatch.backendDecks(deckList);
|
|
}
|
|
|
|
static uploadServerDeck(path: string, treeItem: DeckStorageTreeItem): void {
|
|
ServerDispatch.deckUpload(path, treeItem);
|
|
}
|
|
|
|
static createServerDeckDir(path: string, dirName: string): void {
|
|
ServerDispatch.deckNewDir(path, dirName);
|
|
}
|
|
|
|
static deleteServerDeckDir(path: string): void {
|
|
ServerDispatch.deckDelDir(path);
|
|
}
|
|
|
|
static replayList(matchList: ReplayMatch[]): void {
|
|
ServerDispatch.replayList(matchList);
|
|
}
|
|
|
|
static replayAdded(matchInfo: ReplayMatch): void {
|
|
ServerDispatch.replayAdded(matchInfo);
|
|
}
|
|
|
|
static replayModifyMatch(gameId: number, doNotHide: boolean): void {
|
|
ServerDispatch.replayModifyMatch(gameId, doNotHide);
|
|
}
|
|
|
|
static replayDeleteMatch(gameId: number): void {
|
|
ServerDispatch.replayDeleteMatch(gameId);
|
|
}
|
|
}
|
|
|
|
|