RoomManager.ts
1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { RoomDescription } from "../../common/dataType";
import { WordDatabase } from "../database/WordDatabase";
import { User } from "../user/User";
import { Room } from "./Room";
export class RoomManager {
private rooms: Map<string, Room>;
public wordDatabase: WordDatabase;
constructor() {
this.rooms = new Map<string, Room>();
this.wordDatabase = new WordDatabase("./database.db");
}
public create(name: string, maxConnections: number, admin?: User): Room {
const room = new Room(this, name, admin, maxConnections);
this.rooms.set(room.uuid, room);
return room;
}
public get(uuid: string): Room | undefined {
return this.rooms.get(uuid);
}
public delete(uuid: string): void {
const room = this.get(uuid);
if (room !== undefined) {
room.close();
this.rooms.delete(uuid);
}
}
public list(): RoomDescription[] {
var roomData: RoomDescription[] = [];
this.rooms.forEach((room) => {
roomData.push(room.getDescription());
});
return roomData;
}
}