about summary refs log tree commit diff stats
path: root/src/ap_state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ap_state.cpp')
-rw-r--r--src/ap_state.cpp43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/ap_state.cpp b/src/ap_state.cpp index 32ae8f0..80d96a1 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp
@@ -22,6 +22,7 @@
22#include <tuple> 22#include <tuple>
23 23
24#include "game_data.h" 24#include "game_data.h"
25#include "ipc_state.h"
25#include "logger.h" 26#include "logger.h"
26#include "tracker_frame.h" 27#include "tracker_frame.h"
27#include "tracker_state.h" 28#include "tracker_state.h"
@@ -43,6 +44,7 @@ struct APState {
43 TrackerFrame* tracker_frame = nullptr; 44 TrackerFrame* tracker_frame = nullptr;
44 45
45 bool client_active = false; 46 bool client_active = false;
47 std::string status_message = "Not connected to Archipelago.";
46 std::mutex client_mutex; 48 std::mutex client_mutex;
47 49
48 bool connected = false; 50 bool connected = false;
@@ -113,7 +115,10 @@ struct APState {
113 initialized = true; 115 initialized = true;
114 } 116 }
115 117
116 tracker_frame->SetStatusMessage("Connecting to Archipelago server...."); 118 {
119 std::lock_guard client_guard(client_mutex);
120 SetStatusMessage("Connecting to Archipelago server....");
121 }
117 TrackerLog(fmt::format("Connecting to Archipelago server ({})...", server)); 122 TrackerLog(fmt::format("Connecting to Archipelago server ({})...", server));
118 123
119 { 124 {
@@ -169,8 +174,7 @@ struct APState {
169 "Connected to Archipelago server. Authenticating as {} {}", player, 174 "Connected to Archipelago server. Authenticating as {} {}", player,
170 (password.empty() ? "without password" 175 (password.empty() ? "without password"
171 : "with password " + password))); 176 : "with password " + password)));
172 tracker_frame->SetStatusMessage( 177 SetStatusMessage("Connected to Archipelago server. Authenticating...");
173 "Connected to Archipelago server. Authenticating...");
174 178
175 apclient->ConnectSlot(player, password, ITEM_HANDLING, {"Tracker"}, 179 apclient->ConnectSlot(player, password, ITEM_HANDLING, {"Tracker"},
176 {AP_MAJOR, AP_MINOR, AP_REVISION}); 180 {AP_MAJOR, AP_MINOR, AP_REVISION});
@@ -187,14 +191,14 @@ struct APState {
187 }); 191 });
188 192
189 apclient->set_slot_disconnected_handler([this]() { 193 apclient->set_slot_disconnected_handler([this]() {
190 tracker_frame->SetStatusMessage( 194 SetStatusMessage(
191 "Disconnected from Archipelago. Attempting to reconnect..."); 195 "Disconnected from Archipelago. Attempting to reconnect...");
192 TrackerLog( 196 TrackerLog(
193 "Slot disconnected from Archipelago. Attempting to reconnect..."); 197 "Slot disconnected from Archipelago. Attempting to reconnect...");
194 }); 198 });
195 199
196 apclient->set_socket_disconnected_handler([this]() { 200 apclient->set_socket_disconnected_handler([this]() {
197 tracker_frame->SetStatusMessage( 201 SetStatusMessage(
198 "Disconnected from Archipelago. Attempting to reconnect..."); 202 "Disconnected from Archipelago. Attempting to reconnect...");
199 TrackerLog( 203 TrackerLog(
200 "Socket disconnected from Archipelago. Attempting to reconnect..."); 204 "Socket disconnected from Archipelago. Attempting to reconnect...");
@@ -229,10 +233,12 @@ struct APState {
229 apclient->set_slot_connected_handler([this, player, server, 233 apclient->set_slot_connected_handler([this, player, server,
230 &connection_mutex]( 234 &connection_mutex](
231 const nlohmann::json& slot_data) { 235 const nlohmann::json& slot_data) {
232 tracker_frame->SetStatusMessage( 236 SetStatusMessage(
233 fmt::format("Connected to Archipelago! ({}@{})", player, server)); 237 fmt::format("Connected to Archipelago! ({}@{}).", player, server));
234 TrackerLog("Connected to Archipelago!"); 238 TrackerLog("Connected to Archipelago!");
235 239
240 IPC_SetTrackerSlot(server, player);
241
236 save_name = fmt::format("zzAP_{}_{}.save", apclient->get_seed(), 242 save_name = fmt::format("zzAP_{}_{}.save", apclient->get_seed(),
237 apclient->get_player_number()); 243 apclient->get_player_number());
238 data_storage_prefix = 244 data_storage_prefix =
@@ -328,7 +334,7 @@ struct APState {
328 has_connection_result = true; 334 has_connection_result = true;
329 } 335 }
330 336
331 tracker_frame->SetStatusMessage("Disconnected from Archipelago."); 337 SetStatusMessage("Disconnected from Archipelago.");
332 338
333 std::vector<std::string> error_messages; 339 std::vector<std::string> error_messages;
334 error_messages.push_back("Could not connect to Archipelago."); 340 error_messages.push_back("Could not connect to Archipelago.");
@@ -376,7 +382,10 @@ struct APState {
376 if (interval == 0) { 382 if (interval == 0) {
377 DestroyClient(); 383 DestroyClient();
378 384
379 tracker_frame->SetStatusMessage("Disconnected from Archipelago."); 385 {
386 std::lock_guard client_guard(client_mutex);
387 SetStatusMessage("Disconnected from Archipelago.");
388 }
380 TrackerLog("Timeout while connecting to Archipelago server."); 389 TrackerLog("Timeout while connecting to Archipelago server.");
381 wxMessageBox("Timeout while connecting to Archipelago server.", 390 wxMessageBox("Timeout while connecting to Archipelago server.",
382 "Connection failed", wxOK | wxICON_ERROR); 391 "Connection failed", wxOK | wxICON_ERROR);
@@ -400,6 +409,17 @@ struct APState {
400 } 409 }
401 } 410 }
402 411
412 std::string GetStatusMessage() {
413 std::lock_guard client_guard(client_mutex);
414 return status_message;
415 }
416
417 void SetStatusMessage(std::string msg) {
418 status_message = std::move(msg);
419
420 tracker_frame->UpdateStatusMessage();
421 }
422
403 void HandleDataStorage(const std::string& key, const nlohmann::json& value) { 423 void HandleDataStorage(const std::string& key, const nlohmann::json& value) {
404 if (value.is_boolean()) { 424 if (value.is_boolean()) {
405 data_storage[key] = value.get<bool>(); 425 data_storage[key] = value.get<bool>();
@@ -527,6 +547,8 @@ void AP_Connect(std::string server, std::string player, std::string password) {
527 GetState().Connect(server, player, password); 547 GetState().Connect(server, player, password);
528} 548}
529 549
550std::string AP_GetStatusMessage() { return GetState().GetStatusMessage(); }
551
530std::string AP_GetSaveName() { return GetState().save_name; } 552std::string AP_GetSaveName() { return GetState().save_name; }
531 553
532bool AP_HasCheckedGameLocation(int location_id) { 554bool AP_HasCheckedGameLocation(int location_id) {
@@ -590,7 +612,8 @@ bool AP_IsLocationVisible(int classification) {
590 return false; 612 return false;
591 } 613 }
592 614
593 if (GetState().door_shuffle_mode == kDOORS_MODE && !GetState().early_color_hallways) { 615 if (GetState().door_shuffle_mode == kDOORS_MODE &&
616 !GetState().early_color_hallways) {
594 world_state |= kLOCATION_SMALL_SPHERE_ONE; 617 world_state |= kLOCATION_SMALL_SPHERE_ONE;
595 } 618 }
596 619