From 1bf33c8027c57cfed1d2816c84f5f7ad1e517a65 Mon Sep 17 00:00:00 2001 From: GokuWeedLord Date: Sun, 10 Dec 2017 23:51:06 +1100 Subject: [PATCH] base scripts init code, call init before zone init for onZoneInit callback --- scripts/native/CMakeLists.txt | 5 ++++ .../Server_Zone/Script/NativeScript.cpp | 5 ++++ src/servers/Server_Zone/Script/NativeScript.h | 2 ++ .../Server_Zone/Script/ScriptManager.cpp | 26 ++++++++++++++++--- .../Server_Zone/Script/ScriptManager.h | 4 +-- src/servers/Server_Zone/ServerZone.cpp | 4 +-- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/scripts/native/CMakeLists.txt b/scripts/native/CMakeLists.txt index 3ce99db2..51a9e18d 100644 --- a/scripts/native/CMakeLists.txt +++ b/scripts/native/CMakeLists.txt @@ -22,4 +22,9 @@ foreach(_sourcefile ${SCRIPT_FILES}) LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/compiledscripts/" LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/compiledscripts/" ) + + add_custom_command(TARGET "${_file}" POST_BUILD + COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/${_file}.exp" + COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/${_file}.lib" + ) endforeach(_sourcefile ${SCRIPT_FILES}) \ No newline at end of file diff --git a/src/servers/Server_Zone/Script/NativeScript.cpp b/src/servers/Server_Zone/Script/NativeScript.cpp index bc41bd93..3b3f08de 100644 --- a/src/servers/Server_Zone/Script/NativeScript.cpp +++ b/src/servers/Server_Zone/Script/NativeScript.cpp @@ -105,6 +105,11 @@ namespace Core { } } + const std::string NativeScript::getModuleExtension() + { + return m_loader.getModuleExtension(); + } + boost::shared_ptr< NativeScript > create_script_engine( ) { diff --git a/src/servers/Server_Zone/Script/NativeScript.h b/src/servers/Server_Zone/Script/NativeScript.h index 1b6197c1..e2499767 100644 --- a/src/servers/Server_Zone/Script/NativeScript.h +++ b/src/servers/Server_Zone/Script/NativeScript.h @@ -44,6 +44,8 @@ namespace Core { void loadScript( std::string ); void unloadScript( std::string ); void clearAllScripts(); + + const std::string getModuleExtension(); }; diff --git a/src/servers/Server_Zone/Script/ScriptManager.cpp b/src/servers/Server_Zone/Script/ScriptManager.cpp index 0f66c00e..5d847045 100644 --- a/src/servers/Server_Zone/Script/ScriptManager.cpp +++ b/src/servers/Server_Zone/Script/ScriptManager.cpp @@ -19,6 +19,8 @@ #include #include +#include + extern Core::Logger g_log; extern Core::Data::ExdData g_exdData; extern Core::ServerZone g_serverZone; @@ -33,7 +35,24 @@ Core::Scripting::ScriptManager::~ScriptManager() } -void Core::Scripting::ScriptManager::loadDir( std::string dirname, std::set& chaiFiles ) +bool Core::Scripting::ScriptManager::init() +{ + std::set< std::string > files; + + loadDir( g_serverZone.getConfig()->getValue< std::string >( "Settings.General.ScriptPath", "./compiledscripts/" ), + files, m_nativeScriptHandler->getModuleExtension() ); + + for( auto itr = files.begin(); itr != files.end(); ++itr ) + { + auto& path = *itr; + + g_log.debug( "got module: " + path ); + } + + return true; +} + +void Core::Scripting::ScriptManager::loadDir( std::string dirname, std::set& files, std::string ext ) { g_log.info( "ScriptEngine: loading scripts from " + dirname ); @@ -44,10 +63,9 @@ void Core::Scripting::ScriptManager::loadDir( std::string dirname, std::set& chaiFiles ); + void loadDir( std::string dirname, std::set& files, std::string ext ); }; diff --git a/src/servers/Server_Zone/ServerZone.cpp b/src/servers/Server_Zone/ServerZone.cpp index 1c35aabd..8044f7ec 100644 --- a/src/servers/Server_Zone/ServerZone.cpp +++ b/src/servers/Server_Zone/ServerZone.cpp @@ -222,11 +222,11 @@ void Core::ServerZone::run( int32_t argc, char* argv[] ) Network::HivePtr hive( new Network::Hive() ); Network::addServerToHive< Network::GameConnection >( m_ip, m_port, hive ); + g_scriptMgr.init(); + g_log.info( "ZoneMgr: Setting up zones" ); g_zoneMgr.createZones(); -// g_scriptMgr.init(); - std::vector< std::thread > thread_list; thread_list.emplace_back( std::thread( std::bind( &Network::Hive::Run, hive.get() ) ) );