Removing completely any analysis of the URL from the front.

Instead, data related to room is sent from the admin, via the pusher.
This commit is contained in:
David Négrier 2022-01-05 14:32:02 +01:00
parent c85679b42c
commit 968e71cbca
6 changed files with 28 additions and 33 deletions

View File

@ -6,12 +6,11 @@
import type { Unsubscriber } from "svelte/store"; import type { Unsubscriber } from "svelte/store";
import { playersStore } from "../../Stores/PlayersStore"; import { playersStore } from "../../Stores/PlayersStore";
import { connectionManager } from "../../Connexion/ConnectionManager"; import { connectionManager } from "../../Connexion/ConnectionManager";
import { GameConnexionTypes } from "../../Url/UrlManager";
import { get } from "svelte/store"; import { get } from "svelte/store";
let blockActive = true; let blockActive = true;
let reportActive = !blockActive; let reportActive = !blockActive;
let anonymous: boolean = false; let disableReport: boolean = false;
let userUUID: string | undefined = playersStore.getPlayerById(get(showReportScreenStore).userId)?.userUuid; let userUUID: string | undefined = playersStore.getPlayerById(get(showReportScreenStore).userId)?.userUuid;
let userName = "No name"; let userName = "No name";
let unsubscriber: Unsubscriber; let unsubscriber: Unsubscriber;
@ -26,7 +25,7 @@
} }
} }
}); });
anonymous = connectionManager.getConnexionType === GameConnexionTypes.anonymous; disableReport = !connectionManager.currentRoom?.canReport ?? true;
}); });
onDestroy(() => { onDestroy(() => {
@ -65,7 +64,7 @@
<button type="button" class="nes-btn" on:click|preventDefault={close}>X</button> <button type="button" class="nes-btn" on:click|preventDefault={close}>X</button>
</section> </section>
</section> </section>
<section class="report-menu-action {anonymous ? 'hidden' : ''}"> <section class="report-menu-action {disableReport ? 'hidden' : ''}">
<section class="justify-center"> <section class="justify-center">
<button <button
type="button" type="button"

View File

@ -17,9 +17,7 @@
</p> </p>
{:else if $limitMapStore} {:else if $limitMapStore}
<p> <p>
This map is available for 2 days. You can register your domain <a This map is available for 2 days. You can register your domain <a href={registerLink}>here</a>!
href={registerLink}>here</a
>!
</p> </p>
{:else} {:else}
<h2>Warning!</h2> <h2>Warning!</h2>

View File

@ -154,12 +154,7 @@ class ConnectionManager {
) )
); );
urlManager.pushRoomIdToUrl(this._currentRoom); urlManager.pushRoomIdToUrl(this._currentRoom);
} else if ( } else if (connexionType === GameConnexionTypes.room || connexionType === GameConnexionTypes.empty) {
connexionType === GameConnexionTypes.organization ||
connexionType === GameConnexionTypes.anonymous ||
connexionType === GameConnexionTypes.limit ||
connexionType === GameConnexionTypes.empty
) {
this.authToken = localUserStore.getAuthToken(); this.authToken = localUserStore.getAuthToken();
let roomPath: string; let roomPath: string;
@ -241,12 +236,12 @@ class ConnectionManager {
} }
//if limit room active test headband //if limit room active test headband
if (connexionType === GameConnexionTypes.limit) { if (this._currentRoom.expireOn !== undefined) {
warningContainerStore.activateWarningContainer(); warningContainerStore.activateWarningContainer();
limitMapStore.set(true); limitMapStore.set(true);
//check time of map //check time of map
if (!urlManager.isActiveLimitRoom) { if (new Date() > this._currentRoom.expireOn) {
showLimitRoomModalStore.set(true); showLimitRoomModalStore.set(true);
} }
} }

View File

