Merge pull request #33 from salexandru1/master

Various fixes
This commit is contained in:
PixieCore 2021-08-14 22:57:41 +02:00 committed by GitHub
commit 302a9c1378
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 12 deletions

View File

@ -13,7 +13,7 @@ private:
bool ThemeSet = false;
public:
CCompanion();
~CCompanion();
////////////////////
// Enums //
@ -35,7 +35,7 @@ public:
// Server Browser //
////////////////////
R5Net::Client r5net;
R5Net::Client* r5net;
std::vector<ServerListing> ServerList;
ImGuiTextFilter ServerBrowserFilter;

View File

@ -15,7 +15,7 @@ CCompanion* g_ServerBrowser = nullptr;
* _ccompanion.cpp
*-----------------------------------------------------------------------------*/
CCompanion::CCompanion() : MatchmakingServerStringBuffer("r5a-comp-sv.herokuapp.com"), r5net(R5Net::Client("r5a-comp-sv.herokuapp.com"))
CCompanion::CCompanion() : MatchmakingServerStringBuffer("r5a-comp-sv.herokuapp.com"), r5net(new R5Net::Client("r5a-comp-sv.herokuapp.com"))
{
memset(ServerConnStringBuffer, 0, sizeof(ServerConnStringBuffer));
@ -44,6 +44,11 @@ CCompanion::CCompanion() : MatchmakingServerStringBuffer("r5a-comp-sv.herokuapp.
HostingServerRequestThread.detach();
}
CCompanion::~CCompanion()
{
delete r5net;
}
void CCompanion::UpdateHostingStatus()
{
if (!GameGlobals::HostState || !GameGlobals::Cvar) // Is HostState and Cvar valid?
@ -86,7 +91,7 @@ void CCompanion::RefreshServerList()
std::cout << " [+CCompanion+] Refreshing server list with string " << MatchmakingServerStringBuffer << "\n";
#endif
bThreadLocked = true;
ServerList = r5net.GetServersList();
ServerList = r5net->GetServersList();
bThreadLocked = false;
});
@ -97,7 +102,7 @@ void CCompanion::RefreshServerList()
void CCompanion::SendHostingPostRequest()
{
HostToken = "";
bool result = r5net.PostServerHost(HostRequestMessage, HostToken, ServerListing{ MyServer.name, std::string(GameGlobals::HostState->m_levelName), "", GameGlobals::Cvar->FindVar("hostport")->m_pzsCurrentValue, MyServer.password});
bool result = r5net->PostServerHost(HostRequestMessage, HostToken, ServerListing{ MyServer.name, std::string(GameGlobals::HostState->m_levelName), "", GameGlobals::Cvar->FindVar("hostport")->m_pzsCurrentValue, MyServer.password});
if (result)
{
HostRequestMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f);
@ -307,7 +312,7 @@ void CCompanion::ServerBrowserSection()
{
PrivateServerRequestMessage = "";
ServerListing server;
bool result = r5net.GetServerByToken(server, PrivateServerRequestMessage, PrivateServerToken, PrivateServerPassword); // Send token connect request.
bool result = r5net->GetServerByToken(server, PrivateServerRequestMessage, PrivateServerToken, PrivateServerPassword); // Send token connect request.
if (!server.name.empty())
{
ConnectToServer(server.ip, server.port); // Connect to the server
@ -420,8 +425,12 @@ void CCompanion::HostServerSection()
void CCompanion::SettingsSection()
{
ImGui::Text("In renovation");
//ImGui::InputText("Matchmaking Server String", MatchmakingServerStringBuffer, IM_ARRAYSIZE(MatchmakingServerStringBuffer), 0);
ImGui::InputTextWithHint("##MatchmakingServerString", "Matchmaking Server String", & MatchmakingServerStringBuffer);
if (ImGui::Button("Update Settings"))
{
if (r5net) delete r5net;
r5net = new R5Net::Client(MatchmakingServerStringBuffer);
}
}
void CCompanion::Draw(const char* title)

View File

@ -10,7 +10,7 @@ std::vector<ServerListing> R5Net::Client::GetServersList()
auto res = m_HttpClient.Get("/servers");
if (res)
if (!res) return std::vector<ServerListing>();
{
nlohmann::json root = nlohmann::json::parse(res->body);
for (auto obj : root["servers"])
@ -35,9 +35,15 @@ bool R5Net::Client::PostServerHost(std::string& outMessage, std::string& outToke
auto res = m_HttpClient.Post("/servers/add", reqBodyStr.c_str(), reqBodyStr.length(), "application/json");
if (!res)
{
outMessage = "Failed to reach comp-server";
outToken = "";
return false;
}
nlohmann::json resBody = nlohmann::json::parse(res->body);
if (res && resBody["success"].is_boolean() && resBody["success"])
if (resBody["success"].is_boolean() && resBody["success"])
{
outMessage = "Broadcasting!";
@ -67,7 +73,13 @@ bool R5Net::Client::GetServerByToken(ServerListing& outServer, std::string& outE
httplib::Result res = m_HttpClient.Post("/server/byToken", reqBody.dump().c_str(), reqBody.dump().length(), "application/json");
std::cout << "YEEEEEEEEEEEEEE" << res->body << "\n";
if (!res)
{
outError = "Failed to reach comp-server";
outServer = ServerListing{};
return false;
}
nlohmann::json resBody = nlohmann::json::parse(res->body);
if (res && resBody["success"].is_boolean() && resBody["success"])