Merge branch 'develop' of github.com:thecodingmachine/workadventure into codeAPI
This commit is contained in:
@@ -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,10 +160,12 @@ export class MapController extends BaseHttpController {
|
||||
}
|
||||
}
|
||||
}
|
||||
const mapDetails = await adminApi.fetchMapDetails(query.playUri as string, userId);
|
||||
const mapDetails = isMapDetailsData.safeParse(
|
||||
await adminApi.fetchMapDetails(query.playUri as string, userId)
|
||||
);
|
||||
|
||||
if (isMapDetailsData(mapDetails) && DISABLE_ANONYMOUS) {
|
||||
mapDetails.authenticationMandatory = true;
|
||||
if (mapDetails.success && DISABLE_ANONYMOUS) {
|
||||
mapDetails.data.authenticationMandatory = true;
|
||||
}
|
||||
|
||||
res.json(mapDetails);
|
||||
|
||||
Reference in New Issue
Block a user