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

This commit is contained in:
_Bastler 2021-12-20 17:14:18 +01:00
commit d03e1b3536
4 changed files with 33 additions and 9 deletions

View File

@ -251,7 +251,12 @@ const roomManager: IRoomManagerServer = {
},
sendAdminMessage(call: ServerUnaryCall<AdminMessage>, callback: sendUnaryData<EmptyMessage>): void {
socketManager
.sendAdminMessage(call.request.getRoomid(), call.request.getRecipientuuid(), call.request.getMessage())
.sendAdminMessage(
call.request.getRoomid(),
call.request.getRecipientuuid(),
call.request.getMessage(),
call.request.getType()
)
.catch((e) => console.error(e));
callback(null, new EmptyMessage());

View File

@ -691,7 +691,7 @@ export class SocketManager {
}
}
public async sendAdminMessage(roomId: string, recipientUuid: string, message: string): Promise<void> {
public async sendAdminMessage(roomId: string, recipientUuid: string, message: string, type: string): Promise<void> {
const room = await this.roomsPromises.get(roomId);
if (!room) {
console.error(
@ -715,7 +715,7 @@ export class SocketManager {
for (const recipient of recipients) {
const sendUserMessage = new SendUserMessage();
sendUserMessage.setMessage(message);
sendUserMessage.setType("ban"); //todo: is the type correct?
sendUserMessage.setType(type);
const serverToClientMessage = new ServerToClientMessage();
serverToClientMessage.setSendusermessage(sendUserMessage);

View File

@ -1,5 +1,5 @@
import { CharacterLayer, ExSocketInterface } from "../Model/Websocket/ExSocketInterface"; //TODO fix import by "_Model/.."
import { GameRoomPolicyTypes } from "../Model/PusherRoom";
import { GameRoomPolicyTypes, PusherRoom } from "../Model/PusherRoom";
import { PointInterface } from "../Model/Websocket/PointInterface";
import {
SetPlayerDetailsMessage,
@ -273,6 +273,7 @@ export class IoSocketController {
rejected: true,
message: err?.response?.data.message,
status: err?.response?.status,
roomId,
},
websocketKey,
websocketProtocol,
@ -367,6 +368,7 @@ export class IoSocketController {
rejected: true,
reason: e instanceof InvalidTokenError ? tokenInvalidException : null,
message: e.message,
roomId,
},
websocketKey,
websocketProtocol,
@ -379,6 +381,7 @@ export class IoSocketController {
rejected: true,
reason: null,
message: "500 Internal Server Error",
roomId,
},
websocketKey,
websocketProtocol,
@ -392,6 +395,11 @@ export class IoSocketController {
/* Handlers */
open: (ws) => {
if (ws.rejected === true) {
// If there is a room in the error, let's check if we need to clean it.
if (ws.roomId) {
socketManager.deleteRoomIfEmptyFromId(ws.roomId as string);
}
//FIX ME to use status code
if (ws.reason === tokenInvalidException) {
socketManager.emitTokenExpiredMessage(ws);

View File

@ -359,11 +359,7 @@ export class SocketManager implements ZoneEventListener {
debug("Leaving room %s.", socket.roomId);
room.leave(socket);
if (room.isEmpty()) {
room.close();
this.rooms.delete(socket.roomId);
debug("Room %s is empty. Deleting.", socket.roomId);
}
this.deleteRoomIfEmpty(room);
} else {
console.error("Could not find the GameRoom the user is leaving!");
}
@ -382,6 +378,21 @@ export class SocketManager implements ZoneEventListener {
}
}
private deleteRoomIfEmpty(room: PusherRoom): void {
if (room.isEmpty()) {
room.close();
this.rooms.delete(room.roomUrl);
debug("Room %s is empty. Deleting.", room.roomUrl);
}
}
public deleteRoomIfEmptyFromId(roomUrl: string): void {
const room = this.rooms.get(roomUrl);
if (room) {
this.deleteRoomIfEmpty(room);
}
}
async getOrCreateRoom(roomUrl: string): Promise<PusherRoom> {
//check and create new world for a room
let room = this.rooms.get(roomUrl);