Rooms and matchmaking
* Added missing config (route) data * Fetch room class, database hash * Basic room querying * Built-in room generation during first runtime * Matchmaking response base and notes for myself, later today * Instance fixes * Challenge and quick play routes (unused for now) * Rooms route (untested) * Matchmaking goto route * Avatar route addition * Settings/set route
This commit is contained in:
@@ -1,3 +1,20 @@
|
||||
/* Galvanic Corrosion - Rec Room custom server for communities.
|
||||
<https://gitea.proxnet.dev/zombieb-galvanic-corrosion>
|
||||
Copyright (C) 2025 @zombieb (Discord / proxnet Gitea)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
import Logging from "@proxnet/undead-logging";
|
||||
import { Profile } from "../profiles.ts";
|
||||
import { RoomInstance, InstanceOptions } from "./types.ts";
|
||||
@@ -7,15 +24,25 @@ const log = new Logging("Instances");
|
||||
|
||||
const config = Config.getConfig();
|
||||
|
||||
// `Profile` isn't synchronized. Fix this.
|
||||
const instancePlayers: Map<RoomInstance, Set<Profile>> = new Map();
|
||||
/**
|
||||
* `Map<roomId (number), RoomInstance>`
|
||||
*/
|
||||
const instanceMap: Map<number, Set<RoomInstance>> = new Map();
|
||||
/**
|
||||
* `Map<instanceId (number), roomId (number)>`
|
||||
*/
|
||||
const instanceRoomMap: Map<number, number> = new Map();
|
||||
|
||||
class InstancesBase {
|
||||
|
||||
getInstance(id: number) {
|
||||
const instances = instancePlayers.keys();
|
||||
const instance = instances.find(val => val.roomInstanceId == id);
|
||||
if (instance) return instance;
|
||||
else return null;
|
||||
}
|
||||
|
||||
getAllInstances() {
|
||||
return new Set([...instanceMap.values()].flatMap(set => [...set]));
|
||||
}
|
||||
@@ -62,9 +89,8 @@ class InstancesBase {
|
||||
}
|
||||
|
||||
updateGlobalInstancesIsFull() {
|
||||
for (const instance of this.getAllInstances()) {
|
||||
for (const instance of this.getAllInstances())
|
||||
instance.isFull = this.getInstancePlayers(instance).size >= instance.maxCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
updateSingleInstanceIsFull(instance: RoomInstance) {
|
||||
@@ -78,7 +104,7 @@ class InstancesBase {
|
||||
}
|
||||
|
||||
#generateUniqueInstanceId() {
|
||||
let newInstanceId = Math.round(Math.random() * Math.pow(2, 31))
|
||||
let newInstanceId = Math.round(Math.random() * Math.pow(2, 31));
|
||||
const allInstances = this.getAllInstances();
|
||||
while (Array.from(allInstances.values()).map(val => val.roomInstanceId).includes(newInstanceId)) newInstanceId = Math.round(Math.random() * Math.pow(2, 31));
|
||||
return newInstanceId;
|
||||
@@ -119,6 +145,8 @@ class InstancesBase {
|
||||
this.getInstancePlayers(newInstance).add(options.FirstPlayer);
|
||||
}
|
||||
|
||||
return newInstance;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user