mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Added integration with server browser api
This commit is contained in:
parent
4bff66e88b
commit
1dc25a193e
@ -520,14 +520,55 @@ public:
|
||||
void RefreshServerList()
|
||||
{
|
||||
ServerList.clear();
|
||||
|
||||
static bool bThreadLocked = false;
|
||||
|
||||
if (!bThreadLocked) {
|
||||
std::thread t([this]() {
|
||||
std::cout << "Refreshing server list..." << std::endl;
|
||||
bThreadLocked = true;
|
||||
httplib::Client client(MatchmakingServerStringBuffer);
|
||||
client.set_connection_timeout(10);
|
||||
auto res = client.Get("/servers");
|
||||
if (res)
|
||||
{
|
||||
json root = json::parse(res->body);
|
||||
for (auto obj : root["servers"])
|
||||
{
|
||||
ServerList.push_back(
|
||||
new ServerListing(obj["name"], obj["map"], obj["ip"], obj["version"])
|
||||
);
|
||||
}
|
||||
}
|
||||
bThreadLocked = false;
|
||||
});
|
||||
|
||||
t.detach();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SendHostingPostRequest()
|
||||
{
|
||||
httplib::Client client(MatchmakingServerStringBuffer);
|
||||
auto res = client.Get("/browse");
|
||||
json root = json::parse(res->body);
|
||||
for (auto obj : root["servers"])
|
||||
client.set_connection_timeout(10);
|
||||
// send a post request to "/servers/add" with a json body
|
||||
json body = json::object();
|
||||
body["name"] = ServerNameBuffer;
|
||||
body["map"] = *SelectedMap;
|
||||
body["version"] = "1.0";
|
||||
|
||||
std::string body_str = body.dump();
|
||||
|
||||
std::cout << body_str << "\n";
|
||||
|
||||
auto res = client.Post("/servers/add", body_str.c_str(), body_str.length(), "application/json");
|
||||
if (res)
|
||||
{
|
||||
//ServerList.push_back(
|
||||
// new ServerListing(obj["token"], obj["name"], obj["version"])
|
||||
//);
|
||||
std::cout << "Hosting Request Result: " << res->body << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -537,6 +578,7 @@ public:
|
||||
CurrentSection = section;
|
||||
}
|
||||
|
||||
|
||||
void CompMenu()
|
||||
{
|
||||
ImGui::BeginTabBar("CompMenu");
|
||||
@ -660,6 +702,7 @@ public:
|
||||
{
|
||||
ToggleDevCommands();
|
||||
}
|
||||
SendHostingPostRequest();
|
||||
|
||||
}
|
||||
if (StartAsDedi)
|
||||
|
Loading…
x
Reference in New Issue
Block a user