Merge branch 'develop' into codeAPI
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import { v4 } from "uuid";
|
||||
import { BaseHttpController } from "./BaseHttpController";
|
||||
import { adminApi, FetchMemberDataByUuidResponse } from "../Services/AdminApi";
|
||||
import { adminApi } from "../Services/AdminApi";
|
||||
import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
|
||||
import { parse } from "query-string";
|
||||
import { openIDClient } from "../Services/OpenIDClient";
|
||||
import { DISABLE_ANONYMOUS } from "../Enum/EnvironmentVariable";
|
||||
import { RegisterData } from "../Messages/JsonMessages/RegisterData";
|
||||
import { adminService } from "../Services/AdminService";
|
||||
|
||||
export interface TokenInterface {
|
||||
userUuid: string;
|
||||
@@ -166,10 +167,11 @@ export class AuthenticateController extends BaseHttpController {
|
||||
|
||||
//Get user data from Admin Back Office
|
||||
//This is very important to create User Local in LocalStorage in WorkAdventure
|
||||
const resUserData = await this.getUserByUserIdentifier(
|
||||
const resUserData = await adminService.fetchMemberDataByUuid(
|
||||
authTokenData.identifier,
|
||||
playUri as string,
|
||||
IPAddress
|
||||
IPAddress,
|
||||
[]
|
||||
);
|
||||
|
||||
if (authTokenData.accessToken == undefined) {
|
||||
@@ -221,7 +223,7 @@ export class AuthenticateController extends BaseHttpController {
|
||||
|
||||
//Get user data from Admin Back Office
|
||||
//This is very important to create User Local in LocalStorage in WorkAdventure
|
||||
const data = await this.getUserByUserIdentifier(email, playUri as string, IPAddress);
|
||||
const data = await adminService.fetchMemberDataByUuid(email, playUri as string, IPAddress, []);
|
||||
|
||||
return res.json({ ...data, authToken, username: userInfo?.username, locale: userInfo?.locale });
|
||||
} catch (e) {
|
||||
@@ -432,34 +434,4 @@ export class AuthenticateController extends BaseHttpController {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param email
|
||||
* @param playUri
|
||||
* @param IPAddress
|
||||
* @return FetchMemberDataByUuidResponse|object
|
||||
* @private
|
||||
*/
|
||||
private async getUserByUserIdentifier(
|
||||
email: string,
|
||||
playUri: string,
|
||||
IPAddress: string
|
||||
): Promise<FetchMemberDataByUuidResponse | object> {
|
||||
let data: FetchMemberDataByUuidResponse = {
|
||||
email: email,
|
||||
userUuid: email,
|
||||
tags: [],
|
||||
messages: [],
|
||||
visitCardUrl: null,
|
||||
textures: [],
|
||||
userRoomToken: undefined,
|
||||
};
|
||||
try {
|
||||
data = await adminApi.fetchMemberDataByUuid(email, playUri, IPAddress, []);
|
||||
} catch (err) {
|
||||
console.error("openIDCallback => fetchMemberDataByUuid", err);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export class DebugController extends BaseHttpController {
|
||||
return obj;
|
||||
} else if (value instanceof Set) {
|
||||
const obj: Array<unknown> = [];
|
||||
for (const [setKey, setValue] of value.entries()) {
|
||||
for (const setValue of value.values()) {
|
||||
obj.push(setValue);
|
||||
}
|
||||
return obj;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ExSocketInterface } from "../Model/Websocket/ExSocketInterface"; //TODO fix import by "_Model/.."
|
||||
import { ExSocketInterface } from "../Model/Websocket/ExSocketInterface";
|
||||
import { GameRoomPolicyTypes } from "../Model/PusherRoom";
|
||||
import { PointInterface } from "../Model/Websocket/PointInterface";
|
||||
import {
|
||||
@@ -27,18 +27,19 @@ import { UserMovesMessage } from "../Messages/generated/messages_pb";
|
||||
import { parse } from "query-string";
|
||||
import { AdminSocketTokenData, jwtTokenManager, tokenInvalidException } from "../Services/JWTTokenManager";
|
||||
import { adminApi, FetchMemberDataByUuidResponse } from "../Services/AdminApi";
|
||||
import { SocketManager, socketManager } from "../Services/SocketManager";
|
||||
import { socketManager } from "../Services/SocketManager";
|
||||
import { emitInBatch } from "../Services/IoSocketHelpers";
|
||||
import { ADMIN_API_URL, ADMIN_SOCKETS_TOKEN, DISABLE_ANONYMOUS, SOCKET_IDLE_TIMER } from "../Enum/EnvironmentVariable";
|
||||
import { Zone } from "_Model/Zone";
|
||||
import { ExAdminSocketInterface } from "_Model/Websocket/ExAdminSocketInterface";
|
||||
import { isAdminMessageInterface } from "../Model/Websocket/Admin/AdminMessages";
|
||||
import { Zone } from "../Model/Zone";
|
||||
import { ExAdminSocketInterface } from "../Model/Websocket/ExAdminSocketInterface";
|
||||
import { AdminMessageInterface, isAdminMessageInterface } from "../Model/Websocket/Admin/AdminMessages";
|
||||
import Axios from "axios";
|
||||
import { InvalidTokenError } from "../Controller/InvalidTokenError";
|
||||
import HyperExpress from "hyper-express";
|
||||
import { localWokaService } from "../Services/LocalWokaService";
|
||||
import { WebSocket } from "uWebSockets.js";
|
||||
import { WokaDetail } from "../Messages/JsonMessages/PlayerTextures";
|
||||
import { z } from "zod";
|
||||
|
||||
/**
|
||||
* The object passed between the "open" and the "upgrade" methods when opening a websocket
|
||||
@@ -96,11 +97,18 @@ export class IoSocketController {
|
||||
console.log("Admin socket connect to client on " + Buffer.from(ws.getRemoteAddressAsText()).toString());
|
||||
ws.disconnecting = false;
|
||||
},
|
||||
message: (ws, arrayBuffer, isBinary): void => {
|
||||
message: (ws, arrayBuffer): void => {
|
||||
try {
|
||||
const message = JSON.parse(new TextDecoder("utf-8").decode(new Uint8Array(arrayBuffer)));
|
||||
const message: AdminMessageInterface = JSON.parse(
|
||||
new TextDecoder("utf-8").decode(new Uint8Array(arrayBuffer))
|
||||
);
|
||||
|
||||
if (!isAdminMessageInterface(message)) {
|
||||
try {
|
||||
isAdminMessageInterface.parse(message);
|
||||
} catch (err) {
|
||||
if (err instanceof z.ZodError) {
|
||||
console.error(err.issues);
|
||||
}
|
||||
console.error("Invalid message received.", message);
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
@@ -186,14 +194,12 @@ export class IoSocketController {
|
||||
.catch((error) => console.error(error));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const tmp: never = message.event;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
},
|
||||
close: (ws, code, message) => {
|
||||
close: (ws) => {
|
||||
const Client = ws as ExAdminSocketInterface;
|
||||
try {
|
||||
Client.disconnecting = true;
|
||||
@@ -224,7 +230,6 @@ export class IoSocketController {
|
||||
upgradeAborted.aborted = true;
|
||||
});
|
||||
|
||||
const url = req.getUrl();
|
||||
const query = parse(req.getQuery());
|
||||
const websocketKey = req.getHeader("sec-websocket-key");
|
||||
const websocketProtocol = req.getHeader("sec-websocket-protocol");
|
||||
@@ -522,7 +527,7 @@ export class IoSocketController {
|
||||
});
|
||||
}
|
||||
},
|
||||
message: (ws, arrayBuffer, isBinary): void => {
|
||||
message: (ws, arrayBuffer): void => {
|
||||
const client = ws as ExSocketInterface;
|
||||
const message = ClientToServerMessage.deserializeBinary(new Uint8Array(arrayBuffer));
|
||||
|
||||
@@ -590,7 +595,7 @@ export class IoSocketController {
|
||||
drain: (ws) => {
|
||||
console.log("WebSocket backpressure: " + ws.getBufferedAmount());
|
||||
},
|
||||
close: (ws, code, message) => {
|
||||
close: (ws) => {
|
||||
const Client = ws as ExSocketInterface;
|
||||
try {
|
||||
Client.disconnecting = true;
|
||||
|
||||
@@ -160,9 +160,11 @@ export class MapController extends BaseHttpController {
|
||||
}
|
||||
}
|
||||
}
|
||||
const mapDetails = await adminApi.fetchMapDetails(query.playUri as string, userId);
|
||||
const mapDetails = isMapDetailsData.parse(
|
||||
await adminApi.fetchMapDetails(query.playUri as string, userId)
|
||||
);
|
||||
|
||||
if (isMapDetailsData(mapDetails) && DISABLE_ANONYMOUS) {
|
||||
if (DISABLE_ANONYMOUS) {
|
||||
mapDetails.authenticationMandatory = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user