mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-01-21 20:27:02 +00:00
Address some fo the feedback
This commit is contained in:
parent
2b325165aa
commit
181bb0ce14
@ -133,3 +133,12 @@ void ChatWebAPI::Listen() {
|
|||||||
void ChatWebAPI::ReceiveRequests() {
|
void ChatWebAPI::ReceiveRequests() {
|
||||||
mg_mgr_poll(&mgr, 15);
|
mg_mgr_poll(&mgr, 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<json> ChatWebAPI::ParseJSON(char* data) {
|
||||||
|
try {
|
||||||
|
return std::make_optional<json>(json::parse(data));
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
LOG_DEBUG("Failed to parse JSON: %s", e.what());
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -14,8 +14,10 @@ public:
|
|||||||
void ReceiveRequests();
|
void ReceiveRequests();
|
||||||
void Listen();
|
void Listen();
|
||||||
private:
|
private:
|
||||||
struct mg_mgr mgr;
|
|
||||||
static void HandleRequests(struct mg_connection *c, int ev, void *ev_data);
|
static void HandleRequests(struct mg_connection *c, int ev, void *ev_data);
|
||||||
|
static std::optional<json> ParseJSON(char * data);
|
||||||
|
|
||||||
|
struct mg_mgr mgr;
|
||||||
inline static const std::string root_path = "/api/v1/";
|
inline static const std::string root_path = "/api/v1/";
|
||||||
inline static const char * json_content_type = "Content-Type: application/json\r\n";
|
inline static const char * json_content_type = "Content-Type: application/json\r\n";
|
||||||
};
|
};
|
||||||
|
@ -18,9 +18,6 @@
|
|||||||
#include "dPlatforms.h"
|
#include "dPlatforms.h"
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "json.hpp"
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
enum eInventoryType : uint32_t;
|
enum eInventoryType : uint32_t;
|
||||||
enum class eObjectBits : size_t;
|
enum class eObjectBits : size_t;
|
||||||
@ -263,20 +260,6 @@ namespace GeneralUtils {
|
|||||||
return (str.size() == 3) ? TryParse<NiPoint3>(str[0], str[1], str[2]) : std::nullopt;
|
return (str.size() == 3) ? TryParse<NiPoint3>(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 <typename T>
|
|
||||||
[[nodiscard]] std::optional<json> TryParse(const std::string_view str) {
|
|
||||||
try {
|
|
||||||
return json::parse(str);
|
|
||||||
} catch (const std::exception& e) {
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::u16string to_u16string(const T value) {
|
std::u16string to_u16string(const T value) {
|
||||||
return GeneralUtils::ASCIIToUTF16(std::to_string(value));
|
return GeneralUtils::ASCIIToUTF16(std::to_string(value));
|
||||||
|
Loading…
Reference in New Issue
Block a user