about summary refs log tree commit diff stats
path: root/ap_state.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-05-03 01:29:41 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-05-03 01:29:41 -0400
commit47e59ea969c775bea316b1a910c845a7c8482091 (patch)
tree0cc5e900ba213a1aeb81cb95722a8def13c71c6b /ap_state.cpp
parent1af4d354fbbded3b8086e370b6f4c20d084a5d68 (diff)
downloadlingo-ap-tracker-47e59ea969c775bea316b1a910c845a7c8482091.tar.gz
lingo-ap-tracker-47e59ea969c775bea316b1a910c845a7c8482091.tar.bz2
lingo-ap-tracker-47e59ea969c775bea316b1a910c845a7c8482091.zip
Changes to get it to compile on Windows
Diffstat (limited to 'ap_state.cpp')
-rw-r--r--ap_state.cpp40
1 files changed, 24 insertions, 16 deletions
diff --git a/ap_state.cpp b/ap_state.cpp index 910feb7..2c8ba0a 100644 --- a/ap_state.cpp +++ b/ap_state.cpp
@@ -1,8 +1,12 @@
1#include "ap_state.h" 1#include "ap_state.h"
2 2
3#include <hkutil/string.h> 3#define HAS_STD_FILESYSTEM
4#define _WEBSOCKETPP_CPP11_STRICT_
5#pragma comment(lib, "crypt32")
4 6
7#include <apclient.hpp>
5#include <apuuid.hpp> 8#include <apuuid.hpp>
9#include <hkutil/string.h>
6#include <chrono> 10#include <chrono>
7#include <exception> 11#include <exception>
8#include <list> 12#include <list>
@@ -17,13 +21,15 @@ constexpr int AP_REVISION = 0;
17 21
18constexpr int ITEM_HANDLING = 7; // <- all 22constexpr int ITEM_HANDLING = 7; // <- all
19 23
24static APClient* apclient = nullptr;
25
20APState::APState() { 26APState::APState() {
21 std::thread([this]() { 27 std::thread([this]() {
22 for (;;) { 28 for (;;) {
23 { 29 {
24 std::lock_guard client_guard(client_mutex_); 30 std::lock_guard client_guard(client_mutex_);
25 if (apclient_) { 31 if (apclient) {
26 apclient_->poll(); 32 apclient->poll();
27 } 33 }
28 } 34 }
29 35
@@ -39,11 +45,13 @@ void APState::Connect(std::string server, std::string player,
39 { 45 {
40 std::lock_guard client_guard(client_mutex_); 46 std::lock_guard client_guard(client_mutex_);
41 47
42 if (apclient_) { 48 if (apclient) {
43 apclient_->reset(); 49 apclient->reset();
50 delete apclient;
51 apclient = nullptr;
44 } 52 }
45 53
46 apclient_ = std::make_unique<APClient>(ap_get_uuid(""), "Lingo", server); 54 apclient = new APClient(ap_get_uuid(""), "Lingo", server);
47 } 55 }
48 56
49 inventory_.clear(); 57 inventory_.clear();
@@ -52,15 +60,15 @@ void APState::Connect(std::string server, std::string player,
52 bool connected = false; 60 bool connected = false;
53 bool has_connection_result = false; 61 bool has_connection_result = false;
54 62
55 apclient_->set_room_info_handler([&]() { 63 apclient->set_room_info_handler([&]() {
56 tracker_frame_->SetStatusMessage( 64 tracker_frame_->SetStatusMessage(
57 "Connected to Archipelago server. Authenticating..."); 65 "Connected to Archipelago server. Authenticating...");
58 66
59 apclient_->ConnectSlot(player, password, ITEM_HANDLING, {"Tracker"}, 67 apclient->ConnectSlot(player, password, ITEM_HANDLING, {"Tracker"},
60 {AP_MAJOR, AP_MINOR, AP_REVISION}); 68 {AP_MAJOR, AP_MINOR, AP_REVISION});
61 }); 69 });
62 70
63 apclient_->set_location_checked_handler( 71 apclient->set_location_checked_handler(
64 [&](const std::list<int64_t>& locations) { 72 [&](const std::list<int64_t>& locations) {
65 for (const int64_t location_id : locations) { 73 for (const int64_t location_id : locations) {
66 checked_locations_.insert(location_id); 74 checked_locations_.insert(location_id);
@@ -70,15 +78,15 @@ void APState::Connect(std::string server, std::string player,
70 RefreshTracker(); 78 RefreshTracker();
71 }); 79 });
72 80
73 apclient_->set_slot_disconnected_handler([&]() { 81 apclient->set_slot_disconnected_handler([&]() {
74 tracker_frame_->SetStatusMessage("Disconnected from Archipelago."); 82 tracker_frame_->SetStatusMessage("Disconnected from Archipelago.");
75 }); 83 });
76 84
77 apclient_->set_socket_disconnected_handler([&]() { 85 apclient->set_socket_disconnected_handler([&]() {
78 tracker_frame_->SetStatusMessage("Disconnected from Archipelago."); 86 tracker_frame_->SetStatusMessage("Disconnected from Archipelago.");
79 }); 87 });
80 88
81 apclient_->set_items_received_handler( 89 apclient->set_items_received_handler(
82 [&](const std::list<APClient::NetworkItem>& items) { 90 [&](const std::list<APClient::NetworkItem>& items) {
83 for (const APClient::NetworkItem& item : items) { 91 for (const APClient::NetworkItem& item : items) {
84 // TODO: Progressive items. 92 // TODO: Progressive items.
@@ -90,7 +98,7 @@ void APState::Connect(std::string server, std::string player,
90 RefreshTracker(); 98 RefreshTracker();
91 }); 99 });
92 100
93 apclient_->set_slot_connected_handler([&](const nlohmann::json& slot_data) { 101 apclient->set_slot_connected_handler([&](const nlohmann::json& slot_data) {
94 tracker_frame_->SetStatusMessage("Connected to Archipelago!"); 102 tracker_frame_->SetStatusMessage("Connected to Archipelago!");
95 103
96 door_shuffle_mode_ = slot_data["shuffle_doors"].get<DoorShuffleMode>(); 104 door_shuffle_mode_ = slot_data["shuffle_doors"].get<DoorShuffleMode>();
@@ -100,7 +108,7 @@ void APState::Connect(std::string server, std::string player,
100 has_connection_result = true; 108 has_connection_result = true;
101 }); 109 });
102 110
103 apclient_->set_slot_refused_handler( 111 apclient->set_slot_refused_handler(
104 [&](const std::list<std::string>& errors) { 112 [&](const std::list<std::string>& errors) {
105 connected = false; 113 connected = false;
106 has_connection_result = true; 114 has_connection_result = true;
@@ -163,7 +171,7 @@ void APState::Connect(std::string server, std::string player,
163 section_id++) { 171 section_id++) {
164 const Location& location = map_area.locations.at(section_id); 172 const Location& location = map_area.locations.at(section_id);
165 173
166 int64_t ap_id = apclient_->get_location_id(location.ap_location_name); 174 int64_t ap_id = apclient->get_location_id(location.ap_location_name);
167 if (ap_id == APClient::INVALID_NAME_ID) { 175 if (ap_id == APClient::INVALID_NAME_ID) {
168 std::cout << "Could not find AP location ID for " 176 std::cout << "Could not find AP location ID for "
169 << location.ap_location_name << std::endl; 177 << location.ap_location_name << std::endl;
@@ -232,7 +240,7 @@ void APState::RefreshTracker() {
232} 240}
233 241
234int64_t APState::GetItemId(const std::string& item_name) { 242int64_t APState::GetItemId(const std::string& item_name) {
235 int64_t ap_id = apclient_->get_item_id(item_name); 243 int64_t ap_id = apclient->get_item_id(item_name);
236 if (ap_id == APClient::INVALID_NAME_ID) { 244 if (ap_id == APClient::INVALID_NAME_ID) {
237 std::cout << "Could not find AP item ID for " << item_name << std::endl; 245 std::cout << "Could not find AP item ID for " << item_name << std::endl;
238 } 246 }