@ -101,14 +101,14 @@ LuaState::LuaState()
CommandController : : Init ( * this ) ;
dataEnv = sol : : environment ( * lua , sol : : create , lua - > globals ( ) ) ;
lua - > set ( " Data " , dataEnv ) ; // plain global environment for communicating between mod s
lua - > set ( " Data " , dataEnv ) ; // plain global environment for communicating between mod ule s
auto coreTable = dataEnv . create ( " Core " ) ;
coreTable [ " VERSION " ] = TES3MP_VERSION ;
coreTable [ " PROTOCOL " ] = TES3MP_PROTO_VERSION ;
coreTable [ " loadedMod s" ] = coreTable . create ( ) ;
coreTable [ " loadedMod ule s" ] = coreTable . create ( ) ;
configEnv = sol : : environment ( * lua , sol : : create , lua - > globals ( ) ) ;
lua - > set ( " Config " , configEnv ) ; // plain global environment for mod configuration
lua - > set ( " Config " , configEnv ) ; // plain global environment for mod ule configuration
// Enable a special Sol error handler for Windows, because exceptions aren't caught properly
// in main.cpp for it
@ -227,10 +227,10 @@ LuaState::LuaState()
}
} ) ;
lua - > set_function ( " setModname " , [ ] ( const std : : string & mod n ame) {
lua - > set_function ( " setModname " , [ ] ( const std : : string & mod N ame) {
auto mc = mwmp : : Networking : : getPtr ( ) - > getMasterClient ( ) ;
if ( mc )
mc - > SetModname ( mod n ame) ;
mc - > SetModname ( mod N ame) ;
} ) ;
lua - > set_function ( " setHostname " , [ ] ( const std : : string & hostname ) {
@ -281,24 +281,24 @@ LuaState::LuaState()
} ) ;
}
sol : : environment LuaState : : openScript ( std : : string homePath , std : : string mod n ame)
sol : : environment LuaState : : openScript ( std : : string homePath , std : : string mod uleN ame)
{
cout < < " Loading fi le: " < < homePath + " /mod s/" + modn ame + " /main.lua " < < endl ;
cout < < " Loading modu le: " < < homePath + " /mod ules/" + moduleN ame + " /main.lua " < < endl ;
sol : : environment env ( * lua , sol : : create , lua - > globals ( ) ) ;
std : : string package_path = env [ " package " ] [ " path " ] ;
env [ " package " ] [ " path " ] = Utils : : convertPath ( homePath + " /mod s/" + modn ame + " /?.lua " ) + " ; " + package_path ;
env [ " package " ] [ " path " ] = Utils : : convertPath ( homePath + " /mod ules/" + moduleN ame + " /?.lua " ) + " ; " + package_path ;
package_path = env [ " package " ] [ " path " ] ;
env . set_function ( " getDataFolder " , [ homePath , mod n ame] ( ) - > const string {
return homePath + " /data/ " + mod n ame + ' / ' ;
env . set_function ( " getDataFolder " , [ homePath , mod uleN ame] ( ) - > const string {
return homePath + " /data/ " + mod uleN ame + ' / ' ;
} ) ;
env . set_function ( " getMod Folder" , [ homePath , mod n ame] ( ) - > const string {
return homePath + " /mod s/" + modn ame + ' / ' ;
env . set_function ( " getMod ule Folder" , [ homePath , mod uleN ame] ( ) - > const string {
return homePath + " /mod ules/" + moduleN ame + ' / ' ;
} ) ;
lua - > script_file ( homePath + " /mod s/" + modn ame + " /main.lua " , env ) ;
lua - > script_file ( homePath + " /mod ules/" + moduleN ame + " /main.lua " , env ) ;
return env ;
}
@ -386,25 +386,25 @@ int CompVersion(const string &wishVersion, const string &depVersionFound)
return 0 ;
}
void checkDependencies ( const vector < Server PluginInfo> & mods , const ServerPluginInfo & sp i, bool fatal = true )
void checkDependencies ( const vector < Server ModuleInfo> & modules , const ServerModuleInfo & sm i, bool fatal = true )
{
for ( auto & dependency : s p i. dependencies )
for ( auto & dependency : s m i. dependencies )
{
const std : : string & depNameRequest = dependency . first ;
const std : : string & depVersionRequest = dependency . second ;
const auto & depEnvIt = find_if ( mod s. begin ( ) , mod s. end ( ) , [ & depNameRequest ] ( const auto & val ) {
const auto & depEnvIt = find_if ( mod ule s. begin ( ) , mod ule s. end ( ) , [ & depNameRequest ] ( const auto & val ) {
return val . name = = depNameRequest ;
} ) ;
if ( depEnvIt ! = mod s. end ( ) )
if ( depEnvIt ! = mod ule s. end ( ) )
{
const string & depVersionFound = depEnvIt - > version ;
if ( CompVersion ( depVersionRequest , depVersionFound ) ! = 0 )
{
stringstream sstr ;
sstr < < depNameRequest < < " : version \" " < < depVersionFound < < " \" is not applicable for \" "
< < s p i. name < < " \" expected \" " < < depVersionRequest + " \" " ;
< < s m i. name < < " \" expected \" " < < depVersionRequest + " \" " ;
if ( fatal )
throw runtime_error ( sstr . str ( ) ) ;
else
@ -423,16 +423,16 @@ void checkDependencies(const vector<ServerPluginInfo> &mods, const ServerPluginI
}
}
vector < vector < Server Plugin Info> : : iterator > loadOrderSolver ( vector < Server PluginInfo> & mod s)
vector < vector < Server Module Info> : : iterator > loadOrderSolver ( vector < Server ModuleInfo> & module s)
{
vector < vector < Server Plugin Info> : : iterator > notResolved ;
vector < vector < Server Plugin Info> : : iterator > result ;
vector < vector < Server Module Info> : : iterator > notResolved ;
vector < vector < Server Module Info> : : iterator > result ;
for ( auto it = mod s. begin ( ) ; it ! = mod s. end ( ) ; + + it )
for ( auto it = mod ule s. begin ( ) ; it ! = mod ule s. end ( ) ; + + it )
{
checkDependencies ( mod s, * it ) ;
checkDependencies ( mod ule s, * it ) ;
if ( it - > dependencies . empty ( ) ) // if server plugin doesn't have any dependencies we can safely put it on result
if ( it - > dependencies . empty ( ) ) // if the server module doesn't have any dependencies, we can safely add it to the result
result . push_back ( it ) ;
else
notResolved . push_back ( it ) ;
@ -449,9 +449,9 @@ vector<vector<ServerPluginInfo>::iterator> loadOrderSolver(vector<ServerPluginIn
return dep . first = = a - > name ;
} ) ;
if ( found ! = result . end ( ) )
continue ; // if dependency already in correct order, otherwise hold plugin in unresolved
continue ; // if the dependency is already in the correct order, otherwise hold it among the unresolved ones
// check if someone depends on this plugin
// check if any module depends on this one
found = find_if ( notResolved . begin ( ) , notResolved . end ( ) , [ & dep ] ( auto & a ) {
return dep . first = = a - > name ;
} ) ;
@ -490,35 +490,35 @@ vector<vector<ServerPluginInfo>::iterator> loadOrderSolver(vector<ServerPluginIn
return result ;
}
void LuaState : : loadMod s( const std : : string & mod Dir, std : : vector < std : : string > * list )
void LuaState : : loadMod ule s( const std : : string & mod ule Dir, std : : vector < std : : string > * list )
{
using namespace boost : : filesystem ;
auto readConfig = [ this ] ( path homePath ) {
const auto mainScript = " main.lua " ;
if ( ! is_directory ( homePath / " mod s" ) )
if ( ! is_directory ( homePath / " mod ule s" ) )
throw runtime_error ( homePath . string ( ) + " : No such directory. " ) ;
for ( const auto & mod Dir : directory_iterator ( homePath / " mod s" ) )
for ( const auto & mod ule Dir : directory_iterator ( homePath / " mod ule s" ) )
{
if ( is_directory ( mod Dir. status ( ) ) & & exists ( mod Dir. path ( ) / mainScript ) )
if ( is_directory ( mod ule Dir. status ( ) ) & & exists ( mod ule Dir. path ( ) / mainScript ) )
{
boost : : property_tree : : ptree pt ;
auto _path = homePath . string ( ) + " /mod s/" + mod Dir. path ( ) . filename ( ) . string ( ) ;
boost : : property_tree : : read_json ( _path + " /mod i nfo.json" , pt ) ;
auto _path = homePath . string ( ) + " /mod ule s/" + mod ule Dir. path ( ) . filename ( ) . string ( ) ;
boost : : property_tree : : read_json ( _path + " /mod uleI nfo.json" , pt ) ;
Server PluginInfo mod Info;
Server ModuleInfo module Info;
mod Info. path = make_pair ( homePath . string ( ) , mod Dir. path ( ) . filename ( ) . string ( ) ) ;
mod Info. author = pt . get < string > ( " author " ) ;
mod Info. version = pt . get < string > ( " version " ) ;
mod ule Info. path = make_pair ( homePath . string ( ) , mod ule Dir. path ( ) . filename ( ) . string ( ) ) ;
mod ule Info. author = pt . get < string > ( " author " ) ;
mod ule Info. version = pt . get < string > ( " version " ) ;
for ( const auto & v : pt . get_child ( " dependencies " ) )
mod Info. dependencies . emplace_back ( v . first , v . second . get_value < string > ( ) ) ;
mod ule Info. dependencies . emplace_back ( v . first , v . second . get_value < string > ( ) ) ;
auto name = pt . get < string > ( " name " ) ;
mod Info. name = name ;
mod s. push_back ( move ( mod Info) ) ;
mod ule Info. name = name ;
mod ule s. push_back ( move ( mod ule Info) ) ;
}
}
} ;
@ -531,7 +531,7 @@ void LuaState::loadMods(const std::string &modDir, std::vector<std::string> *lis
# endif
path envServerDir = mod Dir;
path envServerDir = mod ule Dir;
if ( envServerDir . empty ( ) )
envServerDir = current_path ( ) ;
@ -540,37 +540,37 @@ void LuaState::loadMods(const std::string &modDir, std::vector<std::string> *lis
addGlobalCPath ( envServerDir . string ( ) + " /lib/? " + libExt ) ;
readConfig ( envServerDir ) ;
vector < vector < Server PluginInfo> : : iterator > sortedPlugin List;
vector < vector < Server ModuleInfo> : : iterator > sortedModule List;
if ( list ! = nullptr & & ! list - > empty ( ) ) // manual sorted list
{
for ( const auto & mssp : * list )
{
bool found = false ;
for ( auto it = mod s. begin ( ) ; it ! = mod s. end ( ) ; + + it )
for ( auto it = mod ule s. begin ( ) ; it ! = mod ule s. end ( ) ; + + it )
{
if ( it - > name = = mssp )
{
checkDependencies ( mod s, * it , false ) ; // check dependencies, but do not throw exceptions
sorted Plugin List. push_back ( it ) ;
checkDependencies ( mod ule s, * it , false ) ; // check dependencies, but do not throw exceptions
sorted Module List. push_back ( it ) ;
found = true ;
break ;
}
}
if ( ! found )
throw runtime_error ( " Plugin : \" " + mssp + " \" not found " ) ;
throw runtime_error ( " Module : \" " + mssp + " \" not found " ) ;
}
}
else
sorted Plugin List = loadOrderSolver ( mod s) ;
sorted Module List = loadOrderSolver ( mod ule s) ;
for ( auto & & mod : sortedPlugin List)
for ( auto & & mod ule : sortedModule List)
{
mod - > env = openScript ( mod - > path . first , mod - > path . second ) ;
mod ule - > env = openScript ( mod ule - > path . first , mod ule - > path . second ) ;
sol : : table loaded = dataEnv [ " Core " ] [ " loadedMod s" ] ;
loaded . add ( mod - > name ) ;
cout < < " mod n ame: " < < mod - > name < < endl ;
sol : : table loaded = dataEnv [ " Core " ] [ " loadedMod ule s" ] ;
loaded . add ( mod ule - > name ) ;
cout < < " mod uleN ame: " < < mod ule - > name < < endl ;
}
dataEnv [ " Core " ] [ " LOADED_MOD S" ] = mod s. size ( ) ;
dataEnv [ " Core " ] [ " LOADED_MOD ULE S" ] = mod ule s. size ( ) ;
}