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

fix crash when starting the server with no scripts, fixes #284

This commit is contained in:
Adam 2018-04-04 11:25:07 +10:00
parent 99feacfe99
commit c0779d6b1e
2 changed files with 24 additions and 4 deletions

View file

@ -54,9 +54,15 @@ bool Core::Scripting::ScriptMgr::init()
auto pConfig = g_fw.get< XMLConfig >(); auto pConfig = g_fw.get< XMLConfig >();
auto pLog = g_fw.get< Logger >(); auto pLog = g_fw.get< Logger >();
loadDir( pConfig->getValue< std::string >( "Settings.General.Scripts.Path", "./compiledscripts/" ), auto status = loadDir( pConfig->getValue< std::string >( "Settings.General.Scripts.Path", "./compiledscripts/" ),
files, m_nativeScriptMgr->getModuleExtension() ); files, m_nativeScriptMgr->getModuleExtension() );
if( !status )
{
pLog->error( std::string( __func__ ) + ": failed to load scripts, the server will not function correctly without scripts loaded." );
return false;
}
uint32_t scriptsFound = 0; uint32_t scriptsFound = 0;
uint32_t scriptsLoaded = 0; uint32_t scriptsLoaded = 0;
@ -114,11 +120,17 @@ void Core::Scripting::ScriptMgr::watchDirectories()
}); });
} }
void Core::Scripting::ScriptMgr::loadDir( const std::string& dirname, std::set<std::string> &files, const std::string& ext ) bool Core::Scripting::ScriptMgr::loadDir( const std::string& dirname, std::set<std::string>& files, const std::string& ext )
{ {
auto pLog = g_fw.get< Logger >(); auto pLog = g_fw.get< Logger >();
pLog->info( "ScriptEngine: loading scripts from " + dirname ); pLog->info( "ScriptMgr: loading scripts from " + dirname );
if( !boost::filesystem::exists( dirname ) )
{
pLog->error( "ScriptMgr: scripts directory doesn't exist" );
return false;
}
boost::filesystem::path targetDir( dirname ); boost::filesystem::path targetDir( dirname );
@ -132,6 +144,14 @@ void Core::Scripting::ScriptMgr::loadDir( const std::string& dirname, std::set<s
files.insert( i.string() ); files.insert( i.string() );
} }
} }
if( files.size() )
return true;
else
{
pLog->error( "ScriptMgr: couldn't find any script modules" );
return false;
}
} }
void Core::Scripting::ScriptMgr::onPlayerFirstEnterWorld( Entity::Player& player ) void Core::Scripting::ScriptMgr::onPlayerFirstEnterWorld( Entity::Player& player )

View file

@ -61,7 +61,7 @@ namespace Core
bool onInstanceUpdate( InstanceContentPtr instance, uint32_t currTime ); bool onInstanceUpdate( InstanceContentPtr instance, uint32_t currTime );
bool onInstanceEnterTerritory( InstanceContentPtr instance, Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 ); bool onInstanceEnterTerritory( InstanceContentPtr instance, Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 );
void loadDir( const std::string& dirname, std::set<std::string> &files, const std::string& ext ); bool loadDir( const std::string& dirname, std::set<std::string> &files, const std::string& ext );
NativeScriptMgr& getNativeScriptHandler(); NativeScriptMgr& getNativeScriptHandler();
}; };