Merge pull request #1703 from thecodingmachine/2daysLimit_stupid_front

2 days limit improvements
This commit is contained in:
David Négrier 2022-01-05 16:36:57 +01:00 committed by GitHub
commit d24e074fbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 31 deletions

View File

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

View File

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

View File

@ -18,7 +18,10 @@ export interface RoomRedirect {
export class Room {
public readonly id: string;
public readonly isPublic: boolean;
/**
* @deprecated
*/
private readonly isPublic: boolean;
private _authenticationMandatory: boolean = DISABLE_ANONYMOUS;
private _iframeAuthentication?: string = OPID_LOGIN_SCREEN_PROVIDER;
private _mapUrl: string | undefined;
@ -27,6 +30,8 @@ export class Room {
private readonly _search: URLSearchParams;
private _contactPage: string | undefined;
private _group: string | null = null;
private _expireOn: Date | undefined;
private _canReport: boolean = false;
private constructor(private roomUrl: URL) {
this.id = roomUrl.pathname;
@ -121,6 +126,10 @@ export class Room {
data.authenticationMandatory != null ? data.authenticationMandatory : DISABLE_ANONYMOUS;
this._iframeAuthentication = data.iframeAuthentication || OPID_LOGIN_SCREEN_PROVIDER;
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);
} else {
throw new Error("Data received by the /map endpoint of the Pusher is not in a valid format.");
@ -143,6 +152,8 @@ export class Room {
* Instance name is:
* - In a public URL: the second part of the URL ( _/[instance]/map.json)
* - In a private URL: [organizationId/worldId]
*
* @deprecated
*/
public getInstance(): string {
if (this.instance !== undefined) {
@ -222,4 +233,12 @@ export class Room {
get group(): string | null {
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";
export enum GameConnexionTypes {
anonymous = 1,
organization,
room = 1,
register,
empty,
unknown,
jwt,
login,
limit,
}
//this class is responsible with analysing and editing the game's url
@ -20,12 +18,8 @@ class UrlManager {
return GameConnexionTypes.login;
} else if (url === "/jwt") {
return GameConnexionTypes.jwt;
} else if (url.includes("*/")) {
return GameConnexionTypes.limit;
} else if (url.includes("_/")) {
return GameConnexionTypes.anonymous;
} else if (url.includes("@/")) {
return GameConnexionTypes.organization;
} else if (url.includes("_/") || url.includes("*/") || url.includes("@/")) {
return GameConnexionTypes.room;
} else if (url.includes("register/")) {
return GameConnexionTypes.register;
} else if (url === "/") {
@ -58,15 +52,6 @@ class UrlManager {
pushStartLayerNameToUrl(startLayerName: string): void {
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();

View File

@ -20,6 +20,10 @@ export const isMapDetailsData = new tg.IsInterface()
})
.withOptionalProperties({
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();