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", {