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

Merge pull request #413 from NotAdam/boost_scrap

remove boost, its gone
This commit is contained in:
Mordred 2018-10-26 12:01:58 +02:00 committed by GitHub
commit 842cbb2a78
4 changed files with 52 additions and 118 deletions

View file

@ -1,39 +0,0 @@
if(UNIX)
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS system)
if(Boost_FOUND)
set(BOOST_LIBRARY_DIR ${Boost_LIBRARY_DIR})
else()
if (EXISTS /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME})
set(Boost_INCLUDE_DIR /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME})
set(BOOST_LIBRARYDIR /opt/build_libs/${SAPPHIRE_BOOST_FOLDER_NAME}/stage/lib)
else()
message(FATAL_ERROR "Unable to find boost ${SAPPHIRE_BOOST_VER} package!")
endif()
endif()
else()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME})
message(STATUS "Using boost in /libraries/external")
set(Boost_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME})
set(BOOST_LIBRARYDIR ${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/external/${SAPPHIRE_BOOST_FOLDER_NAME}/lib32-msvc-14.0)
else()
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS system)
if(Boost_FOUND)
set(BOOST_LIBRARY_DIR ${Boost_LIBRARY_DIR})
elseif ((EXISTS $ENV{BOOST_ROOT_DIR}) AND (EXISTS $ENV{BOOST_LIB_DIR}))
set(Boost_INCLUDE_DIR $ENV{BOOST_ROOT_DIR})
set(BOOST_LIBRARYDIR $ENV{BOOST_LIB_DIR})
else()
message(FATAL_ERROR "SapphireError: Unable to find boost ${SAPPHIRE_BOOST_VER} package and environment variables BOOST_ROOT_DIR and BOOST_LIB_DIR not set!")
endif()
endif()
endif()
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost ${SAPPHIRE_BOOST_VER} COMPONENTS log log_setup thread date_time filesystem system)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${BOOST_LIBRARYDIR})

View file

