diff --git a/dChatServer/ChatWebAPI.cpp b/dChatServer/ChatWebAPI.cpp index a569cc19..4934ab8c 100644 --- a/dChatServer/ChatWebAPI.cpp +++ b/dChatServer/ChatWebAPI.cpp @@ -133,3 +133,12 @@ void ChatWebAPI::Listen() { void ChatWebAPI::ReceiveRequests() { mg_mgr_poll(&mgr, 15); } + +std::optional ChatWebAPI::ParseJSON(char* data) { + try { + return std::make_optional(json::parse(data)); + } catch (const std::exception& e) { + LOG_DEBUG("Failed to parse JSON: %s", e.what()); + return std::nullopt; + } +} diff --git a/dChatServer/ChatWebAPI.h b/dChatServer/ChatWebAPI.h index ee01351f..f563fd1b 100644 --- a/dChatServer/ChatWebAPI.h +++ b/dChatServer/ChatWebAPI.h @@ -14,10 +14,12 @@ public: void ReceiveRequests(); void Listen(); private: - struct mg_mgr mgr; static void HandleRequests(struct mg_connection *c, int ev, void *ev_data); + static std::optional ParseJSON(char * data); + + struct mg_mgr mgr; inline static const std::string root_path = "/api/v1/"; inline static const char * json_content_type = "Content-Type: application/json\r\n"; }; -#endif \ No newline at end of file +#endif diff --git a/dCommon/GeneralUtils.h b/dCommon/GeneralUtils.h index 3ab0caea..663ac7bc 100644 --- a/dCommon/GeneralUtils.h +++ b/dCommon/GeneralUtils.h @@ -18,9 +18,6 @@ #include "dPlatforms.h" #include "Game.h" #include "Logger.h" -#include "json.hpp" - -using json = nlohmann::json; enum eInventoryType : uint32_t; enum class eObjectBits : size_t; @@ -263,20 +260,6 @@ namespace GeneralUtils { return (str.size() == 3) ? TryParse(str[0], str[1], str[2]) : std::nullopt; } - /** - * The TryParse overload for handling json parsing - * @param str The string that is the json to parse - * @returns An std::optional containing the desired json if it can be parsed from the string - */ - template - [[nodiscard]] std::optional TryParse(const std::string_view str) { - try { - return json::parse(str); - } catch (const std::exception& e) { - return std::nullopt; - } - } - template std::u16string to_u16string(const T value) { return GeneralUtils::ASCIIToUTF16(std::to_string(value));