1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-25 14:07:46 +00:00

base scripts init code, call init before zone init for onZoneInit callback

This commit is contained in:
GokuWeedLord 2017-12-10 23:51:06 +11:00
parent aa72e715b6
commit 1bf33c8027
6 changed files with 38 additions and 8 deletions

View file

@ -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})

View file

@ -105,6 +105,11 @@ namespace Core {
}
}
const std::string NativeScript::getModuleExtension()
{
return m_loader.getModuleExtension();
}
boost::shared_ptr< NativeScript > create_script_engine( )
{

View file

@ -44,6 +44,8 @@ namespace Core {
void loadScript( std::string );
void unloadScript( std::string );
void clearAllScripts();
const std::string getModuleExtension();
};

View file

@ -19,6 +19,8 @@
#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include <Server_Common/Config/XMLConfig.h>
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<std::string>& 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<std::string>& 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<std:
BOOST_FOREACH( boost::filesystem::path const& i, make_pair( iter, eod ) )
{
if( is_regular_file( i ) && boost::filesystem::extension( i.string() ) == ".chai" ||
boost::filesystem::extension( i.string() ) == ".inc" )
if( is_regular_file( i ) && boost::filesystem::extension( i.string() ) == ext )
{
chaiFiles.insert( i.string() );
files.insert( i.string() );
}
}

View file

@ -32,7 +32,7 @@ namespace Core
ScriptManager();
~ScriptManager();
int32_t init();
bool init();
void reload();
void onPlayerFirstEnterWorld( Entity::Player& player );
@ -60,7 +60,7 @@ namespace Core
bool onEventHandlerTradeReturn( Entity::Player& player, uint32_t eventId, uint16_t subEvent, uint16_t param, uint32_t catalogId );
void loadDir( std::string dirname, std::set<std::string>& chaiFiles );
void loadDir( std::string dirname, std::set<std::string>& files, std::string ext );
};

View file

@ -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() ) ) );