@ -4,12 +4,7 @@
#include "PlayerMinimal.h" #include "PlayerMinimal.h"
#include <time.h> #include <time.h>
#define BOOST_SPIRIT_THREADSAFE #include <sstream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
@ -122,15 +117,8 @@ Core::Network::SapphireAPI::createCharacter( const int& accountId, const std::st
newPlayer.setContentId( getNextContentId() ); newPlayer.setContentId( getNextContentId() );
newPlayer.setName( name.c_str() ); newPlayer.setName( name.c_str() );
boost::property_tree::ptree pt;
auto json = nlohmann::json::parse( infoJson ); auto json = nlohmann::json::parse( infoJson );
std::stringstream ss;
ss << infoJson;
boost::property_tree::read_json( ss, pt );
const char* ptr = infoJson.c_str() + 50; const char* ptr = infoJson.c_str() + 50;
std::string lookPart( ptr ); std::string lookPart( ptr );
@ -143,18 +131,31 @@ Core::Network::SapphireAPI::createCharacter( const int& accountId, const std::st
std::vector< int32_t > tmpVector; std::vector< int32_t > tmpVector;
std::vector< int32_t > tmpVector2; std::vector< int32_t > tmpVector2;
BOOST_FOREACH( boost::property_tree::ptree::value_type& v, pt.get_child( "content" ) ) for( auto& v : json["content"] )
{ {
boost::property_tree::ptree subtree1 = v.second; for( auto& vs : v )
BOOST_FOREACH( boost::property_tree::ptree::value_type& vs, subtree1 )
{ {
boost::property_tree::ptree subtree2 = vs.second; tmpVector.push_back( vs.get< int >() );
//std::cout << vs.second.data();
tmpVector.push_back( std::stoi( vs.second.data() ) );
} }
if( !v.second.data().empty() )
tmpVector2.push_back( std::stoi( v.second.data() ) ); if( !v.empty() )
tmpVector2.push_back( v.get< int >() );
} }
// leaving this in for now for reference
// BOOST_FOREACH( boost::property_tree::ptree::value_type& v, pt.get_child( "content" ) )
// {
// boost::property_tree::ptree subtree1 = v.second;
// BOOST_FOREACH( boost::property_tree::ptree::value_type& vs, subtree1 )
// {
// boost::property_tree::ptree subtree2 = vs.second;
// //std::cout << vs.second.data();
// tmpVector.push_back( std::stoi( vs.second.data() ) );
// }
// if( !v.second.data().empty() )
// tmpVector2.push_back( std::stoi( v.second.data() ) );
// }
std::vector< int32_t >::iterator it = tmpVector.begin(); std::vector< int32_t >::iterator it = tmpVector.begin();
for( int32_t i = 0; it != tmpVector.end(); ++it, i++ ) for( int32_t i = 0; it != tmpVector.end(); ++it, i++ )
{ {

View file

@ -1,8 +1,6 @@
#include "server_http.hpp" #include "server_http.hpp"
#include "client_http.hpp" #include "client_http.hpp"
#define BOOST_SPIRIT_THREADSAFE
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <Logging/Logger.h> #include <Logging/Logger.h>

View file

@ -6,13 +6,11 @@
#include <time.h> #include <time.h>
#include <iomanip> #include <iomanip>
#define BOOST_SPIRIT_THREADSAFE
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
extern Core::Logger g_log; extern Core::Logger g_log;
typedef std::vector< std::tuple< std::string, uint32_t, uint64_t, std::string>> CharList; typedef std::vector< std::tuple< std::string, uint32_t, uint64_t, std::string > > CharList;
Core::Network::RestConnector::RestConnector() Core::Network::RestConnector::RestConnector()
{ {
@ -97,15 +95,11 @@ bool Core::Network::RestConnector::checkNameTaken( std::string name )
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; auto json = nlohmann::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 )
{ {
@ -113,7 +107,7 @@ bool Core::Network::RestConnector::checkNameTaken( std::string name )
return true; return true;
} }
if( pt.get< std::string >( "result" ) != "invalid" && pt.get< std::string >( "result" ) == "false" ) if( json["result"] != "invalid" && json["result"] == "false" )
return false; return false;
return true; return true;
} }
@ -135,15 +129,11 @@ uint32_t Core::Network::RestConnector::getNextCharId()
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; auto json = nlohmann::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 )
{ {
@ -153,7 +143,7 @@ uint32_t Core::Network::RestConnector::getNextCharId()
if( content.find( "invalid" ) == std::string::npos ) if( content.find( "invalid" ) == std::string::npos )
{ {
return pt.get< uint32_t >( "result" ); return json["result"].get< uint32_t >();
} }
else else
{ {
@ -178,15 +168,11 @@ uint64_t Core::Network::RestConnector::getNextContentId()
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; auto json = nlohmann::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 )
{ {
@ -196,7 +182,7 @@ uint64_t Core::Network::RestConnector::getNextContentId()
if( content.find( "invalid" ) == std::string::npos ) if( content.find( "invalid" ) == std::string::npos )
{ {
return pt.get< uint64_t >( "result" ); return json["result"].get< uint64_t >();
} }
else else
{ {
@ -223,15 +209,11 @@ CharList Core::Network::RestConnector::getCharList( char* sId )
g_log.debug( content ); g_log.debug( content );
if( r->status_code.find( "200" ) != std::string::npos ) if( r->status_code.find( "200" ) != std::string::npos )
{ {
using namespace boost::property_tree; auto json = nlohmann::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 )
{ {
@ -239,18 +221,19 @@ CharList Core::Network::RestConnector::getCharList( char* sId )
return list; return list;
} }
if( pt.get< std::string >( "result" ).find( "invalid" ) == std::string::npos ) if( json["result"].get< std::string >().find( "invalid" ) == std::string::npos )
{ {
g_log.debug( pt.get_value< std::string >( "result" ) ); g_log.debug( json["result"] );
for( auto& child : pt.get_child( "charArray" ) ) for( auto& child : json["charArray"] )
{ {
g_log.debug( child.second.get< std::string >( "contentId" ) ); g_log.debug( child["contentId"] );
list.push_back( std::make_tuple( child.second.get< std::string >( "name" ), //std::string, uint32_t, uint64_t, std::string
atoi( child.second.get< std::string >( "charId" ).c_str() ), list.push_back( std::make_tuple( child["name"].get< std::string >() ),
child.second.get< uint64_t >( "contentId" ), child["charId"].get< uint32_t >(),
child.second.get< std::string >( "infoJson" ) ) ); child["contentId"].get< uint64_t >(),
child["infoJson"].get< std::string >() );
} }
return list; return list;
@ -280,15 +263,10 @@ bool Core::Network::RestConnector::deleteCharacter( char* sId, std::string name
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; auto json = nlohmann::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 )
{ {
@ -321,15 +299,11 @@ int Core::Network::RestConnector::createCharacter( char* sId, std::string name,
g_log.debug( content ); g_log.debug( content );
if( r->status_code.find( "200" ) != std::string::npos ) if( r->status_code.find( "200" ) != std::string::npos )
{ {
using namespace boost::property_tree; auto json = nlohmann::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 )
{ {
@ -338,7 +312,7 @@ int Core::Network::RestConnector::createCharacter( char* sId, std::string name,
} }
if( content.find( "invalid" ) == std::string::npos ) if( content.find( "invalid" ) == std::string::npos )
return atoi( pt.get< std::string >( "result" ).c_str() ); return json["result"].get< int >();
return -1; return -1;
} }
else else