diff --git a/include/Common.h b/include/Common.h index eab8e70..11305d5 100644 --- a/include/Common.h +++ b/include/Common.h @@ -86,6 +86,8 @@ public: }; } + static std::string GetServerCheckUrl() { return "https://check.beammp.com"; } + static std::string GetBackendUrlForAuth() { return "https://auth.beammp.com"; } static std::string GetBackendUrlForSocketIO() { return "https://backend.beammp.com"; } static void CheckForUpdates(); diff --git a/include/TConsole.h b/include/TConsole.h index 722cda9..0a32dce 100644 --- a/include/TConsole.h +++ b/include/TConsole.h @@ -61,6 +61,7 @@ private: void Command_Version(const std::string& cmd, const std::vector& args); void Command_ProtectMod(const std::string& cmd, const std::vector& args); void Command_ReloadMods(const std::string& cmd, const std::vector& args); + void Command_NetTest(const std::string& cmd, const std::vector& args); void Command_Say(const std::string& FullCommand); bool EnsureArgsCount(const std::vector& args, size_t n); @@ -81,6 +82,7 @@ private: { "version", [this](const auto& a, const auto& b) { Command_Version(a, b); } }, { "protectmod", [this](const auto& a, const auto& b) { Command_ProtectMod(a, b); } }, { "reloadmods", [this](const auto& a, const auto& b) { Command_ReloadMods(a, b); } }, + { "nettest", [this](const auto& a, const auto& b) { Command_NetTest(a, b); } }, }; std::unique_ptr mCommandline { nullptr }; diff --git a/src/TConsole.cpp b/src/TConsole.cpp index 287f3b3..33ff8f0 100644 --- a/src/TConsole.cpp +++ b/src/TConsole.cpp @@ -24,6 +24,7 @@ #include "CustomAssert.h" #include "LuaAPI.h" #include "TLuaEngine.h" +#include "Http.h" #include #include @@ -291,6 +292,30 @@ void TConsole::Command_ReloadMods(const std::string& cmd, const std::vector& args) { + unsigned int status = 0; + + std::string T = Http::GET( + Application::GetServerCheckUrl() + "/api/v2/beammp/" + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)), &status + ); + + beammp_debugf("Status and response from Server Check API: {0}, {1}", status, T); + + auto Doc = nlohmann::json::parse(T, nullptr, false); + + if (Doc.is_discarded() || !Doc.is_object()) { + beammp_warn("Failed to parse Server Check API response, however the server will most likely still work correctly."); + } else { + std::string status = Doc["status"]; + std::string details = "Response from Server Check API: " + std::string(Doc["details"]); + if (status == "ok") { + beammp_info(details); + } else { + beammp_warn(details); + } + } +} + void TConsole::Command_Kick(const std::string&, const std::vector& args) { if (!EnsureArgsCount(args, 1, size_t(-1))) { return;