Fix the issue where we would create new worlds on ports that were still being used (#625)

* Wait for world to shutdown

We need to wait for the message that the world has shutdown before shutting it down.

* Dont sent people to dead instances

* Added shutting down check

Added check for isShuttingDown

* Update when we remove from master
This commit is contained in:
David Markowitz 2022-07-18 16:08:33 -07:00 committed by GitHub
parent ef8c2a40f3
commit b55606d41e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 5 deletions

View File

@ -280,7 +280,7 @@ bool InstanceManager::IsInstanceFull(Instance* instance, bool isFriendTransfer)
Instance * InstanceManager::FindInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneId) { Instance * InstanceManager::FindInstance(LWOMAPID mapID, bool isFriendTransfer, LWOCLONEID cloneId) {
for (Instance* i : m_Instances) { for (Instance* i : m_Instances) {
if (i && i->GetMapID() == mapID && i->GetCloneID() == cloneId && !IsInstanceFull(i, isFriendTransfer) && !i->GetIsPrivate() && !i->GetShutdownComplete()) { if (i && i->GetMapID() == mapID && i->GetCloneID() == cloneId && !IsInstanceFull(i, isFriendTransfer) && !i->GetIsPrivate() && !i->GetShutdownComplete() && !i->GetIsShuttingDown()) {
return i; return i;
} }
} }
@ -290,7 +290,7 @@ Instance * InstanceManager::FindInstance(LWOMAPID mapID, bool isFriendTransfer,
Instance * InstanceManager::FindInstance(LWOMAPID mapID, LWOINSTANCEID instanceID) { Instance * InstanceManager::FindInstance(LWOMAPID mapID, LWOINSTANCEID instanceID) {
for (Instance* i : m_Instances) { for (Instance* i : m_Instances) {
if (i && i->GetMapID() == mapID && i->GetInstanceID() == instanceID && !i->GetIsPrivate()) { if (i && i->GetMapID() == mapID && i->GetInstanceID() == instanceID && !i->GetIsPrivate() && !i->GetShutdownComplete() && !i->GetIsShuttingDown()) {
return i; return i;
} }
} }

View File

@ -31,6 +31,7 @@ public:
m_PendingAffirmations = {}; m_PendingAffirmations = {};
m_PendingRequests = {}; m_PendingRequests = {};
m_Ready = false; m_Ready = false;
m_IsShuttingDown = false;
} }
const std::string& GetIP() const { return m_IP; } const std::string& GetIP() const { return m_IP; }
@ -46,6 +47,8 @@ public:
bool GetIsReady() const { return m_Ready; } bool GetIsReady() const { return m_Ready; }
void SetIsReady(bool value) { m_Ready = value; } void SetIsReady(bool value) { m_Ready = value; }
bool GetIsShuttingDown() const { return m_IsShuttingDown; }
void SetIsShuttingDown(bool value) { m_IsShuttingDown = value; }
std::vector<PendingInstanceRequest>& GetPendingRequests() { return m_PendingRequests; } std::vector<PendingInstanceRequest>& GetPendingRequests() { return m_PendingRequests; }
std::vector<PendingInstanceRequest>& GetPendingAffirmations() { return m_PendingAffirmations; } std::vector<PendingInstanceRequest>& GetPendingAffirmations() { return m_PendingAffirmations; }
@ -82,6 +85,7 @@ private:
std::vector<Player> m_Players; std::vector<Player> m_Players;
SystemAddress m_SysAddr; SystemAddress m_SysAddr;
bool m_Ready; bool m_Ready;
bool m_IsShuttingDown;
std::vector<PendingInstanceRequest> m_PendingRequests; std::vector<PendingInstanceRequest> m_PendingRequests;
std::vector<PendingInstanceRequest> m_PendingAffirmations; std::vector<PendingInstanceRequest> m_PendingAffirmations;

View File

@ -311,7 +311,7 @@ int main(int argc, char** argv) {
if (affirmTimeout == 1000) { if (affirmTimeout == 1000) {
instance->Shutdown(); instance->Shutdown();
instance->SetShutdownComplete(true); instance->SetIsShuttingDown(true);
Game::im->RedirectPendingRequests(instance); Game::im->RedirectPendingRequests(instance);
} }
@ -358,6 +358,7 @@ void HandlePacket(Packet* packet) {
Instance* instance = Instance* instance =
Game::im->GetInstanceBySysAddr(packet->systemAddress); Game::im->GetInstanceBySysAddr(packet->systemAddress);
if (instance) { if (instance) {
Game::logger->Log("MasterServer", "Actually disconnected from zone %i clone %i instance %i port %i\n", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance->GetPort());
Game::im->RemoveInstance(instance); //Delete the old Game::im->RemoveInstance(instance); //Delete the old
} }
@ -694,8 +695,8 @@ void HandlePacket(Packet* packet) {
return; return;
} }
Game::logger->Log("MasterServer", "Got shutdown response\n"); Game::logger->Log("MasterServer", "Got shutdown response from zone %i clone %i instance %i port %i\n", instance->GetMapID(), instance->GetCloneID(), instance->GetInstanceID(), instance->GetPort());
instance->SetShutdownComplete(true); instance->SetIsShuttingDown(true);
break; break;
} }