/* QuoteServ core functions */ #include "module.h" #include "instaserv.h" class InstaServService: public InstaServCore { Reference InstaServ; std::vector defaults; std::map buffers; public: InstaServService(const Anope::string &modname, const Anope::string &creator); ~InstaServService(); void OnReload(Configuration::Conf *conf) anope_override; void OnShutdown() anope_override; void OnRestart() anope_override; virtual void OnExpire(User *u); EventReturn OnBotPrivmsg(User *u, BotInfo *bi, Anope::string &msg) anope_override; BotInfo* GetBotInfo(); virtual InstaMessageBuffer *GetBuffer(User *u); virtual bool HasBuffer(User *u); virtual void SetBuffer(User *u, InstaMessageBuffer *buffer); }; InstaServService::InstaServService(const Anope::string &modname, const Anope::string &creator) : InstaServCore(modname, creator) { } InstaServService::~InstaServService() { OnShutdown(); } BotInfo *InstaServService::GetBotInfo() { return *InstaServ; } void InstaServService::OnReload(Configuration::Conf *conf) { const Anope::string &channick = conf->GetModule(this)->Get("client"); if (channick.empty()) throw ConfigException(Module::name + ": must be defined"); BotInfo *bi = BotInfo::Find(channick, true); if (!bi) throw ConfigException(Module::name + ": no bot named " + channick); InstaServ = bi; } void InstaServService::OnShutdown() { } void InstaServService::OnRestart() { OnShutdown(); } InstaMessageBuffer *InstaServService::GetBuffer(User *u) { std::map::iterator it = buffers.find(u); if (it == buffers.end()) return NULL; return it->second; } bool InstaServService::HasBuffer(User *u) { std::map::iterator it = buffers.find(u); return it != buffers.end(); } void InstaServService::SetBuffer(User *u, InstaMessageBuffer *buffer) { buffers[u] = buffer; } EventReturn InstaServService::OnBotPrivmsg(User *u, BotInfo *bi, Anope::string &msg) { if (bi == InstaServ) { InstaMessageBuffer *buffer = GetBuffer(u); if (buffer) { if (msg == "EOF") buffer->OnEndBuffer(); else buffer->Add(msg); return EVENT_STOP; } } return EVENT_CONTINUE; } void InstaServService::OnExpire(User *u) { std::map::iterator it = buffers.find(u); if (it != buffers.end()) buffers.erase(it); } MODULE_INIT(InstaServService)