Merge branch 'develop' of github.com:thecodingmachine/workadventure
This commit is contained in:
commit
d03e1b3536
@ -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());
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user