diff --git a/src/common/Database/DbConnection.cpp b/src/common/Database/DbConnection.cpp index a4353394..366fc954 100644 --- a/src/common/Database/DbConnection.cpp +++ b/src/common/Database/DbConnection.cpp @@ -1,13 +1,13 @@ #include "DbConnection.h" #include "DbWorker.h" #include - #include "Logging/Logger.h" + #include "PreparedStatement.h" #include +#include "Framework.h" - -extern Core::Logger g_log; +extern Core::Framework g_fw; Core::Db::DbConnection::DbConnection( ConnectionInfo &connInfo ) : m_reconnecting( false ), @@ -67,7 +67,7 @@ uint32_t Core::Db::DbConnection::open() } catch( std::runtime_error& e ) { - g_log.error( e.what() ); + g_fw.get< Logger >()->error( e.what() ); return 1; } @@ -119,7 +119,7 @@ bool Core::Db::DbConnection::execute( const std::string& sql ) } catch( std::runtime_error& e ) { - g_log.error( e.what() ); + g_fw.get< Logger >()->error( e.what() ); return false; } } @@ -134,7 +134,7 @@ boost::shared_ptr< Mysql::ResultSet > Core::Db::DbConnection::query( const std:: } catch( std::runtime_error& e ) { - g_log.error( e.what() ); + g_fw.get< Logger >()->error( e.what() ); return nullptr; } } @@ -148,13 +148,11 @@ boost::shared_ptr< Mysql::ResultSet > Core::Db::DbConnection::query( boost::shar if( !ping() ) { - g_log.error( "MysqlConnection went down" ); // naivly reconnect and hope for the best open(); lockIfReady(); if( !prepareStatements() ) - g_log.error( "Mysql Statements failed to prepare..." ); - g_log.info( "MysqlConnection reestablished" ); + return nullptr; } uint32_t index = stmt->getIndex(); @@ -172,7 +170,7 @@ boost::shared_ptr< Mysql::ResultSet > Core::Db::DbConnection::query( boost::shar } catch( std::runtime_error& e ) { - g_log.error( e.what() ); + g_fw.get< Logger >()->error( e.what() ); return nullptr; } @@ -198,7 +196,7 @@ bool Core::Db::DbConnection::execute( boost::shared_ptr< Core::Db::PreparedState } catch( std::runtime_error& e ) { - g_log.error( e.what() ); + g_fw.get< Logger >()->error( e.what() ); return false; } } @@ -234,7 +232,7 @@ void Core::Db::DbConnection::prepareStatement( uint32_t index, const std::string } catch( std::runtime_error& e ) { - g_log.error( e.what() ); + g_fw.get< Logger >()->error( e.what() ); m_prepareError = true; } diff --git a/src/common/Framework.cpp b/src/common/Framework.cpp new file mode 100644 index 00000000..9951e8a2 --- /dev/null +++ b/src/common/Framework.cpp @@ -0,0 +1,5 @@ +#include "Framework.h" + +#include +#include +#include diff --git a/src/common/Framework.h b/src/common/Framework.h new file mode 100644 index 00000000..06e48ba5 --- /dev/null +++ b/src/common/Framework.h @@ -0,0 +1,36 @@ +#ifndef _CORE_FRAMEWORK_H +#define _CORE_FRAMEWORK_H + +#include +#include +#include +#include +#include + +namespace Core +{ + + class Framework + { + using TypenameToObject = std::map< std::type_index, boost::shared_ptr< void > >; + TypenameToObject ObjectMap; + + public: + template< typename T > + boost::shared_ptr< T > get() + { + auto iType = ObjectMap.find( typeid( T ) ); + assert( !( iType == ObjectMap.end() ) ); + return boost::static_pointer_cast< T >( iType->second ); + } + + template< typename T > + void set( boost::shared_ptr< T > value ) + { + ObjectMap[typeid( T )] = value; + } + }; + +} + +#endif // _CORE_FRAMEWORK_H diff --git a/src/servers/Scripts/common/ScriptLoader.cpp b/src/servers/Scripts/common/ScriptLoader.cpp index e4bc7a56..c1871bea 100644 --- a/src/servers/Scripts/common/ScriptLoader.cpp +++ b/src/servers/Scripts/common/ScriptLoader.cpp @@ -2,19 +2,19 @@ #include "Aethernet.cpp" #include "Aetheryte.cpp" -#include "HouFurOrchestrion.cpp" -#include "CmnDefInnBed.cpp" #include "CmnDefCutSceneReplay.cpp" +#include "CmnDefInnBed.cpp" #include "CmnDefLinkShell.cpp" +#include "HouFurOrchestrion.cpp" const ScriptObject* ptrs[] = { static_cast< ScriptObject* >( new Aethernet ), static_cast< ScriptObject* >( new Aetheryte ), - static_cast< ScriptObject* >( new HouFurOrchestrion ), - static_cast< ScriptObject* >( new CmnDefInnBed ), static_cast< ScriptObject* >( new CmnDefCutSceneReplay ), + static_cast< ScriptObject* >( new CmnDefInnBed ), static_cast< ScriptObject* >( new CmnDefLinkShell ), + static_cast< ScriptObject* >( new HouFurOrchestrion ), nullptr }; diff --git a/src/servers/Scripts/instances/ScriptLoader.cpp b/src/servers/Scripts/instances/ScriptLoader.cpp index 0eaf9ab6..7d8fbf10 100644 --- a/src/servers/Scripts/instances/ScriptLoader.cpp +++ b/src/servers/Scripts/instances/ScriptLoader.cpp @@ -1,542 +1,542 @@ #include