From 993cc3dfd6da7ed35d0e278080df195717f0dd4a Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 2 Dec 2017 15:39:08 +0200 Subject: [PATCH] [Server] Rename server "plugins"/"mods" into "modules" for clarity The terms "plugins" and "mods" were used interchangeably to refer to collections of server scripts, which was bound to cause confusion later on, especially with client data files frequently being referred to as "plugins" and "mods" as well. Moreover, the server configuration file now starts its manual ordering with "Module1" for consistency with the pluginlist.json (soon to be dataFileList.json) of the CoreScripts. --- apps/openmw-mp/Script/EventController.cpp | 12 +-- apps/openmw-mp/Script/EventController.hpp | 2 +- apps/openmw-mp/Script/LuaState.cpp | 104 +++++++++++----------- apps/openmw-mp/Script/LuaState.hpp | 10 +-- apps/openmw-mp/main.cpp | 12 +-- files/tes3mp/tes3mp-server-default.cfg | 8 +- 6 files changed, 74 insertions(+), 74 deletions(-) diff --git a/apps/openmw-mp/Script/EventController.cpp b/apps/openmw-mp/Script/EventController.cpp index c402265d2..a87578894 100644 --- a/apps/openmw-mp/Script/EventController.cpp +++ b/apps/openmw-mp/Script/EventController.cpp @@ -24,8 +24,8 @@ void EventController::Init(LuaState &lua) eventsTable["raise"] = [&lua](unsigned event, sol::table data) { lua.getEventCtrl().raiseEvent(event, data); }; - eventsTable["raiseSpecified"] = [&lua](unsigned event, const std::string &modname, sol::table data) { - lua.getEventCtrl().raiseEvent(event, data, modname); + eventsTable["raiseSpecified"] = [&lua](unsigned event, const std::string &moduleName, sol::table data) { + lua.getEventCtrl().raiseEvent(event, data, moduleName); }; } @@ -132,15 +132,15 @@ Event EventController::createEvent() return lastEvent++; } -void EventController::raiseEvent(Event id, sol::table data, const string &modname) +void EventController::raiseEvent(Event id, sol::table data, const string &moduleName) { auto iter = events.find(id); if (iter != events.end()) { - if (!modname.empty()) + if (!moduleName.empty()) { - auto f = std::find_if (iter->second.begin(), iter->second.end(), [&modname](const auto &item){ - return item.first["ModName"]["name"] == modname; + auto f = std::find_if (iter->second.begin(), iter->second.end(), [&moduleName](const auto &item){ + return item.first["ModuleName"]["name"] == moduleName; }); if (f != iter->second.end()) f->second.call(data); // call only specified mod diff --git a/apps/openmw-mp/Script/EventController.hpp b/apps/openmw-mp/Script/EventController.hpp index ba72306da..b8ce7c26a 100644 --- a/apps/openmw-mp/Script/EventController.hpp +++ b/apps/openmw-mp/Script/EventController.hpp @@ -140,7 +140,7 @@ public: void registerEvent(int event, sol::environment &env, sol::function& func); CallbackCollection& GetEvents(Event event); Event createEvent(); - void raiseEvent(Event id, sol::table data, const std::string &modname = ""); + void raiseEvent(Event id, sol::table data, const std::string &moduleName = ""); void stop(int event); template diff --git a/apps/openmw-mp/Script/LuaState.cpp b/apps/openmw-mp/Script/LuaState.cpp index abcb00c2c..dbbe90317 100644 --- a/apps/openmw-mp/Script/LuaState.cpp +++ b/apps/openmw-mp/Script/LuaState.cpp @@ -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 mods + lua->set("Data", dataEnv); // plain global environment for communicating between modules auto coreTable = dataEnv.create("Core"); coreTable["VERSION"] = TES3MP_VERSION; coreTable["PROTOCOL"] = TES3MP_PROTO_VERSION; - coreTable["loadedMods"] = coreTable.create(); + coreTable["loadedModules"] = 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 module 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 &modname) { + lua->set_function("setModname", [](const std::string &modName) { auto mc = mwmp::Networking::getPtr()->getMasterClient(); if (mc) - mc->SetModname(modname); + mc->SetModname(modName); }); lua->set_function("setHostname", [](const std::string &hostname) { @@ -281,24 +281,24 @@ LuaState::LuaState() }); } -sol::environment LuaState::openScript(std::string homePath, std::string modname) +sol::environment LuaState::openScript(std::string homePath, std::string moduleName) { - cout << "Loading file: " << homePath + "/mods/" + modname + "/main.lua" << endl; + cout << "Loading module: " << homePath + "/modules/" + moduleName + "/main.lua" << endl; sol::environment env(*lua, sol::create, lua->globals()); std::string package_path = env["package"]["path"]; - env["package"]["path"] = Utils::convertPath(homePath + "/mods/" + modname + "/?.lua") + ";" + package_path; + env["package"]["path"] = Utils::convertPath(homePath + "/modules/" + moduleName + "/?.lua") + ";" + package_path; package_path = env["package"]["path"]; - env.set_function("getDataFolder", [homePath, modname]() -> const string { - return homePath + "/data/" + modname + '/'; + env.set_function("getDataFolder", [homePath, moduleName]() -> const string { + return homePath + "/data/" + moduleName + '/'; }); - env.set_function("getModFolder", [homePath, modname]() -> const string { - return homePath + "/mods/" + modname + '/'; + env.set_function("getModuleFolder", [homePath, moduleName]() -> const string { + return homePath + "/modules/" + moduleName + '/'; }); - lua->script_file(homePath + "/mods/" + modname + "/main.lua", env); + lua->script_file(homePath + "/modules/" + moduleName + "/main.lua", env); return env; } @@ -386,25 +386,25 @@ int CompVersion(const string &wishVersion, const string &depVersionFound) return 0; } -void checkDependencies(const vector &mods, const ServerPluginInfo &spi, bool fatal = true) +void checkDependencies(const vector &modules, const ServerModuleInfo &smi, bool fatal = true) { - for (auto &dependency : spi.dependencies) + for (auto &dependency : smi.dependencies) { const std::string &depNameRequest = dependency.first; const std::string &depVersionRequest = dependency.second; - const auto &depEnvIt = find_if(mods.begin(), mods.end(), [&depNameRequest](const auto &val) { + const auto &depEnvIt = find_if(modules.begin(), modules.end(), [&depNameRequest](const auto &val) { return val.name == depNameRequest; }); - if (depEnvIt != mods.end()) + if (depEnvIt != modules.end()) { const string &depVersionFound = depEnvIt->version; if (CompVersion(depVersionRequest, depVersionFound) != 0) { stringstream sstr; sstr << depNameRequest << ": version \"" << depVersionFound << "\" is not applicable for \"" - << spi.name << "\" expected \"" << depVersionRequest + "\""; + << smi.name << "\" expected \"" << depVersionRequest + "\""; if (fatal) throw runtime_error(sstr.str()); else @@ -423,16 +423,16 @@ void checkDependencies(const vector &mods, const ServerPluginI } } -vector::iterator> loadOrderSolver(vector &mods) +vector::iterator> loadOrderSolver(vector &modules) { - vector::iterator> notResolved; - vector::iterator> result; + vector::iterator> notResolved; + vector::iterator> result; - for (auto it = mods.begin(); it != mods.end(); ++it) + for (auto it = modules.begin(); it != modules.end(); ++it) { - checkDependencies(mods, *it); + checkDependencies(modules, *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::iterator> loadOrderSolver(vectorname; }); 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::iterator> loadOrderSolver(vector *list) +void LuaState::loadModules(const std::string &moduleDir, std::vector *list) { using namespace boost::filesystem; auto readConfig = [this](path homePath){ const auto mainScript = "main.lua"; - if (!is_directory(homePath / "mods")) + if (!is_directory(homePath / "modules")) throw runtime_error(homePath.string() + ": No such directory."); - for (const auto &modDir : directory_iterator(homePath / "mods")) + for (const auto &moduleDir : directory_iterator(homePath / "modules")) { - if (is_directory(modDir.status()) && exists(modDir.path() / mainScript)) + if (is_directory(moduleDir.status()) && exists(moduleDir.path() / mainScript)) { boost::property_tree::ptree pt; - auto _path = homePath.string() + "/mods/" + modDir.path().filename().string(); - boost::property_tree::read_json(_path + "/modinfo.json", pt); + auto _path = homePath.string() + "/modules/" + moduleDir.path().filename().string(); + boost::property_tree::read_json(_path + "/moduleInfo.json", pt); - ServerPluginInfo modInfo; + ServerModuleInfo moduleInfo; - modInfo.path = make_pair(homePath.string(), modDir.path().filename().string()); - modInfo.author = pt.get("author"); - modInfo.version = pt.get("version"); + moduleInfo.path = make_pair(homePath.string(), moduleDir.path().filename().string()); + moduleInfo.author = pt.get("author"); + moduleInfo.version = pt.get("version"); for (const auto &v : pt.get_child("dependencies")) - modInfo.dependencies.emplace_back(v.first, v.second.get_value()); + moduleInfo.dependencies.emplace_back(v.first, v.second.get_value()); auto name = pt.get("name"); - modInfo.name = name; - mods.push_back(move(modInfo)); + moduleInfo.name = name; + modules.push_back(move(moduleInfo)); } } }; @@ -531,7 +531,7 @@ void LuaState::loadMods(const std::string &modDir, std::vector *lis #endif - path envServerDir = modDir; + path envServerDir = moduleDir; if (envServerDir.empty()) envServerDir = current_path(); @@ -540,37 +540,37 @@ void LuaState::loadMods(const std::string &modDir, std::vector *lis addGlobalCPath(envServerDir.string() + "/lib/?" + libExt); readConfig(envServerDir); - vector::iterator> sortedPluginList; + vector::iterator> sortedModuleList; if (list != nullptr && !list->empty()) // manual sorted list { for (const auto &mssp : *list) { bool found = false; - for (auto it = mods.begin(); it != mods.end(); ++it) + for (auto it = modules.begin(); it != modules.end(); ++it) { if (it->name == mssp) { - checkDependencies(mods, *it, false); // check dependencies, but do not throw exceptions - sortedPluginList.push_back(it); + checkDependencies(modules, *it, false); // check dependencies, but do not throw exceptions + sortedModuleList.push_back(it); found = true; break; } } if (!found) - throw runtime_error("Plugin: \"" + mssp + "\" not found"); + throw runtime_error("Module: \"" + mssp + "\" not found"); } } else - sortedPluginList = loadOrderSolver(mods); + sortedModuleList = loadOrderSolver(modules); - for (auto &&mod : sortedPluginList) + for (auto &&module : sortedModuleList) { - mod->env = openScript(mod->path.first, mod->path.second); + module->env = openScript(module->path.first, module->path.second); - sol::table loaded = dataEnv["Core"]["loadedMods"]; - loaded.add(mod->name); - cout << "modname: " << mod->name << endl; + sol::table loaded = dataEnv["Core"]["loadedModules"]; + loaded.add(module->name); + cout << "moduleName: " << module->name << endl; } - dataEnv["Core"]["LOADED_MODS"] = mods.size(); + dataEnv["Core"]["LOADED_MODULES"] = modules.size(); } diff --git a/apps/openmw-mp/Script/LuaState.hpp b/apps/openmw-mp/Script/LuaState.hpp index 879f4aba2..3914e94dc 100644 --- a/apps/openmw-mp/Script/LuaState.hpp +++ b/apps/openmw-mp/Script/LuaState.hpp @@ -16,10 +16,10 @@ class EventController; //class TimerController; -struct ServerPluginInfo +struct ServerModuleInfo { std::string name; - std::pair path; // homePath, modname + std::pair path; // homePath, moduleName std::string version; std::string author; std::vector> dependencies; // name, requestedVersion @@ -36,7 +36,7 @@ public: void addGlobalCPath(const std::string &path); sol::table getCoreTable() { return dataEnv["Core"]; } sol::environment &getDataEnv(){ return dataEnv; } - void loadMods(const std::string &path, std::vector *list = nullptr); + void loadModules(const std::string &path, std::vector *list = nullptr); CommandController &getCmdCtrl(); EventController &getEventCtrl(); @@ -46,7 +46,7 @@ public: ActorController &getActorCtrl(); private: - sol::environment openScript(std::string path, std::string modname); + sol::environment openScript(std::string path, std::string moduleName); private: std::shared_ptr lua; sol::environment dataEnv; @@ -57,5 +57,5 @@ private: std::unique_ptr actorCtrl; std::unique_ptr objectCtrl; - std::vector mods; + std::vector modules; }; diff --git a/apps/openmw-mp/main.cpp b/apps/openmw-mp/main.cpp index 79037a2b8..ea3a9aecf 100644 --- a/apps/openmw-mp/main.cpp +++ b/apps/openmw-mp/main.cpp @@ -253,23 +253,23 @@ int main(int argc, char *argv[]) Networking networking(peer); - string plugin_home = mgr.getString("home", "Plugins"); + string moduleHome = mgr.getString("home", "Modules"); - if (mgr.getBool("autoSort", "Plugins")) - networking.getState().loadMods(plugin_home); + if (mgr.getBool("autoSort", "Modules")) + networking.getState().loadModules(moduleHome); else { std::vector list; try { - for (int i = 0;; ++i) - list.push_back(mgr.getString("Plugin" + to_string(i), "Plugins")); + for (int i = 1;; ++i) + list.push_back(mgr.getString("Module" + to_string(i), "Modules")); } catch (...) {} // Manager::getString throws runtime_error exception if setting is not exist - networking.getState().loadMods(plugin_home, &list); + networking.getState().loadModules(moduleHome, &list); } diff --git a/files/tes3mp/tes3mp-server-default.cfg b/files/tes3mp/tes3mp-server-default.cfg index 42fc08b33..e08283d4d 100644 --- a/files/tes3mp/tes3mp-server-default.cfg +++ b/files/tes3mp/tes3mp-server-default.cfg @@ -14,9 +14,9 @@ address = master.tes3mp.com port = 25560 rate = 1000 -[Plugins] +[Modules] home = ~/local/openmw/tes3mp autoSort = true -# If autoSort is disabled, then use "Plugin[n] = [plugin-name]" for manual ordering -# Plugin0 = Core -# Plugin1 = Coop +# If autoSort is disabled, then use "Module# = " for manual ordering +# Module1 = Core +# Module2 = Coop