WIP: how to respond to too many users
This commit is contained in:
parent
664e699fd3
commit
326c2e4183
5 changed files with 61 additions and 12 deletions
|
@ -163,8 +163,8 @@ export class IoSocketController {
|
|||
let memberTags: string[] = [];
|
||||
let memberTextures: CharacterTexture[] = [];
|
||||
const room = await socketManager.getOrCreateRoom(roomId);
|
||||
if (room.getUsers().size > MAX_USERS_PER_ROOM) {
|
||||
res.writeStatus("302").end('Too many users');
|
||||
if (room.isFull()) {
|
||||
res.writeStatus("503").end('Too many users');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
|
|
@ -4,6 +4,7 @@ import {HttpRequest, HttpResponse, TemplatedApp} from "uWebSockets.js";
|
|||
import {BaseController} from "./BaseController";
|
||||
import {parse} from "query-string";
|
||||
import {adminApi} from "../Services/AdminApi";
|
||||
import {socketManager} from "../Services/SocketManager";
|
||||
|
||||
//todo: delete this
|
||||
export class MapController extends BaseController{
|
||||
|
@ -12,6 +13,7 @@ export class MapController extends BaseController{
|
|||
super();
|
||||
this.App = App;
|
||||
this.getMapUrl();
|
||||
this.canConnectToMap();
|
||||
}
|
||||
|
||||
|
||||
|
@ -67,4 +69,23 @@ export class MapController extends BaseController{
|
|||
|
||||
});
|
||||
}
|
||||
|
||||
canConnectToMap() {
|
||||
this.App.options("/canjoin", (res: HttpResponse, req: HttpRequest) => {
|
||||
this.addCorsHeaders(res);
|
||||
|
||||
res.end();
|
||||
});
|
||||
|
||||
this.App.get("/canjoin", (res: HttpResponse, req: HttpRequest) => {
|
||||
const query = parse(req.getQuery());
|
||||
const roomId = query.roomId as string;
|
||||
const world = socketManager.getWorlds().get(roomId);
|
||||
if (!world) {
|
||||
res.writeStatus('404').end('No room found');
|
||||
return;
|
||||
}
|
||||
res.writeStatus("200").end(world.isFull() ? '1':'0');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import {ViewportInterface} from "_Model/Websocket/ViewportMessage";
|
|||
import {Movable} from "_Model/Movable";
|
||||
import {extractDataFromPrivateRoomId, extractRoomSlugPublicRoomId, isRoomAnonymous} from "./RoomIdentifier";
|
||||
import {arrayIntersect} from "../Services/ArrayHelper";
|
||||
import {MAX_USERS_PER_ROOM} from "_Enum/EnvironmentVariable";
|
||||
|
||||
export type ConnectCallback = (user: User, group: Group) => void;
|
||||
export type DisconnectCallback = (user: User, group: Group) => void;
|
||||
|
@ -179,6 +180,10 @@ export class GameRoom {
|
|||
}
|
||||
}
|
||||
|
||||
isFull() : boolean {
|
||||
return this.getUsers().size > MAX_USERS_PER_ROOM;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a user leave a group and closes and destroy the group if the group contains only one remaining person.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue