From e93dc762b9d11beec9c837c59638c270ba875675 Mon Sep 17 00:00:00 2001 From: Jerom Venneker Date: Wed, 30 Jul 2025 18:02:33 +0200 Subject: [PATCH] Fixed item queue issue caused by soft resetting the game --- soh/soh/Network/Archipelago/Archipelago.cpp | 22 ++++++++++++++------- soh/soh/Network/Archipelago/Archipelago.h | 1 + 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/soh/soh/Network/Archipelago/Archipelago.cpp b/soh/soh/Network/Archipelago/Archipelago.cpp index 5f9aa89f5..9556ed56d 100644 --- a/soh/soh/Network/Archipelago/Archipelago.cpp +++ b/soh/soh/Network/Archipelago/Archipelago.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "soh/Network/Archipelago/ArchipelagoConsoleWindow.h" #include "soh/Enhancements/randomizer/randomizerTypes.h" @@ -107,6 +108,7 @@ bool ArchipelagoClient::StartClient() { SohUtils::CopyStringToCharArray(gSaveContext.ship.quest.data.archipelago.roomPass, password, ARRAY_COUNT(gSaveContext.ship.quest.data.archipelago.roomPass)); + ResetQueue(); SynchSentLocations(); SynchReceivedLocations(); } @@ -278,12 +280,11 @@ void ArchipelagoClient::GameLoaded() { } if (!isRightSaveLoaded()) { - ArchipelagoConsole_SendMessage("Connec"); - //disconnecting = true; - CVarSetString(CVAR_REMOTE_ARCHIPELAGO("ServerAddress"), gSaveContext.ship.quest.data.archipelago.archiUri); - CVarSetString(CVAR_REMOTE_ARCHIPELAGO("SlotName"), gSaveContext.ship.quest.data.archipelago.slotName); - CVarSetString(CVAR_REMOTE_ARCHIPELAGO("Password"), gSaveContext.ship.quest.data.archipelago.roomPass); - StartClient(); + ArchipelagoConsole_SendMessage("Disconnecting from previous slot and connecting to this one..."); + CVarSetString(CVAR_REMOTE_ARCHIPELAGO("ServerAddress"), gSaveContext.ship.quest.data.archipelago.archiUri); + CVarSetString(CVAR_REMOTE_ARCHIPELAGO("SlotName"), gSaveContext.ship.quest.data.archipelago.slotName); + CVarSetString(CVAR_REMOTE_ARCHIPELAGO("Password"), gSaveContext.ship.quest.data.archipelago.roomPass); + StartClient(); return; } @@ -307,6 +308,7 @@ void ArchipelagoClient::StartLocationScouts() { void ArchipelagoClient::SynchItems() { // Send a Synch request to get any items we may have missed + ResetQueue(); apClient->Sync(); } @@ -441,6 +443,7 @@ void ArchipelagoClient::Poll() { if (disconnecting) { apClient->reset(); apClient = nullptr; + ResetQueue(); disconnecting = false; CVarSetInteger(CVAR_REMOTE_ARCHIPELAGO("ConnectionStatus"), 0); // disconnected return; @@ -448,7 +451,6 @@ void ArchipelagoClient::Poll() { // queue another item to be received if (!itemQueued && receiveQueue.size() > 0) { - const ApItem item = receiveQueue.front(); receiveQueue.pop(); QueueItem(item); @@ -457,6 +459,12 @@ void ArchipelagoClient::Poll() { apClient->poll(); } +void ArchipelagoClient::ResetQueue(){ + itemQueued = false; + std::queue empty; + std::swap( receiveQueue, empty ); +} + bool ArchipelagoClient::slotMatch(const std::string& slotName, const std::string& roomHash) { if (apClient == nullptr) { return false; diff --git a/soh/soh/Network/Archipelago/Archipelago.h b/soh/soh/Network/Archipelago/Archipelago.h index 00973536f..4a0d486fc 100644 --- a/soh/soh/Network/Archipelago/Archipelago.h +++ b/soh/soh/Network/Archipelago/Archipelago.h @@ -60,6 +60,7 @@ class ArchipelagoClient { void SendGameWon(); void SendMessageToConsole(const std::string message); void Poll(); + void ResetQueue(); bool slotMatch(const std::string& slotName, const std::string& roomHash);