External API update (#2111)
* External API update - Remove tags field for map information - Remove room_policy fiels for map information This two paramter will be used directly in the admin * Delete use less updateRoomWithAdminData Signed-off-by: Gregoire Parant <g.parant@thecodingmachine.com> Co-authored-by: David Négrier <d.negrier@thecodingmachine.com>
This commit is contained in:
parent
03edc197d3
commit
f402fea86a
@ -559,11 +559,7 @@ export class GameRoom {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
mapUrl,
|
mapUrl,
|
||||||
policy_type: 1,
|
|
||||||
tags: [],
|
|
||||||
authenticationMandatory: null,
|
authenticationMandatory: null,
|
||||||
roomSlug: null,
|
|
||||||
contactPage: null,
|
|
||||||
group: null,
|
group: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,10 @@ import { z } from "zod";
|
|||||||
|
|
||||||
export const isMapDetailsData = z.object({
|
export const isMapDetailsData = z.object({
|
||||||
mapUrl: z.string(),
|
mapUrl: z.string(),
|
||||||
policy_type: z.number(),
|
|
||||||
tags: z.array(z.string()),
|
|
||||||
authenticationMandatory: z.optional(z.nullable(z.boolean())),
|
authenticationMandatory: z.optional(z.nullable(z.boolean())),
|
||||||
roomSlug: z.nullable(z.string()), // deprecated
|
|
||||||
contactPage: z.nullable(z.string()),
|
|
||||||
group: z.nullable(z.string()),
|
group: z.nullable(z.string()),
|
||||||
|
|
||||||
|
contactPage: z.optional(z.nullable(z.string())),
|
||||||
iframeAuthentication: z.optional(z.nullable(z.string())),
|
iframeAuthentication: z.optional(z.nullable(z.string())),
|
||||||
// The date (in ISO 8601 format) at which the room will expire
|
// The date (in ISO 8601 format) at which the room will expire
|
||||||
expireOn: z.optional(z.string()),
|
expireOn: z.optional(z.string()),
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { ExSocketInterface } from "../Model/Websocket/ExSocketInterface";
|
import { ExSocketInterface } from "../Model/Websocket/ExSocketInterface";
|
||||||
import { GameRoomPolicyTypes } from "../Model/PusherRoom";
|
|
||||||
import { PointInterface } from "../Model/Websocket/PointInterface";
|
import { PointInterface } from "../Model/Websocket/PointInterface";
|
||||||
import {
|
import {
|
||||||
SetPlayerDetailsMessage,
|
SetPlayerDetailsMessage,
|
||||||
@ -296,7 +295,6 @@ export class IoSocketController {
|
|||||||
let memberMessages: unknown;
|
let memberMessages: unknown;
|
||||||
let memberUserRoomToken: string | undefined;
|
let memberUserRoomToken: string | undefined;
|
||||||
let memberTextures: WokaDetail[] = [];
|
let memberTextures: WokaDetail[] = [];
|
||||||
const room = await socketManager.getOrCreateRoom(roomId);
|
|
||||||
let userData: FetchMemberDataByUuidResponse = {
|
let userData: FetchMemberDataByUuidResponse = {
|
||||||
email: userIdentifier,
|
email: userIdentifier,
|
||||||
userUuid: userIdentifier,
|
userUuid: userIdentifier,
|
||||||
@ -359,20 +357,6 @@ export class IoSocketController {
|
|||||||
memberVisitCardUrl = userData.visitCardUrl;
|
memberVisitCardUrl = userData.visitCardUrl;
|
||||||
memberTextures = userData.textures;
|
memberTextures = userData.textures;
|
||||||
memberUserRoomToken = userData.userRoomToken;
|
memberUserRoomToken = userData.userRoomToken;
|
||||||
|
|
||||||
if (
|
|
||||||
room.policyType === GameRoomPolicyTypes.USE_TAGS_POLICY &&
|
|
||||||
(userData.anonymous === true || !room.canAccess(memberTags))
|
|
||||||
) {
|
|
||||||
throw new Error("Insufficient privileges to access this room");
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
room.policyType === GameRoomPolicyTypes.MEMBERS_ONLY_POLICY &&
|
|
||||||
userData.anonymous === true
|
|
||||||
) {
|
|
||||||
throw new Error("Use the login URL to connect");
|
|
||||||
}
|
|
||||||
|
|
||||||
characterLayerObjs = memberTextures;
|
characterLayerObjs = memberTextures;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(
|
console.log(
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { ExSocketInterface } from "../Model/Websocket/ExSocketInterface";
|
import { ExSocketInterface } from "../Model/Websocket/ExSocketInterface";
|
||||||
import { PositionDispatcher } from "./PositionDispatcher";
|
import { PositionDispatcher } from "./PositionDispatcher";
|
||||||
import { ViewportInterface } from "../Model/Websocket/ViewportMessage";
|
import { ViewportInterface } from "../Model/Websocket/ViewportMessage";
|
||||||
import { arrayIntersect } from "../Services/ArrayHelper";
|
|
||||||
import { ZoneEventListener } from "../Model/Zone";
|
import { ZoneEventListener } from "../Model/Zone";
|
||||||
import { apiClientRepository } from "../Services/ApiClientRepository";
|
import { apiClientRepository } from "../Services/ApiClientRepository";
|
||||||
import {
|
import {
|
||||||
@ -24,8 +23,6 @@ export enum GameRoomPolicyTypes {
|
|||||||
|
|
||||||
export class PusherRoom {
|
export class PusherRoom {
|
||||||
private readonly positionNotifier: PositionDispatcher;
|
private readonly positionNotifier: PositionDispatcher;
|
||||||
public tags: string[];
|
|
||||||
public policyType: GameRoomPolicyTypes;
|
|
||||||
private versionNumber: number = 1;
|
private versionNumber: number = 1;
|
||||||
private backConnection!: ClientReadableStream<BatchToPusherRoomMessage>;
|
private backConnection!: ClientReadableStream<BatchToPusherRoomMessage>;
|
||||||
private isClosing: boolean = false;
|
private isClosing: boolean = false;
|
||||||
@ -33,9 +30,6 @@ export class PusherRoom {
|
|||||||
//public readonly variables = new Map<string, string>();
|
//public readonly variables = new Map<string, string>();
|
||||||
|
|
||||||
constructor(public readonly roomUrl: string, private socketListener: ZoneEventListener) {
|
constructor(public readonly roomUrl: string, private socketListener: ZoneEventListener) {
|
||||||
this.tags = [];
|
|
||||||
this.policyType = GameRoomPolicyTypes.ANONYMOUS_POLICY;
|
|
||||||
|
|
||||||
// A zone is 10 sprites wide.
|
// A zone is 10 sprites wide.
|
||||||
this.positionNotifier = new PositionDispatcher(this.roomUrl, 320, 320, this.socketListener);
|
this.positionNotifier = new PositionDispatcher(this.roomUrl, 320, 320, this.socketListener);
|
||||||
}
|
}
|
||||||
@ -53,10 +47,6 @@ export class PusherRoom {
|
|||||||
this.listeners.delete(socket);
|
this.listeners.delete(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public canAccess(userTags: string[]): boolean {
|
|
||||||
return arrayIntersect(userTags, this.tags);
|
|
||||||
}
|
|
||||||
|
|
||||||
public isEmpty(): boolean {
|
public isEmpty(): boolean {
|
||||||
return this.positionNotifier.isEmpty();
|
return this.positionNotifier.isEmpty();
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ export const isFetchMemberDataByUuidResponse = z.object({
|
|||||||
visitCardUrl: z.nullable(z.string()),
|
visitCardUrl: z.nullable(z.string()),
|
||||||
textures: z.array(isWokaDetail),
|
textures: z.array(isWokaDetail),
|
||||||
messages: z.array(z.unknown()),
|
messages: z.array(z.unknown()),
|
||||||
|
|
||||||
anonymous: z.optional(z.boolean()),
|
anonymous: z.optional(z.boolean()),
|
||||||
userRoomToken: z.optional(z.string()),
|
userRoomToken: z.optional(z.string()),
|
||||||
});
|
});
|
||||||
|
@ -42,7 +42,7 @@ import {
|
|||||||
ErrorScreenMessage,
|
ErrorScreenMessage,
|
||||||
} from "../Messages/generated/messages_pb";
|
} from "../Messages/generated/messages_pb";
|
||||||
import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils";
|
import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils";
|
||||||
import { ADMIN_API_URL, JITSI_ISS, JITSI_URL, SECRET_JITSI_KEY } from "../Enum/EnvironmentVariable";
|
import { JITSI_ISS, JITSI_URL, SECRET_JITSI_KEY } from "../Enum/EnvironmentVariable";
|
||||||
import { emitInBatch } from "./IoSocketHelpers";
|
import { emitInBatch } from "./IoSocketHelpers";
|
||||||
import Jwt from "jsonwebtoken";
|
import Jwt from "jsonwebtoken";
|
||||||
import { clientEventsEmitter } from "./ClientEventsEmitter";
|
import { clientEventsEmitter } from "./ClientEventsEmitter";
|
||||||
@ -52,7 +52,6 @@ import { GroupDescriptor, UserDescriptor, ZoneEventListener } from "../Model/Zon
|
|||||||
import Debug from "debug";
|
import Debug from "debug";
|
||||||
import { ExAdminSocketInterface } from "../Model/Websocket/ExAdminSocketInterface";
|
import { ExAdminSocketInterface } from "../Model/Websocket/ExAdminSocketInterface";
|
||||||
import { compressors } from "hyper-express";
|
import { compressors } from "hyper-express";
|
||||||
import { isMapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
|
|
||||||
import { adminService } from "./AdminService";
|
import { adminService } from "./AdminService";
|
||||||
import { ErrorApiData } from "../Messages/JsonMessages/ErrorApiData";
|
import { ErrorApiData } from "../Messages/JsonMessages/ErrorApiData";
|
||||||
import { BoolValue, Int32Value, StringValue } from "google-protobuf/google/protobuf/wrappers_pb";
|
import { BoolValue, Int32Value, StringValue } from "google-protobuf/google/protobuf/wrappers_pb";
|
||||||
@ -455,28 +454,12 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
let room = this.rooms.get(roomUrl);
|
let room = this.rooms.get(roomUrl);
|
||||||
if (room === undefined) {
|
if (room === undefined) {
|
||||||
room = new PusherRoom(roomUrl, this);
|
room = new PusherRoom(roomUrl, this);
|
||||||
if (ADMIN_API_URL) {
|
|
||||||
await this.updateRoomWithAdminData(room);
|
|
||||||
}
|
|
||||||
await room.init();
|
await room.init();
|
||||||
this.rooms.set(roomUrl, room);
|
this.rooms.set(roomUrl, room);
|
||||||
}
|
}
|
||||||
return room;
|
return room;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateRoomWithAdminData(room: PusherRoom): Promise<void> {
|
|
||||||
const data = await adminService.fetchMapDetails(room.roomUrl);
|
|
||||||
const mapDetailsData = isMapDetailsData.safeParse(data);
|
|
||||||
|
|
||||||
if (mapDetailsData.success) {
|
|
||||||
room.tags = mapDetailsData.data.tags;
|
|
||||||
room.policyType = Number(mapDetailsData.data.policy_type);
|
|
||||||
} else {
|
|
||||||
// TODO: if the updated room data is actually a redirect, we need to take everybody on the map
|
|
||||||
// and redirect everybody to the new location (so we need to close the connection for everybody)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public getWorlds(): Map<string, PusherRoom> {
|
public getWorlds(): Map<string, PusherRoom> {
|
||||||
return this.rooms;
|
return this.rooms;
|
||||||
}
|
}
|
||||||
@ -697,8 +680,7 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
const room = this.rooms.get(roomId);
|
const room = this.rooms.get(roomId);
|
||||||
//this function is run for every users connected to the room, so we need to make sure the room wasn't already refreshed.
|
//this function is run for every users connected to the room, so we need to make sure the room wasn't already refreshed.
|
||||||
if (!room || !room.needsUpdate(versionNumber)) return;
|
if (!room || !room.needsUpdate(versionNumber)) return;
|
||||||
|
//TODO check right of user in admin
|
||||||
this.updateRoomWithAdminData(room);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleEmotePromptMessage(client: ExSocketInterface, emoteEventmessage: EmotePromptMessage) {
|
handleEmotePromptMessage(client: ExSocketInterface, emoteEventmessage: EmotePromptMessage) {
|
||||||
|
Loading…
Reference in New Issue
Block a user