Merge branch 'develop' of github.com:thecodingmachine/workadventure

This commit is contained in:
_Bastler 2021-08-16 19:21:09 +02:00
commit 1958449178
17 changed files with 153 additions and 149 deletions

View File

@ -102,7 +102,7 @@
{/if} {/if}
{#if $consoleGlobalMessageManagerVisibleStore} {#if $consoleGlobalMessageManagerVisibleStore}
<div> <div>
<ConsoleGlobalMessageManager game={game}></ConsoleGlobalMessageManager> <ConsoleGlobalMessageManager></ConsoleGlobalMessageManager>
</div> </div>
{/if} {/if}
{#if $helpCameraSettingsVisibleStore} {#if $helpCameraSettingsVisibleStore}

View File

@ -3,10 +3,8 @@
import InputTextGlobalMessage from "./InputTextGlobalMessage.svelte"; import InputTextGlobalMessage from "./InputTextGlobalMessage.svelte";
import UploadAudioGlobalMessage from "./UploadAudioGlobalMessage.svelte"; import UploadAudioGlobalMessage from "./UploadAudioGlobalMessage.svelte";
import { gameManager } from "../../Phaser/Game/GameManager"; import { gameManager } from "../../Phaser/Game/GameManager";
import type { Game } from "../../Phaser/Game/Game";
import { consoleGlobalMessageManagerVisibleStore } from "../../Stores/ConsoleGlobalMessageManagerStore"; import { consoleGlobalMessageManagerVisibleStore } from "../../Stores/ConsoleGlobalMessageManagerStore";
export let game: Game;
let inputSendTextActive = true; let inputSendTextActive = true;
let uploadMusicActive = false; let uploadMusicActive = false;
let handleSendText: { sendTextMessage(broadcast: boolean): void }; let handleSendText: { sendTextMessage(broadcast: boolean): void };
@ -57,10 +55,10 @@
</div> </div>
<div class="content-console-global-message"> <div class="content-console-global-message">
{#if inputSendTextActive} {#if inputSendTextActive}
<InputTextGlobalMessage game={game} gameManager={gameManager} bind:handleSending={handleSendText}/> <InputTextGlobalMessage gameManager={gameManager} bind:handleSending={handleSendText}/>
{/if} {/if}
{#if uploadMusicActive} {#if uploadMusicActive}
<UploadAudioGlobalMessage game={game} gameManager={gameManager} bind:handleSending={handleSendAudio}/> <UploadAudioGlobalMessage gameManager={gameManager} bind:handleSending={handleSendAudio}/>
{/if} {/if}
</div> </div>
<div class="footer-console-global-message"> <div class="footer-console-global-message">

View File

@ -1,7 +1,6 @@
<script lang="ts"> <script lang="ts">
import { consoleGlobalMessageManagerFocusStore, consoleGlobalMessageManagerVisibleStore } from "../../Stores/ConsoleGlobalMessageManagerStore"; import { consoleGlobalMessageManagerFocusStore, consoleGlobalMessageManagerVisibleStore } from "../../Stores/ConsoleGlobalMessageManagerStore";
import {onDestroy, onMount} from "svelte"; import {onDestroy, onMount} from "svelte";
import type { Game } from "../../Phaser/Game/Game";
import type { GameManager } from "../../Phaser/Game/GameManager"; import type { GameManager } from "../../Phaser/Game/GameManager";
import { AdminMessageEventTypes } from "../../Connexion/AdminMessagesService"; import { AdminMessageEventTypes } from "../../Connexion/AdminMessagesService";
import type { Quill } from "quill"; import type { Quill } from "quill";
@ -31,10 +30,9 @@
// remove formatting button // remove formatting button
]; ];
export let game: Game;
export let gameManager: GameManager; export let gameManager: GameManager;
const gameScene = gameManager.getCurrentGameScene(game.findAnyScene()); const gameScene = gameManager.getCurrentGameScene();
let quill: Quill; let quill: Quill;
let INPUT_CONSOLE_MESSAGE: HTMLDivElement; let INPUT_CONSOLE_MESSAGE: HTMLDivElement;

View File

@ -1,6 +1,5 @@
<script lang="ts"> <script lang="ts">
import { HtmlUtils } from "../../WebRtc/HtmlUtils"; import { HtmlUtils } from "../../WebRtc/HtmlUtils";
import type { Game } from "../../Phaser/Game/Game";
import type { GameManager } from "../../Phaser/Game/GameManager"; import type { GameManager } from "../../Phaser/Game/GameManager";
import { consoleGlobalMessageManagerFocusStore, consoleGlobalMessageManagerVisibleStore } from "../../Stores/ConsoleGlobalMessageManagerStore"; import { consoleGlobalMessageManagerFocusStore, consoleGlobalMessageManagerVisibleStore } from "../../Stores/ConsoleGlobalMessageManagerStore";
import { AdminMessageEventTypes } from "../../Connexion/AdminMessagesService"; import { AdminMessageEventTypes } from "../../Connexion/AdminMessagesService";
@ -11,10 +10,9 @@
files: Array<File>; files: Array<File>;
} }
export let game: Game;
export let gameManager: GameManager; export let gameManager: GameManager;
let gameScene = gameManager.getCurrentGameScene(game.findAnyScene()); let gameScene = gameManager.getCurrentGameScene();
let fileInput: HTMLInputElement; let fileInput: HTMLInputElement;
let fileName: string; let fileName: string;
let fileSize: string; let fileSize: string;

