Files
DarkflameServer/dDashboardServer/routes/InstanceLimits.h
Aaron Kimbrell e213a7aeff feat: web dashboard and playground work
The NexusDashboard-parity dashboard (dDashboardServer) and everything built on it on the experimental branch:
accounts, characters, properties and moderation tools, permissions shared with in-game slash commands, economy
reports, World 3D and property 3D views with client scenery, scheduled events (features, vanity changes, live
events, announcements, restarts), vanity files and events, the CDClient browser, the message inspector with saved
captures, chat filter tools, community challenges, live ops, the AI moderator helper, and the server-side changes
they need.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:30:43 -05:00

39 lines
1.8 KiB
C++

#pragma once
#include <cstdint>
#include <optional>
#include <string>
/**
* Player caps and spare instances per zone, as the master server applies them (dMasterServer/InstanceManager): a
* player is sent to a running public instance while it has fewer players than the soft cap (a friend joining them
* while it has fewer than the hard cap), otherwise a new instance starts. The hard cap is also the most connections
* its world server accepts. Caps not set here come from the client's ZoneTable. Pure; unit tested.
*/
namespace InstanceLimits {
constexpr uint32_t MAX_CAP = 500;
constexpr uint32_t MAX_SPARE = 5;
struct Caps {
uint32_t soft{};
uint32_t hard{};
};
// The caps new instances get, as InstanceManager::GetSoftCap/GetHardCap work them out
inline Caps Effective(std::optional<uint32_t> softCap, std::optional<uint32_t> hardCap, Caps client) {
const auto hard = hardCap.value_or(client.hard);
return { std::min(softCap.value_or(client.soft), hard), hard };
}
// What is wrong with a zone's limits as entered, if anything
inline std::optional<std::string> Validate(uint32_t zoneId, std::optional<uint32_t> softCap, std::optional<uint32_t> hardCap, uint32_t spare, Caps client) {
if (zoneId == 0) return "Character selection (zone 0) has no player cap";
if (hardCap && (*hardCap < 1 || *hardCap > MAX_CAP)) return "The hard cap must be 1 to " + std::to_string(MAX_CAP);
if (softCap && (*softCap < 1 || *softCap > MAX_CAP)) return "The soft cap must be 1 to " + std::to_string(MAX_CAP);
const auto hard = hardCap.value_or(client.hard);
if (softCap && *softCap > hard) return "The soft cap can't be above the hard cap (" + std::to_string(hard) + ")";
if (spare > MAX_SPARE) return "Keep at most " + std::to_string(MAX_SPARE) + " spare instances";
return std::nullopt;
}
}