Merge branch 'develop' of github.com:thecodingmachine/workadventure into HotFixCleanTokenParamUrl

# Conflicts:
#	back/src/Services/Logger.ts
This commit is contained in:
David Négrier 2021-11-24 17:03:29 +01:00
commit 94959e2e91
37 changed files with 162 additions and 542 deletions

View file

@ -27,7 +27,6 @@ import { ADMIN_API_URL } from "../Enum/EnvironmentVariable";
import { LocalUrlError } from "../Services/LocalUrlError";
import { emitErrorOnRoomSocket } from "../Services/MessageHelpers";
import { VariableError } from "../Services/VariableError";
import log from "../Services/Logger";
export type ConnectCallback = (user: User, group: Group) => void;
export type DisconnectCallback = (user: User, group: Group) => void;
@ -153,7 +152,7 @@ export class GameRoom {
public leave(user: User) {
const userObj = this.users.get(user.id);
if (userObj === undefined) {
log.warn("User ", user.id, "does not belong to this game room! It should!");
console.warn("User ", user.id, "does not belong to this game room! It should!");
}
if (userObj !== undefined && typeof userObj.group !== "undefined") {
this.leaveGroup(userObj);
@ -445,7 +444,7 @@ export class GameRoom {
const match = /\/_\/[^/]+\/(.+)/.exec(roomUrlObj.pathname);
if (!match) {
log.error("Unexpected room URL", roomUrl);
console.error("Unexpected room URL", roomUrl);
throw new Error('Unexpected room URL "' + roomUrl + '"');
}
@ -461,7 +460,7 @@ export class GameRoom {
const result = await adminApi.fetchMapDetails(roomUrl);
if (!isMapDetailsData(result)) {
log.error("Unexpected room details received from server", result);
console.error("Unexpected room details received from server", result);
throw new Error("Unexpected room details received from server");
}
return result;
@ -520,9 +519,7 @@ export class GameRoom {
for (const roomListener of this.roomListeners) {
emitErrorOnRoomSocket(
roomListener,
"Your map '" +
this.mapUrl +
"' does not seem accessible from the WorkAdventure servers. Is it behind a firewall or a proxy? Your map should be accessible from the WorkAdventure servers. If you use the scripting API in this map, please be aware that server-side checks and variable persistence is disabled."
"Your map does not seem accessible from the WorkAdventure servers. Is it behind a firewall or a proxy? Your map should be accessible from the WorkAdventure servers. If you use the scripting API in this map, please be aware that server-side checks and variable persistence is disabled."
);
}
}, 1000);

View file

@ -31,7 +31,6 @@ import { User, UserSocket } from "./Model/User";
import { GameRoom } from "./Model/GameRoom";
import Debug from "debug";
import { Admin } from "./Model/Admin";
import log from "./Services/Logger";
const debug = Debug("roommanager");
@ -41,7 +40,7 @@ export type RoomSocket = ServerWritableStream<RoomMessage, BatchToPusherRoomMess
const roomManager: IRoomManagerServer = {
joinRoom: (call: UserSocket): void => {
log.info("joinRoom called");
console.log("joinRoom called");
let room: GameRoom | null = null;
let user: User | null = null;
@ -132,11 +131,11 @@ const roomManager: IRoomManagerServer = {
}
}
} catch (e) {
log.error(e);
console.error(e);
emitError(call, e);
call.end();
}
})().catch((e) => log.error(e));
})().catch((e) => console.error(e));
});
call.on("end", () => {
@ -150,7 +149,7 @@ const roomManager: IRoomManagerServer = {
});
call.on("error", (err: Error) => {
log.error("An error occurred in joinRoom stream:", err);
console.error("An error occurred in joinRoom stream:", err);
});
},
@ -168,7 +167,7 @@ const roomManager: IRoomManagerServer = {
debug("listenZone cancelled");
socketManager
.removeZoneListener(call, zoneMessage.getRoomid(), zoneMessage.getX(), zoneMessage.getY())
.catch((e) => log.error(e));
.catch((e) => console.error(e));
call.end();
});
@ -176,12 +175,12 @@ const roomManager: IRoomManagerServer = {
debug("listenZone connection closed");
socketManager
.removeZoneListener(call, zoneMessage.getRoomid(), zoneMessage.getX(), zoneMessage.getY())
.catch((e) => log.error(e));
.catch((e) => console.error(e));
}).on("error", (e) => {
log.error("An error occurred in listenZone stream:", e);
console.error("An error occurred in listenZone stream:", e);
socketManager
.removeZoneListener(call, zoneMessage.getRoomid(), zoneMessage.getX(), zoneMessage.getY())
.catch((e) => log.error(e));
.catch((e) => console.error(e));
call.end();
});
},
@ -196,22 +195,22 @@ const roomManager: IRoomManagerServer = {
call.on("cancelled", () => {
debug("listenRoom cancelled");
socketManager.removeRoomListener(call, roomMessage.getRoomid()).catch((e) => log.error(e));
socketManager.removeRoomListener(call, roomMessage.getRoomid()).catch((e) => console.error(e));
call.end();
});
call.on("close", () => {
debug("listenRoom connection closed");
socketManager.removeRoomListener(call, roomMessage.getRoomid()).catch((e) => log.error(e));
socketManager.removeRoomListener(call, roomMessage.getRoomid()).catch((e) => console.error(e));
}).on("error", (e) => {
log.error("An error occurred in listenRoom stream:", e);
socketManager.removeRoomListener(call, roomMessage.getRoomid()).catch((e) => log.error(e));
console.error("An error occurred in listenRoom stream:", e);
socketManager.removeRoomListener(call, roomMessage.getRoomid()).catch((e) => console.error(e));
call.end();
});
},
adminRoom(call: AdminSocket): void {
log.info("adminRoom called");
console.log("adminRoom called");
const admin = new Admin(call);
let room: GameRoom | null = null;
@ -226,7 +225,7 @@ const roomManager: IRoomManagerServer = {
.then((gameRoom: GameRoom) => {
room = gameRoom;
})
.catch((e) => log.error(e));
.catch((e) => console.error(e));
} else {
throw new Error("The first message sent MUST be of type JoinRoomMessage");
}
@ -247,13 +246,13 @@ const roomManager: IRoomManagerServer = {
});
call.on("error", (err: Error) => {
log.error("An error occurred in joinAdminRoom stream:", err);
console.error("An error occurred in joinAdminRoom stream:", err);
});
},
sendAdminMessage(call: ServerUnaryCall<AdminMessage>, callback: sendUnaryData<EmptyMessage>): void {
socketManager
.sendAdminMessage(call.request.getRoomid(), call.request.getRecipientuuid(), call.request.getMessage())
.catch((e) => log.error(e));
.catch((e) => console.error(e));
callback(null, new EmptyMessage());
},
@ -266,7 +265,7 @@ const roomManager: IRoomManagerServer = {
// FIXME Work in progress
socketManager
.banUser(call.request.getRoomid(), call.request.getRecipientuuid(), call.request.getMessage())
.catch((e) => log.error(e));
.catch((e) => console.error(e));
callback(null, new EmptyMessage());
},
@ -274,7 +273,7 @@ const roomManager: IRoomManagerServer = {
// FIXME: we could improve return message by returning a Success|ErrorMessage message
socketManager
.sendAdminRoomMessage(call.request.getRoomid(), call.request.getMessage(), call.request.getType())
.catch((e) => log.error(e));
.catch((e) => console.error(e));
callback(null, new EmptyMessage());
},
sendWorldFullWarningToRoom(
@ -282,7 +281,7 @@ const roomManager: IRoomManagerServer = {
callback: sendUnaryData<EmptyMessage>
): void {
// FIXME: we could improve return message by returning a Success|ErrorMessage message
socketManager.dispatchWorldFullWarning(call.request.getRoomid()).catch((e) => log.error(e));
socketManager.dispatchWorldFullWarning(call.request.getRoomid()).catch((e) => console.error(e));
callback(null, new EmptyMessage());
},
sendRefreshRoomPrompt(
@ -290,7 +289,7 @@ const roomManager: IRoomManagerServer = {
callback: sendUnaryData<EmptyMessage>
): void {
// FIXME: we could improve return message by returning a Success|ErrorMessage message
socketManager.dispatchRoomRefresh(call.request.getRoomid()).catch((e) => log.error(e));
socketManager.dispatchRoomRefresh(call.request.getRoomid()).catch((e) => console.error(e));
callback(null, new EmptyMessage());
},
};

View file

@ -2,7 +2,6 @@ import { createWriteStream } from "fs";
import { join, dirname } from "path";
import Busboy from "busboy";
import mkdirp from "mkdirp";
import log from "../../Services/Logger";
function formData(
contType: string,
@ -20,7 +19,7 @@ function formData(
filename?: (oldName: string) => string;
} = {}
) {
log.info("Enter form data");
console.log("Enter form data");
options.headers = {
"content-type": contType,
};
@ -48,10 +47,7 @@ function formData(
if (typeof options.tmpDir === "string") {
if (typeof options.filename === "function") filename = options.filename(filename);
const fileToSave = join(options.tmpDir, filename);
mkdirp(dirname(fileToSave)).then(
() => {},
() => {}
);
mkdirp(dirname(fileToSave));
file.pipe(createWriteStream(fileToSave));
value.filePath = fileToSave;

View file

@ -1,5 +1,4 @@
import { CPU_OVERHEAT_THRESHOLD } from "../Enum/EnvironmentVariable";
import log from "./Logger";
function secNSec2ms(secNSec: Array<number> | number) {
if (Array.isArray(secNSec)) {
@ -29,16 +28,16 @@ class CpuTracker {
if (!this.overHeating && this.cpuPercent > CPU_OVERHEAT_THRESHOLD) {
this.overHeating = true;
log.warn('CPU high threshold alert. Going in "overheat" mode');
console.warn('CPU high threshold alert. Going in "overheat" mode');
} else if (this.overHeating && this.cpuPercent <= CPU_OVERHEAT_THRESHOLD) {
this.overHeating = false;
log.info('CPU is back to normal. Canceling "overheat" mode');
console.log('CPU is back to normal. Canceling "overheat" mode');
}
/*log.info('elapsed time ms: ', elapTimeMS)
log.info('elapsed user ms: ', elapUserMS)
log.info('elapsed system ms:', elapSystMS)
log.info('cpu percent: ', this.cpuPercent)*/
/*console.log('elapsed time ms: ', elapTimeMS)
console.log('elapsed user ms: ', elapUserMS)
console.log('elapsed system ms:', elapSystMS)
console.log('cpu percent: ', this.cpuPercent)*/
}, 100);
}

View file

@ -1,16 +0,0 @@
import * as winston from "winston";
const logger = winston.createLogger({
transports: [
new winston.transports.Console({
format: winston.format.combine(
//winston.format.colorize(),
winston.format.timestamp(),
winston.format.align(),
winston.format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`)
),
}),
],
});
export default logger;

View file

@ -6,7 +6,6 @@ import { LocalUrlError } from "./LocalUrlError";
import { ITiledMap } from "@workadventure/tiled-map-type-guard";
import { isTiledMap } from "@workadventure/tiled-map-type-guard/dist";
import { STORE_VARIABLES_FOR_LOCAL_MAPS } from "../Enum/EnvironmentVariable";
import log from "./Logger";
class MapFetcher {
async fetchMap(mapUrl: string): Promise<ITiledMap> {
@ -31,7 +30,7 @@ class MapFetcher {
if (!isTiledMap(res.data)) {
//TODO fixme
//throw new Error("Invalid map format for map " + mapUrl);
log.error("Invalid map format for map " + mapUrl);
console.error("Invalid map format for map " + mapUrl);
}
return res.data;

View file

@ -9,7 +9,6 @@ import {
} from "../Messages/generated/messages_pb";
import { UserSocket } from "_Model/User";
import { RoomSocket, ZoneSocket } from "../RoomManager";
import log from "./Logger";
export function emitError(Client: UserSocket, message: string): void {
const errorMessage = new ErrorMessage();
@ -21,11 +20,11 @@ export function emitError(Client: UserSocket, message: string): void {
//if (!Client.disconnecting) {
Client.write(serverToClientMessage);
//}
log.warn(message);
console.warn(message);
}
export function emitErrorOnRoomSocket(Client: RoomSocket, message: string): void {
log.error(message);
console.error(message);
const errorMessage = new ErrorMessage();
errorMessage.setMessage(message);
@ -39,11 +38,11 @@ export function emitErrorOnRoomSocket(Client: RoomSocket, message: string): void
//if (!Client.disconnecting) {
Client.write(batchToPusherMessage);
//}
log.warn(message);
console.warn(message);
}
export function emitErrorOnZoneSocket(Client: ZoneSocket, message: string): void {
log.error(message);
console.error(message);
const errorMessage = new ErrorMessage();
errorMessage.setMessage(message);
@ -57,5 +56,5 @@ export function emitErrorOnZoneSocket(Client: ZoneSocket, message: string): void
//if (!Client.disconnecting) {
Client.write(batchToPusherMessage);
//}
log.warn(message);
console.warn(message);
}

View file

@ -1,6 +1,5 @@
import { ClientOpts, createClient, RedisClient } from "redis";
import { REDIS_HOST, REDIS_PASSWORD, REDIS_PORT } from "../Enum/EnvironmentVariable";
import log from "./Logger";
let redisClient: RedisClient | null = null;
@ -17,7 +16,7 @@ if (REDIS_HOST !== undefined) {
redisClient = createClient(config);
redisClient.on("error", (err) => {
log.error("Error connecting to Redis:", err);
console.error("Error connecting to Redis:", err);
});
}

View file

@ -2,11 +2,10 @@ import { RedisVariablesRepository } from "./RedisVariablesRepository";
import { redisClient } from "../RedisClient";
import { VoidVariablesRepository } from "./VoidVariablesRepository";
import { VariablesRepositoryInterface } from "./VariablesRepositoryInterface";
import log from "../../Services/Logger";
let variablesRepository: VariablesRepositoryInterface;
if (!redisClient) {
log.warn("WARNING: Redis isnot configured. No variables will be persisted.");
console.warn("WARNING: Redis isnot configured. No variables will be persisted.");
variablesRepository = new VoidVariablesRepository();
} else {
variablesRepository = new RedisVariablesRepository(redisClient);

View file

@ -56,7 +56,6 @@ import { Zone } from "_Model/Zone";
import Debug from "debug";
import { Admin } from "_Model/Admin";
import crypto from "crypto";
import log from "./Logger";
const debug = Debug("sockermanager");
@ -90,7 +89,7 @@ export class SocketManager {
const { room, user } = await this.joinRoom(socket, joinRoomMessage);
if (!socket.writable) {
log.warn("Socket was aborted");
console.warn("Socket was aborted");
return {
room,
user,
@ -157,7 +156,7 @@ export class SocketManager {
name: playerDetailsMessage.getName(),
characterLayers: playerDetailsMessage.getCharacterlayersList()
};
//log.info(SocketIoEvent.SET_PLAYER_DETAILS, playerDetails);
//console.log(SocketIoEvent.SET_PLAYER_DETAILS, playerDetails);
if (!isSetPlayerDetailsMessage(playerDetails)) {
emitError(client, 'Invalid SET_PLAYER_DETAILS message received: ');
return;
@ -193,7 +192,7 @@ export class SocketManager {
//send only at user
const remoteUser = room.getUsers().get(data.getReceiverid());
if (remoteUser === undefined) {
log.warn(
console.warn(
"While exchanging a WebRTC signal: client with id ",
data.getReceiverid(),
" does not exist. This might be a race condition."
@ -223,7 +222,7 @@ export class SocketManager {
//send only at user
const remoteUser = room.getUsers().get(data.getReceiverid());
if (remoteUser === undefined) {
log.warn(
console.warn(
"While exchanging a WEBRTC_SCREEN_SHARING signal: client with id ",
data.getReceiverid(),
" does not exist. This might be a race condition."
@ -261,7 +260,7 @@ export class SocketManager {
}
} finally {
clientEventsEmitter.emitClientLeave(user.uuid, room.roomUrl);
log.info("A user left");
console.log("A user left");
}
}
@ -309,7 +308,7 @@ export class SocketManager {
const user = room.join(socket, joinRoomMessage);
clientEventsEmitter.emitClientJoin(user.uuid, roomId);
log.info(new Date().toISOString() + " user '" + user.uuid + "' joined room '" + roomId + "'");
console.log(new Date().toISOString() + " A user joined");
return { room, user };
}
@ -338,7 +337,7 @@ export class SocketManager {
} else if (thing instanceof Group) {
this.emitCreateUpdateGroupEvent(listener, fromZone, thing);
} else {
log.error("Unexpected type for Movable.");
console.error("Unexpected type for Movable.");
}
}
@ -353,11 +352,11 @@ export class SocketManager {
emitZoneMessage(subMessage, listener);
//listener.emitInBatch(subMessage);
//log.info("Sending USER_MOVED event");
//console.log("Sending USER_MOVED event");
} else if (thing instanceof Group) {
this.emitCreateUpdateGroupEvent(listener, null, thing);
} else {
log.error("Unexpected type for Movable.");
console.error("Unexpected type for Movable.");
}
}
@ -367,7 +366,7 @@ export class SocketManager {
} else if (thing instanceof Group) {
this.emitDeleteGroupEvent(listener, thing.getId(), newZone);
} else {
log.error("Unexpected type for Movable.");
console.error("Unexpected type for Movable.");
}
}
@ -636,7 +635,7 @@ export class SocketManager {
batchMessage.addPayload(subMessage);
} else {
log.error("Unexpected type for Movable returned by setViewport");
console.error("Unexpected type for Movable returned by setViewport");
}
}
@ -694,7 +693,7 @@ export class SocketManager {
public async sendAdminMessage(roomId: string, recipientUuid: string, message: string): Promise<void> {
const room = await this.roomsPromises.get(roomId);
if (!room) {
log.error(
console.error(
"In sendAdminMessage, could not find room with id '" +
roomId +
"'. Maybe the room was closed a few milliseconds ago and there was a race condition?"
@ -704,7 +703,7 @@ export class SocketManager {
const recipients = room.getUsersByUuid(recipientUuid);
if (recipients.length === 0) {
log.error(
console.error(
"In sendAdminMessage, could not find user with id '" +
recipientUuid +
"'. Maybe the user left the room a few milliseconds ago and there was a race condition?"
@ -727,7 +726,7 @@ export class SocketManager {
public async banUser(roomId: string, recipientUuid: string, message: string): Promise<void> {
const room = await this.roomsPromises.get(roomId);
if (!room) {
log.error(
console.error(
"In banUser, could not find room with id '" +
roomId +
"'. Maybe the room was closed a few milliseconds ago and there was a race condition?"
@ -737,7 +736,7 @@ export class SocketManager {
const recipients = room.getUsersByUuid(recipientUuid);
if (recipients.length === 0) {
log.error(
console.error(
"In banUser, could not find user with id '" +
recipientUuid +
"'. Maybe the user left the room a few milliseconds ago and there was a race condition?"
@ -766,7 +765,7 @@ export class SocketManager {
const room = await this.roomsPromises.get(roomId);
if (!room) {
//todo: this should cause the http call to return a 500
log.error(
console.error(
"In sendAdminRoomMessage, could not find room with id '" +
roomId +
"'. Maybe the room was closed a few milliseconds ago and there was a race condition?"
@ -790,7 +789,7 @@ export class SocketManager {
const room = await this.roomsPromises.get(roomId);
if (!room) {
//todo: this should cause the http call to return a 500
log.error(
console.error(
"In dispatchWorldFullWarning, could not find room with id '" +
roomId +
"'. Maybe the room was closed a few milliseconds ago and there was a race condition?"

View file

@ -11,7 +11,6 @@ import { User } from "_Model/User";
import { variablesRepository } from "./Repository/VariablesRepository";
import { redisClient } from "./RedisClient";
import { VariableError } from "./VariableError";
import log from "./Logger";
interface Variable {
defaultValue?: string;
@ -100,7 +99,7 @@ export class VariablesManager {
for (const object of layer.objects) {
if (object.type === "variable") {
if (object.template) {
log.warn(
console.warn(
'Warning, a variable object is using a Tiled "template". WorkAdventure does not support objects generated from Tiled templates.'
);
continue;
@ -208,7 +207,7 @@ export class VariablesManager {
if (variableObject !== undefined && variableObject.persist) {
variablesRepository
.saveVariable(this.roomUrl, name, value)
.catch((e) => log.error("Error while saving variable in Redis:", e));
.catch((e) => console.error("Error while saving variable in Redis:", e));
}
return readableBy;