From 252c6dd818a832dc98a070dab46fb39350caffa0 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 14 Jun 2022 22:29:08 +0200 Subject: [PATCH] R5Net cleanup and optimizations --- r5dev/networksystem/r5net.cpp | 52 +++++++++++++++++------------------ r5dev/networksystem/r5net.h | 12 ++++---- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/r5dev/networksystem/r5net.cpp b/r5dev/networksystem/r5net.cpp index cff5661e..bb0ffd39 100644 --- a/r5dev/networksystem/r5net.cpp +++ b/r5dev/networksystem/r5net.cpp @@ -8,7 +8,7 @@ //----------------------------------------------------------------------------- // Purpose: returns the sdk version string. //----------------------------------------------------------------------------- -std::string R5Net::Client::GetSDKVersion() +string R5Net::Client::GetSDKVersion() { return SDK_VERSION; } @@ -16,14 +16,14 @@ std::string R5Net::Client::GetSDKVersion() //----------------------------------------------------------------------------- // Purpose: returns a vector of hosted servers. //----------------------------------------------------------------------------- -std::vector R5Net::Client::GetServersList(std::string& svOutMessage) +vector R5Net::Client::GetServersList(string& svOutMessage) { - std::vector vslList{}; + vector vslList{}; nlohmann::json jsRequestBody = nlohmann::json::object(); jsRequestBody["version"] = GetSDKVersion(); - std::string svRequestBody = jsRequestBody.dump(4); + string svRequestBody = jsRequestBody.dump(4); if (r5net_show_debug->GetBool()) { @@ -64,7 +64,7 @@ std::vector R5Net::Client::GetServersList(std::string& svOutMessa { if (jsResultBody["err"].is_string()) { - svOutMessage = jsResultBody["err"].get(); + svOutMessage = jsResultBody["err"].get(); } else { @@ -82,17 +82,17 @@ std::vector R5Net::Client::GetServersList(std::string& svOutMessa if (jsResultBody["err"].is_string()) { - svOutMessage = jsResultBody["err"].get(); + svOutMessage = jsResultBody["err"].get(); } else { - svOutMessage = std::string("Failed to reach comp-server ") + std::to_string(htResults->status); + svOutMessage = string("Failed to reach comp-server ") + std::to_string(htResults->status); } return vslList; } - svOutMessage = std::string("Failed to reach comp-server ") + std::to_string(htResults->status); + svOutMessage = string("Failed to reach comp-server ") + std::to_string(htResults->status); return vslList; } @@ -110,7 +110,7 @@ std::vector R5Net::Client::GetServersList(std::string& svOutMessa // &slServerListing - // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- -bool R5Net::Client::PostServerHost(std::string& svOutMessage, std::string& svOutToken, const ServerListing& slServerListing) +bool R5Net::Client::PostServerHost(string& svOutMessage, string& svOutToken, const ServerListing& slServerListing) { nlohmann::json jsRequestBody = nlohmann::json::object(); jsRequestBody["name"] = slServerListing.svServerName; @@ -122,7 +122,7 @@ bool R5Net::Client::PostServerHost(std::string& svOutMessage, std::string& svOut jsRequestBody["encKey"] = slServerListing.svEncryptionKey; jsRequestBody["hidden"] = slServerListing.bHidden; - std::string svRequestBody = jsRequestBody.dump(4); + string svRequestBody = jsRequestBody.dump(4); if (r5net_show_debug->GetBool()) { @@ -143,11 +143,11 @@ bool R5Net::Client::PostServerHost(std::string& svOutMessage, std::string& svOut { if (jsResultBody["token"].is_string()) { - svOutToken = jsResultBody["token"].get(); + svOutToken = jsResultBody["token"].get(); } else { - svOutToken = std::string(); + svOutToken = string(); } return true; @@ -156,7 +156,7 @@ bool R5Net::Client::PostServerHost(std::string& svOutMessage, std::string& svOut { if (jsResultBody["err"].is_string()) { - svOutMessage = jsResultBody["err"].get(); + svOutMessage = jsResultBody["err"].get(); } else { @@ -175,23 +175,23 @@ bool R5Net::Client::PostServerHost(std::string& svOutMessage, std::string& svOut if (jsResultBody["err"].is_string()) { - svOutMessage = jsResultBody["err"].get(); + svOutMessage = jsResultBody["err"].get(); } else { - svOutMessage = std::string("Failed to reach comp-server ") + std::to_string(htResults->status); + svOutMessage = string("Failed to reach comp-server ") + std::to_string(htResults->status); } - svOutToken = std::string(); + svOutToken = string(); return false; } - svOutToken = std::string(); - svOutMessage = std::string("Failed to reach comp-server ") + std::to_string(htResults->status); + svOutToken = string(); + svOutMessage = string("Failed to reach comp-server ") + std::to_string(htResults->status); return false; } - svOutToken = std::string(); + svOutToken = string(); svOutMessage = "Failed to reach comp-server. Unknown error code."; return false; } @@ -206,12 +206,12 @@ bool R5Net::Client::PostServerHost(std::string& svOutMessage, std::string& svOut // svToken - // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- -bool R5Net::Client::GetServerByToken(ServerListing& slOutServer, std::string& svOutMessage, const std::string svToken) +bool R5Net::Client::GetServerByToken(ServerListing& slOutServer, string& svOutMessage, const string& svToken) { nlohmann::json jsRequestBody = nlohmann::json::object(); jsRequestBody["token"] = svToken; - std::string svRequestBody = jsRequestBody.dump(4); + string svRequestBody = jsRequestBody.dump(4); if (r5net_show_debug->GetBool()) { @@ -250,7 +250,7 @@ bool R5Net::Client::GetServerByToken(ServerListing& slOutServer, std::string& sv { if (jsResultBody["err"].is_string()) { - svOutMessage = jsResultBody["err"].get(); + svOutMessage = jsResultBody["err"].get(); } else { @@ -272,17 +272,17 @@ bool R5Net::Client::GetServerByToken(ServerListing& slOutServer, std::string& sv if (jsResultBody["err"].is_string()) { - svOutMessage = jsResultBody["err"].get(); + svOutMessage = jsResultBody["err"].get(); } else { - svOutMessage = std::string("Failed to reach comp-server ") + std::to_string(htResults->status); + svOutMessage = string("Failed to reach comp-server ") + std::to_string(htResults->status); } return false; } - svOutMessage = std::string("Failed to reach comp-server ") + std::to_string(htResults->status); + svOutMessage = string("Failed to reach comp-server ") + std::to_string(htResults->status); return false; } @@ -301,7 +301,7 @@ bool R5Net::Client::GetServerByToken(ServerListing& slOutServer, std::string& sv // &svOutErrCl - // Output : Returns true if banned, false if not banned. //----------------------------------------------------------------------------- -bool R5Net::Client::GetClientIsBanned(const string svIpAddress, uint64_t nOriginID, string& svOutErrCl) +bool R5Net::Client::GetClientIsBanned(const string& svIpAddress, uint64_t nOriginID, string& svOutErrCl) { nlohmann::json jsRequestBody = nlohmann::json::object(); jsRequestBody["ip"] = svIpAddress; diff --git a/r5dev/networksystem/r5net.h b/r5dev/networksystem/r5net.h index 971aec48..c958dd62 100644 --- a/r5dev/networksystem/r5net.h +++ b/r5dev/networksystem/r5net.h @@ -6,16 +6,16 @@ namespace R5Net class Client { public: - Client(std::string serverString) : m_HttpClient(serverString.c_str()) + Client(string serverString) : m_HttpClient(serverString.c_str()) { m_HttpClient.set_connection_timeout(10); } - std::vector GetServersList(std::string& svOutMessage); - bool PostServerHost(std::string& svOutMessage, std::string& svOutToken, const ServerListing& slServerListing); - bool GetServerByToken(ServerListing& slOutServer, std::string& svOutMessage, const std::string svToken); - bool GetClientIsBanned(std::string svIpAddress, uint64_t nOriginID, std::string& svOutErrCl); - std::string GetSDKVersion(); + vector GetServersList(string& svOutMessage); + bool PostServerHost(string& svOutMessage, string& svOutToken, const ServerListing& slServerListing); + bool GetServerByToken(ServerListing& slOutServer, string& svOutMessage, const string& svToken); + bool GetClientIsBanned(const string& svIpAddress, uint64_t nOriginID, string& svOutErrCl); + string GetSDKVersion(); Client* pR5net = nullptr; Client* GetR5Net() { return pR5net; }