@ -27,6 +27,8 @@ export class Room {
private readonly _search: URLSearchParams; private readonly _search: URLSearchParams;
private _contactPage: string | undefined; private _contactPage: string | undefined;
private _group: string | null = null; private _group: string | null = null;
private _expireOn: Date | undefined;
private _canReport: boolean = false;
private constructor(private roomUrl: URL) { private constructor(private roomUrl: URL) {
this.id = roomUrl.pathname; this.id = roomUrl.pathname;
@ -121,6 +123,10 @@ export class Room {
data.authenticationMandatory != null ? data.authenticationMandatory : DISABLE_ANONYMOUS; data.authenticationMandatory != null ? data.authenticationMandatory : DISABLE_ANONYMOUS;
this._iframeAuthentication = data.iframeAuthentication || OPID_LOGIN_SCREEN_PROVIDER; this._iframeAuthentication = data.iframeAuthentication || OPID_LOGIN_SCREEN_PROVIDER;
this._contactPage = data.contactPage || CONTACT_URL; this._contactPage = data.contactPage || CONTACT_URL;
if (data.expireOn) {
this._expireOn = new Date(data.expireOn);
}
this._canReport = data.canReport ?? false;
return new MapDetail(data.mapUrl, data.textures); return new MapDetail(data.mapUrl, data.textures);
} else { } else {
throw new Error("Data received by the /map endpoint of the Pusher is not in a valid format."); throw new Error("Data received by the /map endpoint of the Pusher is not in a valid format.");
@ -222,4 +228,12 @@ export class Room {
get group(): string | null { get group(): string | null {
return this._group; return this._group;
} }
get expireOn(): Date | undefined {
return this._expireOn;
}
get canReport(): boolean {
return this._canReport;
}
} }

View File

@ -2,14 +2,12 @@ import type { Room } from "../Connexion/Room";
import { localUserStore } from "../Connexion/LocalUserStore"; import { localUserStore } from "../Connexion/LocalUserStore";
export enum GameConnexionTypes { export enum GameConnexionTypes {
anonymous = 1, room = 1,
organization,
register, register,
empty, empty,
unknown, unknown,
jwt, jwt,
login, login,
limit,
} }
//this class is responsible with analysing and editing the game's url //this class is responsible with analysing and editing the game's url
@ -20,12 +18,8 @@ class UrlManager {
return GameConnexionTypes.login; return GameConnexionTypes.login;
} else if (url === "/jwt") { } else if (url === "/jwt") {
return GameConnexionTypes.jwt; return GameConnexionTypes.jwt;
} else if (url.includes("*/")) { } else if (url.includes("_/") || url.includes("*/") || url.includes("@/")) {
return GameConnexionTypes.limit; return GameConnexionTypes.room;
} else if (url.includes("_/")) {
return GameConnexionTypes.anonymous;
} else if (url.includes("@/")) {
return GameConnexionTypes.organization;
} else if (url.includes("register/")) { } else if (url.includes("register/")) {
return GameConnexionTypes.register; return GameConnexionTypes.register;
} else if (url === "/") { } else if (url === "/") {
@ -58,15 +52,6 @@ class UrlManager {
pushStartLayerNameToUrl(startLayerName: string): void { pushStartLayerNameToUrl(startLayerName: string): void {
window.location.hash = startLayerName; window.location.hash = startLayerName;
} }
get isActiveLimitRoom(): boolean {
const match = /\*\/(\w+)\/(?:\w+)/.exec(window.location.pathname.toString());
const timestamp = match ? Number.parseInt(match[1]) : null;
if (!timestamp) {
return false;
}
return new Date().getTime() - 48 * 60 * 60 * 1000 < timestamp;
}
} }
export const urlManager = new UrlManager(); export const urlManager = new UrlManager();

View File

@ -20,6 +20,10 @@ export const isMapDetailsData = new tg.IsInterface()
}) })
.withOptionalProperties({ .withOptionalProperties({
iframeAuthentication: tg.isNullable(tg.isString), iframeAuthentication: tg.isNullable(tg.isString),
// The date (in ISO 8601 format) at which the room will expire
expireOn: tg.isString,
// Whether the "report" feature is enabled or not on this room
canReport: tg.isBoolean,
}) })
.get(); .get();