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()
|
void RefreshServerList()
|
||||||
{
|
{
|
||||||
ServerList.clear();
|
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);
|
httplib::Client client(MatchmakingServerStringBuffer);
|
||||||
auto res = client.Get("/browse");
|
client.set_connection_timeout(10);
|
||||||
json root = json::parse(res->body);
|
// send a post request to "/servers/add" with a json body
|
||||||
for (auto obj : root["servers"])
|
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(
|
std::cout << "Hosting Request Result: " << res->body << "\n";
|
||||||
// new ServerListing(obj["token"], obj["name"], obj["version"])
|
|
||||||
//);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -537,6 +578,7 @@ public:
|
|||||||
CurrentSection = section;
|
CurrentSection = section;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CompMenu()
|
void CompMenu()
|
||||||
{
|
{
|
||||||
ImGui::BeginTabBar("CompMenu");
|
ImGui::BeginTabBar("CompMenu");
|
||||||
@ -660,6 +702,7 @@ public:
|
|||||||
{
|
{
|
||||||
ToggleDevCommands();
|
ToggleDevCommands();
|
||||||
}
|
}
|
||||||
|
SendHostingPostRequest();
|
||||||
|
|
||||||
}
|
}
|
||||||
if (StartAsDedi)
|
if (StartAsDedi)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user