View File

@ -29,8 +29,10 @@ class ConnectionManager {
}); });
} }
public loadOpenIDScreen() { /**
localUserStore.setAuthToken(null); * @return Promise<void>
*/
public loadOpenIDScreen(): Promise<void> {
const state = localUserStore.generateState(); const state = localUserStore.generateState();
const nonce = localUserStore.generateNonce(); const nonce = localUserStore.generateNonce();
@ -45,7 +47,18 @@ class ConnectionManager {
loginUrl = `http://` + loginUrl; loginUrl = `http://` + loginUrl;
} }
localUserStore.setAuthToken(null);
//TODO refactor this and don't realise previous call
return Axios.get(loginUrl)
.then(() => {
window.location.assign(loginUrl); window.location.assign(loginUrl);
})
.catch((err) => {
console.error(err, "We don't have URL to regenerate authentication user");
//TODO show modal login
window.location.reload();
});
} }
public logout() { public logout() {

View File

@ -19,6 +19,7 @@ export class GameManager {
private characterLayers: string[] | null; private characterLayers: string[] | null;
private companion: string | null; private companion: string | null;
private startRoom!: Room; private startRoom!: Room;
private scenePlugin!: Phaser.Scenes.ScenePlugin;
currentGameSceneName: string | null = null; currentGameSceneName: string | null = null;
constructor() { constructor() {
@ -28,8 +29,9 @@ export class GameManager {
} }
public async init(scenePlugin: Phaser.Scenes.ScenePlugin): Promise<string> { public async init(scenePlugin: Phaser.Scenes.ScenePlugin): Promise<string> {
this.scenePlugin = scenePlugin;
this.startRoom = await connectionManager.initGameConnexion(); this.startRoom = await connectionManager.initGameConnexion();
this.loadMap(this.startRoom, scenePlugin); this.loadMap(this.startRoom);
if(!this.playerName) { if(!this.playerName) {
const res = await Axios.get("/"); const res = await Axios.get("/");
@ -74,20 +76,20 @@ export class GameManager {
return this.companion; return this.companion;
} }
public loadMap(room: Room, scenePlugin: Phaser.Scenes.ScenePlugin) { public loadMap(room: Room) {
const roomID = room.key; const roomID = room.key;
const gameIndex = scenePlugin.getIndex(roomID); const gameIndex = this.scenePlugin.getIndex(roomID);
if (gameIndex === -1) { if (gameIndex === -1) {
const game: Phaser.Scene = new GameScene(room, room.mapUrl); const game: Phaser.Scene = new GameScene(room, room.mapUrl);
scenePlugin.add(roomID, game, false); this.scenePlugin.add(roomID, game, false);
} }
} }
public goToStartingMap(scenePlugin: Phaser.Scenes.ScenePlugin): void { public goToStartingMap(): void {
console.log("starting " + (this.currentGameSceneName || this.startRoom.key)); console.log("starting " + (this.currentGameSceneName || this.startRoom.key));
scenePlugin.start(this.currentGameSceneName || this.startRoom.key); this.scenePlugin.start(this.currentGameSceneName || this.startRoom.key);
scenePlugin.launch(MenuSceneName); this.scenePlugin.launch(MenuSceneName);
if ( if (
!localUserStore.getHelpCameraSettingsShown() && !localUserStore.getHelpCameraSettingsShown() &&
@ -108,33 +110,33 @@ export class GameManager {
* Temporary leave a gameScene to go back to the loginScene for example. * Temporary leave a gameScene to go back to the loginScene for example.
* This will close the socket connections and stop the gameScene, but won't remove it. * This will close the socket connections and stop the gameScene, but won't remove it.
*/ */
leaveGame(scene: Phaser.Scene, targetSceneName: string, sceneClass: Phaser.Scene): void { leaveGame(targetSceneName: string, sceneClass: Phaser.Scene): void {
if (this.currentGameSceneName === null) throw "No current scene id set!"; if (this.currentGameSceneName === null) throw "No current scene id set!";
const gameScene: GameScene = scene.scene.get(this.currentGameSceneName) as GameScene; const gameScene: GameScene = this.scenePlugin.get(this.currentGameSceneName) as GameScene;
gameScene.cleanupClosingScene(); gameScene.cleanupClosingScene();
scene.scene.stop(this.currentGameSceneName); this.scenePlugin.stop(this.currentGameSceneName);
scene.scene.sleep(MenuSceneName); this.scenePlugin.sleep(MenuSceneName);
if (!scene.scene.get(targetSceneName)) { if (!this.scenePlugin.get(targetSceneName)) {
scene.scene.add(targetSceneName, sceneClass, false); this.scenePlugin.add(targetSceneName, sceneClass, false);
} }
scene.scene.run(targetSceneName); this.scenePlugin.run(targetSceneName);
} }
/** /**
* follow up to leaveGame() * follow up to leaveGame()
*/ */
tryResumingGame(scene: Phaser.Scene, fallbackSceneName: string) { tryResumingGame(fallbackSceneName: string) {
if (this.currentGameSceneName) { if (this.currentGameSceneName) {
scene.scene.start(this.currentGameSceneName); this.scenePlugin.start(this.currentGameSceneName);
scene.scene.wake(MenuSceneName); this.scenePlugin.wake(MenuSceneName);
} else { } else {
scene.scene.run(fallbackSceneName); this.scenePlugin.run(fallbackSceneName);
} }
} }
public getCurrentGameScene(scene: Phaser.Scene): GameScene { public getCurrentGameScene(): GameScene {
if (this.currentGameSceneName === null) throw "No current scene id set!"; if (this.currentGameSceneName === null) throw "No current scene id set!";
return scene.scene.get(this.currentGameSceneName) as GameScene; return this.scenePlugin.get(this.currentGameSceneName) as GameScene;
} }
} }

View File

@ -927,9 +927,10 @@ export class GameScene extends DirtyScene {
}); });
this.gameMap.onPropertyChange("zone", (newValue, oldValue) => { this.gameMap.onPropertyChange("zone", (newValue, oldValue) => {
if (newValue === undefined || newValue === false || newValue === "") { if (oldValue) {
iframeListener.sendLeaveEvent(oldValue as string); iframeListener.sendLeaveEvent(oldValue as string);
} else { }
if (newValue) {
iframeListener.sendEnterEvent(newValue as string); iframeListener.sendEnterEvent(newValue as string);
} }
}); });
@ -1482,7 +1483,7 @@ export class GameScene extends DirtyScene {
private async loadNextGame(exitRoomPath: URL): Promise<void> { private async loadNextGame(exitRoomPath: URL): Promise<void> {
try { try {
const room = await Room.createRoom(exitRoomPath); const room = await Room.createRoom(exitRoomPath);
return gameManager.loadMap(room, this.scene); return gameManager.loadMap(room);
} catch (e /*: unknown*/) { } catch (e /*: unknown*/) {
console.warn('Error while pre-loading exit room "' + exitRoomPath.toString() + '"', e); console.warn('Error while pre-loading exit room "' + exitRoomPath.toString() + '"', e);
} }
@ -1542,7 +1543,7 @@ export class GameScene extends DirtyScene {
}); });
} catch (err) { } catch (err) {
if (err instanceof TextureError) { if (err instanceof TextureError) {
gameManager.leaveGame(this, SelectCharacterSceneName, new SelectCharacterScene()); gameManager.leaveGame(SelectCharacterSceneName, new SelectCharacterScene());
} }
throw err; throw err;
} }

View File

@ -282,7 +282,7 @@ export class CustomizeScene extends AbstractCharacterScene {
this.scene.sleep(CustomizeSceneName); this.scene.sleep(CustomizeSceneName);
waScaleManager.restoreZoom(); waScaleManager.restoreZoom();
this.events.removeListener("wake"); this.events.removeListener("wake");
gameManager.tryResumingGame(this, EnableCameraSceneName); gameManager.tryResumingGame(EnableCameraSceneName);
customCharacterSceneVisibleStore.set(false); customCharacterSceneVisibleStore.set(false);
} }

View File

@ -9,42 +9,35 @@ import {PinchManager} from "../UserInput/PinchManager";
import Zone = Phaser.GameObjects.Zone; import Zone = Phaser.GameObjects.Zone;
import { MenuScene } from "../Menu/MenuScene"; import { MenuScene } from "../Menu/MenuScene";
import { ResizableScene } from "./ResizableScene"; import { ResizableScene } from "./ResizableScene";
import { import { enableCameraSceneVisibilityStore } from "../../Stores/MediaStore";
enableCameraSceneVisibilityStore,
} from "../../Stores/MediaStore";
export const EnableCameraSceneName = "EnableCameraScene"; export const EnableCameraSceneName = "EnableCameraScene";
export class EnableCameraScene extends ResizableScene { export class EnableCameraScene extends ResizableScene {
constructor() { constructor() {
super({ super({
key: EnableCameraSceneName key: EnableCameraSceneName,
}); });
} }
preload() { preload() {}
}
create() { create() {
this.input.keyboard.on("keyup-ENTER", () => {
this.input.keyboard.on('keyup-ENTER', () => {
this.login(); this.login();
}); });
enableCameraSceneVisibilityStore.showEnableCameraScene(); enableCameraSceneVisibilityStore.showEnableCameraScene();
} }
public onResize(): void { public onResize(): void {}
}
update(time: number, delta: number): void { update(time: number, delta: number): void {}
}
public login(): void { public login(): void {
enableCameraSceneVisibilityStore.hideEnableCameraScene(); enableCameraSceneVisibilityStore.hideEnableCameraScene();
this.scene.sleep(EnableCameraSceneName); this.scene.sleep(EnableCameraSceneName);
gameManager.goToStartingMap(this.scene); gameManager.goToStartingMap();
} }
} }

View File

@ -6,18 +6,16 @@ import {loginSceneVisibleStore} from "../../Stores/LoginSceneStore";
export const LoginSceneName = "LoginScene"; export const LoginSceneName = "LoginScene";
export class LoginScene extends ResizableScene { export class LoginScene extends ResizableScene {
private name: string = "";
private name: string = '';
constructor() { constructor() {
super({ super({
key: LoginSceneName key: LoginSceneName,
}); });
this.name = gameManager.getPlayerName() || ''; this.name = gameManager.getPlayerName() || "";
} }
preload() { preload() {}
}
create() { create() {
loginSceneVisibleStore.set(true); loginSceneVisibleStore.set(true);
@ -27,15 +25,13 @@ export class LoginScene extends ResizableScene {
name = name.trim(); name = name.trim();
gameManager.setPlayerName(name); gameManager.setPlayerName(name);
this.scene.stop(LoginSceneName) this.scene.stop(LoginSceneName);
gameManager.tryResumingGame(this, SelectCharacterSceneName); gameManager.tryResumingGame(SelectCharacterSceneName);
this.scene.remove(LoginSceneName); this.scene.remove(LoginSceneName);
loginSceneVisibleStore.set(false); loginSceneVisibleStore.set(false);
} }
update(time: number, delta: number): void { update(time: number, delta: number): void {}
}
public onResize(): void { public onResize(): void {}
}
} }

View File

@ -101,7 +101,7 @@ export class SelectCharacterScene extends AbstractCharacterScene {
this.scene.stop(SelectCharacterSceneName); this.scene.stop(SelectCharacterSceneName);
waScaleManager.restoreZoom(); waScaleManager.restoreZoom();
gameManager.setCharacterLayers([this.selectedPlayer.texture.key]); gameManager.setCharacterLayers([this.selectedPlayer.texture.key]);
gameManager.tryResumingGame(this, EnableCameraSceneName); gameManager.tryResumingGame(EnableCameraSceneName);
this.players = []; this.players = [];
selectCharacterSceneVisibleStore.set(false); selectCharacterSceneVisibleStore.set(false);
this.events.removeListener("wake"); this.events.removeListener("wake");

View File

@ -28,12 +28,12 @@ export class SelectCompanionScene extends ResizableScene {
constructor() { constructor() {
super({ super({
key: SelectCompanionSceneName key: SelectCompanionSceneName,
}); });
} }
preload() { preload() {
getAllCompanionResources(this.load).forEach(model => { getAllCompanionResources(this.load).forEach((model) => {
this.companionModels.push(model); this.companionModels.push(model);
}); });
@ -42,7 +42,6 @@ export class SelectCompanionScene extends ResizableScene {
} }
create() { create() {
selectCompanionSceneVisibleStore.set(true); selectCompanionSceneVisibleStore.set(true);
waScaleManager.saveZoom(); waScaleManager.saveZoom();
@ -53,13 +52,15 @@ export class SelectCompanionScene extends ResizableScene {
} }
// input events // input events
this.input.keyboard.on('keyup-ENTER', this.selectCompanion.bind(this)); this.input.keyboard.on("keyup-ENTER", this.selectCompanion.bind(this));
this.input.keyboard.on('keydown-RIGHT', this.moveToRight.bind(this)); this.input.keyboard.on("keydown-RIGHT", this.moveToRight.bind(this));
this.input.keyboard.on('keydown-LEFT', this.moveToLeft.bind(this)); this.input.keyboard.on("keydown-LEFT", this.moveToLeft.bind(this));
if (localUserStore.getCompanion()) { if (localUserStore.getCompanion()) {
const companionIndex = this.companionModels.findIndex((companion) => companion.name === localUserStore.getCompanion()); const companionIndex = this.companionModels.findIndex(
(companion) => companion.name === localUserStore.getCompanion()
);
if (companionIndex > -1 || companionIndex < this.companions.length) { if (companionIndex > -1 || companionIndex < this.companions.length) {
this.currentCompanion = companionIndex; this.currentCompanion = companionIndex;
this.selectedCompanion = this.companions[companionIndex]; this.selectedCompanion = this.companions[companionIndex];
@ -93,22 +94,22 @@ export class SelectCompanionScene extends ResizableScene {
// next scene // next scene
this.scene.stop(SelectCompanionSceneName); this.scene.stop(SelectCompanionSceneName);
waScaleManager.restoreZoom(); waScaleManager.restoreZoom();
gameManager.tryResumingGame(this, EnableCameraSceneName); gameManager.tryResumingGame(EnableCameraSceneName);
this.scene.remove(SelectCompanionSceneName); this.scene.remove(SelectCompanionSceneName);
selectCompanionSceneVisibleStore.set(false); selectCompanionSceneVisibleStore.set(false);
} }
private createCurrentCompanion(): void { private createCurrentCompanion(): void {
for (let i = 0; i < this.companionModels.length; i++) { for (let i = 0; i < this.companionModels.length; i++) {
const companionResource = this.companionModels[i] const companionResource = this.companionModels[i];
const [middleX, middleY] = this.getCompanionPosition(); const [middleX, middleY] = this.getCompanionPosition();
const companion = this.physics.add.sprite(middleX, middleY, companionResource.name, 0); const companion = this.physics.add.sprite(middleX, middleY, companionResource.name, 0);
this.setUpCompanion(companion, i); this.setUpCompanion(companion, i);
this.anims.create({ this.anims.create({
key: companionResource.name, key: companionResource.name,
frames: this.anims.generateFrameNumbers(companionResource.name, {start: 0, end: 2,}), frames: this.anims.generateFrameNumbers(companionResource.name, { start: 0, end: 2 }),
frameRate: 10, frameRate: 10,
repeat: -1 repeat: -1,
}); });
companion.setInteractive().on("pointerdown", () => { companion.setInteractive().on("pointerdown", () => {
@ -149,7 +150,7 @@ export class SelectCompanionScene extends ResizableScene {
} }
public moveToRight() { public moveToRight() {
if(this.currentCompanion === (this.companions.length - 1)){ if (this.currentCompanion === this.companions.length - 1) {
return; return;
} }
this.currentCompanion += 1; this.currentCompanion += 1;
@ -174,50 +175,47 @@ export class SelectCompanionScene extends ResizableScene {
if (this.currentCompanion !== num) { if (this.currentCompanion !== num) {
companionVisible = false; companionVisible = false;
} }
if( num === (this.currentCompanion + 1) ){ if (num === this.currentCompanion + 1) {
companionY -= deltaY; companionY -= deltaY;
companionX += deltaX; companionX += deltaX;
companionScale = 0.8; companionScale = 0.8;
companionOpactity = 0.6; companionOpactity = 0.6;
companionVisible = true; companionVisible = true;
} }
if( num === (this.currentCompanion + 2) ){ if (num === this.currentCompanion + 2) {
companionY -= deltaY; companionY -= deltaY;
companionX += (deltaX * 2); companionX += deltaX * 2;
companionScale = 0.8; companionScale = 0.8;
companionOpactity = 0.6; companionOpactity = 0.6;
companionVisible = true; companionVisible = true;
} }
if( num === (this.currentCompanion - 1) ){ if (num === this.currentCompanion - 1) {
companionY -= deltaY; companionY -= deltaY;
companionX -= deltaX; companionX -= deltaX;
companionScale = 0.8; companionScale = 0.8;
companionOpactity = 0.6; companionOpactity = 0.6;
companionVisible = true; companionVisible = true;
} }
if( num === (this.currentCompanion - 2) ){ if (num === this.currentCompanion - 2) {
companionY -= deltaY; companionY -= deltaY;
companionX -= (deltaX * 2); companionX -= deltaX * 2;
companionScale = 0.8; companionScale = 0.8;
companionOpactity = 0.6; companionOpactity = 0.6;
companionVisible = true; companionVisible = true;
} }
return {companionX, companionY, companionScale, companionOpactity, companionVisible} return { companionX, companionY, companionScale, companionOpactity, companionVisible };
} }
/** /**
* Returns pixel position by on column and row number * Returns pixel position by on column and row number
*/ */
private getCompanionPosition(): [number, number] { private getCompanionPosition(): [number, number] {
return [ return [this.game.renderer.width / 2, this.game.renderer.height / 3];
this.game.renderer.width / 2,
this.game.renderer.height / 3
];
} }
private setUpCompanion(companion: Phaser.Physics.Arcade.Sprite, numero: number) { private setUpCompanion(companion: Phaser.Physics.Arcade.Sprite, numero: number) {
const { companionX, companionY, companionScale, companionOpactity, companionVisible } =
const {companionX, companionY, companionScale, companionOpactity, companionVisible} = this.defineSetupCompanion(numero); this.defineSetupCompanion(numero);
companion.setBounce(0.2); companion.setBounce(0.2);
companion.setCollideWorldBounds(true); companion.setCollideWorldBounds(true);
companion.setVisible(companionVisible); companion.setVisible(companionVisible);

View File

@ -171,7 +171,7 @@ export class MenuScene extends Phaser.Scene {
this.closeAll(); this.closeAll();
this.sideMenuOpened = true; this.sideMenuOpened = true;
this.menuButton.getChildByID("openMenuButton").innerHTML = "X"; this.menuButton.getChildByID("openMenuButton").innerHTML = "X";
const connection = gameManager.getCurrentGameScene(this).connection; const connection = gameManager.getCurrentGameScene().connection;
if (connection && connection.isAdmin()) { if (connection && connection.isAdmin()) {
const adminSection = this.menuElement.getChildByID("adminConsoleSection") as HTMLElement; const adminSection = this.menuElement.getChildByID("adminConsoleSection") as HTMLElement;
adminSection.hidden = false; adminSection.hidden = false;
@ -322,18 +322,18 @@ export class MenuScene extends Phaser.Scene {
switch ((event?.target as HTMLInputElement).id) { switch ((event?.target as HTMLInputElement).id) {
case "changeNameButton": case "changeNameButton":
this.closeSideMenu(); this.closeSideMenu();
gameManager.leaveGame(this, LoginSceneName, new LoginScene()); gameManager.leaveGame(LoginSceneName, new LoginScene());
break; break;
case "sparkButton": case "sparkButton":
this.gotToCreateMapPage(); this.gotToCreateMapPage();
break; break;
case "changeSkinButton": case "changeSkinButton":
this.closeSideMenu(); this.closeSideMenu();
gameManager.leaveGame(this, SelectCharacterSceneName, new SelectCharacterScene()); gameManager.leaveGame(SelectCharacterSceneName, new SelectCharacterScene());
break; break;
case "changeCompanionButton": case "changeCompanionButton":
this.closeSideMenu(); this.closeSideMenu();
gameManager.leaveGame(this, SelectCompanionSceneName, new SelectCompanionScene()); gameManager.leaveGame(SelectCompanionSceneName, new SelectCompanionScene());
break; break;
case "closeButton": case "closeButton":
this.closeSideMenu(); this.closeSideMenu();

View File

@ -62,7 +62,7 @@ export class ReportMenu extends Phaser.GameObjects.DOMElement {
this.opened = true; this.opened = true;
gameManager.getCurrentGameScene(this.scene).userInputManager.disableControls(); gameManager.getCurrentGameScene().userInputManager.disableControls();
this.scene.tweens.add({ this.scene.tweens.add({
targets: this, targets: this,
@ -73,7 +73,7 @@ export class ReportMenu extends Phaser.GameObjects.DOMElement {
} }
public close(): void { public close(): void {
gameManager.getCurrentGameScene(this.scene).userInputManager.restoreControls(); gameManager.getCurrentGameScene().userInputManager.restoreControls();
this.opened = false; this.opened = false;
const mainEl = this.getChildByID("gameReport") as HTMLElement; const mainEl = this.getChildByID("gameReport") as HTMLElement;
this.scene.tweens.add({ this.scene.tweens.add({
@ -112,9 +112,7 @@ export class ReportMenu extends Phaser.GameObjects.DOMElement {
gamePError.style.display = "block"; gamePError.style.display = "block";
return; return;
} }
gameManager gameManager.getCurrentGameScene().connection?.emitReportPlayerMessage(this.userUuid, gameTextArea.value);
.getCurrentGameScene(this.scene)
.connection?.emitReportPlayerMessage(this.userUuid, gameTextArea.value);
this.close(); this.close();
} }
} }

View File

@ -174,7 +174,7 @@ export class IoSocketController {
} }
const tokenData = const tokenData =
token && typeof token === "string" ? jwtTokenManager.decodeJWTToken(token) : null; token && typeof token === "string" ? jwtTokenManager.verifyJWTToken(token) : null;
const userIdentifier = tokenData ? tokenData.identifier : ""; const userIdentifier = tokenData ? tokenData.identifier : "";
let memberTags: string[] = []; let memberTags: string[] = [];

View File

@ -6,7 +6,8 @@ import { ADMIN_API_URL } from "../Enum/EnvironmentVariable";
import { GameRoomPolicyTypes } from "../Model/PusherRoom"; import { GameRoomPolicyTypes } from "../Model/PusherRoom";
import { MapDetailsData } from "../Services/AdminApi/MapDetailsData"; import { MapDetailsData } from "../Services/AdminApi/MapDetailsData";
import { socketManager } from "../Services/SocketManager"; import { socketManager } from "../Services/SocketManager";
import { jwtTokenManager } from "../Services/JWTTokenManager"; import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
import { v4 } from "uuid";
export class MapController extends BaseController { export class MapController extends BaseController {
constructor(private App: TemplatedApp) { constructor(private App: TemplatedApp) {
@ -71,8 +72,16 @@ export class MapController extends BaseController {
try { try {
let userId: string | undefined = undefined; let userId: string | undefined = undefined;
if (query.authToken != undefined) { if (query.authToken != undefined) {
const authTokenData = jwtTokenManager.decodeJWTToken(query.authToken as string); let authTokenData: AuthTokenData;
try {
authTokenData = jwtTokenManager.verifyJWTToken(query.authToken as string);
userId = authTokenData.identifier; userId = authTokenData.identifier;
} catch (e) {
// Decode token, in this case we don't need to create new token.
authTokenData = jwtTokenManager.verifyJWTToken(query.authToken as string, true);
userId = authTokenData.identifier;
console.info("JWT expire, but decoded", userId);
}
} }
const mapDetails = await adminApi.fetchMapDetails(query.playUri as string, userId); const mapDetails = await adminApi.fetchMapDetails(query.playUri as string, userId);

View File

@ -15,9 +15,9 @@ class JWTTokenManager {
return Jwt.sign({ identifier }, SECRET_KEY, { expiresIn: "200d" }); return Jwt.sign({ identifier }, SECRET_KEY, { expiresIn: "200d" });
} }
public decodeJWTToken(token: string): AuthTokenData { public verifyJWTToken(token: string, ignoreExpiration: boolean = false): AuthTokenData {
try { try {
return Jwt.verify(token, SECRET_KEY, { ignoreExpiration: false }) as AuthTokenData; return Jwt.verify(token, SECRET_KEY, { ignoreExpiration }) as AuthTokenData;
} catch (e) { } catch (e) {
throw { reason: tokenInvalidException, message: e.message }; throw { reason: tokenInvalidException, message: e.message };
} }