diff --git a/apex.sln b/apex.sln index d2240193..6f04a266 100644 --- a/apex.sln +++ b/apex.sln @@ -11,28 +11,56 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "r5dedicated", "r5dedicated\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Minhook", "external\minhook\libMinHook.vcxproj", "{F142A341-5EE0-442D-A15F-98AE9B48DBAE}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "r5net", "r5net\r5net.vcxproj", "{F04BE619-0326-4FF1-B06B-FBE882E04D5E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {18F8C75E-3844-4AA6-AB93-980A08253519}.Debug|x64.ActiveCfg = Debug|x64 {18F8C75E-3844-4AA6-AB93-980A08253519}.Debug|x64.Build.0 = Debug|x64 + {18F8C75E-3844-4AA6-AB93-980A08253519}.Debug|x86.ActiveCfg = Debug|Win32 + {18F8C75E-3844-4AA6-AB93-980A08253519}.Debug|x86.Build.0 = Debug|Win32 {18F8C75E-3844-4AA6-AB93-980A08253519}.Release|x64.ActiveCfg = Release|x64 {18F8C75E-3844-4AA6-AB93-980A08253519}.Release|x64.Build.0 = Release|x64 + {18F8C75E-3844-4AA6-AB93-980A08253519}.Release|x86.ActiveCfg = Release|Win32 + {18F8C75E-3844-4AA6-AB93-980A08253519}.Release|x86.Build.0 = Release|Win32 {28CC6B4F-7A95-4933-ADA9-65E38D48516D}.Debug|x64.ActiveCfg = Debug|x64 {28CC6B4F-7A95-4933-ADA9-65E38D48516D}.Debug|x64.Build.0 = Debug|x64 + {28CC6B4F-7A95-4933-ADA9-65E38D48516D}.Debug|x86.ActiveCfg = Debug|Win32 + {28CC6B4F-7A95-4933-ADA9-65E38D48516D}.Debug|x86.Build.0 = Debug|Win32 {28CC6B4F-7A95-4933-ADA9-65E38D48516D}.Release|x64.ActiveCfg = Release|x64 {28CC6B4F-7A95-4933-ADA9-65E38D48516D}.Release|x64.Build.0 = Release|x64 + {28CC6B4F-7A95-4933-ADA9-65E38D48516D}.Release|x86.ActiveCfg = Release|Win32 + {28CC6B4F-7A95-4933-ADA9-65E38D48516D}.Release|x86.Build.0 = Release|Win32 {71988D92-343C-49AB-B52B-0AE0E83B0401}.Debug|x64.ActiveCfg = Debug|x64 {71988D92-343C-49AB-B52B-0AE0E83B0401}.Debug|x64.Build.0 = Debug|x64 + {71988D92-343C-49AB-B52B-0AE0E83B0401}.Debug|x86.ActiveCfg = Debug|Win32 + {71988D92-343C-49AB-B52B-0AE0E83B0401}.Debug|x86.Build.0 = Debug|Win32 {71988D92-343C-49AB-B52B-0AE0E83B0401}.Release|x64.ActiveCfg = Release|x64 {71988D92-343C-49AB-B52B-0AE0E83B0401}.Release|x64.Build.0 = Release|x64 + {71988D92-343C-49AB-B52B-0AE0E83B0401}.Release|x86.ActiveCfg = Release|Win32 + {71988D92-343C-49AB-B52B-0AE0E83B0401}.Release|x86.Build.0 = Release|Win32 {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Debug|x64.ActiveCfg = Debug|x64 {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Debug|x64.Build.0 = Debug|x64 + {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Debug|x86.ActiveCfg = Debug|Win32 + {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Debug|x86.Build.0 = Debug|Win32 {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Release|x64.ActiveCfg = Release|x64 {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Release|x64.Build.0 = Release|x64 + {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Release|x86.ActiveCfg = Release|Win32 + {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Release|x86.Build.0 = Release|Win32 + {F04BE619-0326-4FF1-B06B-FBE882E04D5E}.Debug|x64.ActiveCfg = Debug|x64 + {F04BE619-0326-4FF1-B06B-FBE882E04D5E}.Debug|x64.Build.0 = Debug|x64 + {F04BE619-0326-4FF1-B06B-FBE882E04D5E}.Debug|x86.ActiveCfg = Debug|Win32 + {F04BE619-0326-4FF1-B06B-FBE882E04D5E}.Debug|x86.Build.0 = Debug|Win32 + {F04BE619-0326-4FF1-B06B-FBE882E04D5E}.Release|x64.ActiveCfg = Release|x64 + {F04BE619-0326-4FF1-B06B-FBE882E04D5E}.Release|x64.Build.0 = Release|x64 + {F04BE619-0326-4FF1-B06B-FBE882E04D5E}.Release|x86.ActiveCfg = Release|Win32 + {F04BE619-0326-4FF1-B06B-FBE882E04D5E}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/r5dev/BuildVersion.rc b/r5dev/BuildVersion.rc new file mode 100644 index 00000000..de49eb04 --- /dev/null +++ b/r5dev/BuildVersion.rc @@ -0,0 +1,59 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE 9, 1 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED diff --git a/r5dev/include/CCompanion.h b/r5dev/include/CCompanion.h index 82303379..395f6c4a 100644 --- a/r5dev/include/CCompanion.h +++ b/r5dev/include/CCompanion.h @@ -1,6 +1,7 @@ #pragma once #include "serverlisting.h" #include "gui_utility.h" +#include "r5net.h" /////////////////////////////////////////////////////////////////////////////// // Initialization @@ -13,6 +14,7 @@ private: public: CCompanion(); + //////////////////// // Enums // //////////////////// @@ -32,15 +34,17 @@ public: //////////////////// // Server Browser // //////////////////// - ImVector ServerList; - ServerListing* SelectedServer; + + R5Net::Client r5net; + + std::vector ServerList; ImGuiTextFilter ServerBrowserFilter; char ServerConnStringBuffer[256] = { 0 }; //////////////////// // Settings // //////////////////// - char MatchmakingServerStringBuffer[256] = { 0 }; + std::string MatchmakingServerStringBuffer; //////////////////// // Host Server // @@ -135,7 +139,6 @@ public: void RefreshServerList(); void SendHostingPostRequest(); - const nlohmann::json SendGetServerByTokenRequest(const std::string &token, const std::string &password); void CompMenu(); void ServerBrowserSection(); void SettingsSection(); diff --git a/r5dev/include/serverlisting.h b/r5dev/include/serverlisting.h deleted file mode 100644 index 6321a0fd..00000000 --- a/r5dev/include/serverlisting.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -class ServerListing -{ -public: - - ServerListing() = default; - - ServerListing(std::string name, std::string map, std::string ip, std::string port) : name(name), map(map), ip(ip), port(port) - { - // for future constructor use. - } - - void Select(); - - std::string name; - std::string map; - std::string ip; - std::string port; - std::string password; -}; - diff --git a/r5dev/r5dev.vcxproj b/r5dev/r5dev.vcxproj index 7a0958d8..00dd2b71 100644 --- a/r5dev/r5dev.vcxproj +++ b/r5dev/r5dev.vcxproj @@ -82,16 +82,16 @@ true - $(SolutionDir)external\minhook\include;$(SolutionDir)external\imgui\include;$(SolutionDir)external\spdlog\include;$(SolutionDir)shared\include;$(SolutionDir)r5dev\include;$(IncludePath) - $(SolutionDir)external\minhook\lib\$(Configuration);$(LibraryPath) + $(SolutionDir)r5net\include;$(SolutionDir)external\minhook\include;$(SolutionDir)external\imgui\include;$(SolutionDir)external\spdlog\include;$(SolutionDir)shared\include;$(SolutionDir)r5dev\include;$(IncludePath) + $(SolutionDir)external\minhook\lib\$(Configuration);$(SolutionDir)r5net\lib\$(Configuration);$(LibraryPath) $(SolutionDir)bin\$(Configuration)\ r5detours $(SolutionDir)build\$(ProjectName)\$(Configuration)\ false - $(SolutionDir)external\minhook\include;$(SolutionDir)external\imgui\include;$(SolutionDir)external\spdlog\include;$(SolutionDir)shared\include;$(SolutionDir)r5dev\include;$(IncludePath) - $(SolutionDir)external\minhook\lib\$(Configuration);$(LibraryPath) + $(SolutionDir)r5net\include;$(SolutionDir)external\minhook\include;$(SolutionDir)external\imgui\include;$(SolutionDir)external\spdlog\include;$(SolutionDir)shared\include;$(SolutionDir)r5dev\include;$(IncludePath) + $(SolutionDir)external\minhook\lib\$(Configuration);$(SolutionDir)r5net\lib\$(Configuration);$(LibraryPath) $(SolutionDir)bin\$(Configuration)\ $(SolutionDir)build\$(ProjectName)\$(Configuration)\ r5detours @@ -148,7 +148,7 @@ true false r5dev.def - Minhook.x64.lib;%(AdditionalDependencies) + Minhook.x64.lib;r5net.lib;%(AdditionalDependencies) @@ -185,7 +185,7 @@ true false r5dev.def - Minhook.x64.lib;%(AdditionalDependencies) + Minhook.x64.lib;r5net.lib;%(AdditionalDependencies) @@ -319,7 +319,6 @@ - @@ -400,14 +399,15 @@ Create pch.h - - Use - pch.h - + + + {f04be619-0326-4ff1-b06b-fbe882e04d5e} + + diff --git a/r5dev/r5dev.vcxproj.filters b/r5dev/r5dev.vcxproj.filters index 395730dd..36ede3c6 100644 --- a/r5dev/r5dev.vcxproj.filters +++ b/r5dev/r5dev.vcxproj.filters @@ -177,9 +177,6 @@ gui\interface - - gui - gui @@ -521,9 +518,6 @@ gui\include - - gui\include - r5-sdk\include diff --git a/r5dev/resource.h b/r5dev/resource.h new file mode 100644 index 00000000..f1b308d1 --- /dev/null +++ b/r5dev/resource.h @@ -0,0 +1,14 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by BuildVersion.rc + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/r5dev/src/CCompanion.cpp b/r5dev/src/CCompanion.cpp index 21116d49..48d1a41e 100644 --- a/r5dev/src/CCompanion.cpp +++ b/r5dev/src/CCompanion.cpp @@ -5,6 +5,7 @@ #include "patterns.h" #include "gameclasses.h" #include "CCompanion.h" +#include "r5net.h" #define OVERLAY_DEBUG @@ -14,11 +15,9 @@ CCompanion* g_ServerBrowser = nullptr; * _ccompanion.cpp *-----------------------------------------------------------------------------*/ -CCompanion::CCompanion() +CCompanion::CCompanion() : MatchmakingServerStringBuffer("r5a-comp-sv.herokuapp.com"), r5net(R5Net::Client("r5a-comp-sv.herokuapp.com")) { - memset(MatchmakingServerStringBuffer, 0, sizeof(MatchmakingServerStringBuffer)); memset(ServerConnStringBuffer, 0, sizeof(ServerConnStringBuffer)); - strcpy_s(MatchmakingServerStringBuffer, "r5a-comp-sv.herokuapp.com"); std::string path = "stbsp"; for (const auto& entry : std::filesystem::directory_iterator(path)) @@ -87,19 +86,7 @@ void CCompanion::RefreshServerList() std::cout << " [+CCompanion+] Refreshing server list with string " << MatchmakingServerStringBuffer << "\n"; #endif bThreadLocked = true; - httplib::Client client(MatchmakingServerStringBuffer); - client.set_connection_timeout(10); - auto res = client.Get("/servers"); - if (res) - { - nlohmann::json root = nlohmann::json::parse(res->body); - for (auto obj : root["servers"]) - { - ServerList.push_back( - new ServerListing(obj["name"].get(), obj["map"].get(), obj["ip"].get(), obj["port"].get()) - ); - } - } + ServerList = r5net.GetServersList(); bThreadLocked = false; }); @@ -109,76 +96,25 @@ void CCompanion::RefreshServerList() void CCompanion::SendHostingPostRequest() { - httplib::Client client(MatchmakingServerStringBuffer); - client.set_connection_timeout(10); - - // send a post request to "/servers/add" with a json body - nlohmann::json body = nlohmann::json::object(); - body["name"] = MyServer.name; - body["map"] = std::string(GameGlobals::HostState->m_levelName); - static ConVar* hostport = GameGlobals::Cvar->FindVar("hostport"); // static since it won't move memory locations. - body["port"] = hostport->m_pzsCurrentValue; //body["port"] = MyServer.port; - body["password"] = MyServer.password; - - std::string body_str = body.dump(); - -#ifdef OVERLAY_DEBUG - std::cout << " [+CCompanion+] Sending request now, Body: " << body_str << "\n"; -#endif - - httplib::Result result = client.Post("/servers/add", body_str.c_str(), body_str.length(), "application/json"); -#ifdef OVERLAY_DEBUG + HostToken = ""; + 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) { - std::cout << " [+CCompanion+] Request Result: " << result->body << "\n"; - nlohmann::json res = nlohmann::json::parse(result->body); - if (!res["success"] && !res["err"].is_null()) + HostRequestMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f); + std::stringstream msg; + msg << "Broadcasting! "; + if (!HostToken.empty()) { - HostRequestMessage = res["err"].get(); - HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); - } - else if (res["success"].get() == true) - { - std::stringstream msg; - msg << "Broadcasting! "; - HostToken = ""; - if (res["token"].is_string()) - { - msg << "Share the following token for people to connect: "; - HostToken = res["token"].get(); - } - HostRequestMessage = msg.str().c_str(); - HostRequestMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f); - } - else - { - HostRequestMessage = ""; - HostRequestMessageColor = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + msg << "Share the following token for people to connect: "; } + HostRequestMessage = msg.str().c_str(); + } -#endif -} - -const nlohmann::json CCompanion::SendGetServerByTokenRequest(const std::string &token, const std::string &password) -{ - httplib::Client client(MatchmakingServerStringBuffer); - client.set_connection_timeout(10); - - nlohmann::json reqBody = nlohmann::json::object(); - - reqBody["token"] = token; - reqBody["password"] = password; - - std::string reqBody_str = reqBody.dump(); - - httplib::Result res = client.Post("/server/byToken", reqBody_str.c_str(), reqBody_str.length(), "application/json"); - if (res && !res->body.empty()) + else { - return nlohmann::json::parse(res->body); + HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); } - - return nlohmann::json::object(); } @@ -222,11 +158,11 @@ void CCompanion::ServerBrowserSection() ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthStretch, 8); ImGui::TableHeadersRow(); - for (ServerListing* server : ServerList) + for (ServerListing& server : ServerList) { - const char* name = server->name.c_str(); - const char* map = server->map.c_str(); - const char* port = server->port.c_str(); + const char* name = server.name.c_str(); + const char* map = server.map.c_str(); + const char* port = server.port.c_str(); if (ServerBrowserFilter.PassFilter(name) || ServerBrowserFilter.PassFilter(map) @@ -243,12 +179,11 @@ void CCompanion::ServerBrowserSection() ImGui::TableNextColumn(); std::string selectButtonText = "Connect##"; - selectButtonText += (server->name + server->ip + server->map); + selectButtonText += (server.name + server.ip + server.map); if (ImGui::Button(selectButtonText.c_str())) { - SelectedServer = server; - server->Select(); + //server->Select(); } } @@ -370,27 +305,19 @@ void CCompanion::ServerBrowserSection() if (ImGui::Button("Connect##PrivateServersConnectModal_ConnectButton", ImVec2(ImGui::GetWindowContentRegionWidth() / 2.f, 19))) { - nlohmann::json response = SendGetServerByTokenRequest(PrivateServerToken, PrivateServerPassword); // Send token connect request. - if (response["success"].get()) // Was the response successful? + PrivateServerRequestMessage = ""; + ServerListing server; + bool result = r5net.GetServerByToken(server, PrivateServerRequestMessage, PrivateServerToken, PrivateServerPassword); // Send token connect request. + if (!server.name.empty()) { - nlohmann::json server = response["server"].get(); // Get server field. - - if (server["ip"].is_string() && server["port"].is_string()) // Check if both field are a string. - { - std::string name = server["name"].get(); // Please do this if you grab values from the response. - std::string ip = server["ip"].get(); - std::string port = server["port"].get(); - - ConnectToServer(ip, port); // Connect to the server - PrivateServerRequestMessage = "Found Server: " + name; - PrivateServerMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f); - ImGui::CloseCurrentPopup(); - } + ConnectToServer(server.ip, server.port); // Connect to the server + PrivateServerRequestMessage = "Found Server: " + server.name; + PrivateServerMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f); + ImGui::CloseCurrentPopup(); } else { - std::string err = response["err"].get(); - PrivateServerRequestMessage = "Error: " + err; + PrivateServerRequestMessage = "Error: " + PrivateServerRequestMessage; PrivateServerMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); } @@ -494,7 +421,8 @@ void CCompanion::HostServerSection() void CCompanion::SettingsSection() { - ImGui::InputText("Matchmaking Server String", MatchmakingServerStringBuffer, IM_ARRAYSIZE(MatchmakingServerStringBuffer), 0); + ImGui::Text("In renovation"); + //ImGui::InputText("Matchmaking Server String", MatchmakingServerStringBuffer, IM_ARRAYSIZE(MatchmakingServerStringBuffer), 0); } void CCompanion::Draw(const char* title) diff --git a/r5dev/src/serverlisting.cpp b/r5dev/src/serverlisting.cpp deleted file mode 100644 index 828521ad..00000000 --- a/r5dev/src/serverlisting.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "pch.h" -#include "serverlisting.h" -#include "CCompanion.h" - -void ServerListing::Select() -{ - std::stringstream cmd; - cmd << "connect " << this->ip << ":" << this->port; - g_ServerBrowser->ProcessCommand(cmd.str().c_str()); -} \ No newline at end of file diff --git a/r5net/include/pch.h b/r5net/include/pch.h new file mode 100644 index 00000000..c41f119c --- /dev/null +++ b/r5net/include/pch.h @@ -0,0 +1,26 @@ +#pragma once +#pragma message("Precompiling r5net headers.\n") + +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/// + + +#include "httplib.h" +#include "json.hpp" diff --git a/r5net/include/r5net.h b/r5net/include/r5net.h new file mode 100644 index 00000000..5a708dd3 --- /dev/null +++ b/r5net/include/r5net.h @@ -0,0 +1,31 @@ +#pragma once + +#include "serverlisting.h" + +namespace R5Net +{ + + struct Config + { + std::string MOTD; + int SERVER_TTL; + int MIN_REQUIRED_VERSION; + }; + class Client + { + httplib::Client m_HttpClient; + + public: + Client(std::string serverString) : m_HttpClient(serverString.c_str()) + { + m_HttpClient.set_connection_timeout(10); + } + + + std::vector GetServersList(); + + bool PostServerHost(std::string& outMessage, std::string& outToken, const ServerListing& serverListing); + + bool GetServerByToken(ServerListing& outServer, std::string& outError, const std::string& token, const std::string& password = ""); + }; +} \ No newline at end of file diff --git a/r5net/include/serverlisting.h b/r5net/include/serverlisting.h new file mode 100644 index 00000000..86811e5f --- /dev/null +++ b/r5net/include/serverlisting.h @@ -0,0 +1,13 @@ +#pragma once + +#include "pch.h" + +struct ServerListing +{ + std::string name; + std::string map; + std::string ip; + std::string port; + std::string password; +}; + diff --git a/r5net/r5net.vcxproj b/r5net/r5net.vcxproj new file mode 100644 index 00000000..2fc91ca7 --- /dev/null +++ b/r5net/r5net.vcxproj @@ -0,0 +1,177 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + Create + Create + + + + + + 16.0 + Win32Proj + {f04be619-0326-4ff1-b06b-fbe882e04d5e} + r5net + 10.0 + + + + StaticLibrary + true + v142 + Unicode + + + StaticLibrary + false + v142 + true + Unicode + + + StaticLibrary + true + v142 + Unicode + + + StaticLibrary + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + $(ProjectDir)lib\$(Configuration) + $(SolutionDir)build\$(ProjectName)\$(Configuration) + $(SolutionDir)shared\include;$(ProjectDir)include;$(IncludePath) + + + false + $(ProjectDir)lib\$(Configuration) + $(SolutionDir)build\$(ProjectName)\$(Configuration) + $(SolutionDir)shared\include;$(ProjectDir)include;$(IncludePath) + + + + Level3 + true + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + Use + pch.h + + + + + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + Use + pch.h + + + + + true + true + true + + + + + Level3 + true + _DEBUG;_LIB;%(PreprocessorDefinitions) + true + Use + pch.h + stdcpp17 + + + + + true + + + + + Level3 + true + true + true + NDEBUG;_LIB;%(PreprocessorDefinitions) + true + Use + pch.h + stdcpp17 + + + + + true + true + true + + + + + + \ No newline at end of file diff --git a/r5net/r5net.vcxproj.filters b/r5net/r5net.vcxproj.filters new file mode 100644 index 00000000..849b004e --- /dev/null +++ b/r5net/r5net.vcxproj.filters @@ -0,0 +1,33 @@ + + + + + {676c0758-86e4-4159-8aaf-17969db2d381} + + + {a3728292-4416-44be-a05c-5642a99dbbad} + + + + + include + + + include + + + include + + + + + src + + + src + + + src + + + \ No newline at end of file diff --git a/r5net/src/pch.cpp b/r5net/src/pch.cpp new file mode 100644 index 00000000..8d6bea21 --- /dev/null +++ b/r5net/src/pch.cpp @@ -0,0 +1,3 @@ +#pragma once + +#include "pch.h" \ No newline at end of file diff --git a/r5net/src/r5net.cpp b/r5net/src/r5net.cpp new file mode 100644 index 00000000..269dccf0 --- /dev/null +++ b/r5net/src/r5net.cpp @@ -0,0 +1,98 @@ +// r5net.cpp : Defines the functions for the static library. +// + +#include "pch.h" +#include "r5net.h" + + +using namespace R5Net; + +std::vector Client::GetServersList() +{ + std::vector list; + + auto res = m_HttpClient.Get("/servers"); + + if (res) + { + nlohmann::json root = nlohmann::json::parse(res->body); + for (auto obj : root["servers"]) + { + list.push_back( + ServerListing{ obj["name"].get(), obj["map"].get(), obj["ip"].get(), obj["port"].get() } + ); + } + } + + return list; +} + +bool Client::PostServerHost(std::string& outMessage, std::string& outToken, const ServerListing& serverListing) +{ + nlohmann::json reqBody = nlohmann::json::object(); + reqBody["name"] = serverListing.name; + reqBody["map"] = serverListing.map; + reqBody["port"] = serverListing.port; + reqBody["password"] = serverListing.password; + + std::string reqBodyStr = reqBody.dump(); + + auto res = m_HttpClient.Post("/servers/add", reqBodyStr.c_str(), reqBodyStr.length(), "application/json"); + + + nlohmann::json resBody = nlohmann::json::parse(res->body); + if (res && resBody["success"].is_boolean() && resBody["success"]) + { + outMessage = "Broadcasting!"; + + if (resBody["token"].is_string()) + outToken = resBody["token"].get(); + else + outToken = ""; + return true; + } + else + { + if (resBody["err"].is_string()) + outMessage = resBody["err"].get(); + else + outMessage = "An unknown error occured!"; + + return false; + } +} + +bool R5Net::Client::GetServerByToken(ServerListing& outServer, std::string& outError, const std::string& token, const std::string& password) +{ + nlohmann::json reqBody = nlohmann::json::object(); + + reqBody["token"] = token; + reqBody["password"] = password; + + httplib::Result res = m_HttpClient.Post("/server/byToken", reqBody.dump().c_str(), reqBody.dump().length(), "application/json"); + + std::cout << "YEEEEEEEEEEEEEE" << res->body << "\n"; + nlohmann::json resBody = nlohmann::json::parse(res->body); + + if (res && resBody["success"].is_boolean() && resBody["success"]) + { + outServer = ServerListing{ + reqBody["name"].get(), + reqBody["map"].get(), + reqBody["ip"].get(), + reqBody["port"].get() + }; + return true; + } + else + { + if (resBody["err"].is_string()) + outError = resBody["err"].get(); + else + outError = ""; + + outServer = ServerListing{}; + return false; + } +} + diff --git a/r5net/src/serverlisting.cpp b/r5net/src/serverlisting.cpp new file mode 100644 index 00000000..376b3ca2 --- /dev/null +++ b/r5net/src/serverlisting.cpp @@ -0,0 +1,3 @@ +#include "pch.h" + +#include "serverlisting.h"