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');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue