71 lines
1.6 KiB
C++
Raw Normal View History

#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 {
struct Module: public interface::Module
{
interface::Server *m_server;
Module(interface::Server *server):
2014-09-29 23:50:37 +03:00
interface::Module("main"),
m_server(server)
{
2014-09-29 23:50:37 +03:00
log_v(MODULE, "main construct");
}
~Module()
{
2014-09-29 23:50:37 +03:00
log_v(MODULE, "main destruct");
}
void init()
{
2014-09-29 23:50:37 +03:00
log_v(MODULE, "main init");
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);
}
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\")");
});
}
};
extern "C" {
2014-09-29 23:50:37 +03:00
EXPORT void* createModule_main(interface::Server *server){
return (void*)(new Module(server));
}
}
}
// vim: set noet ts=4 sw=4: