Merge pull request #75 from jeromkiller/AddArchipelagoClientLib

Fixed item queue issue caused by soft resetting the game
This commit is contained in:
aMannus
2025-07-30 19:21:22 +02:00
committed by GitHub
2 changed files with 16 additions and 7 deletions

View File

@@ -7,6 +7,7 @@
#include <filesystem> #include <filesystem>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <utility>
#include "soh/Network/Archipelago/ArchipelagoConsoleWindow.h" #include "soh/Network/Archipelago/ArchipelagoConsoleWindow.h"
#include "soh/Enhancements/randomizer/randomizerTypes.h" #include "soh/Enhancements/randomizer/randomizerTypes.h"
@@ -107,6 +108,7 @@ bool ArchipelagoClient::StartClient() {
SohUtils::CopyStringToCharArray(gSaveContext.ship.quest.data.archipelago.roomPass, password, SohUtils::CopyStringToCharArray(gSaveContext.ship.quest.data.archipelago.roomPass, password,
ARRAY_COUNT(gSaveContext.ship.quest.data.archipelago.roomPass)); ARRAY_COUNT(gSaveContext.ship.quest.data.archipelago.roomPass));
ResetQueue();
SynchSentLocations(); SynchSentLocations();
SynchReceivedLocations(); SynchReceivedLocations();
} }
@@ -278,12 +280,11 @@ void ArchipelagoClient::GameLoaded() {
} }
if (!isRightSaveLoaded()) { if (!isRightSaveLoaded()) {
ArchipelagoConsole_SendMessage("Connec"); ArchipelagoConsole_SendMessage("Disconnecting from previous slot and connecting to this one...");
//disconnecting = true; CVarSetString(CVAR_REMOTE_ARCHIPELAGO("ServerAddress"), gSaveContext.ship.quest.data.archipelago.archiUri);
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("SlotName"), gSaveContext.ship.quest.data.archipelago.slotName); CVarSetString(CVAR_REMOTE_ARCHIPELAGO("Password"), gSaveContext.ship.quest.data.archipelago.roomPass);
CVarSetString(CVAR_REMOTE_ARCHIPELAGO("Password"), gSaveContext.ship.quest.data.archipelago.roomPass); StartClient();
StartClient();
return; return;
} }
@@ -307,6 +308,7 @@ void ArchipelagoClient::StartLocationScouts() {
void ArchipelagoClient::SynchItems() { void ArchipelagoClient::SynchItems() {
// Send a Synch request to get any items we may have missed // Send a Synch request to get any items we may have missed
ResetQueue();
apClient->Sync(); apClient->Sync();
} }
@@ -441,6 +443,7 @@ void ArchipelagoClient::Poll() {
if (disconnecting) { if (disconnecting) {
apClient->reset(); apClient->reset();
apClient = nullptr; apClient = nullptr;
ResetQueue();
disconnecting = false; disconnecting = false;
CVarSetInteger(CVAR_REMOTE_ARCHIPELAGO("ConnectionStatus"), 0); // disconnected CVarSetInteger(CVAR_REMOTE_ARCHIPELAGO("ConnectionStatus"), 0); // disconnected
return; return;
@@ -448,7 +451,6 @@ void ArchipelagoClient::Poll() {
// queue another item to be received // queue another item to be received
if (!itemQueued && receiveQueue.size() > 0) { if (!itemQueued && receiveQueue.size() > 0) {
const ApItem item = receiveQueue.front(); const ApItem item = receiveQueue.front();
receiveQueue.pop(); receiveQueue.pop();
QueueItem(item); QueueItem(item);
@@ -457,6 +459,12 @@ void ArchipelagoClient::Poll() {
apClient->poll(); apClient->poll();
} }
void ArchipelagoClient::ResetQueue(){
itemQueued = false;
std::queue<ApItem> empty;
std::swap( receiveQueue, empty );
}
bool ArchipelagoClient::slotMatch(const std::string& slotName, const std::string& roomHash) { bool ArchipelagoClient::slotMatch(const std::string& slotName, const std::string& roomHash) {
if (apClient == nullptr) { if (apClient == nullptr) {
return false; return false;

View File

@@ -60,6 +60,7 @@ class ArchipelagoClient {
void SendGameWon(); void SendGameWon();
void SendMessageToConsole(const std::string message); void SendMessageToConsole(const std::string message);
void Poll(); void Poll();
void ResetQueue();
bool slotMatch(const std::string& slotName, const std::string& roomHash); bool slotMatch(const std::string& slotName, const std::string& roomHash);