2014-09-16 22:42:47 +03:00
|
|
|
#include "interface/module.h"
|
2014-09-16 23:14:04 +03:00
|
|
|
#include "interface/server.h"
|
2014-09-17 00:41:27 +03:00
|
|
|
#include "interface/fs.h"
|
2014-09-17 01:04:51 +03:00
|
|
|
#include "interface/event.h"
|
2014-09-17 23:44:42 +03:00
|
|
|
#include "core/log.h"
|
2014-09-16 22:42:47 +03:00
|
|
|
|
2014-09-17 01:04:51 +03:00
|
|
|
using interface::Event;
|
|
|
|
|
2014-09-17 02:18:03 +03:00
|
|
|
namespace __loader {
|
|
|
|
|
2014-09-16 23:14:04 +03:00
|
|
|
struct Module: public interface::Module
|
2014-09-16 22:42:47 +03:00
|
|
|
{
|
2014-09-16 23:21:41 +03:00
|
|
|
interface::Server *m_server;
|
|
|
|
|
|
|
|
Module(interface::Server *server):
|
2014-09-17 23:00:31 +03:00
|
|
|
interface::Module("__loader"),
|
2014-09-17 18:26:58 +03:00
|
|
|
m_server(server)
|
2014-09-16 23:14:04 +03:00
|
|
|
{
|
2014-09-17 23:44:42 +03:00
|
|
|
log_v(MODULE, "__loader construct");
|
2014-09-16 23:14:04 +03:00
|
|
|
}
|
2014-09-16 22:42:47 +03:00
|
|
|
|
2014-09-18 01:46:16 +03:00
|
|
|
~Module()
|
2014-09-17 14:53:06 +03:00
|
|
|
{
|
2014-09-18 01:46:16 +03:00
|
|
|
log_v(MODULE, "__loader destruct");
|
2014-09-17 14:53:06 +03:00
|
|
|
}
|
|
|
|
|
2014-09-18 01:46:16 +03:00
|
|
|
void init()
|
2014-09-16 23:14:04 +03:00
|
|
|
{
|
2014-09-18 01:46:16 +03:00
|
|
|
log_v(MODULE, "__loader init");
|
|
|
|
m_server->sub_event(this, Event::t("core:load_modules"));
|
2014-09-18 17:52:44 +03:00
|
|
|
m_server->sub_event(this, Event::t("core:module_modified"));
|
2014-09-16 23:14:04 +03:00
|
|
|
}
|
2014-09-16 22:42:47 +03:00
|
|
|
|
2014-09-17 18:52:59 +03:00
|
|
|
void event(const Event::Type &type, const Event::Private *p)
|
2014-09-17 01:04:51 +03:00
|
|
|
{
|
2014-09-18 17:52:44 +03:00
|
|
|
EVENT_VOIDN("core:load_modules", on_load_modules)
|
|
|
|
EVENT_TYPEN("core:module_modified", on_module_modified,
|
|
|
|
interface::ModuleModifiedEvent)
|
2014-09-17 01:04:51 +03:00
|
|
|
}
|
|
|
|
|
2014-09-17 16:43:05 +03:00
|
|
|
void on_load_modules()
|
2014-09-16 23:21:41 +03:00
|
|
|
{
|
2014-09-18 19:43:14 +03:00
|
|
|
ss_ builtin = m_server->get_builtin_modules_path();
|
|
|
|
m_server->load_module("network", builtin+"/network");
|
2014-09-18 23:47:05 +03:00
|
|
|
m_server->load_module("client_file", builtin+"/client_file");
|
2014-09-18 21:54:29 +03:00
|
|
|
m_server->load_module("client_lua", builtin+"/client_lua");
|
2014-09-19 15:47:21 +03:00
|
|
|
m_server->load_module("client_data", builtin+"/client_data");
|
2014-09-17 04:04:50 +03:00
|
|
|
|
2014-09-18 21:54:29 +03:00
|
|
|
sv_<ss_> load_list = {
|
2014-09-20 01:37:37 +03:00
|
|
|
//"test1",
|
|
|
|
//"test2",
|
|
|
|
"minigame",
|
2014-09-18 21:54:29 +03:00
|
|
|
};
|
2014-09-17 02:18:03 +03:00
|
|
|
for(const ss_ &name : load_list){
|
|
|
|
m_server->load_module(name, m_server->get_modules_path()+"/"+name);
|
|
|
|
}
|
2014-09-17 04:04:50 +03:00
|
|
|
|
2014-09-17 02:18:03 +03:00
|
|
|
/*// TODO: Dependencies
|
2014-09-17 00:41:27 +03:00
|
|
|
auto list = interface::getGlobalFilesystem()->list_directory(m_server->get_modules_path());
|
|
|
|
for(const interface::Filesystem::Node &n : list){
|
|
|
|
if(n.name == "__loader")
|
|
|
|
continue;
|
|
|
|
m_server->load_module(n.name, m_server->get_modules_path()+"/"+n.name);
|
2014-09-17 02:18:03 +03:00
|
|
|
}*/
|
2014-09-16 23:21:41 +03:00
|
|
|
}
|
2014-09-18 17:52:44 +03:00
|
|
|
|
|
|
|
void on_module_modified(const interface::ModuleModifiedEvent &event)
|
|
|
|
{
|
2014-09-18 21:54:29 +03:00
|
|
|
log_v(MODULE, "__loader::on_module_modified(): %s", cs(event.name));
|
|
|
|
if(event.name == "__loader")
|
|
|
|
return;
|
2014-09-18 17:52:44 +03:00
|
|
|
m_server->reload_module(event.name, event.path);
|
|
|
|
}
|
2014-09-16 23:14:04 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
extern "C" {
|
2014-09-17 02:18:03 +03:00
|
|
|
EXPORT void* createModule___loader(interface::Server *server){
|
|
|
|
return (void*)(new Module(server));
|
|
|
|
}
|
2014-09-16 23:14:04 +03:00
|
|
|
}
|
2014-09-16 22:42:47 +03:00
|
|
|
}
|