1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-27 06:47:45 +00:00

Merge pull request #412 from NotAdam/boost_scrap

boost-b-gone
This commit is contained in:
Mordred 2018-10-26 11:36:54 +02:00 committed by GitHub
commit b3493d49bc
5 changed files with 63 additions and 85 deletions

View file

@ -192,7 +192,7 @@ namespace SimpleWeb {
return nullptr; return nullptr;
auto timer=std::make_shared<asio::deadline_timer>(io_service); auto timer=std::make_shared<asio::deadline_timer>(io_service);
timer->expires_from_now(boost::posix_time::seconds(config.timeout)); timer->expires_from_now( std::chrono::seconds( config.timeout ) );
timer->async_wait([this](const std::error_code& ec) { timer->async_wait([this](const std::error_code& ec) {
if(!ec) { if(!ec) {
close(); close();

View file

@ -3,9 +3,8 @@
#define BOOST_SPIRIT_THREADSAFE #define BOOST_SPIRIT_THREADSAFE
#include <boost/property_tree/ptree.hpp> #include <nlohmann/json.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <Logging/Logger.h> #include <Logging/Logger.h>
#include <Config/ConfigMgr.h> #include <Config/ConfigMgr.h>
@ -256,18 +255,16 @@ void createAccount( shared_ptr< HttpServer::Response > response, shared_ptr< Htt
print_request_info( request ); print_request_info( request );
try try
{ {
auto json = nlohmann::json::parse( request->content );
using namespace boost::property_tree; std::string pass = json["pass"];
ptree pt; std::string user = json["username"];
read_json( request->content, pt );
std::string pass = pt.get< string >( "pass" );
std::string user = pt.get< string >( "username" );
// reloadConfig(); // reloadConfig();
std::string sId; std::string sId;
if( g_sapphireAPI.createAccount( user, pass, sId ) ) if( g_sapphireAPI.createAccount( user, pass, sId ) )
{ {
// todo: construct proper json object here
std::string json_string = "{\"sId\":\"" + sId + std::string json_string = "{\"sId\":\"" + sId +
"\", \"lobbyHost\":\"" + "\", \"lobbyHost\":\"" +
m_pConfig->getValue< std::string >( "GlobalNetwork", "LobbyHost" ) + m_pConfig->getValue< std::string >( "GlobalNetwork", "LobbyHost" ) +
@ -290,18 +287,17 @@ void login( shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer:
print_request_info( request ); print_request_info( request );
try try
{ {
using namespace boost::property_tree; auto json = nlohmann::json::parse( request->content );
ptree pt;
read_json( request->content, pt );
std::string pass = pt.get< string >( "pass" ); std::string pass = json["pass"];
std::string user = pt.get< string >( "username" ); std::string user = json["username"];
std::string sId; std::string sId;
// reloadConfig(); // reloadConfig();
if( g_sapphireAPI.login( user, pass, sId ) ) if( g_sapphireAPI.login( user, pass, sId ) )
{ {
// todo: build proper json object and stringify it
std::string json_string = "{\"sId\":\"" + sId + std::string json_string = "{\"sId\":\"" + sId +
"\", \"lobbyHost\":\"" + "\", \"lobbyHost\":\"" +
m_pConfig->getValue< std::string >( "GlobalNetwork", "LobbyHost" ) + m_pConfig->getValue< std::string >( "GlobalNetwork", "LobbyHost" ) +
@ -326,12 +322,11 @@ void deleteCharacter( shared_ptr< HttpServer::Response > response, shared_ptr< H
print_request_info( request ); print_request_info( request );
try try
{ {
using namespace boost::property_tree; auto json = nlohmann::json::parse( request->content );
ptree pt;
read_json( request->content, pt ); std::string sId = json["sId"];
std::string sId = pt.get< string >( "sId" ); std::string secret = json["secret"];
std::string secret = pt.get< string >( "secret" ); std::string name = json["name"];
std::string name = pt.get< string >( "name" );
// reloadConfig(); // reloadConfig();
@ -362,13 +357,12 @@ void createCharacter( shared_ptr< HttpServer::Response > response, shared_ptr< H
print_request_info( request ); print_request_info( request );
try try
{ {
using namespace boost::property_tree; auto json = nlohmann::json::parse( request->content );
ptree pt;
read_json( request->content, pt ); std::string sId = json["sId"];
std::string sId = pt.get< string >( "sId" ); std::string secret = json["secret"];
std::string secret = pt.get< string >( "secret" ); std::string name = json["name"];
std::string name = pt.get< string >( "name" ); std::string infoJson = json["infoJson"];
std::string infoJson = pt.get< string >( "infoJson" );
std::string finalJson = Core::Util::base64_decode( infoJson ); std::string finalJson = Core::Util::base64_decode( infoJson );
@ -412,12 +406,12 @@ void insertSession( shared_ptr< HttpServer::Response > response, shared_ptr< Htt
try try
{ {
using namespace boost::property_tree; auto json = nlohmann::json::parse( request->content );
ptree pt;
read_json( request->content, pt ); std::string sId = json["sId"];
std::string sId = pt.get< string >( "sId" ); uint32_t accountId = json["accountId"].get< uint32_t >();
uint32_t accountId = pt.get< uint32_t >( "accountId" ); std::string secret = json["secret"];
std::string secret = pt.get< string >( "secret" );
// reloadConfig(); // reloadConfig();
if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret ) if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret )
{ {
@ -444,12 +438,10 @@ void checkNameTaken( shared_ptr< HttpServer::Response > response, shared_ptr< Ht
try try
{ {
using namespace boost::property_tree; auto json = nlohmann::json::parse( request->content );
ptree pt;
read_json( request->content, pt );
std::string name = pt.get< string >( "name" ); std::string name = json["name"];
std::string secret = pt.get< string >( "secret" ); std::string secret = json["secret"];
// reloadConfig(); // reloadConfig();
@ -480,11 +472,10 @@ void checkSession( shared_ptr< HttpServer::Response > response, shared_ptr< Http
print_request_info( request ); print_request_info( request );
try try
{ {
using namespace boost::property_tree; auto json = nlohmann::json::parse( request->content );
ptree pt;
read_json( request->content, pt ); std::string sId = json["sId"];
std::string sId = pt.get< string >( "sId" ); std::string secret = json["secret"];
std::string secret = pt.get< string >( "secret" );
int32_t result = g_sapphireAPI.checkSession( sId ); int32_t result = g_sapphireAPI.checkSession( sId );
// reloadConfig(); // reloadConfig();
@ -521,10 +512,9 @@ void getNextCharId( shared_ptr< HttpServer::Response > response, shared_ptr< Htt
print_request_info( request ); print_request_info( request );
try try
{ {
using namespace boost::property_tree; auto json = nlohmann::json::parse( request->content );
ptree pt;
read_json( request->content, pt ); std::string secret = json["secret"];
std::string secret = pt.get< string >( "secret" );
// reloadConfig(); // reloadConfig();
@ -553,10 +543,9 @@ void getNextContentId( shared_ptr< HttpServer::Response > response, shared_ptr<
try try
{ {
using namespace boost::property_tree; auto json = nlohmann::json::parse( request->content );
ptree pt;
read_json( request->content, pt ); std::string secret = json["secret"];
std::string secret = pt.get< string >( "secret" );
// reloadConfig(); // reloadConfig();
@ -584,11 +573,10 @@ void getCharacterList( shared_ptr< HttpServer::Response > response, shared_ptr<
print_request_info( request ); print_request_info( request );
try try
{ {
using namespace boost::property_tree; auto json = nlohmann::json::parse( request->content );
ptree pt;
read_json( request->content, pt ); std::string sId = json["sId"];
std::string sId = pt.get< string >( "sId" ); std::string secret = json["secret"];
std::string secret = pt.get< string >( "secret" );
// reloadConfig(); // reloadConfig();
@ -604,26 +592,22 @@ void getCharacterList( shared_ptr< HttpServer::Response > response, shared_ptr<
else else
{ {
auto charList = g_sapphireAPI.getCharList( result ); auto charList = g_sapphireAPI.getCharList( result );
using boost::property_tree::ptree;
ptree pt; auto json = nlohmann::json();
ptree char_tree;
for( auto entry : charList ) for( auto entry : charList )
{ {
ptree tree_entry; json["charArray"].push_back( {
tree_entry.put( "name", std::string( entry.getName() ) ); { "name", std::string( entry.getName() ) },
tree_entry.put( "charId", std::to_string( entry.getId() ) ); { "charId", std::to_string( entry.getId() ) },
tree_entry.put( "contentId", std::to_string( entry.getContentId() ) ); { "contentId", std::to_string( entry.getContentId() ) },
tree_entry.put( "infoJson", std::string( entry.getInfoJson() ) ); { "infoJson", std::string( entry.getInfoJson() ) }
char_tree.push_back( std::make_pair( "", tree_entry ) ); } );
} }
pt.add_child( "charArray", char_tree ); json["result"] = "success";
pt.put( "result", "success" );
std::ostringstream oss; *response << buildHttpResponse( 200, json.dump(), JSON );
write_json( oss, pt );
std::string responseStr = oss.str();
*response << buildHttpResponse( 200, responseStr, JSON );
} }
} }
else else

View file

@ -225,7 +225,7 @@ namespace SimpleWeb {
return nullptr; return nullptr;
auto timer=std::make_shared<asio::deadline_timer>(*io_service); auto timer=std::make_shared<asio::deadline_timer>(*io_service);
timer->expires_from_now(boost::posix_time::seconds(seconds)); timer->expires_from_now( std::chrono::seconds( seconds ) );
timer->async_wait([socket](const std::error_code& ec){ timer->async_wait([socket](const std::error_code& ec){
if(!ec) { if(!ec) {
std::error_code ec; std::error_code ec;

View file

@ -8,9 +8,7 @@
#define BOOST_SPIRIT_THREADSAFE #define BOOST_SPIRIT_THREADSAFE
#include <boost/property_tree/ptree.hpp> #include <nlohmann/json.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/json_parser.hpp>
extern Core::Logger g_log; extern Core::Logger g_log;
@ -57,15 +55,11 @@ Core::LobbySessionPtr Core::Network::RestConnector::getSession( char* sId )
std::string content = std::string( std::istreambuf_iterator< char >( r->content ), {} ); std::string content = std::string( std::istreambuf_iterator< char >( r->content ), {} );
if( r->status_code.find( "200" ) != std::string::npos ) if( r->status_code.find( "200" ) != std::string::npos )
{ {
using namespace boost::property_tree; nlohmann::json json;
ptree pt;
try try
{ {
std::stringstream ss; json.parse( content );
ss << content;
read_json( ss, pt );
} }
catch( std::exception& e ) catch( std::exception& e )
{ {
@ -76,7 +70,7 @@ Core::LobbySessionPtr Core::Network::RestConnector::getSession( char* sId )
if( content.find( "invalid" ) == std::string::npos ) if( content.find( "invalid" ) == std::string::npos )
{ {
LobbySessionPtr pSession( new Core::LobbySession() ); LobbySessionPtr pSession( new Core::LobbySession() );
pSession->setAccountID( atoi( pt.get< std::string >( "result" ).c_str() ) ); pSession->setAccountID( json["result"].get< uint32_t >() );
pSession->setSessionId( ( uint8_t* ) sId ); pSession->setSessionId( ( uint8_t* ) sId );
return pSession; return pSession;
} }

View file

@ -209,7 +209,7 @@ namespace SimpleWeb {
return nullptr; return nullptr;
auto timer = std::make_shared< asio::deadline_timer >( io_service ); auto timer = std::make_shared< asio::deadline_timer >( io_service );
timer->expires_from_now( boost::posix_time::seconds( config.timeout ) ); timer->expires_from_now( std::chrono::seconds( config.timeout ) );
timer->async_wait( [this]( const std::error_code& ec ) { timer->async_wait( [this]( const std::error_code& ec ) {
if( !ec ) { if( !ec ) {
close(); close();