Files
DarkflameServer/dMasterServer/InstanceLimits.h
Aaron Kimbrell b87b7df6a6 fix(master): max_instances does not stop an instance that replaces another
A live update, a world reload and an instance migration start a new
instance that takes over from a running one, which stops once it is
empty. With max_instances reached they were refused, which left the old
instance with no replacement. These starts are no longer held to
max_instances; they still have to be zones of the ZoneTable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 07:03:02 -06:00

48 lines
1.8 KiB
C++

#ifndef __INSTANCELIMITS__H__
#define __INSTANCELIMITS__H__
#include <cstdint>
#include "eTransferFailure.h"
namespace InstanceLimits {
// The most world instances that run at once when the config does not say
constexpr uint32_t DefaultMaxInstances = 256;
enum class eNewInstance : uint8_t {
Allowed,
UnknownZone,
TooManyInstances
};
/**
* Whether a new world instance may be started for a zone.
* @param mapID the zone asked for, 0 is the character select and has no row in the ZoneTable
* @param isInZoneTable whether the ZoneTable has a row for the zone
* @param runningInstances the instances that run already
* @param maxInstances the most instances that may run at once, 0 for no limit
* @param replacement whether it takes over from a running instance that stops once it is empty (a live update,
* a world reload, an instance migration): it is not held to maxInstances, so the old one is always replaced
*/
constexpr eNewInstance CheckNewInstance(const uint32_t mapID, const bool isInZoneTable, const uint64_t runningInstances, const uint32_t maxInstances, const bool replacement = false) {
// Players always have to be able to reach the character select
if (mapID == 0) return eNewInstance::Allowed;
if (!isInZoneTable) return eNewInstance::UnknownZone;
if (!replacement && maxInstances != 0 && runningInstances >= maxInstances) return eNewInstance::TooManyInstances;
return eNewInstance::Allowed;
}
/**
* What the player who asked for the zone is told when no instance was started for it.
*/
constexpr eTransferFailure TransferFailure(const eNewInstance newInstance) {
switch (newInstance) {
case eNewInstance::UnknownZone: return eTransferFailure::MapLoad;
case eNewInstance::TooManyInstances: return eTransferFailure::NoServer;
default: return eTransferFailure::Other;
}
}
}
#endif //!__INSTANCELIMITS__H__