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:
grégoire parant 2022-04-25 11:00:01 +02:00 committed by GitHub
parent 03edc197d3
commit f402fea86a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 4 additions and 54 deletions

View File

@ -559,11 +559,7 @@ export class GameRoom {
return {
mapUrl,
policy_type: 1,
tags: [],
authenticationMandatory: null,
roomSlug: null,
contactPage: null,
group: null,
};
}

View File

@ -7,13 +7,10 @@ import { z } from "zod";
export const isMapDetailsData = z.object({
mapUrl: z.string(),
policy_type: z.number(),
tags: z.array(z.string()),
authenticationMandatory: z.optional(z.nullable(z.boolean())),
roomSlug: z.nullable(z.string()), // deprecated
contactPage: z.nullable(z.string()),
group: z.nullable(z.string()),
contactPage: 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
expireOn: z.optional(z.string()),

View File

@ -1,5 +1,4 @@
import { ExSocketInterface } from "../Model/Websocket/ExSocketInterface";
import { GameRoomPolicyTypes } from "../Model/PusherRoom";
import { PointInterface } from "../Model/Websocket/PointInterface";
import {
SetPlayerDetailsMessage,
@ -296,7 +295,6 @@ export class IoSocketController {
let memberMessages: unknown;
let memberUserRoomToken: string | undefined;
let memberTextures: WokaDetail[] = [];
const room = await socketManager.getOrCreateRoom(roomId);
let userData: FetchMemberDataByUuidResponse = {
email: userIdentifier,
userUuid: userIdentifier,
@ -359,20 +357,6 @@ export class IoSocketController {
memberVisitCardUrl = userData.visitCardUrl;
memberTextures = userData.textures;
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;
} catch (e) {
console.log(

View File

@ -1,7 +1,6 @@
import { ExSocketInterface } from "../Model/Websocket/ExSocketInterface";
import { PositionDispatcher } from "./PositionDispatcher";
import { ViewportInterface } from "../Model/Websocket/ViewportMessage";
import { arrayIntersect } from "../Services/ArrayHelper";
import { ZoneEventListener } from "../Model/Zone";
import { apiClientRepository } from "../Services/ApiClientRepository";
import {
@ -24,8 +23,6 @@ export enum GameRoomPolicyTypes {
export class PusherRoom {
private readonly positionNotifier: PositionDispatcher;
public tags: string[];
public policyType: GameRoomPolicyTypes;
private versionNumber: number = 1;
private backConnection!: ClientReadableStream<BatchToPusherRoomMessage>;
private isClosing: boolean = false;
@ -33,9 +30,6 @@ export class PusherRoom {
//public readonly variables = new Map<string, string>();
constructor(public readonly roomUrl: string, private socketListener: ZoneEventListener) {
this.tags = [];
this.policyType = GameRoomPolicyTypes.ANONYMOUS_POLICY;
// A zone is 10 sprites wide.
this.positionNotifier = new PositionDispatcher(this.roomUrl, 320, 320, this.socketListener);
}
@ -53,10 +47,6 @@ export class PusherRoom {
this.listeners.delete(socket);
}
public canAccess(userTags: string[]): boolean {
return arrayIntersect(userTags, this.tags);
}
public isEmpty(): boolean {
return this.positionNotifier.isEmpty();
}

View File

@ -22,6 +22,7 @@ export const isFetchMemberDataByUuidResponse = z.object({
visitCardUrl: z.nullable(z.string()),
textures: z.array(isWokaDetail),
messages: z.array(z.unknown()),
anonymous: z.optional(z.boolean()),
userRoomToken: z.optional(z.string()),
});

View File

@ -42,7 +42,7 @@ import {
ErrorScreenMessage,
} from "../Messages/generated/messages_pb";
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 Jwt from "jsonwebtoken";
import { clientEventsEmitter } from "./ClientEventsEmitter";
@ -52,7 +52,6 @@ import { GroupDescriptor, UserDescriptor, ZoneEventListener } from "../Model/Zon
import Debug from "debug";
import { ExAdminSocketInterface } from "../Model/Websocket/ExAdminSocketInterface";
import { compressors } from "hyper-express";
import { isMapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
import { adminService } from "./AdminService";
import { ErrorApiData } from "../Messages/JsonMessages/ErrorApiData";
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);
if (room === undefined) {
room = new PusherRoom(roomUrl, this);
if (ADMIN_API_URL) {
await this.updateRoomWithAdminData(room);
}
await room.init();
this.rooms.set(roomUrl, 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> {
return this.rooms;
}
@ -697,8 +680,7 @@ export class SocketManager implements ZoneEventListener {
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.
if (!room || !room.needsUpdate(versionNumber)) return;
this.updateRoomWithAdminData(room);
//TODO check right of user in admin
}
handleEmotePromptMessage(client: ExSocketInterface, emoteEventmessage: EmotePromptMessage) {