-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
112 lines (94 loc) · 3.38 KB
/
main.cpp
File metadata and controls
112 lines (94 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "main.h"
#include <chrono>
#include <cstdint>
#include <ostream>
#include <thread>
#include "Archipelago.h"
#include "readerwriterqueue.h"
using namespace std;
using namespace PINE;
using namespace moodycamel;
using namespace Rac2;
int main(int, char **) {
input_queue = ReaderWriterQueue<string>(20);
input_reader = thread([&]() {
while (true) {
string input;
getline(cin, input);
input_queue.enqueue(input);
}
});
input_reader.detach();
rac2 = make_unique<Rac2_interface>();
rac2_connected = false;
while (true) {
// Connect to PCSX2
while (!rac2_connected) {
cout << "Attempting to connect to PCSX2...\n";
if (rac2->connect()) {
if (rac2->id == "SCUS-97268") {
cout << "Successfully connected to " << rac2->platform
<< "\n"
<< "Game found = " << rac2->title << " (" << rac2->id
<< ")\n";
rac2_connected = true;
if (!(AP_IsInit() && AP_GetConnectionStatus() ==
AP_ConnectionStatus::Connected)) {
printp(
"There is no active multiworld server connection. "
"Connect using command: /connect server:port "
"slotname");
}
}
} else {
sleep(2);
}
}
// Proccess Input
string input;
if (input_queue.try_dequeue(input)) {
vector<string> tokens = tokenize(input);
if (tokens[0] == "/help") {
// TODO: print command help
printp("Command help coming soon `\\_( ͡° ͜ʖ ͡°)_/¯");
} else if (tokens[0] == "/connect" && tokens.size() == 3) {
ap_connect(tokens[1], tokens[2]);
} else if (tokens[0] == "connect" && tokens.size() == 4) {
ap_connect(tokens[1], tokens[2], tokens[3]);
} else {
printp(
"Invalid command. Try using '/help' for a list of "
"valid commands");
}
}
sleep(1);
}
}
bool ap_connect(const std::string address, const std::string slotname,
const string password) {
if (AP_IsInit() &&
AP_GetConnectionStatus() == AP_ConnectionStatus::Connected) {
printp("Already connected to AP server");
}
AP_Init(address.c_str(), "RAC2", slotname.c_str(), password.c_str());
AP_SetItemClearCallback([]() {
// TODO: Clear all item states
});
AP_SetItemRecvCallback([](int64_t item_id, bool notify) {
// TODO: add the item with the given ID to the current state. The
// second parameter decides whether or not to notify the player
});
AP_SetLocationCheckedCallback([](int64_t location_id) {
// TODO: mark the location with the given id as checked.
});
AP_Start();
for (int i = 0; i < 5; i++) {
if (AP_GetConnectionStatus() == AP_ConnectionStatus::Connected) {
return true;
}
this_thread::sleep_for(chrono::seconds(1));
}
printp("Connection to AP server failed. Error: %d", int(AP_GetConnectionStatus()));
AP_Shutdown();
return false;
}