From 3bf03c54f40388f183c2c22b8978bd3a9eb187a5 Mon Sep 17 00:00:00 2001 From: Toofy Date: Tue, 23 Jan 2024 23:38:23 +0000 Subject: [PATCH] Fixed up json object and added lobbyPort for api response --- src/api/main.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/api/main.cpp b/src/api/main.cpp index d0c231ce09..c21f0ddd0a 100644 --- a/src/api/main.cpp +++ b/src/api/main.cpp @@ -244,12 +244,14 @@ void createAccount( shared_ptr< HttpServer::Response > response, shared_ptr< Htt std::string sId; if( g_sapphireAPI.createAccount( user, pass, sId ) ) { - // todo: construct proper json object here - std::string json_string = "{\"sId\":\"" + sId + - "\", \"lobbyHost\":\"" + - m_config.global.network.lobbyHost + - "\", \"frontierHost\":\"" + - m_config.global.network.restHost + "\"}"; + nlohmann::json response_json = { + {"sId", sId}, + {"lobbyHost", m_config.global.network.lobbyHost}, + {"frontierHost", m_config.global.network.restHost}, + {"lobbyPort", m_config.global.network.lobbyPort} + }; + + std::string json_string = response_json.dump(); *response << buildHttpResponse( 200, json_string, JSON ); } else @@ -277,12 +279,15 @@ void login( shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer: // reloadConfig(); if( g_sapphireAPI.login( user, pass, sId ) ) { - // todo: build proper json object and stringify it - std::string json_string = "{\"sId\":\"" + sId + - "\", \"lobbyHost\":\"" + - m_config.global.network.lobbyHost + - "\", \"frontierHost\":\"" + - m_config.global.network.restHost + "\"}"; + nlohmann::json response_json = { + {"sId", sId}, + {"lobbyHost", m_config.global.network.lobbyHost}, + {"frontierHost", m_config.global.network.restHost}, + {"lobbyPort", m_config.global.network.lobbyPort} + }; + + std::string json_string = response_json.dump(); + *response << buildHttpResponse( 200, json_string, JSON ); } else @@ -294,7 +299,6 @@ void login( shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer: *response << buildHttpResponse( 500 ); Logger::error( e.what() ); } - } void deleteCharacter( shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer::Request > request )