2014-09-27 16:11:35 +03:00
|
|
|
#include "core/log.h"
|
|
|
|
#include "interface/module.h"
|
|
|
|
#include "interface/server.h"
|
|
|
|
#include "interface/event.h"
|
|
|
|
#include "network/api.h"
|
|
|
|
#include "client_file/api.h"
|
|
|
|
|
|
|
|
using interface::Event;
|
|
|
|
|
2014-09-29 23:50:37 +03:00
|
|
|
namespace main {
|
2014-09-27 16:11:35 +03:00
|
|
|
|
|
|
|
struct Module: public interface::Module
|
|
|
|
{
|
|
|
|
interface::Server *m_server;
|
|
|
|
|
|
|
|
Module(interface::Server *server):
|
2014-09-29 23:50:37 +03:00
|
|
|
interface::Module("main"),
|
2014-09-27 16:11:35 +03:00
|
|
|
m_server(server)
|
|
|
|
{
|
2014-09-29 23:50:37 +03:00
|
|
|
log_v(MODULE, "main construct");
|
2014-09-27 16:11:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
~Module()
|
|
|
|
{
|
2014-09-29 23:50:37 +03:00
|
|
|
log_v(MODULE, "main destruct");
|
2014-09-27 16:11:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void init()
|
|
|
|
{
|
2014-09-29 23:50:37 +03:00
|
|
|
log_v(MODULE, "main init");
|
2014-09-27 16:11:35 +03:00
|
|
|
m_server->sub_event(this, Event::t("core:start"));
|
|
|
|
m_server->sub_event(this, Event::t("network:new_client"));
|
|
|
|
m_server->sub_event(this, Event::t("client_file:files_transmitted"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void event(const Event::Type &type, const Event::Private *p)
|
|
|
|
{
|
|
|
|
EVENT_VOIDN("core:start", on_start)
|
|
|
|
EVENT_TYPEN("network:new_client", on_new_client, network::NewClient)
|
|
|
|
EVENT_TYPEN("client_file:files_transmitted", on_files_transmitted,
|
|
|
|
client_file::FilesTransmitted)
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_start()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_new_client(const network::NewClient &new_client)
|
|
|
|
{
|
2014-09-29 23:50:37 +03:00
|
|
|
log_i(MODULE, "main::on_new_client: id=%zu", new_client.info.id);
|
2014-09-27 16:11:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void on_files_transmitted(const client_file::FilesTransmitted &event)
|
|
|
|
{
|
|
|
|
log_v(MODULE, "on_files_transmitted(): recipient=%zu", event.recipient);
|
|
|
|
|
|
|
|
network::access(m_server, [&](network::Interface * inetwork){
|
|
|
|
inetwork->send(event.recipient, "core:run_script",
|
2014-09-29 23:50:37 +03:00
|
|
|
"buildat.run_script_file(\"main/init.lua\")");
|
2014-09-27 16:11:35 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
extern "C" {
|
2014-09-29 23:50:37 +03:00
|
|
|
EXPORT void* createModule_main(interface::Server *server){
|
2014-09-27 16:11:35 +03:00
|
|
|
return (void*)(new Module(server));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// vim: set noet ts=4 sw=4:
|