2021-12-05 17:54:36 +00:00
|
|
|
#include "InstanceManager.h"
|
|
|
|
#include <string>
|
|
|
|
#include "Game.h"
|
|
|
|
#include "dServer.h"
|
|
|
|
#include "dLogger.h"
|
|
|
|
#include "dConfig.h"
|
|
|
|
#include "CDClientDatabase.h"
|
|
|
|
#include "CDClientManager.h"
|
|
|
|
#include "CDZoneTableTable.h"
|
|
|
|
#include "dMessageIdentifiers.h"
|
|
|
|
#include "MasterPackets.h"
|
|
|
|
#include "PacketUtils.h"
|
2022-11-27 11:59:59 +00:00
|
|
|
#include "BinaryPathFinder.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
InstanceManager::InstanceManager(dLogger* logger, const std::string& externalIP) {
|
|
|
|
mLogger = logger;
|
|
|
|
mExternalIP = externalIP;
|
|
|
|
m_LastPort = std::atoi(Game::config->GetValue("world_port_start").c_str());
|
|
|
|
m_LastInstanceID = LWOINSTANCEID_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
InstanceManager::~InstanceManager() {
|
|
|
|
for (Instance* i : m_Instances) {
|
|
|
|
delete i;
|
|
|
|
i = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
Instance* InstanceManager::GetInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneID) {
|
|
|
|
mLogger->Log("InstanceManager", "Searching for an instance for mapID %i/%i", mapID, cloneID);
|
2021-12-05 17:54:36 +00:00
|
|
|
Instance* instance = FindInstance(mapID, isFriendTransfer, cloneID);
|
|
|
|
if (instance) return instance;
|
|
|
|
|
2022-12-16 04:39:29 +00:00
|
|
|
// If we are shutting down, return a nullptr so a new instance is not created.
|
|
|
|
if (m_IsShuttingDown) {
|
|
|
|
Game::logger->Log("InstanceManager",
|
|
|
|
"Tried to create a new instance map/instance/clone %i/%i/%i, but Master is shutting down.",
|
|
|
|
mapID,
|
|
|
|
m_LastInstanceID + 1,
|
|
|
|
cloneID);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
//TODO: Update this so that the IP is read from a configuration file instead
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
int softCap = 8;
|
|
|
|
int maxPlayers = 12;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (mapID == 0) {
|
|
|
|
softCap = 999;
|
|
|
|
maxPlayers = softCap;
|
|
|
|
} else {
|
2021-12-05 17:54:36 +00:00
|
|
|
softCap = GetSoftCap(mapID);
|
|
|
|
maxPlayers = GetHardCap(mapID);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
uint32_t port = GetFreePort();
|
|
|
|
instance = new Instance(mExternalIP, port, mapID, ++m_LastInstanceID, cloneID, softCap, maxPlayers);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
//Start the actual process:
|
2021-12-05 17:54:36 +00:00
|
|
|
#ifdef _WIN32
|
2022-11-27 11:59:59 +00:00
|
|
|
std::string cmd = "start " + (BinaryPathFinder::GetBinaryDir() / "WorldServer.exe").string() + " -zone ";
|
2021-12-05 17:54:36 +00:00
|
|
|
#else
|
|
|
|
std::string cmd;
|
2022-07-28 13:39:57 +00:00
|
|
|
if (std::atoi(Game::config->GetValue("use_sudo_world").c_str())) {
|
2022-11-27 11:59:59 +00:00
|
|
|
cmd = "sudo " + (BinaryPathFinder::GetBinaryDir() / "WorldServer").string() + " -zone ";
|
2021-12-05 17:54:36 +00:00
|
|
|
} else {
|
2022-11-27 11:59:59 +00:00
|
|
|
cmd = (BinaryPathFinder::GetBinaryDir() / "WorldServer").string() + " -zone ";
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
cmd.append(std::to_string(mapID));
|
|
|
|
cmd.append(" -port ");
|
|
|
|
cmd.append(std::to_string(port));
|
|
|
|
cmd.append(" -instance ");
|
|
|
|
cmd.append(std::to_string(m_LastInstanceID));
|
|
|
|
cmd.append(" -maxclients ");
|
|
|
|
cmd.append(std::to_string(maxPlayers));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
cmd.append(" -clone ");
|
|
|
|
cmd.append(std::to_string(cloneID));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
2022-07-28 13:39:57 +00:00
|
|
|
cmd.append("&"); //Sends our next process to the background on Linux
|
2021-12-05 17:54:36 +00:00
|
|
|
#endif
|
|
|
|
|
2022-12-15 14:13:49 +00:00
|
|
|
auto ret = system(cmd.c_str());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
m_Instances.push_back(instance);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (instance) {
|
|
|
|
mLogger->Log("InstanceManager", "Created new instance: %i/%i/%i with min/max %i/%i", mapID, m_LastInstanceID, cloneID, softCap, maxPlayers);
|
|
|
|
return instance;
|
|
|
|
} else mLogger->Log("InstanceManager", "Failed to create a new instance!");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
return nullptr;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool InstanceManager::IsPortInUse(uint32_t port) {
|
|
|
|
for (Instance* i : m_Instances) {
|
|
|
|
if (i && i->GetPort() == port) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-14 03:05:33 +00:00
|
|
|
uint32_t InstanceManager::GetFreePort() {
|
2022-07-28 13:39:57 +00:00
|
|
|
uint32_t port = m_LastPort;
|
|
|
|
std::vector<uint32_t> usedPorts;
|
|
|
|
for (Instance* i : m_Instances) {
|
|
|
|
usedPorts.push_back(i->GetPort());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(usedPorts.begin(), usedPorts.end());
|
|
|
|
|
|
|
|
int portIdx = 0;
|
|
|
|
while (portIdx < usedPorts.size() && port == usedPorts[portIdx]) {
|
|
|
|
//increment by 3 since each instance uses 3 ports (instance, world-server, world-chat)
|
|
|
|
port += 3;
|
|
|
|
portIdx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return port;
|
2021-12-14 03:05:33 +00:00
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
void InstanceManager::AddPlayer(SystemAddress systemAddr, LWOMAPID mapID, LWOINSTANCEID instanceID) {
|
|
|
|
Instance* inst = FindInstance(mapID, instanceID);
|
|
|
|
if (inst) {
|
|
|
|
Player player;
|
|
|
|
player.addr = systemAddr;
|
|
|
|
player.id = 0; //TODO: Update this to include the LWOOBJID of the player's character.
|
|
|
|
inst->AddPlayer(player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceManager::RemovePlayer(SystemAddress systemAddr, LWOMAPID mapID, LWOINSTANCEID instanceID) {
|
|
|
|
Instance* inst = FindInstance(mapID, instanceID);
|
|
|
|
if (inst) {
|
|
|
|
Player player;
|
|
|
|
player.addr = systemAddr;
|
|
|
|
player.id = 0; //TODO: Update this to include the LWOOBJID of the player's character.
|
|
|
|
inst->RemovePlayer(player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
std::vector<Instance*> InstanceManager::GetInstances() const {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_Instances;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceManager::AddInstance(Instance* instance) {
|
|
|
|
if (instance == nullptr) return;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Instances.push_back(instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceManager::RemoveInstance(Instance* instance) {
|
2022-07-28 13:39:57 +00:00
|
|
|
for (uint32_t i = 0; i < m_Instances.size(); ++i) {
|
|
|
|
if (m_Instances[i] == instance) {
|
2021-12-05 17:54:36 +00:00
|
|
|
instance->SetShutdownComplete(true);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2022-12-15 13:46:03 +00:00
|
|
|
if (!Game::shouldShutdown) RedirectPendingRequests(instance);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
delete m_Instances[i];
|
|
|
|
|
|
|
|
m_Instances.erase(m_Instances.begin() + i);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void InstanceManager::ReadyInstance(Instance* instance) {
|
2021-12-05 17:54:36 +00:00
|
|
|
instance->SetIsReady(true);
|
|
|
|
|
|
|
|
auto& pending = instance->GetPendingRequests();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto& request : pending) {
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto& zoneId = instance->GetZoneID();
|
|
|
|
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("InstanceManager", "Responding to pending request %llu -> %i (%i)", request, zoneId.GetMapID(), zoneId.GetCloneID());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
MasterPackets::SendZoneTransferResponse(
|
|
|
|
Game::server,
|
|
|
|
request.sysAddr,
|
|
|
|
request.id,
|
|
|
|
request.mythranShift,
|
|
|
|
zoneId.GetMapID(),
|
|
|
|
zoneId.GetInstanceID(),
|
|
|
|
zoneId.GetCloneID(),
|
|
|
|
instance->GetIP(),
|
|
|
|
instance->GetPort()
|
|
|
|
);
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
pending.clear();
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void InstanceManager::RequestAffirmation(Instance* instance, const PendingInstanceRequest& request) {
|
2021-12-05 17:54:36 +00:00
|
|
|
instance->GetPendingAffirmations().push_back(request);
|
|
|
|
|
|
|
|
CBITSTREAM;
|
|
|
|
|
|
|
|
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_AFFIRM_TRANSFER_REQUEST);
|
|
|
|
|
|
|
|
bitStream.Write(request.id);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
Game::server->Send(&bitStream, instance->GetSysAddr(), false);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
|
|
|
Game::logger->Log("MasterServer", "Sent affirmation request %llu to %i/%i", request.id,
|
2021-12-05 17:54:36 +00:00
|
|
|
static_cast<int>(instance->GetZoneID().GetMapID()),
|
|
|
|
static_cast<int>(instance->GetZoneID().GetCloneID())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void InstanceManager::AffirmTransfer(Instance* instance, const uint64_t transferID) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto& pending = instance->GetPendingAffirmations();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (auto i = 0u; i < pending.size(); ++i) {
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto& request = pending[i];
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (request.id != transferID) continue;
|
|
|
|
|
|
|
|
const auto& zoneId = instance->GetZoneID();
|
|
|
|
|
|
|
|
MasterPackets::SendZoneTransferResponse(
|
|
|
|
Game::server,
|
|
|
|
request.sysAddr,
|
|
|
|
request.id,
|
|
|
|
request.mythranShift,
|
|
|
|
zoneId.GetMapID(),
|
|
|
|
zoneId.GetInstanceID(),
|
|
|
|
zoneId.GetCloneID(),
|
|
|
|
instance->GetIP(),
|
|
|
|
instance->GetPort()
|
|
|
|
);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
pending.erase(pending.begin() + i);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void InstanceManager::RedirectPendingRequests(Instance* instance) {
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto& zoneId = instance->GetZoneID();
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
for (const auto& request : instance->GetPendingAffirmations()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* in = Game::im->GetInstance(zoneId.GetMapID(), false, zoneId.GetCloneID());
|
|
|
|
|
2022-12-16 04:39:29 +00:00
|
|
|
if (in && !in->GetIsReady()) // Instance not ready, make a pending request
|
2021-12-05 17:54:36 +00:00
|
|
|
{
|
|
|
|
in->GetPendingRequests().push_back(request);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Game::im->RequestAffirmation(in, request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Instance* InstanceManager::GetInstanceBySysAddr(SystemAddress& sysAddr) {
|
|
|
|
for (uint32_t i = 0; i < m_Instances.size(); ++i) {
|
|
|
|
if (m_Instances[i] && m_Instances[i]->GetSysAddr() == sysAddr) {
|
|
|
|
return m_Instances[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InstanceManager::IsInstanceFull(Instance* instance, bool isFriendTransfer) {
|
2022-07-25 02:26:51 +00:00
|
|
|
if (!isFriendTransfer && instance->GetSoftCap() > instance->GetCurrentClientCount())
|
2021-12-05 17:54:36 +00:00
|
|
|
return false;
|
2022-07-25 02:26:51 +00:00
|
|
|
else if (isFriendTransfer && instance->GetHardCap() > instance->GetCurrentClientCount())
|
2021-12-05 17:54:36 +00:00
|
|
|
return false;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
Instance* InstanceManager::FindInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneId) {
|
2021-12-05 17:54:36 +00:00
|
|
|
for (Instance* i : m_Instances) {
|
2022-07-18 23:08:33 +00:00
|
|
|
if (i && i->GetMapID() == mapID && i->GetCloneID() == cloneId && !IsInstanceFull(i, isFriendTransfer) && !i->GetIsPrivate() && !i->GetShutdownComplete() && !i->GetIsShuttingDown()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
Instance* InstanceManager::FindInstance(LWOMAPID mapID, LWOINSTANCEID instanceID) {
|
2021-12-05 17:54:36 +00:00
|
|
|
for (Instance* i : m_Instances) {
|
2022-07-28 13:39:57 +00:00
|
|
|
if (i && i->GetMapID() == mapID && i->GetInstanceID() == instanceID && !i->GetIsPrivate() && !i->GetShutdownComplete() && !i->GetIsShuttingDown()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
Instance* InstanceManager::CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID cloneID, const std::string& password) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* instance = FindPrivateInstance(password);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (instance != nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2022-12-16 04:39:29 +00:00
|
|
|
if (m_IsShuttingDown) {
|
|
|
|
Game::logger->Log("InstanceManager",
|
|
|
|
"Tried to create a new private instance map/instance/clone %i/%i/%i, but Master is shutting down.",
|
|
|
|
mapID,
|
|
|
|
m_LastInstanceID + 1,
|
|
|
|
cloneID);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
int maxPlayers = 999;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-14 03:05:33 +00:00
|
|
|
uint32_t port = GetFreePort();
|
|
|
|
instance = new Instance(mExternalIP, port, mapID, ++m_LastInstanceID, cloneID, maxPlayers, maxPlayers, true, password);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
//Start the actual process:
|
2022-11-27 11:59:59 +00:00
|
|
|
std::string cmd = "start " + (BinaryPathFinder::GetBinaryDir() / "WorldServer").string() + " -zone ";
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
2022-11-27 11:59:59 +00:00
|
|
|
cmd = (BinaryPathFinder::GetBinaryDir() / "WorldServer").string() + " -zone ";
|
2021-12-05 17:54:36 +00:00
|
|
|
#endif
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
cmd.append(std::to_string(mapID));
|
|
|
|
cmd.append(" -port ");
|
|
|
|
cmd.append(std::to_string(port));
|
|
|
|
cmd.append(" -instance ");
|
|
|
|
cmd.append(std::to_string(m_LastInstanceID));
|
|
|
|
cmd.append(" -maxclients ");
|
|
|
|
cmd.append(std::to_string(maxPlayers));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
cmd.append(" -clone ");
|
|
|
|
cmd.append(std::to_string(cloneID));
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
#ifndef WIN32
|
2022-07-28 13:39:57 +00:00
|
|
|
cmd.append("&"); //Sends our next process to the background on Linux
|
2021-12-05 17:54:36 +00:00
|
|
|
#endif
|
|
|
|
|
2022-12-15 14:13:49 +00:00
|
|
|
auto ret = system(cmd.c_str());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
m_Instances.push_back(instance);
|
|
|
|
|
|
|
|
if (instance) return instance;
|
2022-07-25 02:26:51 +00:00
|
|
|
else mLogger->Log("InstanceManager", "Failed to create a new instance!");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
Instance* InstanceManager::FindPrivateInstance(const std::string& password) {
|
|
|
|
for (auto* instance : m_Instances) {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (!instance) continue;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (!instance->GetIsPrivate()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-07-25 02:26:51 +00:00
|
|
|
mLogger->Log("InstanceManager", "Password: %s == %s => %d", password.c_str(), instance->GetPassword().c_str(), password == instance->GetPassword());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (instance->GetPassword() == password) {
|
2021-12-05 17:54:36 +00:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int InstanceManager::GetSoftCap(LWOMAPID mapID) {
|
2023-03-17 14:36:21 +00:00
|
|
|
CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable<CDZoneTableTable>();
|
2021-12-05 17:54:36 +00:00
|
|
|
if (zoneTable) {
|
|
|
|
const CDZoneTable* zone = zoneTable->Query(mapID);
|
|
|
|
|
|
|
|
if (zone != nullptr) {
|
|
|
|
return zone->population_soft_cap;
|
|
|
|
}
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
int InstanceManager::GetHardCap(LWOMAPID mapID) {
|
2023-03-17 14:36:21 +00:00
|
|
|
CDZoneTableTable* zoneTable = CDClientManager::Instance().GetTable<CDZoneTableTable>();
|
2021-12-05 17:54:36 +00:00
|
|
|
if (zoneTable) {
|
|
|
|
const CDZoneTable* zone = zoneTable->Query(mapID);
|
|
|
|
|
|
|
|
if (zone != nullptr) {
|
|
|
|
return zone->population_hard_cap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void Instance::SetShutdownComplete(const bool value) {
|
2021-12-05 17:54:36 +00:00
|
|
|
m_Shutdown = value;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
bool Instance::GetShutdownComplete() const {
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_Shutdown;
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void Instance::Shutdown() {
|
2021-12-05 17:54:36 +00:00
|
|
|
CBITSTREAM;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
PacketUtils::WriteHeader(bitStream, MASTER, MSG_MASTER_SHUTDOWN);
|
|
|
|
|
|
|
|
Game::server->Send(&bitStream, this->m_SysAddr, false);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2022-12-15 12:02:38 +00:00
|
|
|
Game::logger->Log("Instance", "Triggered world shutdown for zone/clone/instance %i/%i/%i", GetMapID(), GetCloneID(), GetInstanceID());
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|