From f7daf16ac5dc4a0f460c9717fb480ded6d909457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?gr=C3=A9goire=20parant?= Date: Wed, 11 Aug 2021 17:09:17 +0200 Subject: [PATCH 1/6] New version of cache management (#1365) Signed-off-by: Gregoire Parant --- front/dist/service-worker-prod.js | 2 +- front/src/Components/Video/VideoMediaBox.svelte | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/front/dist/service-worker-prod.js b/front/dist/service-worker-prod.js index 2f8d6a51..919b0b91 100644 --- a/front/dist/service-worker-prod.js +++ b/front/dist/service-worker-prod.js @@ -1,4 +1,4 @@ -let CACHE_NAME = 'workavdenture-cache-v1.2'; +let CACHE_NAME = 'workavdenture-cache-v1.4.14'; let urlsToCache = [ '/' ]; diff --git a/front/src/Components/Video/VideoMediaBox.svelte b/front/src/Components/Video/VideoMediaBox.svelte index 6b981dc8..924bb13a 100644 --- a/front/src/Components/Video/VideoMediaBox.svelte +++ b/front/src/Components/Video/VideoMediaBox.svelte @@ -22,7 +22,6 @@ let isMobile : boolean|null; const unsubscribe = obtainedMediaConstraintIsMobileStore.subscribe(value => { - console.log('unsubscribe => obtainedMediaConstraintIsMobileStore', value); isMobile = value; }); onDestroy(unsubscribe); From 02a21209ec7cd6830850d6d1838dfe58cfeb9ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?gr=C3=A9goire=20parant?= Date: Sun, 15 Aug 2021 08:51:35 +0200 Subject: [PATCH 2/6] Exit scene acess denied detected (#1369) * Add auth token user to get right in admin and check if user have right Signed-off-by: Gregoire Parant * Update error show Signed-off-by: Gregoire Parant --- front/src/Connexion/Room.ts | 2 ++ front/src/Phaser/Game/GameScene.ts | 28 +++++++++++++++++++-- front/src/Phaser/Login/EntryScene.ts | 13 +++++++++- front/src/Phaser/Reconnecting/ErrorScene.ts | 6 ++++- pusher/src/Controller/BaseController.ts | 7 +++++- pusher/src/Controller/MapController.ts | 9 ++++++- pusher/src/Services/AdminApi.ts | 10 ++++++-- 7 files changed, 67 insertions(+), 8 deletions(-) diff --git a/front/src/Connexion/Room.ts b/front/src/Connexion/Room.ts index 2053911d..be9b5294 100644 --- a/front/src/Connexion/Room.ts +++ b/front/src/Connexion/Room.ts @@ -1,6 +1,7 @@ import Axios from "axios"; import { PUSHER_URL } from "../Enum/EnvironmentVariable"; import type { CharacterTexture } from "./LocalUser"; +import { localUserStore } from "./LocalUserStore"; export class MapDetail { constructor(public readonly mapUrl: string, public readonly textures: CharacterTexture[] | undefined) {} @@ -87,6 +88,7 @@ export class Room { const result = await Axios.get(`${PUSHER_URL}/map`, { params: { playUri: this.roomUrl.toString(), + authToken: localUserStore.getAuthToken(), }, }); diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index ce947224..16fa2c83 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -94,6 +94,7 @@ import { userIsAdminStore } from "../../Stores/GameStore"; import { layoutManagerActionStore } from "../../Stores/LayoutManagerStore"; import { get } from "svelte/store"; import { EmbeddedWebsiteManager } from "./EmbeddedWebsiteManager"; +import { helpCameraSettingsVisibleStore } from "../../Stores/HelpCameraSettingsStore"; export interface GameSceneInitInterface { initPosition: PointInterface | null; @@ -814,13 +815,24 @@ export class GameScene extends DirtyScene { private triggerOnMapLayerPropertyChange() { this.gameMap.onPropertyChange("exitSceneUrl", (newValue, oldValue) => { - if (newValue) + if (newValue) { this.onMapExit( Room.getRoomPathFromExitSceneUrl(newValue as string, window.location.toString(), this.MapUrlFile) ); + } else { + setTimeout(() => { + layoutManagerActionStore.removeAction("roomAccessDenied"); + }, 2000); + } }); this.gameMap.onPropertyChange("exitUrl", (newValue, oldValue) => { - if (newValue) this.onMapExit(Room.getRoomPathFromExitUrl(newValue as string, window.location.toString())); + if (newValue) { + this.onMapExit(Room.getRoomPathFromExitUrl(newValue as string, window.location.toString())); + } else { + setTimeout(() => { + layoutManagerActionStore.removeAction("roomAccessDenied"); + }, 2000); + } }); this.gameMap.onPropertyChange("openWebsite", (newValue, oldValue, allProps) => { if (newValue === undefined) { @@ -1290,6 +1302,18 @@ ${escapedMessage} targetRoom = await Room.createRoom(roomUrl); } catch (e /*: unknown*/) { console.error('Error while fetching new room "' + roomUrl.toString() + '"', e); + + //show information room access denied + layoutManagerActionStore.addAction({ + uuid: "roomAccessDenied", + type: "warning", + message: "Room access denied. You don't have right to access on this room.", + callback: () => { + layoutManagerActionStore.removeAction("roomAccessDenied"); + }, + userInputManager: this.userInputManager, + }); + this.mapTransitioning = false; return; } diff --git a/front/src/Phaser/Login/EntryScene.ts b/front/src/Phaser/Login/EntryScene.ts index 3180d0f6..63181ae9 100644 --- a/front/src/Phaser/Login/EntryScene.ts +++ b/front/src/Phaser/Login/EntryScene.ts @@ -1,6 +1,6 @@ import { gameManager } from "../Game/GameManager"; import { Scene } from "phaser"; -import { ErrorScene } from "../Reconnecting/ErrorScene"; +import { ErrorScene, ErrorSceneName } from "../Reconnecting/ErrorScene"; import { WAError } from "../Reconnecting/WAError"; import { waScaleManager } from "../Services/WaScaleManager"; @@ -36,6 +36,17 @@ export class EntryScene extends Scene { ), this.scene ); + } else if (err.response && err.response.status == 403) { + ErrorScene.showError( + new WAError( + "Connection rejected", + "You cannot join the World. Try again later" + + (err.response.data ? ". \n\r \n\r" + `${err.response.data}` : "") + + ".", + "If you want more information, you may contact administrator or contact us at: hello@workadventu.re" + ), + this.scene + ); } else { ErrorScene.showError(err, this.scene); } diff --git a/front/src/Phaser/Reconnecting/ErrorScene.ts b/front/src/Phaser/Reconnecting/ErrorScene.ts index fb3d333a..6477b918 100644 --- a/front/src/Phaser/Reconnecting/ErrorScene.ts +++ b/front/src/Phaser/Reconnecting/ErrorScene.ts @@ -90,7 +90,11 @@ export class ErrorScene extends Phaser.Scene { // Axios HTTP error // client received an error response (5xx, 4xx) scene.start(ErrorSceneName, { - title: "HTTP " + error.response.status + " - " + error.response.statusText, + title: + "HTTP " + + error.response.status + + " - " + + (error.response.data ? error.response.data : error.response.statusText), subTitle: "An error occurred while accessing URL:", message: error.response.config.url, }); diff --git a/pusher/src/Controller/BaseController.ts b/pusher/src/Controller/BaseController.ts index ce378a55..a983333a 100644 --- a/pusher/src/Controller/BaseController.ts +++ b/pusher/src/Controller/BaseController.ts @@ -29,7 +29,12 @@ export class BaseController { if (e.response) { res.writeStatus(e.response.status + " " + e.response.statusText); this.addCorsHeaders(res); - res.end("An error occurred: " + e.response.status + " " + e.response.statusText); + res.end( + "An error occurred: " + + e.response.status + + " " + + (e.response.data && e.response.data.message ? e.response.data.message : e.response.statusText) + ); } else { res.writeStatus("500 Internal Server Error"); this.addCorsHeaders(res); diff --git a/pusher/src/Controller/MapController.ts b/pusher/src/Controller/MapController.ts index 6ea2f19d..8becb0fe 100644 --- a/pusher/src/Controller/MapController.ts +++ b/pusher/src/Controller/MapController.ts @@ -5,6 +5,8 @@ import { adminApi } from "../Services/AdminApi"; import { ADMIN_API_URL } from "../Enum/EnvironmentVariable"; import { GameRoomPolicyTypes } from "../Model/PusherRoom"; import { MapDetailsData } from "../Services/AdminApi/MapDetailsData"; +import { socketManager } from "../Services/SocketManager"; +import { jwtTokenManager } from "../Services/JWTTokenManager"; export class MapController extends BaseController { constructor(private App: TemplatedApp) { @@ -67,7 +69,12 @@ export class MapController extends BaseController { (async () => { try { - const mapDetails = await adminApi.fetchMapDetails(query.playUri as string); + let userId: string | undefined = undefined; + if (query.authToken != undefined) { + const authTokenData = jwtTokenManager.decodeJWTToken(query.authToken as string); + userId = authTokenData.identifier; + } + const mapDetails = await adminApi.fetchMapDetails(query.playUri as string, userId); res.writeStatus("200 OK"); this.addCorsHeaders(res); diff --git a/pusher/src/Services/AdminApi.ts b/pusher/src/Services/AdminApi.ts index 61ef8e20..f33480ca 100644 --- a/pusher/src/Services/AdminApi.ts +++ b/pusher/src/Services/AdminApi.ts @@ -31,13 +31,19 @@ export interface FetchMemberDataByUuidResponse { } class AdminApi { - async fetchMapDetails(playUri: string): Promise { + /** + * @var playUri: is url of the room + * @var userId: can to be undefined or email or uuid + * @return MapDetailsData|RoomRedirect + */ + async fetchMapDetails(playUri: string, userId?: string): Promise { if (!ADMIN_API_URL) { return Promise.reject(new Error("No admin backoffice set!")); } - const params: { playUri: string } = { + const params: { playUri: string; userId?: string } = { playUri, + userId, }; const res = await Axios.get(ADMIN_API_URL + "/api/map", { From 8d57886bae45dc2f893ce4ae1e410fa87377dc85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?gr=C3=A9goire=20parant?= Date: Sun, 15 Aug 2021 22:51:06 +0200 Subject: [PATCH 3/6] Update token generation (#1372) - Permit only decode token to get map details, - If user have token expired, set the token to null and reload the page. This feature will be updated when authentication stategy will be finished. Signed-off-by: Gregoire Parant --- front/src/Connexion/ConnectionManager.ts | 19 ++++++++++++++++--- pusher/src/Controller/IoSocketController.ts | 2 +- pusher/src/Controller/MapController.ts | 15 ++++++++++++--- pusher/src/Services/JWTTokenManager.ts | 4 ++-- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/front/src/Connexion/ConnectionManager.ts b/front/src/Connexion/ConnectionManager.ts index 38272737..9e245d3a 100644 --- a/front/src/Connexion/ConnectionManager.ts +++ b/front/src/Connexion/ConnectionManager.ts @@ -29,11 +29,24 @@ class ConnectionManager { }); } - public loadOpenIDScreen() { - localUserStore.setAuthToken(null); + /** + * @return Promise + */ + public loadOpenIDScreen(): Promise { const state = localUserStore.generateState(); const nonce = localUserStore.generateNonce(); - window.location.assign(`http://${PUSHER_URL}/login-screen?state=${state}&nonce=${nonce}`); + localUserStore.setAuthToken(null); + + //TODO refactor this and don't realise previous call + return Axios.get(`http://${PUSHER_URL}/login-screen?state=${state}&nonce=${nonce}`) + .then(() => { + window.location.assign(`http://${PUSHER_URL}/login-screen?state=${state}&nonce=${nonce}`); + }) + .catch((err) => { + console.error(err, "We don't have URL to regenerate authentication user"); + //TODO show modal login + window.location.reload(); + }); } public logout() { diff --git a/pusher/src/Controller/IoSocketController.ts b/pusher/src/Controller/IoSocketController.ts index daf45ce4..0466100c 100644 --- a/pusher/src/Controller/IoSocketController.ts +++ b/pusher/src/Controller/IoSocketController.ts @@ -174,7 +174,7 @@ export class IoSocketController { } const tokenData = - token && typeof token === "string" ? jwtTokenManager.decodeJWTToken(token) : null; + token && typeof token === "string" ? jwtTokenManager.verifyJWTToken(token) : null; const userIdentifier = tokenData ? tokenData.identifier : ""; let memberTags: string[] = []; diff --git a/pusher/src/Controller/MapController.ts b/pusher/src/Controller/MapController.ts index 8becb0fe..ccaa231f 100644 --- a/pusher/src/Controller/MapController.ts +++ b/pusher/src/Controller/MapController.ts @@ -6,7 +6,8 @@ import { ADMIN_API_URL } from "../Enum/EnvironmentVariable"; import { GameRoomPolicyTypes } from "../Model/PusherRoom"; import { MapDetailsData } from "../Services/AdminApi/MapDetailsData"; 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 { constructor(private App: TemplatedApp) { @@ -71,8 +72,16 @@ export class MapController extends BaseController { try { let userId: string | undefined = undefined; if (query.authToken != undefined) { - const authTokenData = jwtTokenManager.decodeJWTToken(query.authToken as string); - userId = authTokenData.identifier; + let authTokenData: AuthTokenData; + try { + authTokenData = jwtTokenManager.verifyJWTToken(query.authToken as string); + 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); diff --git a/pusher/src/Services/JWTTokenManager.ts b/pusher/src/Services/JWTTokenManager.ts index bb21531c..4711ccfd 100644 --- a/pusher/src/Services/JWTTokenManager.ts +++ b/pusher/src/Services/JWTTokenManager.ts @@ -15,9 +15,9 @@ class JWTTokenManager { return Jwt.sign({ identifier }, SECRET_KEY, { expiresIn: "200d" }); } - public decodeJWTToken(token: string): AuthTokenData { + public verifyJWTToken(token: string, ignoreExpiration: boolean = false): AuthTokenData { try { - return Jwt.verify(token, SECRET_KEY, { ignoreExpiration: false }) as AuthTokenData; + return Jwt.verify(token, SECRET_KEY, { ignoreExpiration }) as AuthTokenData; } catch (e) { throw { reason: tokenInvalidException, message: e.message }; } From 482a6da1d888f9275d9e08704d255a50753af2e9 Mon Sep 17 00:00:00 2001 From: GRL Date: Mon, 16 Aug 2021 11:43:29 +0200 Subject: [PATCH 4/6] GameManager has an attribute scenePlugin --- front/src/Api/IframeListener.ts | 3 + .../InputTextGlobalMessage.svelte | 2 +- front/src/Phaser/Game/GameManager.ts | 42 +++++----- front/src/Phaser/Game/GameScene.ts | 4 +- front/src/Phaser/Login/CustomizeScene.ts | 2 +- front/src/Phaser/Login/EnableCameraScene.ts | 37 ++++---- front/src/Phaser/Login/LoginScene.ts | 28 +++---- .../src/Phaser/Login/SelectCharacterScene.ts | 2 +- .../src/Phaser/Login/SelectCompanionScene.ts | 84 +++++++++---------- front/src/Phaser/Menu/MenuScene.ts | 8 +- front/src/Phaser/Menu/ReportMenu.ts | 8 +- 11 files changed, 105 insertions(+), 115 deletions(-) diff --git a/front/src/Api/IframeListener.ts b/front/src/Api/IframeListener.ts index 4dde1b7d..7bf4e2f7 100644 --- a/front/src/Api/IframeListener.ts +++ b/front/src/Api/IframeListener.ts @@ -34,6 +34,7 @@ import { SetTilesEvent, isSetTilesEvent } from "./Events/SetTilesEvent"; import type { SetVariableEvent } from "./Events/SetVariableEvent"; import { ModifyEmbeddedWebsiteEvent, isEmbeddedWebsiteEvent } from "./Events/EmbeddedWebsiteEvent"; import { EmbeddedWebsite } from "./iframe/Room/EmbeddedWebsite"; +import { gameManager } from "../Phaser/Game/GameManager"; type AnswererCallback = ( query: IframeQueryMap[T]["query"], @@ -155,6 +156,8 @@ class IframeListener { return; } + //await gameManager.getCurrentGameScene() + foundSrc = this.getBaseUrl(foundSrc, message.source); if (isIframeQueryWrapper(payload)) { diff --git a/front/src/Components/ConsoleGlobalMessageManager/InputTextGlobalMessage.svelte b/front/src/Components/ConsoleGlobalMessageManager/InputTextGlobalMessage.svelte index 7baa8226..6186cba0 100644 --- a/front/src/Components/ConsoleGlobalMessageManager/InputTextGlobalMessage.svelte +++ b/front/src/Components/ConsoleGlobalMessageManager/InputTextGlobalMessage.svelte @@ -34,7 +34,7 @@ export let game: Game; export let gameManager: GameManager; - const gameScene = gameManager.getCurrentGameScene(game.findAnyScene()); + const gameScene = gameManager.getCurrentGameScene(); let quill: Quill; let INPUT_CONSOLE_MESSAGE: HTMLDivElement; diff --git a/front/src/Phaser/Game/GameManager.ts b/front/src/Phaser/Game/GameManager.ts index 7f0b2061..12558d5d 100644 --- a/front/src/Phaser/Game/GameManager.ts +++ b/front/src/Phaser/Game/GameManager.ts @@ -18,6 +18,7 @@ export class GameManager { private characterLayers: string[] | null; private companion: string | null; private startRoom!: Room; + private scenePlugin!: Phaser.Scenes.ScenePlugin; currentGameSceneName: string | null = null; constructor() { @@ -27,8 +28,9 @@ export class GameManager { } public async init(scenePlugin: Phaser.Scenes.ScenePlugin): Promise { + this.scenePlugin = scenePlugin; this.startRoom = await connectionManager.initGameConnexion(); - this.loadMap(this.startRoom, scenePlugin); + this.loadMap(this.startRoom); if (!this.playerName) { return LoginSceneName; @@ -68,20 +70,20 @@ export class GameManager { return this.companion; } - public loadMap(room: Room, scenePlugin: Phaser.Scenes.ScenePlugin) { + public loadMap(room: Room) { const roomID = room.key; - const gameIndex = scenePlugin.getIndex(roomID); + const gameIndex = this.scenePlugin.getIndex(roomID); if (gameIndex === -1) { 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)); - scenePlugin.start(this.currentGameSceneName || this.startRoom.key); - scenePlugin.launch(MenuSceneName); + this.scenePlugin.start(this.currentGameSceneName || this.startRoom.key); + this.scenePlugin.launch(MenuSceneName); if ( !localUserStore.getHelpCameraSettingsShown() && @@ -102,33 +104,33 @@ export class GameManager { * 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. */ - 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!"; - const gameScene: GameScene = scene.scene.get(this.currentGameSceneName) as GameScene; + const gameScene: GameScene = this.scenePlugin.get(this.currentGameSceneName) as GameScene; gameScene.cleanupClosingScene(); - scene.scene.stop(this.currentGameSceneName); - scene.scene.sleep(MenuSceneName); - if (!scene.scene.get(targetSceneName)) { - scene.scene.add(targetSceneName, sceneClass, false); + this.scenePlugin.stop(this.currentGameSceneName); + this.scenePlugin.sleep(MenuSceneName); + if (!this.scenePlugin.get(targetSceneName)) { + this.scenePlugin.add(targetSceneName, sceneClass, false); } - scene.scene.run(targetSceneName); + this.scenePlugin.run(targetSceneName); } /** * follow up to leaveGame() */ - tryResumingGame(scene: Phaser.Scene, fallbackSceneName: string) { + tryResumingGame(fallbackSceneName: string) { if (this.currentGameSceneName) { - scene.scene.start(this.currentGameSceneName); - scene.scene.wake(MenuSceneName); + this.scenePlugin.start(this.currentGameSceneName); + this.scenePlugin.wake(MenuSceneName); } 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!"; - return scene.scene.get(this.currentGameSceneName) as GameScene; + return this.scenePlugin.get(this.currentGameSceneName) as GameScene; } } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 16fa2c83..6a80e3c3 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -1443,7 +1443,7 @@ ${escapedMessage} private async loadNextGame(exitRoomPath: URL): Promise { try { const room = await Room.createRoom(exitRoomPath); - return gameManager.loadMap(room, this.scene); + return gameManager.loadMap(room); } catch (e /*: unknown*/) { console.warn('Error while pre-loading exit room "' + exitRoomPath.toString() + '"', e); } @@ -1504,7 +1504,7 @@ ${escapedMessage} }); } catch (err) { if (err instanceof TextureError) { - gameManager.leaveGame(this, SelectCharacterSceneName, new SelectCharacterScene()); + gameManager.leaveGame(SelectCharacterSceneName, new SelectCharacterScene()); } throw err; } diff --git a/front/src/Phaser/Login/CustomizeScene.ts b/front/src/Phaser/Login/CustomizeScene.ts index 4146a982..04ccea2d 100644 --- a/front/src/Phaser/Login/CustomizeScene.ts +++ b/front/src/Phaser/Login/CustomizeScene.ts @@ -282,7 +282,7 @@ export class CustomizeScene extends AbstractCharacterScene { this.scene.sleep(CustomizeSceneName); waScaleManager.restoreZoom(); this.events.removeListener("wake"); - gameManager.tryResumingGame(this, EnableCameraSceneName); + gameManager.tryResumingGame(EnableCameraSceneName); customCharacterSceneVisibleStore.set(false); } diff --git a/front/src/Phaser/Login/EnableCameraScene.ts b/front/src/Phaser/Login/EnableCameraScene.ts index ba27cd07..55fc4b82 100644 --- a/front/src/Phaser/Login/EnableCameraScene.ts +++ b/front/src/Phaser/Login/EnableCameraScene.ts @@ -1,50 +1,43 @@ -import {gameManager} from "../Game/GameManager"; -import {TextField} from "../Components/TextField"; +import { gameManager } from "../Game/GameManager"; +import { TextField } from "../Components/TextField"; import Image = Phaser.GameObjects.Image; -import {mediaManager} from "../../WebRtc/MediaManager"; -import {SoundMeter} from "../Components/SoundMeter"; -import {HtmlUtils} from "../../WebRtc/HtmlUtils"; -import {touchScreenManager} from "../../Touch/TouchScreenManager"; -import {PinchManager} from "../UserInput/PinchManager"; +import { mediaManager } from "../../WebRtc/MediaManager"; +import { SoundMeter } from "../Components/SoundMeter"; +import { HtmlUtils } from "../../WebRtc/HtmlUtils"; +import { touchScreenManager } from "../../Touch/TouchScreenManager"; +import { PinchManager } from "../UserInput/PinchManager"; import Zone = Phaser.GameObjects.Zone; import { MenuScene } from "../Menu/MenuScene"; -import {ResizableScene} from "./ResizableScene"; -import { - enableCameraSceneVisibilityStore, -} from "../../Stores/MediaStore"; +import { ResizableScene } from "./ResizableScene"; +import { enableCameraSceneVisibilityStore } from "../../Stores/MediaStore"; export const EnableCameraSceneName = "EnableCameraScene"; export class EnableCameraScene extends ResizableScene { - constructor() { super({ - key: EnableCameraSceneName + key: EnableCameraSceneName, }); } - preload() { - } + preload() {} create() { - - this.input.keyboard.on('keyup-ENTER', () => { + this.input.keyboard.on("keyup-ENTER", () => { this.login(); }); enableCameraSceneVisibilityStore.showEnableCameraScene(); } - public onResize(): void { - } + public onResize(): void {} - update(time: number, delta: number): void { - } + update(time: number, delta: number): void {} public login(): void { enableCameraSceneVisibilityStore.hideEnableCameraScene(); this.scene.sleep(EnableCameraSceneName); - gameManager.goToStartingMap(this.scene); + gameManager.goToStartingMap(); } } diff --git a/front/src/Phaser/Login/LoginScene.ts b/front/src/Phaser/Login/LoginScene.ts index 39a8f5f3..0cca9ccd 100644 --- a/front/src/Phaser/Login/LoginScene.ts +++ b/front/src/Phaser/Login/LoginScene.ts @@ -1,23 +1,21 @@ -import {gameManager} from "../Game/GameManager"; -import {SelectCharacterSceneName} from "./SelectCharacterScene"; -import {ResizableScene} from "./ResizableScene"; -import {loginSceneVisibleStore} from "../../Stores/LoginSceneStore"; +import { gameManager } from "../Game/GameManager"; +import { SelectCharacterSceneName } from "./SelectCharacterScene"; +import { ResizableScene } from "./ResizableScene"; +import { loginSceneVisibleStore } from "../../Stores/LoginSceneStore"; export const LoginSceneName = "LoginScene"; export class LoginScene extends ResizableScene { - - private name: string = ''; + private name: string = ""; constructor() { super({ - key: LoginSceneName + key: LoginSceneName, }); - this.name = gameManager.getPlayerName() || ''; + this.name = gameManager.getPlayerName() || ""; } - preload() { - } + preload() {} create() { loginSceneVisibleStore.set(true); @@ -27,15 +25,13 @@ export class LoginScene extends ResizableScene { name = name.trim(); gameManager.setPlayerName(name); - this.scene.stop(LoginSceneName) - gameManager.tryResumingGame(this, SelectCharacterSceneName); + this.scene.stop(LoginSceneName); + gameManager.tryResumingGame(SelectCharacterSceneName); this.scene.remove(LoginSceneName); loginSceneVisibleStore.set(false); } - update(time: number, delta: number): void { - } + update(time: number, delta: number): void {} - public onResize(): void { - } + public onResize(): void {} } diff --git a/front/src/Phaser/Login/SelectCharacterScene.ts b/front/src/Phaser/Login/SelectCharacterScene.ts index 0d3bb431..dbb50c94 100644 --- a/front/src/Phaser/Login/SelectCharacterScene.ts +++ b/front/src/Phaser/Login/SelectCharacterScene.ts @@ -101,7 +101,7 @@ export class SelectCharacterScene extends AbstractCharacterScene { this.scene.stop(SelectCharacterSceneName); waScaleManager.restoreZoom(); gameManager.setCharacterLayers([this.selectedPlayer.texture.key]); - gameManager.tryResumingGame(this, EnableCameraSceneName); + gameManager.tryResumingGame(EnableCameraSceneName); this.players = []; selectCharacterSceneVisibleStore.set(false); this.events.removeListener("wake"); diff --git a/front/src/Phaser/Login/SelectCompanionScene.ts b/front/src/Phaser/Login/SelectCompanionScene.ts index 4c29f942..ed0947cf 100644 --- a/front/src/Phaser/Login/SelectCompanionScene.ts +++ b/front/src/Phaser/Login/SelectCompanionScene.ts @@ -1,18 +1,18 @@ import Image = Phaser.GameObjects.Image; import Rectangle = Phaser.GameObjects.Rectangle; import { addLoader } from "../Components/Loader"; -import { gameManager} from "../Game/GameManager"; +import { gameManager } from "../Game/GameManager"; import { ResizableScene } from "./ResizableScene"; import { EnableCameraSceneName } from "./EnableCameraScene"; import { localUserStore } from "../../Connexion/LocalUserStore"; import type { CompanionResourceDescriptionInterface } from "../Companion/CompanionTextures"; import { getAllCompanionResources } from "../Companion/CompanionTexturesLoadingManager"; -import {touchScreenManager} from "../../Touch/TouchScreenManager"; -import {PinchManager} from "../UserInput/PinchManager"; +import { touchScreenManager } from "../../Touch/TouchScreenManager"; +import { PinchManager } from "../UserInput/PinchManager"; import { MenuScene } from "../Menu/MenuScene"; -import {selectCompanionSceneVisibleStore} from "../../Stores/SelectCompanionStore"; -import {waScaleManager} from "../Services/WaScaleManager"; -import {isMobile} from "../../Enum/EnvironmentVariable"; +import { selectCompanionSceneVisibleStore } from "../../Stores/SelectCompanionStore"; +import { waScaleManager } from "../Services/WaScaleManager"; +import { isMobile } from "../../Enum/EnvironmentVariable"; export const SelectCompanionSceneName = "SelectCompanionScene"; @@ -28,12 +28,12 @@ export class SelectCompanionScene extends ResizableScene { constructor() { super({ - key: SelectCompanionSceneName + key: SelectCompanionSceneName, }); } preload() { - getAllCompanionResources(this.load).forEach(model => { + getAllCompanionResources(this.load).forEach((model) => { this.companionModels.push(model); }); @@ -42,7 +42,6 @@ export class SelectCompanionScene extends ResizableScene { } create() { - selectCompanionSceneVisibleStore.set(true); waScaleManager.saveZoom(); @@ -53,14 +52,16 @@ export class SelectCompanionScene extends ResizableScene { } // 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-LEFT', this.moveToLeft.bind(this)); + this.input.keyboard.on("keydown-RIGHT", this.moveToRight.bind(this)); + this.input.keyboard.on("keydown-LEFT", this.moveToLeft.bind(this)); - if(localUserStore.getCompanion()){ - const companionIndex = this.companionModels.findIndex((companion) => companion.name === localUserStore.getCompanion()); - if(companionIndex > -1 || companionIndex < this.companions.length){ + if (localUserStore.getCompanion()) { + const companionIndex = this.companionModels.findIndex( + (companion) => companion.name === localUserStore.getCompanion() + ); + if (companionIndex > -1 || companionIndex < this.companions.length) { this.currentCompanion = companionIndex; this.selectedCompanion = this.companions[companionIndex]; } @@ -89,26 +90,26 @@ export class SelectCompanionScene extends ResizableScene { this.closeScene(); } - public closeScene(){ + public closeScene() { // next scene this.scene.stop(SelectCompanionSceneName); waScaleManager.restoreZoom(); - gameManager.tryResumingGame(this, EnableCameraSceneName); + gameManager.tryResumingGame(EnableCameraSceneName); this.scene.remove(SelectCompanionSceneName); selectCompanionSceneVisibleStore.set(false); } private createCurrentCompanion(): void { 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 companion = this.physics.add.sprite(middleX, middleY, companionResource.name, 0); this.setUpCompanion(companion, i); this.anims.create({ 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, - repeat: -1 + repeat: -1, }); companion.setInteractive().on("pointerdown", () => { @@ -140,87 +141,84 @@ export class SelectCompanionScene extends ResizableScene { this.selectedCompanion = companion; } - private moveCompanion(){ - for(let i = 0; i < this.companions.length; i++){ + private moveCompanion() { + for (let i = 0; i < this.companions.length; i++) { const companion = this.companions[i]; this.setUpCompanion(companion, i); } this.updateSelectedCompanion(); } - public moveToRight(){ - if(this.currentCompanion === (this.companions.length - 1)){ + public moveToRight() { + if (this.currentCompanion === this.companions.length - 1) { return; } this.currentCompanion += 1; this.moveCompanion(); } - public moveToLeft(){ - if(this.currentCompanion === 0){ + public moveToLeft() { + if (this.currentCompanion === 0) { return; } this.currentCompanion -= 1; this.moveCompanion(); } - private defineSetupCompanion(num: number){ + private defineSetupCompanion(num: number) { const deltaX = 30; const deltaY = 2; let [companionX, companionY] = this.getCompanionPosition(); let companionVisible = true; let companionScale = 1.5; let companionOpactity = 1; - if( this.currentCompanion !== num ){ + if (this.currentCompanion !== num) { companionVisible = false; } - if( num === (this.currentCompanion + 1) ){ + if (num === this.currentCompanion + 1) { companionY -= deltaY; companionX += deltaX; companionScale = 0.8; companionOpactity = 0.6; companionVisible = true; } - if( num === (this.currentCompanion + 2) ){ + if (num === this.currentCompanion + 2) { companionY -= deltaY; - companionX += (deltaX * 2); + companionX += deltaX * 2; companionScale = 0.8; companionOpactity = 0.6; companionVisible = true; } - if( num === (this.currentCompanion - 1) ){ + if (num === this.currentCompanion - 1) { companionY -= deltaY; companionX -= deltaX; companionScale = 0.8; companionOpactity = 0.6; companionVisible = true; } - if( num === (this.currentCompanion - 2) ){ + if (num === this.currentCompanion - 2) { companionY -= deltaY; - companionX -= (deltaX * 2); + companionX -= deltaX * 2; companionScale = 0.8; companionOpactity = 0.6; companionVisible = true; } - return {companionX, companionY, companionScale, companionOpactity, companionVisible} + return { companionX, companionY, companionScale, companionOpactity, companionVisible }; } /** * Returns pixel position by on column and row number */ private getCompanionPosition(): [number, number] { - return [ - this.game.renderer.width / 2, - this.game.renderer.height / 3 - ]; + return [this.game.renderer.width / 2, this.game.renderer.height / 3]; } - private setUpCompanion(companion: Phaser.Physics.Arcade.Sprite, numero: number){ - - const {companionX, companionY, companionScale, companionOpactity, companionVisible} = this.defineSetupCompanion(numero); + private setUpCompanion(companion: Phaser.Physics.Arcade.Sprite, numero: number) { + const { companionX, companionY, companionScale, companionOpactity, companionVisible } = + this.defineSetupCompanion(numero); companion.setBounce(0.2); companion.setCollideWorldBounds(true); - companion.setVisible( companionVisible ); + companion.setVisible(companionVisible); companion.setScale(companionScale, companionScale); companion.setAlpha(companionOpactity); companion.setX(companionX); diff --git a/front/src/Phaser/Menu/MenuScene.ts b/front/src/Phaser/Menu/MenuScene.ts index 8270dada..9dd138ca 100644 --- a/front/src/Phaser/Menu/MenuScene.ts +++ b/front/src/Phaser/Menu/MenuScene.ts @@ -171,7 +171,7 @@ export class MenuScene extends Phaser.Scene { this.closeAll(); this.sideMenuOpened = true; this.menuButton.getChildByID("openMenuButton").innerHTML = "X"; - const connection = gameManager.getCurrentGameScene(this).connection; + const connection = gameManager.getCurrentGameScene().connection; if (connection && connection.isAdmin()) { const adminSection = this.menuElement.getChildByID("adminConsoleSection") as HTMLElement; adminSection.hidden = false; @@ -322,18 +322,18 @@ export class MenuScene extends Phaser.Scene { switch ((event?.target as HTMLInputElement).id) { case "changeNameButton": this.closeSideMenu(); - gameManager.leaveGame(this, LoginSceneName, new LoginScene()); + gameManager.leaveGame(LoginSceneName, new LoginScene()); break; case "sparkButton": this.gotToCreateMapPage(); break; case "changeSkinButton": this.closeSideMenu(); - gameManager.leaveGame(this, SelectCharacterSceneName, new SelectCharacterScene()); + gameManager.leaveGame(SelectCharacterSceneName, new SelectCharacterScene()); break; case "changeCompanionButton": this.closeSideMenu(); - gameManager.leaveGame(this, SelectCompanionSceneName, new SelectCompanionScene()); + gameManager.leaveGame(SelectCompanionSceneName, new SelectCompanionScene()); break; case "closeButton": this.closeSideMenu(); diff --git a/front/src/Phaser/Menu/ReportMenu.ts b/front/src/Phaser/Menu/ReportMenu.ts index effb92b2..5bcec0a8 100644 --- a/front/src/Phaser/Menu/ReportMenu.ts +++ b/front/src/Phaser/Menu/ReportMenu.ts @@ -62,7 +62,7 @@ export class ReportMenu extends Phaser.GameObjects.DOMElement { this.opened = true; - gameManager.getCurrentGameScene(this.scene).userInputManager.disableControls(); + gameManager.getCurrentGameScene().userInputManager.disableControls(); this.scene.tweens.add({ targets: this, @@ -73,7 +73,7 @@ export class ReportMenu extends Phaser.GameObjects.DOMElement { } public close(): void { - gameManager.getCurrentGameScene(this.scene).userInputManager.restoreControls(); + gameManager.getCurrentGameScene().userInputManager.restoreControls(); this.opened = false; const mainEl = this.getChildByID("gameReport") as HTMLElement; this.scene.tweens.add({ @@ -112,9 +112,7 @@ export class ReportMenu extends Phaser.GameObjects.DOMElement { gamePError.style.display = "block"; return; } - gameManager - .getCurrentGameScene(this.scene) - .connection?.emitReportPlayerMessage(this.userUuid, gameTextArea.value); + gameManager.getCurrentGameScene().connection?.emitReportPlayerMessage(this.userUuid, gameTextArea.value); this.close(); } } From d2413896c78c68e71484488616a75c3a2a2ca731 Mon Sep 17 00:00:00 2001 From: GRL Date: Mon, 16 Aug 2021 11:43:29 +0200 Subject: [PATCH 5/6] GameManager has an attribute scenePlugin --- front/src/Api/IframeListener.ts | 3 + front/src/Components/App.svelte | 2 +- .../ConsoleGlobalMessageManager.svelte | 6 +- .../InputTextGlobalMessage.svelte | 4 +- .../UploadAudioGlobalMessage.svelte | 4 +- front/src/Phaser/Game/GameManager.ts | 42 +++++----- front/src/Phaser/Game/GameScene.ts | 4 +- front/src/Phaser/Login/CustomizeScene.ts | 2 +- front/src/Phaser/Login/EnableCameraScene.ts | 37 ++++---- front/src/Phaser/Login/LoginScene.ts | 28 +++---- .../src/Phaser/Login/SelectCharacterScene.ts | 2 +- .../src/Phaser/Login/SelectCompanionScene.ts | 84 +++++++++---------- front/src/Phaser/Menu/MenuScene.ts | 8 +- front/src/Phaser/Menu/ReportMenu.ts | 8 +- 14 files changed, 109 insertions(+), 125 deletions(-) diff --git a/front/src/Api/IframeListener.ts b/front/src/Api/IframeListener.ts index 4dde1b7d..7bf4e2f7 100644 --- a/front/src/Api/IframeListener.ts +++ b/front/src/Api/IframeListener.ts @@ -34,6 +34,7 @@ import { SetTilesEvent, isSetTilesEvent } from "./Events/SetTilesEvent"; import type { SetVariableEvent } from "./Events/SetVariableEvent"; import { ModifyEmbeddedWebsiteEvent, isEmbeddedWebsiteEvent } from "./Events/EmbeddedWebsiteEvent"; import { EmbeddedWebsite } from "./iframe/Room/EmbeddedWebsite"; +import { gameManager } from "../Phaser/Game/GameManager"; type AnswererCallback = ( query: IframeQueryMap[T]["query"], @@ -155,6 +156,8 @@ class IframeListener { return; } + //await gameManager.getCurrentGameScene() + foundSrc = this.getBaseUrl(foundSrc, message.source); if (isIframeQueryWrapper(payload)) { diff --git a/front/src/Components/App.svelte b/front/src/Components/App.svelte index d65f699e..806eaea1 100644 --- a/front/src/Components/App.svelte +++ b/front/src/Components/App.svelte @@ -102,7 +102,7 @@ {/if} {#if $consoleGlobalMessageManagerVisibleStore}
- +
{/if} {#if $helpCameraSettingsVisibleStore} diff --git a/front/src/Components/ConsoleGlobalMessageManager/ConsoleGlobalMessageManager.svelte b/front/src/Components/ConsoleGlobalMessageManager/ConsoleGlobalMessageManager.svelte index c1811650..7a70e173 100644 --- a/front/src/Components/ConsoleGlobalMessageManager/ConsoleGlobalMessageManager.svelte +++ b/front/src/Components/ConsoleGlobalMessageManager/ConsoleGlobalMessageManager.svelte @@ -3,10 +3,8 @@ import InputTextGlobalMessage from "./InputTextGlobalMessage.svelte"; import UploadAudioGlobalMessage from "./UploadAudioGlobalMessage.svelte"; import { gameManager } from "../../Phaser/Game/GameManager"; - import type { Game } from "../../Phaser/Game/Game"; import { consoleGlobalMessageManagerVisibleStore } from "../../Stores/ConsoleGlobalMessageManagerStore"; - export let game: Game; let inputSendTextActive = true; let uploadMusicActive = false; let handleSendText: { sendTextMessage(broadcast: boolean): void }; @@ -57,10 +55,10 @@
{#if inputSendTextActive} - + {/if} {#if uploadMusicActive} - + {/if}