diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-06-10 19:13:22 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-06-10 19:13:22 -0400 |
commit | 33bf1f9653ed608de5554940dc8a0c3f5dc7e4ea (patch) | |
tree | b1db5d3e83ccd8c5219d5db12b01bc3d152b79d1 /src/ap_state.cpp | |
parent | 3b3c3ca4ed98c8d1e884f6c9f8f63d7b7c76e37b (diff) | |
download | lingo-ap-tracker-33bf1f9653ed608de5554940dc8a0c3f5dc7e4ea.tar.gz lingo-ap-tracker-33bf1f9653ed608de5554940dc8a0c3f5dc7e4ea.tar.bz2 lingo-ap-tracker-33bf1f9653ed608de5554940dc8a0c3f5dc7e4ea.zip |
Go back to old logging system
Brought in libfmt to handle string formatting and replace a bunch of ostringstream uses.
Diffstat (limited to 'src/ap_state.cpp')
-rw-r--r-- | src/ap_state.cpp | 79 |
1 files changed, 40 insertions, 39 deletions
diff --git a/src/ap_state.cpp b/src/ap_state.cpp index 8ff0ccd..e4d892b 100644 --- a/src/ap_state.cpp +++ b/src/ap_state.cpp | |||
@@ -4,6 +4,7 @@ | |||
4 | #define _WEBSOCKETPP_CPP11_STRICT_ | 4 | #define _WEBSOCKETPP_CPP11_STRICT_ |
5 | #pragma comment(lib, "crypt32") | 5 | #pragma comment(lib, "crypt32") |
6 | 6 | ||
7 | #include <fmt/core.h> | ||
7 | #include <hkutil/string.h> | 8 | #include <hkutil/string.h> |
8 | 9 | ||
9 | #include <any> | 10 | #include <any> |
@@ -21,6 +22,7 @@ | |||
21 | #include <tuple> | 22 | #include <tuple> |
22 | 23 | ||
23 | #include "game_data.h" | 24 | #include "game_data.h" |
25 | #include "logger.h" | ||
24 | #include "tracker_frame.h" | 26 | #include "tracker_frame.h" |
25 | #include "tracker_state.h" | 27 | #include "tracker_state.h" |
26 | 28 | ||
@@ -75,7 +77,7 @@ struct APState { | |||
75 | 77 | ||
76 | void Connect(std::string server, std::string player, std::string password) { | 78 | void Connect(std::string server, std::string player, std::string password) { |
77 | if (!initialized) { | 79 | if (!initialized) { |
78 | wxLogVerbose("Initializing APState..."); | 80 | TrackerLog("Initializing APState..."); |
79 | 81 | ||
80 | std::thread([this]() { | 82 | std::thread([this]() { |
81 | for (;;) { | 83 | for (;;) { |
@@ -91,14 +93,14 @@ struct APState { | |||
91 | }).detach(); | 93 | }).detach(); |
92 | 94 | ||
93 | for (int panel_id : GD_GetAchievementPanels()) { | 95 | for (int panel_id : GD_GetAchievementPanels()) { |
94 | tracked_data_storage_keys.push_back( | 96 | tracked_data_storage_keys.push_back(fmt::format( |
95 | "Achievement|" + GD_GetPanel(panel_id).achievement_name); | 97 | "Achievement|{}", GD_GetPanel(panel_id).achievement_name)); |
96 | } | 98 | } |
97 | 99 | ||
98 | for (const MapArea& map_area : GD_GetMapAreas()) { | 100 | for (const MapArea& map_area : GD_GetMapAreas()) { |
99 | for (const Location& location : map_area.locations) { | 101 | for (const Location& location : map_area.locations) { |
100 | tracked_data_storage_keys.push_back( | 102 | tracked_data_storage_keys.push_back( |
101 | "Hunt|" + std::to_string(location.ap_location_id)); | 103 | fmt::format("Hunt|{}", location.ap_location_id)); |
102 | } | 104 | } |
103 | } | 105 | } |
104 | 106 | ||
@@ -109,10 +111,10 @@ struct APState { | |||
109 | } | 111 | } |
110 | 112 | ||
111 | tracker_frame->SetStatusMessage("Connecting to Archipelago server...."); | 113 | tracker_frame->SetStatusMessage("Connecting to Archipelago server...."); |
112 | wxLogStatus("Connecting to Archipelago server (%s)...", server); | 114 | TrackerLog(fmt::format("Connecting to Archipelago server ({})...", server)); |
113 | 115 | ||
114 | { | 116 | { |
115 | wxLogVerbose("Destroying old AP client..."); | 117 | TrackerLog("Destroying old AP client..."); |
116 | 118 | ||
117 | std::lock_guard client_guard(client_mutex); | 119 | std::lock_guard client_guard(client_mutex); |
118 | 120 | ||
@@ -158,10 +160,10 @@ struct APState { | |||
158 | apclient->set_room_info_handler([this, player, password]() { | 160 | apclient->set_room_info_handler([this, player, password]() { |
159 | inventory.clear(); | 161 | inventory.clear(); |
160 | 162 | ||
161 | wxLogStatus("Connected to Archipelago server. Authenticating as %s %s", | 163 | TrackerLog(fmt::format( |
162 | player, | 164 | "Connected to Archipelago server. Authenticating as {} {}", player, |
163 | (password.empty() ? "without password" | 165 | (password.empty() ? "without password" |
164 | : "with password " + password)); | 166 | : "with password " + password))); |
165 | tracker_frame->SetStatusMessage( | 167 | tracker_frame->SetStatusMessage( |
166 | "Connected to Archipelago server. Authenticating..."); | 168 | "Connected to Archipelago server. Authenticating..."); |
167 | 169 | ||
@@ -173,7 +175,7 @@ struct APState { | |||
173 | [this](const std::list<int64_t>& locations) { | 175 | [this](const std::list<int64_t>& locations) { |
174 | for (const int64_t location_id : locations) { | 176 | for (const int64_t location_id : locations) { |
175 | checked_locations.insert(location_id); | 177 | checked_locations.insert(location_id); |
176 | wxLogVerbose("Location: %lld", location_id); | 178 | TrackerLog(fmt::format("Location: {}", location_id)); |
177 | } | 179 | } |
178 | 180 | ||
179 | RefreshTracker(false); | 181 | RefreshTracker(false); |
@@ -182,14 +184,14 @@ struct APState { | |||
182 | apclient->set_slot_disconnected_handler([this]() { | 184 | apclient->set_slot_disconnected_handler([this]() { |
183 | tracker_frame->SetStatusMessage( | 185 | tracker_frame->SetStatusMessage( |
184 | "Disconnected from Archipelago. Attempting to reconnect..."); | 186 | "Disconnected from Archipelago. Attempting to reconnect..."); |
185 | wxLogStatus( | 187 | TrackerLog( |
186 | "Slot disconnected from Archipelago. Attempting to reconnect..."); | 188 | "Slot disconnected from Archipelago. Attempting to reconnect..."); |
187 | }); | 189 | }); |
188 | 190 | ||
189 | apclient->set_socket_disconnected_handler([this]() { | 191 | apclient->set_socket_disconnected_handler([this]() { |
190 | tracker_frame->SetStatusMessage( | 192 | tracker_frame->SetStatusMessage( |
191 | "Disconnected from Archipelago. Attempting to reconnect..."); | 193 | "Disconnected from Archipelago. Attempting to reconnect..."); |
192 | wxLogStatus( | 194 | TrackerLog( |
193 | "Socket disconnected from Archipelago. Attempting to reconnect..."); | 195 | "Socket disconnected from Archipelago. Attempting to reconnect..."); |
194 | }); | 196 | }); |
195 | 197 | ||
@@ -197,7 +199,7 @@ struct APState { | |||
197 | [this](const std::list<APClient::NetworkItem>& items) { | 199 | [this](const std::list<APClient::NetworkItem>& items) { |
198 | for (const APClient::NetworkItem& item : items) { | 200 | for (const APClient::NetworkItem& item : items) { |
199 | inventory[item.item]++; | 201 | inventory[item.item]++; |
200 | wxLogVerbose("Item: %lld", item.item); | 202 | TrackerLog(fmt::format("Item: {}", item.item)); |
201 | } | 203 | } |
202 | 204 | ||
203 | RefreshTracker(false); | 205 | RefreshTracker(false); |
@@ -222,10 +224,10 @@ struct APState { | |||
222 | apclient->set_slot_connected_handler([this, &connection_mutex]( | 224 | apclient->set_slot_connected_handler([this, &connection_mutex]( |
223 | const nlohmann::json& slot_data) { | 225 | const nlohmann::json& slot_data) { |
224 | tracker_frame->SetStatusMessage("Connected to Archipelago!"); | 226 | tracker_frame->SetStatusMessage("Connected to Archipelago!"); |
225 | wxLogStatus("Connected to Archipelago!"); | 227 | TrackerLog("Connected to Archipelago!"); |
226 | 228 | ||
227 | data_storage_prefix = | 229 | data_storage_prefix = |
228 | "Lingo_" + std::to_string(apclient->get_player_number()) + "_"; | 230 | fmt::format("Lingo_{}_", apclient->get_player_number()); |
229 | door_shuffle_mode = slot_data["shuffle_doors"].get<DoorShuffleMode>(); | 231 | door_shuffle_mode = slot_data["shuffle_doors"].get<DoorShuffleMode>(); |
230 | color_shuffle = slot_data["shuffle_colors"].get<int>() == 1; | 232 | color_shuffle = slot_data["shuffle_colors"].get<int>() == 1; |
231 | painting_shuffle = slot_data["shuffle_paintings"].get<int>() == 1; | 233 | painting_shuffle = slot_data["shuffle_paintings"].get<int>() == 1; |
@@ -277,18 +279,18 @@ struct APState { | |||
277 | corrected_keys.push_back(data_storage_prefix + key); | 279 | corrected_keys.push_back(data_storage_prefix + key); |
278 | } | 280 | } |
279 | 281 | ||
280 | { | 282 | victory_data_storage_key = |
281 | std::ostringstream vdsks; | 283 | fmt::format("_read_client_status_{}_{}", apclient->get_team_number(), |
282 | vdsks << "_read_client_status_" << apclient->get_team_number() << "_" | 284 | apclient->get_player_number()); |
283 | << apclient->get_player_number(); | ||
284 | victory_data_storage_key = vdsks.str(); | ||
285 | } | ||
286 | 285 | ||
287 | corrected_keys.push_back(victory_data_storage_key); | 286 | corrected_keys.push_back(victory_data_storage_key); |
288 | 287 | ||
289 | apclient->Get(corrected_keys); | 288 | apclient->Get(corrected_keys); |
290 | apclient->SetNotify(corrected_keys); | 289 | apclient->SetNotify(corrected_keys); |
291 | 290 | ||
291 | ResetReachabilityRequirements(); | ||
292 | RefreshTracker(true); | ||
293 | |||
292 | { | 294 | { |
293 | std::lock_guard connection_lock(connection_mutex); | 295 | std::lock_guard connection_lock(connection_mutex); |
294 | if (!has_connection_result) { | 296 | if (!has_connection_result) { |
@@ -333,7 +335,7 @@ struct APState { | |||
333 | } | 335 | } |
334 | 336 | ||
335 | std::string full_message = hatkirby::implode(error_messages, " "); | 337 | std::string full_message = hatkirby::implode(error_messages, " "); |
336 | wxLogError(wxString(full_message)); | 338 | TrackerLog(full_message); |
337 | 339 | ||
338 | wxMessageBox(full_message, "Connection failed", wxOK | wxICON_ERROR); | 340 | wxMessageBox(full_message, "Connection failed", wxOK | wxICON_ERROR); |
339 | }); | 341 | }); |
@@ -355,7 +357,7 @@ struct APState { | |||
355 | DestroyClient(); | 357 | DestroyClient(); |
356 | 358 | ||
357 | tracker_frame->SetStatusMessage("Disconnected from Archipelago."); | 359 | tracker_frame->SetStatusMessage("Disconnected from Archipelago."); |
358 | wxLogStatus("Timeout while connecting to Archipelago server."); | 360 | TrackerLog("Timeout while connecting to Archipelago server."); |
359 | wxMessageBox("Timeout while connecting to Archipelago server.", | 361 | wxMessageBox("Timeout while connecting to Archipelago server.", |
360 | "Connection failed", wxOK | wxICON_ERROR); | 362 | "Connection failed", wxOK | wxICON_ERROR); |
361 | 363 | ||
@@ -374,9 +376,6 @@ struct APState { | |||
374 | } | 376 | } |
375 | 377 | ||
376 | if (connected) { | 378 | if (connected) { |
377 | ResetReachabilityRequirements(); | ||
378 | RefreshTracker(true); | ||
379 | } else { | ||
380 | client_active = false; | 379 | client_active = false; |
381 | } | 380 | } |
382 | } | 381 | } |
@@ -384,11 +383,12 @@ struct APState { | |||
384 | void HandleDataStorage(const std::string& key, const nlohmann::json& value) { | 383 | void HandleDataStorage(const std::string& key, const nlohmann::json& value) { |
385 | if (value.is_boolean()) { | 384 | if (value.is_boolean()) { |
386 | data_storage[key] = value.get<bool>(); | 385 | data_storage[key] = value.get<bool>(); |
387 | wxLogVerbose("Data storage %s retrieved as %s", key, | 386 | TrackerLog(fmt::format("Data storage {} retrieved as {}", key, |
388 | (value.get<bool>() ? "true" : "false")); | 387 | (value.get<bool>() ? "true" : "false"))); |
389 | } else if (value.is_number()) { | 388 | } else if (value.is_number()) { |
390 | data_storage[key] = value.get<int>(); | 389 | data_storage[key] = value.get<int>(); |
391 | wxLogVerbose("Data storage %s retrieved as %d", key, value.get<int>()); | 390 | TrackerLog(fmt::format("Data storage {} retrieved as {}", key, |
391 | value.get<int>())); | ||
392 | } else if (value.is_object()) { | 392 | } else if (value.is_object()) { |
393 | if (key.ends_with("PlayerPos")) { | 393 | if (key.ends_with("PlayerPos")) { |
394 | auto map_value = value.get<std::map<std::string, int>>(); | 394 | auto map_value = value.get<std::map<std::string, int>>(); |
@@ -397,7 +397,7 @@ struct APState { | |||
397 | data_storage[key] = value.get<std::map<std::string, int>>(); | 397 | data_storage[key] = value.get<std::map<std::string, int>>(); |
398 | } | 398 | } |
399 | 399 | ||
400 | wxLogVerbose("Data storage %s retrieved as dictionary", key); | 400 | TrackerLog(fmt::format("Data storage {} retrieved as dictionary", key)); |
401 | } else if (value.is_null()) { | 401 | } else if (value.is_null()) { |
402 | if (key.ends_with("PlayerPos")) { | 402 | if (key.ends_with("PlayerPos")) { |
403 | player_pos = std::nullopt; | 403 | player_pos = std::nullopt; |
@@ -405,7 +405,7 @@ struct APState { | |||
405 | data_storage.erase(key); | 405 | data_storage.erase(key); |
406 | } | 406 | } |
407 | 407 | ||
408 | wxLogVerbose("Data storage %s retrieved as null", key); | 408 | TrackerLog(fmt::format("Data storage {} retrieved as null", key)); |
409 | } else if (value.is_array()) { | 409 | } else if (value.is_array()) { |
410 | auto list_value = value.get<std::vector<std::string>>(); | 410 | auto list_value = value.get<std::vector<std::string>>(); |
411 | 411 | ||
@@ -416,8 +416,8 @@ struct APState { | |||
416 | data_storage[key] = list_value; | 416 | data_storage[key] = list_value; |
417 | } | 417 | } |
418 | 418 | ||
419 | wxLogVerbose("Data storage %s retrieved as list: [%s]", key, | 419 | TrackerLog(fmt::format("Data storage {} retrieved as list: [{}]", key, |
420 | hatkirby::implode(list_value, ", ")); | 420 | hatkirby::implode(list_value, ", "))); |
421 | } | 421 | } |
422 | } | 422 | } |
423 | 423 | ||
@@ -427,7 +427,7 @@ struct APState { | |||
427 | 427 | ||
428 | bool HasCheckedHuntPanel(int location_id) { | 428 | bool HasCheckedHuntPanel(int location_id) { |
429 | std::string key = | 429 | std::string key = |
430 | data_storage_prefix + "Hunt|" + std::to_string(location_id); | 430 | fmt::format("{}Hunt|{}", data_storage_prefix, location_id); |
431 | return data_storage.count(key) && std::any_cast<bool>(data_storage.at(key)); | 431 | return data_storage.count(key) && std::any_cast<bool>(data_storage.at(key)); |
432 | } | 432 | } |
433 | 433 | ||
@@ -436,12 +436,13 @@ struct APState { | |||
436 | } | 436 | } |
437 | 437 | ||
438 | bool HasAchievement(const std::string& name) { | 438 | bool HasAchievement(const std::string& name) { |
439 | std::string key = data_storage_prefix + "Achievement|" + name; | 439 | std::string key = |
440 | fmt::format("{}Achievement|{}", data_storage_prefix, name); | ||
440 | return data_storage.count(key) && std::any_cast<bool>(data_storage.at(key)); | 441 | return data_storage.count(key) && std::any_cast<bool>(data_storage.at(key)); |
441 | } | 442 | } |
442 | 443 | ||
443 | const std::set<std::string>& GetCheckedPaintings() { | 444 | const std::set<std::string>& GetCheckedPaintings() { |
444 | std::string key = data_storage_prefix + "Paintings"; | 445 | std::string key = fmt::format("{}Paintings", data_storage_prefix); |
445 | if (!data_storage.count(key)) { | 446 | if (!data_storage.count(key)) { |
446 | data_storage[key] = std::set<std::string>(); | 447 | data_storage[key] = std::set<std::string>(); |
447 | } | 448 | } |
@@ -458,7 +459,7 @@ struct APState { | |||
458 | } | 459 | } |
459 | 460 | ||
460 | void RefreshTracker(bool reset) { | 461 | void RefreshTracker(bool reset) { |
461 | wxLogVerbose("Refreshing display..."); | 462 | TrackerLog("Refreshing display..."); |
462 | 463 | ||
463 | RecalculateReachability(); | 464 | RecalculateReachability(); |
464 | 465 | ||
@@ -472,7 +473,7 @@ struct APState { | |||
472 | int64_t GetItemId(const std::string& item_name) { | 473 | int64_t GetItemId(const std::string& item_name) { |
473 | int64_t ap_id = apclient->get_item_id(item_name); | 474 | int64_t ap_id = apclient->get_item_id(item_name); |
474 | if (ap_id == APClient::INVALID_NAME_ID) { | 475 | if (ap_id == APClient::INVALID_NAME_ID) { |
475 | wxLogError("Could not find AP item ID for %s", item_name); | 476 | TrackerLog(fmt::format("Could not find AP item ID for {}", item_name)); |
476 | } | 477 | } |
477 | 478 | ||
478 | return ap_id; | 479 | return ap_id; |