diff options
| author | Adam <Adam@anope.org> | 2016-07-28 21:29:35 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2016-07-28 21:29:35 -0400 |
| commit | 0e758a2ac23dc4a001e8e126cec14588da9a9769 (patch) | |
| tree | 45df813323e023c5c89db7279426c4ad0943b4a9 /modules | |
| parent | a3c8afae00c54d5b95c620248b51f90679d7d53f (diff) | |
Allow serializable fields to use storage in the respective objects.
Split service management code nito a proper servicemanager. Make service
references managed instead of lazy lookup. Also made events and
serializable use service manager instead of their respective systems for
management
Diffstat (limited to 'modules')
163 files changed, 2023 insertions, 1930 deletions
diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 1851f47b9..7a31c1ccb 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -22,9 +22,11 @@ macro(build_modules SRC) file(RELATIVE_PATH DEST "${Anope_SOURCE_DIR}/modules" ${SRC}) if(DEST) - set(TARG "module_${DEST}.${SO}") + set(TARG "anope_${DEST}.${SO}") + set(OUT_NAME "${DEST}_${SO}") else() - set(TARG "module_${SO}") + set(TARG "anope_${SO}") + set(OUT_NAME "${SO}") endif() # Reset linker flags @@ -40,14 +42,14 @@ macro(build_modules SRC) set(WIN32_MEMORY) endif() # Generate the module and set its linker flags, also set it to depend on the main Anope executable to be built beforehand - add_library(${TARG} MODULE ${MODULE_SRC}) + add_library(${TARG} SHARED ${MODULE_SRC}) # Windows requires this because it's weird if(WIN32) set(WIN32_NO_LIBS "/nodefaultlib:\"libcmt.lib\" /OPT:NOREF") else() set(WIN32_NO_LIBS) endif() - set_target_properties(${TARG} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" LINK_FLAGS "${TEMP_LDFLAGS} ${WIN32_NO_LIBS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON OUTPUT_NAME "${SO}") + set_target_properties(${TARG} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" OUTPUT_NAME "${OUT_NAME}" LINK_FLAGS "${TEMP_LDFLAGS} ${WIN32_NO_LIBS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON) add_dependencies(${TARG} ${PROGRAM_NAME}) if(GETTEXT_FOUND) add_dependencies(${TARG} module_language) @@ -60,15 +62,41 @@ macro(build_modules SRC) elseif(APPLE) target_link_libraries(${TARG} ${PROGRAM_NAME}) endif() - calculate_dependencies(${MODULE_SRC}) # Set the module to be installed to the module directory under the data directory - install(TARGETS ${TARG} DESTINATION ${LIB_DIR}/modules/${DEST}) + install(TARGETS ${TARG} DESTINATION ${LIB_DIR}/modules) endif() endif() endforeach() endif() endmacro() +macro(build_modules_dependencies SRC) + file(GLOB MODULES_SRCS "${SRC}/*") + foreach(MODULE_SRC ${MODULES_SRCS}) + if(NOT IS_DIRECTORY "${MODULE_SRC}") + string(REGEX MATCH "\\.cpp$" CPP ${MODULE_SRC}) + if(CPP) + file(RELATIVE_PATH FNAME ${SRC} ${MODULE_SRC}) + # Convert the real source file extension to have a .so extension + string(REGEX REPLACE "\\.cpp$" "" SO ${FNAME}) + + file(RELATIVE_PATH DEST "${Anope_SOURCE_DIR}/modules" ${SRC}) + if(DEST) + set(TARG "anope_${DEST}.${SO}") + else() + set(TARG "anope_${SO}") + endif() + + set(DEPS) + calculate_dependencies(${MODULE_SRC} DEPS) + foreach(DEP ${DEPS}) + target_link_libraries(${TARG} ${DEP}) + endforeach() + endif() + endif() + endforeach() +endmacro() + macro(build_subdir) file(GLOB_RECURSE MODULES_SUBDIR_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp") list(SORT MODULES_SUBDIR_SRCS) @@ -77,14 +105,15 @@ macro(build_subdir) get_filename_component(DIR_NAME ${DEST} DIRECTORY) get_filename_component(FOLDER_NAME ${DEST} NAME) if(DIR_NAME) - set(SO "${DIR_NAME}.${FOLDER_NAME}") + set(SO "anope_${DIR_NAME}.${FOLDER_NAME}") else() - set(SO "${FOLDER_NAME}") + set(SO "anope_${FOLDER_NAME}") endif() # Set all the files to use C++ as well as set their compile flags (use the module-specific compile flags, though) set_source_files_properties(${MODULES_SUBDIR_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}") + set(DEPS) # Iterate through the source files in the subdirectory foreach(SRC ${MODULES_SUBDIR_SRCS}) # Reset linker flags @@ -93,7 +122,7 @@ macro(build_subdir) set(TEMP_DEPENDENCIES) # Calculate the library dependencies for the given source file calculate_libraries(${SRC} SKIP_LIBRARIES MODULE TEMP_LDFLAGS TEMP_DEPENDENCIES) - calculate_dependencies(${SRC}) + calculate_dependencies(${SRC} DEPS) # Append this source file's linker flags to the subdirectoy's linker flags, if there are any to append if(TEMP_DEPENDENCIES) @@ -119,13 +148,16 @@ macro(build_subdir) endif() # Generate the module and set its linker flags, also set it to depend on the main Anope executable to be built beforehand - add_library(${SO} MODULE ${MODULES_SUBDIR_SRCS}) - set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" LINK_FLAGS "${SUBDIR_LDFLAGS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON OUTPUT_NAME "${FOLDER_NAME}") + add_library(${SO} SHARED ${MODULES_SUBDIR_SRCS}) + set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE CXX PREFIX "" LINK_FLAGS "${SUBDIR_LDFLAGS}" INSTALL_RPATH_USE_LINK_PATH ON BUILD_WITH_INSTALL_RPATH ON OUTPUT_NAME "${DIR_NAME}_${FOLDER_NAME}") add_dependencies(${SO} ${PROGRAM_NAME}) if(GETTEXT_FOUND) add_dependencies(${SO} module_language) endif() target_link_libraries(${SO} ${SUBDIR_EXTRA_DEPENDS}) + foreach(DEP ${DEPS}) + target_link_libraries(${SO} ${DEP}) + endforeach() # For Windows only, have the module link to the export library of Anope as well as wsock32 and Ws2_32 libraries (most of the modules probably don't need this, but this is to be on the safe side), also set its version if(WIN32) target_link_libraries(${SO} ${PROGRAM_NAME} wsock32 Ws2_32 ${WIN32_MEMORY}) @@ -134,8 +166,9 @@ macro(build_subdir) target_link_libraries(${SO} ${PROGRAM_NAME}) endif() - install(TARGETS ${SO} DESTINATION ${LIB_DIR}/modules/${DIR_NAME}) + install(TARGETS ${SO} DESTINATION ${LIB_DIR}/modules) endmacro() build_modules(${CMAKE_CURRENT_SOURCE_DIR}) +build_modules_dependencies(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/modules/botserv/assign.cpp b/modules/botserv/assign.cpp index 1d2755ad5..96e8b0821 100644 --- a/modules/botserv/assign.cpp +++ b/modules/botserv/assign.cpp @@ -227,8 +227,10 @@ class BSAssign : public Module public: BSAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::Invite>(this) + , EventHook<Event::ServiceBotEvent>(this) - , nobot(this, botinfo, "BS_NOBOT") + , nobot(this, "BS_NOBOT") , commandbsassign(this) , commandbsunassign(this) diff --git a/modules/botserv/autoassign.cpp b/modules/botserv/autoassign.cpp index 8978499ed..4b5074abe 100644 --- a/modules/botserv/autoassign.cpp +++ b/modules/botserv/autoassign.cpp @@ -14,6 +14,7 @@ class BSAutoAssign : public Module { public: BSAutoAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ChanRegistered>(this) { } diff --git a/modules/botserv/badwords.cpp b/modules/botserv/badwords.cpp index afdc2e09f..94cf8803a 100644 --- a/modules/botserv/badwords.cpp +++ b/modules/botserv/badwords.cpp @@ -12,24 +12,25 @@ #include "module.h" #include "modules/botserv/badwords.h" -static EventHandlers<Event::BadWordEvents> *bwevents; - class BadWordImpl : public BadWord { + friend class BadWordsType; + + ChanServ::Channel *channel = nullptr; + Anope::string word; + BadWordType type; + public: BadWordImpl(Serialize::TypeBase *type) : BadWord(type) { } BadWordImpl(Serialize::TypeBase *type, Serialize::ID id) : BadWord(type, id) { } ChanServ::Channel *GetChannel() override; - void SetChannel(ChanServ::Channel *c) override; Anope::string GetWord() override; - void SetWord(const Anope::string &w) override; BadWordType GetType() override; - void SetType(const BadWordType &t) override; }; @@ -40,10 +41,10 @@ class BadWordsType : public Serialize::Type<BadWordImpl> Serialize::Field<BadWordImpl, Anope::string> word; Serialize::Field<BadWordImpl, BadWordType> type; - BadWordsType(Module *me) : Serialize::Type<BadWordImpl>(me, "BadWord") - , channel(this, "ci", true) - , word(this, "word") - , type(this, "type") + BadWordsType(Module *me) : Serialize::Type<BadWordImpl>(me) + , channel(this, "ci", &BadWordImpl::channel, true) + , word(this, "word", &BadWordImpl::word) + , type(this, "type", &BadWordImpl::type) { } }; @@ -84,19 +85,19 @@ struct BadWordsImpl : BadWords BadWord* AddBadWord(ChanServ::Channel *ci, const Anope::string &word, BadWordType type) override { - BadWord *bw = badword.Create(); + BadWord *bw = Serialize::New<BadWord *>(); bw->SetChannel(ci); bw->SetWord(word); bw->SetType(type); - (*bwevents)(&Event::BadWordEvents::OnBadWordAdd, ci, bw); + EventManager::Get()->Dispatch(&Event::BadWordEvents::OnBadWordAdd, ci, bw); return bw; } std::vector<BadWord *> GetBadWords(ChanServ::Channel *ci) override { - return ci->GetRefs<BadWord *>(badword); + return ci->GetRefs<BadWord *>(); } BadWord* GetBadWord(ChanServ::Channel *ci, unsigned index) override @@ -117,7 +118,7 @@ struct BadWordsImpl : BadWords return; BadWord *bw = bws[index]; - (*bwevents)(&Event::BadWordEvents::OnBadWordDel, ci, bw); + EventManager::Get()->Dispatch(&Event::BadWordEvents::OnBadWordDel, ci, bw); delete bw; } @@ -131,7 +132,8 @@ struct BadWordsImpl : BadWords class CommandBSBadwords : public Command { - private: + ServiceReference<BadWords> badwords; + void DoList(CommandSource &source, ChanServ::Channel *ci, const Anope::string &word) { bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); @@ -448,17 +450,14 @@ class BSBadwords : public Module { CommandBSBadwords commandbsbadwords; BadWordsImpl badwords; - EventHandlers<Event::BadWordEvents> events; BadWordsType bwtype; public: BSBadwords(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) , commandbsbadwords(this) , badwords(this) - , events(this) , bwtype(this) { - bwevents = &events; } }; diff --git a/modules/botserv/bot.cpp b/modules/botserv/bot.cpp index b2630bfcb..027df87fa 100644 --- a/modules/botserv/bot.cpp +++ b/modules/botserv/bot.cpp @@ -14,10 +14,6 @@ class CommandBSBot : public Command { - EventHandlers<Event::BotCreate> OnBotCreate; - EventHandlers<Event::BotChange> OnBotChange; - EventHandlers<Event::BotDelete> OnBotDelete; - void DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { const Anope::string &nick = params[1]; @@ -93,7 +89,7 @@ class CommandBSBot : public Command source.Reply(_("\002{0}!{1}@{2}\002 (\002{3}\002) added to the bot list."), bi->nick, bi->GetIdent(), bi->host, bi->realname); - this->OnBotCreate(&Event::BotCreate::OnBotCreate, bi); + EventManager::Get()->Dispatch(&Event::BotCreate::OnBotCreate, bi); } void DoChange(CommandSource &source, const std::vector<Anope::string> ¶ms) @@ -247,7 +243,7 @@ class CommandBSBot : public Command source.Reply(_("Bot \002{0}\002 has been changed to \002{1}!{2}@{3}\002 (\002{4}\002)."), oldnick, bi->nick, bi->GetIdent(), bi->host, bi->realname); Log(LOG_ADMIN, source, this) << "CHANGE " << oldnick << " to " << bi->GetMask() << " " << bi->realname; - this->OnBotChange(&Event::BotChange::OnBotChange, bi); + EventManager::Get()->Dispatch(&Event::BotChange::OnBotChange, bi); } void DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms) @@ -273,7 +269,7 @@ class CommandBSBot : public Command return; } - this->OnBotDelete(&Event::BotDelete::OnBotDelete, bi); + EventManager::Get()->Dispatch(&Event::BotDelete::OnBotDelete, bi); Log(LOG_ADMIN, source, this) << "DEL " << bi->nick; @@ -283,9 +279,6 @@ class CommandBSBot : public Command public: CommandBSBot(Module *creator) : Command(creator, "botserv/bot", 1, 6) - , OnBotCreate(creator) - , OnBotChange(creator) - , OnBotDelete(creator) { this->SetDesc(_("Maintains network bot list")); this->SetSyntax(_("\002ADD \037nicknae\037 \037username\037 \037hostname\037 \037realname\037\002")); diff --git a/modules/botserv/botlist.cpp b/modules/botserv/botlist.cpp index ce899719e..26b23a9fc 100644 --- a/modules/botserv/botlist.cpp +++ b/modules/botserv/botlist.cpp @@ -26,7 +26,7 @@ class CommandBSBotList : public Command list.AddColumn(_("Nick")).AddColumn(_("Mask")); - for (BotInfo *bi : Serialize::GetObjects<BotInfo *>(botinfo)) + for (BotInfo *bi : Serialize::GetObjects<BotInfo *>()) { if (source.HasPriv("botserv/administration") || !bi->GetOperOnly()) { diff --git a/modules/botserv/info.cpp b/modules/botserv/info.cpp index 19fe0a775..85100a4ec 100644 --- a/modules/botserv/info.cpp +++ b/modules/botserv/info.cpp @@ -16,10 +16,8 @@ class CommandBSInfo : public Command { - EventHandlers<Event::ServiceBotEvent> &onbotinfo; - public: - CommandBSInfo(Module *creator, EventHandlers<Event::ServiceBotEvent> &event) : Command(creator, "botserv/info", 1, 1), onbotinfo(event) + CommandBSInfo(Module *creator) : Command(creator, "botserv/info", 1, 1) { this->SetSyntax(_("{\037channel\037 | \037nickname\037}")); } @@ -41,7 +39,7 @@ class CommandBSInfo : public Command info[_("Options")] = bi->bi->GetOperOnly() ? _("Private") : _("None"); info[_("Used on")] = stringify(bi->GetChannelCount()) + " channel(s)"; - this->onbotinfo(&Event::ServiceBotEvent::OnServiceBot, source, bi, ci, info); + EventManager::Get()->Dispatch(&Event::ServiceBotEvent::OnServiceBot, source, bi, ci, info); std::vector<Anope::string> replies; info.Process(replies); @@ -72,7 +70,7 @@ class CommandBSInfo : public Command Anope::string enabled = Language::Translate(source.nc, _("Enabled")); Anope::string disabled = Language::Translate(source.nc, _("Disabled")); - this->onbotinfo(&Event::ServiceBotEvent::OnServiceBot, source, bi, ci, info); + EventManager::Get()->Dispatch(&Event::ServiceBotEvent::OnServiceBot, source, bi, ci, info); std::vector<Anope::string> replies; info.Process(replies); @@ -102,12 +100,10 @@ class CommandBSInfo : public Command class BSInfo : public Module { CommandBSInfo commandbsinfo; - EventHandlers<Event::ServiceBotEvent> onbotinfo; public: BSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandbsinfo(this, onbotinfo) - , onbotinfo(this) + , commandbsinfo(this) { } diff --git a/modules/botserv/kick.cpp b/modules/botserv/kick.cpp index f61c7eb94..00fd36b88 100644 --- a/modules/botserv/kick.cpp +++ b/modules/botserv/kick.cpp @@ -1,14 +1,9 @@ /* BotServ core functions * - * (C) 2003-2014 Anope Team + * (C) 2003-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - * */ #include "module.h" @@ -35,6 +30,41 @@ enum TTBType class KickerDataImpl : public KickerData { + friend class KickerDataType; + + ChanServ::Channel *channel = nullptr; + + bool amsgs = false, + badwords = false, + bolds = false, + caps = false, + colors = false, + flood = false, + italics = false, + repeat = false, + reverses = false, + underlines = false; + + int16_t ttb_bolds = 0, + ttb_colors = 0, + ttb_reverses = 0, + ttb_underlines = 0, + ttb_badwords = 0, + ttb_caps = 0, + ttb_flood = 0, + ttb_repeat = 0, + ttb_italics = 0, + ttb_amsgs = 0; + + int16_t capsmin = 0, + capspercent = 0, + floodlines = 0, + floodsecs = 0, + repeattimes = 0; + + bool dontkickops = false, + dontkickvoices = false; + public: KickerDataImpl(Serialize::TypeBase *type) : KickerData(type) { } KickerDataImpl(Serialize::TypeBase *type, Serialize::ID id) : KickerData(type, id) { } @@ -128,42 +158,66 @@ class KickerDataType : public Serialize::Type<KickerDataImpl> { public: Serialize::ObjectField<KickerDataImpl, ChanServ::Channel *> channel; - Serialize::Field<KickerDataImpl, bool> amsgs, badwords, bolds, caps, colors, flood, italics, repeat, reverses, underlines; - Serialize::Field<KickerDataImpl, int16_t> ttb_bolds, ttb_colors, ttb_reverses, ttb_underlines, ttb_badwords, ttb_caps, ttb_flood, ttb_repeat, ttb_italics, ttb_amsgs, - capsmin, capspercent, - floodlines, floodsecs, - repeattimes; - Serialize::Field<KickerDataImpl, bool> dontkickops, dontkickvoices; - - KickerDataType(Module *owner) : Serialize::Type<KickerDataImpl>(owner, "KickerData") - , channel(this, "channel", true) - , amsgs(this, "amsgs") - , badwords(this, "badwords") - , bolds(this, "bolds") - , caps(this, "caps") - , colors(this, "colors") - , flood(this, "flood") - , italics(this, "italics") - , repeat(this, "repeat") - , reverses(this, "reverses") - , underlines(this, "underlines") - , ttb_bolds(this, "ttb_bolds") - , ttb_colors(this, "ttb_colors") - , ttb_reverses(this, "ttb_reverses") - , ttb_underlines(this, "ttb_underlines") - , ttb_badwords(this, "ttb_badwords") - , ttb_caps(this, "ttb_caps") - , ttb_flood(this, "ttb_flood") - , ttb_repeat(this, "ttb_repeat") - , ttb_italics(this, "ttb_italics") - , ttb_amsgs(this, "ttb_amsgs") - , capsmin(this, "capsmin") - , capspercent(this, "capspercent") - , floodlines(this, "floodlines") - , floodsecs(this, "floodsecs") - , repeattimes(this, "repeattimes") - , dontkickops(this, "dontkickops") - , dontkickvoices(this, "dontkickvoices") + + Serialize::Field<KickerDataImpl, bool> amsgs, + badwords, + bolds, + caps, + colors, + flood, + italics, + repeat, + reverses, + underlines; + + Serialize::Field<KickerDataImpl, int16_t> ttb_bolds, + ttb_colors, + ttb_reverses, + ttb_underlines, + ttb_badwords, + ttb_caps, + ttb_flood, + ttb_repeat, + ttb_italics, + ttb_amsgs, + capsmin, + capspercent, + floodlines, + floodsecs, + repeattimes; + + Serialize::Field<KickerDataImpl, bool> dontkickops, + dontkickvoices; + + KickerDataType(Module *owner) : Serialize::Type<KickerDataImpl>(owner) + , channel(this, "channel", &KickerDataImpl::channel, true) + , amsgs(this, "amsgs", &KickerDataImpl::amsgs) + , badwords(this, "badwords", &KickerDataImpl::badwords) + , bolds(this, "bolds", &KickerDataImpl::bolds) + , caps(this, "caps", &KickerDataImpl::caps) + , colors(this, "colors", &KickerDataImpl::colors) + , flood(this, "flood", &KickerDataImpl::flood) + , italics(this, "italics", &KickerDataImpl::italics) + , repeat(this, "repeat", &KickerDataImpl::repeat) + , reverses(this, "reverses", &KickerDataImpl::reverses) + , underlines(this, "underlines", &KickerDataImpl::underlines) + , ttb_bolds(this, "ttb_bolds", &KickerDataImpl::ttb_bolds) + , ttb_colors(this, "ttb_colors", &KickerDataImpl::ttb_colors) + , ttb_reverses(this, "ttb_reverses", &KickerDataImpl::ttb_reverses) + , ttb_underlines(this, "ttb_underlines", &KickerDataImpl::ttb_underlines) + , ttb_badwords(this, "ttb_badwords", &KickerDataImpl::ttb_badwords) + , ttb_caps(this, "ttb_caps", &KickerDataImpl::ttb_caps) + , ttb_flood(this, "ttb_flood", &KickerDataImpl::ttb_flood) + , ttb_repeat(this, "ttb_repeat", &KickerDataImpl::ttb_repeat) + , ttb_italics(this, "ttb_italics", &KickerDataImpl::ttb_italics) + , ttb_amsgs(this, "ttb_amsgs", &KickerDataImpl::ttb_amsgs) + , capsmin(this, "capsmin", &KickerDataImpl::capsmin) + , capspercent(this, "capspercent", &KickerDataImpl::capspercent) + , floodlines(this, "floodlines", &KickerDataImpl::floodlines) + , floodsecs(this, "floodsecs", &KickerDataImpl::floodsecs) + , repeattimes(this, "repeattimes", &KickerDataImpl::repeattimes) + , dontkickops(this, "dontkickops", &KickerDataImpl::dontkickops) + , dontkickvoices(this, "dontkickvoices", &KickerDataImpl::dontkickvoices) { } }; @@ -477,7 +531,7 @@ class CommandBSKick : public Command if (c_name.find_ci(this_name + " ") == 0) { - ServiceReference<Command> command("Command", info.name); + ServiceReference<Command> command(info.name); if (command) { source.command = c_name; @@ -556,7 +610,7 @@ class CommandBSKickBase : public Command void Process(CommandSource &source, ChanServ::Channel *ci, const Anope::string ¶m, const Anope::string &ttb, void (KickerData::*setter)(const bool &), void (KickerData::*ttbsetter)(const int16_t &), const Anope::string &optname) { - KickerData *kd = ci->GetRef<KickerData *>(kickerdata); + KickerData *kd = ci->GetRef<KickerData *>(); if (param.equals_ci("ON")) { @@ -1195,7 +1249,7 @@ class BanDataPurger : public Timer { bd->purge(); if (bd->empty()) - c->ShrinkOK<BanData>("bandata"); + c->Shrink<BanData>("bandata"); } } } @@ -1226,8 +1280,8 @@ class BSKick : public Module CommandBSSetDontKickVoices commandbssetdontkickvoices; BanDataPurger purger; - - EventHandlers<Event::BotBan> onbotban; + + ServiceReference<BadWords> badwords; BanData::Data &GetBanData(User *u, Channel *c) { @@ -1260,7 +1314,7 @@ class BSKick : public Module Anope::string mask = ci->GetIdealBan(u); ci->c->SetMode(NULL, "BAN", mask); - this->onbotban(&Event::BotBan::OnBotBan, u, ci, mask); + EventManager::Get()->Dispatch(&Event::BotBan::OnBotBan, u, ci, mask); } if (!ci->c->FindUser(u)) @@ -1279,6 +1333,9 @@ class BSKick : public Module public: BSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ServiceBotEvent>(this) + , EventHook<Event::Privmsg>(this) + , bandata(this, "bandata") , userdata(this, "userdata") @@ -1300,8 +1357,6 @@ class BSKick : public Module , commandbssetdontkickvoices(this) , purger(this) - - , onbotban(this) { me = this; } @@ -1313,7 +1368,7 @@ class BSKick : public Module Anope::string enabled = Language::Translate(source.nc, _("Enabled")); Anope::string disabled = Language::Translate(source.nc, _("Disabled")); - KickerData *kd = ci->GetRef<KickerData *>(&kdtype); + KickerData *kd = ci->GetRef<KickerData *>(); if (kd && kd->GetBadwords()) { @@ -1434,7 +1489,7 @@ class BSKick : public Module ChanServ::Channel *ci = c->ci; if (ci == NULL) return; - KickerData *kd = c->ci->GetRef<KickerData *>(&kdtype); + KickerData *kd = c->ci->GetRef<KickerData *>(); if (kd == NULL) return; diff --git a/modules/botserv/main/botserv.cpp b/modules/botserv/main/botserv.cpp index 0b51691fc..a297db153 100644 --- a/modules/botserv/main/botserv.cpp +++ b/modules/botserv/main/botserv.cpp @@ -20,17 +20,25 @@ class BotServCore : public Module, public BotServ::BotServService , public EventHook<Event::LeaveChannel> , public EventHook<Event::Help> , public EventHook<Event::ChannelModeSet> - , public EventHook<Event::CreateChan> + , public EventHook<Event::ChanRegistered> , public EventHook<Event::UserKicked> , public EventHook<Event::CreateBot> { Reference<ServiceBot> BotServ; - ExtensibleRef<bool> persist, inhabit;//XXX? + ExtensibleRef<bool> inhabit; public: BotServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) , BotServ::BotServService(this) - , persist("PERSIST") + , EventHook<Event::SetCorrectModes>(this) + , EventHook<Event::BotAssign>(this) + , EventHook<Event::JoinChannel>(this) + , EventHook<Event::LeaveChannel>(this) + , EventHook<Event::Help>(this) + , EventHook<Event::ChannelModeSet>(this) + , EventHook<Event::ChanRegistered>(this) + , EventHook<Event::UserKicked>(this) + , EventHook<Event::CreateBot>(this) , inhabit("inhabit") { } @@ -119,7 +127,7 @@ class BotServCore : public Module, public BotServ::BotServService void OnLeaveChannel(User *u, Channel *c) override { /* Channel is persistent, it shouldn't be deleted and the service bot should stay */ - if (c->ci && persist && persist->HasExt(c->ci)) + if (c->ci && c->ci->HasFieldS("PERSIST")) return; /* Channel is syncing from a netburst, don't destroy it as more users are probably wanting to join immediately @@ -132,9 +140,14 @@ class BotServCore : public Module, public BotServ::BotServService if (inhabit && inhabit->HasExt(c)) return; - /* This is called prior to removing the user from the channnel, so c->users.size() - 1 should be safe */ - if (c->ci && c->ci->GetBot() && u != c->ci->GetBot() && c->users.size() - 1 <= Config->GetModule(this)->Get<unsigned>("minusers") && c->FindUser(c->ci->GetBot())) - c->ci->GetBot()->Part(c->ci->c); + if (c->ci) + { + ServiceBot *bot = c->ci->GetBot(); + + /* This is called prior to removing the user from the channnel, so c->users.size() - 1 should be safe */ + if (bot && u != bot && c->users.size() - 1 <= Config->GetModule(this)->Get<unsigned>("minusers") && c->FindUser(bot)) + bot->Part(c); + } } EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) override @@ -201,7 +214,7 @@ class BotServCore : public Module, public BotServ::BotServService return EVENT_CONTINUE; } - void OnCreateChan(ChanServ::Channel *ci) override + void OnChanRegistered(ChanServ::Channel *ci) override { /* Set default bot flags */ spacesepstream sep(Config->GetModule(this)->Get<Anope::string>("defaults", "greet fantasy")); diff --git a/modules/botserv/set.cpp b/modules/botserv/set.cpp index b480108af..ee8426e65 100644 --- a/modules/botserv/set.cpp +++ b/modules/botserv/set.cpp @@ -40,7 +40,7 @@ class CommandBSSet : public Command const CommandInfo &info = it->second; if (c_name.find_ci(this_name + " ") == 0) { - ServiceReference<Command> command("Command", info.name); + ServiceReference<Command> command(info.name); if (command) { // XXX dup @@ -203,6 +203,7 @@ class BSSet : public Module public: BSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::BotBan>(this) , commandbsset(this) , commandbssetbanexpire(this) , commandbssetprivate(this) diff --git a/modules/chanserv/CMakeLists.txt b/modules/chanserv/CMakeLists.txt index cd225a94d..afefd9d26 100644 --- a/modules/chanserv/CMakeLists.txt +++ b/modules/chanserv/CMakeLists.txt @@ -1 +1,3 @@ +#add_subdirs(${CMAKE_CURRENT_SOURCE_DIR}) build_modules(${CMAKE_CURRENT_SOURCE_DIR}) +build_modules_dependencies(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/modules/chanserv/cs_access.old b/modules/chanserv/access.cpp index 8e35772a6..c7fc9bace 100644 --- a/modules/chanserv/cs_access.old +++ b/modules/chanserv/access.cpp @@ -1,26 +1,30 @@ /* ChanServ core functions * - * (C) 2003-2014 Anope Team + * (C) 2003-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. */ +/* Dependencies: anope_chanserv.main */ #include "module.h" #include "modules/chanserv.h" -#include "modules/cs_access.h" -#include "main/chanaccess.h" +#include "modules/chanserv/access.h" +#include "modules/chanserv/main/chanaccess.h" #include "main/chanaccesstype.h" -class AccessChanAccess : public ChanAccessImpl +class AccessChanAccessImpl : public AccessChanAccess { + friend class AccessChanAccessType; + + int level = 0; + public: - AccessChanAccess(Serialize::TypeBase *type) : ChanAccessImpl(type) { } - AccessChanAccess(Serialize::TypeBase *type, Serialize::ID id) : ChanAccessImpl(type, id) { } + static constexpr const char *NAME = "accesschanaccess"; + + using AccessChanAccess::AccessChanAccess; int GetLevel(); void SetLevel(const int &); @@ -46,7 +50,6 @@ class AccessChanAccess : public ChanAccessImpl } } -#if 0 bool operator>(ChanServ::ChanAccess &other) override { if (this->GetSerializableType() != other.GetSerializableType()) @@ -62,18 +65,17 @@ class AccessChanAccess : public ChanAccessImpl else return this->GetLevel() < anope_dynamic_static_cast<AccessChanAccess *>(&other)->GetLevel(); } -#endif }; -class AccessChanAccessType : public Serialize::Type<AccessChanAccess, ChanAccessType> +class AccessChanAccessType : public ChanAccessType<AccessChanAccessImpl> { public: - Serialize::Field<AccessChanAccess, int> level; + Serialize::Field<AccessChanAccessImpl, int> level; - AccessChanAccessType(Module *me) : Serialize::Type<AccessChanAccess, ChanAccessType>(me, "AccessChanAccess") - , level(this, "level") + AccessChanAccessType(Module *me) : ChanAccessType<AccessChanAccessImpl>(me) + , level(this, "level", &AccessChanAccessImpl::level) { - SetParent(ChanServ::chanaccess); + Serialize::SetParent(AccessChanAccess::NAME, ChanServ::ChanAccess::NAME); } }; @@ -121,75 +123,51 @@ class CommandCSAccess : public Command ChanServ::AccessGroup u_access = source.AccessFor(ci); ChanServ::ChanAccess *highest = u_access.Highest(); - AccessChanAccess tmp_access(nullptr); - tmp_access.SetChannel(ci); - tmp_access.SetLevel(level); + AccessChanAccess *access = Serialize::New<AccessChanAccess *>(); + access->SetChannel(ci); + access->SetLevel(level); bool override = false; - if ((!highest || *highest <= tmp_access) && !u_access.founder) + if ((!highest || *highest <= *access) && !u_access.founder) { if (source.HasPriv("chanserv/access/modify")) + { override = true; + } else { source.Reply(_("Access denied. You do not have enough privileges on \002{0}\002 to add someone at level \002{1}\002."), ci->GetName(), level); + access->Delete(); return; } } - NickServ::Nick *na = nullptr; - ChanServ::Channel *targ_ci = nullptr; - - if (IRCD->IsChannelValid(mask)) - { - if (Config->GetModule("chanserv")->Get<bool>("disallow_channel_access")) - { - source.Reply(_("Channels may not be on access lists.")); - return; - } - - targ_ci = ChanServ::Find(mask); - if (targ_ci == NULL) - { - source.Reply(_("Channel \002{0}\002 isn't registered."), mask); - return; - } + access->Delete(); - if (ci == targ_ci) - { - source.Reply(_("You can't add a channel to its own access list.")); - return; - } + NickServ::Nick *na = NickServ::FindNick(mask); - mask = targ_ci->GetName(); - } - else + if (!na && Config->GetModule("chanserv")->Get<bool>("disallow_hostmask_access")) { - na = NickServ::FindNick(mask); + source.Reply(_("Masks and unregistered users may not be on access lists.")); + return; + } - if (!na && Config->GetModule("chanserv")->Get<bool>("disallow_hostmask_access")) + if (mask.find_first_of("!*@") == Anope::string::npos && !na) + { + User *targ = User::Find(mask, true); + if (targ != NULL) + mask = "*!*@" + targ->GetDisplayedHost(); + else { - source.Reply(_("Masks and unregistered users may not be on access lists.")); + source.Reply(_("\002{0}\002 isn't registered."), mask); return; } - - if (mask.find_first_of("!*@") == Anope::string::npos && !na) - { - User *targ = User::Find(mask, true); - if (targ != NULL) - mask = "*!*@" + targ->GetDisplayedHost(); - else - { - source.Reply(_("\002{0}\002 isn't registered."), mask); - return; - } - } - - if (na) - mask = na->GetNick(); } + if (na) + mask = na->GetNick(); + for (unsigned i = ci->GetAccessCount(); i > 0; --i) { ChanServ::ChanAccess *access = ci->GetAccess(i - 1); @@ -207,17 +185,15 @@ class CommandCSAccess : public Command } unsigned access_max = Config->GetModule("chanserv")->Get<unsigned>("accessmax", "1024"); - if (access_max && ci->GetDeepAccessCount() >= access_max) + if (access_max && ci->GetAccessCount() >= access_max) { source.Reply(_("Sorry, you can only have %d access entries on a channel, including access entries from other channels."), access_max); return; } - AccessChanAccess *access = anope_dynamic_static_cast<AccessChanAccess *>(accesschanaccess.Create()); + access = Serialize::New<AccessChanAccess *>(); if (na) access->SetObj(na->GetAccount()); - else if (targ_ci) - access->SetObj(targ_ci); access->SetChannel(ci); access->SetMask(mask); access->SetCreator(source.GetNick()); @@ -225,7 +201,7 @@ class CommandCSAccess : public Command access->SetLastSeen(0); access->SetCreated(Anope::CurTime); - Event::OnAccessAdd(&Event::AccessAdd::OnAccessAdd, ci, source, access); + EventManager::Get()->Dispatch(&Event::AccessAdd::OnAccessAdd, ci, source, access); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to add " << mask << " with level " << level; if (p != NULL) @@ -286,7 +262,7 @@ class CommandCSAccess : public Command else nicks = access->Mask(); - Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, access); + EventManager::Get()->Dispatch(&Event::AccessDel::OnAccessDel, ci, source, access); delete access; }, [&]() @@ -324,7 +300,7 @@ class CommandCSAccess : public Command bool override = !u_access.founder && !u_access.HasPriv("ACCESS_CHANGE") && !access->Mask().equals_ci(source.nc->GetDisplay()); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << access->Mask(); - Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, access); + EventManager::Get()->Dispatch(&Event::AccessDel::OnAccessDel, ci, source, access); delete access; } return; @@ -359,8 +335,7 @@ class CommandCSAccess : public Command if (ci->c) for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit) { - ChanServ::ChanAccess::Path p; - if (access->Matches(cit->second->user, cit->second->user->Account(), p)) + if (access->Matches(cit->second->user, cit->second->user->Account())) timebuf = "Now"; } if (timebuf.empty()) @@ -394,8 +369,7 @@ class CommandCSAccess : public Command if (ci->c) for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit) { - ChanServ::ChanAccess::Path p; - if (access->Matches(cit->second->user, cit->second->user->Account(), p)) + if (access->Matches(cit->second->user, cit->second->user->Account())) timebuf = "Now"; } if (timebuf.empty()) @@ -467,7 +441,7 @@ class CommandCSAccess : public Command return; } - Event::OnAccessClear(&Event::AccessClear::OnAccessClear, ci, source); + EventManager::Get()->Dispatch(&Event::AccessClear::OnAccessClear, ci, source); ci->ClearAccess(); @@ -513,9 +487,9 @@ class CommandCSAccess : public Command has_access = true; else if (is_list && source.HasPriv("chanserv/access/list")) has_access = true; - else if (is_list && source.AccessFor(ci).HasPriv("ACCESS_LIST")) + else if (is_list && access.HasPriv("ACCESS_LIST")) has_access = true; - else if (source.AccessFor(ci).HasPriv("ACCESS_CHANGE")) + else if (access.HasPriv("ACCESS_CHANGE")) has_access = true; else if (is_del) { @@ -689,7 +663,7 @@ class CommandCSLevels : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to set " << p->name << " to level " << level; ci->SetLevel(p->name, level); - this->onlevelchange(&Event::LevelChange::OnLevelChange, source, ci, p->name, level); + EventManager::Get()->Dispatch(&Event::LevelChange::OnLevelChange, source, ci, p->name, level); if (level == ChanServ::ACCESS_FOUNDER) source.Reply(_("Level for privilege \002{0}\002 on channel \002{1}\002 changed to \002founder only\002."), p->name, ci->GetName()); @@ -717,7 +691,7 @@ class CommandCSLevels : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable " << p->name; ci->SetLevel(p->name, ChanServ::ACCESS_INVALID); - this->onlevelchange(&Event::LevelChange::OnLevelChange, source, ci, p->name, ChanServ::ACCESS_INVALID); + EventManager::Get()->Dispatch(&Event::LevelChange::OnLevelChange, source, ci, p->name, ChanServ::ACCESS_INVALID); source.Reply(_("Privileged \002{0}\002 disabled on channel \002{1}\002."), p->name, ci->GetName()); return; @@ -772,15 +746,13 @@ class CommandCSLevels : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to reset all levels"; ci->ClearLevels(); - this->onlevelchange(&Event::LevelChange::OnLevelChange, source, ci, "ALL", 0); + EventManager::Get()->Dispatch(&Event::LevelChange::OnLevelChange, source, ci, "ALL", 0); source.Reply(_("Levels for \002{0}\002 reset to defaults."), ci->GetName()); } - EventHandlers<Event::LevelChange> &onlevelchange; - public: - CommandCSLevels(Module *creator, EventHandlers<Event::LevelChange> &event) : Command(creator, "chanserv/levels", 2, 4), onlevelchange(event) + CommandCSLevels(Module *creator) : Command(creator, "chanserv/levels", 2, 4) { this->SetDesc(_("Redefine the meanings of access levels")); this->SetSyntax(_("\037channel\037 SET \037privilege\037 \037level\037")); @@ -905,14 +877,13 @@ class CSAccess : public Module { CommandCSAccess commandcsaccess; CommandCSLevels commandcslevels; - EventHandlers<Event::LevelChange> onlevelchange; AccessChanAccessType accesschanaccesstype; public: CSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::GroupCheckPriv>(this) , commandcsaccess(this) - , commandcslevels(this, onlevelchange) - , onlevelchange(this) + , commandcslevels(this) , accesschanaccesstype(this) { this->SetPermanent(true); diff --git a/modules/chanserv/akick.cpp b/modules/chanserv/akick.cpp index 68adec8df..24bf9bc2d 100644 --- a/modules/chanserv/akick.cpp +++ b/modules/chanserv/akick.cpp @@ -14,6 +14,13 @@ class AutoKickImpl : public AutoKick { + friend class AutoKickType; + + ChanServ::Channel *channel = nullptr; + NickServ::Account *account = nullptr; + Anope::string mask, reason, creator; + time_t addtime = 0, last_time = 0; + public: AutoKickImpl(Serialize::TypeBase *type) : AutoKick(type) { } AutoKickImpl(Serialize::TypeBase *type, Serialize::ID id) : AutoKick(type, id) { } @@ -54,14 +61,14 @@ class AutoKickType : public Serialize::Type<AutoKickImpl> Serialize::Field<AutoKickImpl, time_t> last_time; AutoKickType(Module *me) - : Serialize::Type<AutoKickImpl>(me, "AutoKick") - , ci(this, "ci", true) - , mask(this, "mask") - , nc(this, "nc", true) - , reason(this, "reason") - , creator(this, "creator") - , addtime(this, "addtime") - , last_time(this, "last_time") + : Serialize::Type<AutoKickImpl>(me) + , ci(this, "ci", &AutoKickImpl::channel, true) + , mask(this, "mask", &AutoKickImpl::mask) + , nc(this, "nc", &AutoKickImpl::account, true) + , reason(this, "reason", &AutoKickImpl::reason) + , creator(this, "creator", &AutoKickImpl::creator) + , addtime(this, "addtime", &AutoKickImpl::addtime) + , last_time(this, "last_time", &AutoKickImpl::last_time) { } }; @@ -226,6 +233,7 @@ class CommandCSAKick : public Command } else if (ci->HasFieldS("PEACE")) { +#warning "peace" #if 0 /* Match against all currently online users with equal or * higher access. - Viper */ @@ -273,9 +281,9 @@ class CommandCSAKick : public Command } } - if (ci->GetAkickCount() >= Config->GetModule(this->owner)->Get<unsigned>("autokickmax")) + if (ci->GetAkickCount() >= Config->GetModule(this->GetOwner())->Get<unsigned>("autokickmax")) { - source.Reply(_("Sorry, you can only have \002{0}\002 autokick masks on a channel."), Config->GetModule(this->owner)->Get<unsigned>("autokickmax")); + source.Reply(_("Sorry, you can only have \002{0}\002 autokick masks on a channel."), Config->GetModule(this->GetOwner())->Get<unsigned>("autokickmax")); return; } @@ -287,7 +295,7 @@ class CommandCSAKick : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to add " << mask << (reason == "" ? "" : ": ") << reason; - this->akickevents(&Event::Akick::OnAkickAdd, source, ci, ak); + EventManager::Get()->Dispatch(&Event::Akick::OnAkickAdd, source, ci, ak); source.Reply(_("\002{0}\002 added to \002{1}\002 autokick list."), mask, ci->GetName()); @@ -318,7 +326,7 @@ class CommandCSAKick : public Command AutoKick *ak = ci->GetAkick(number - 1); - this->akickevents(&Event::Akick::OnAkickDel, source, ci, ak); + EventManager::Get()->Dispatch(&Event::Akick::OnAkickDel, source, ci, ak); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << (ak->GetAccount() ? ak->GetAccount()->GetDisplay() : ak->GetMask()); @@ -358,7 +366,7 @@ class CommandCSAKick : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << mask; - this->akickevents(&Event::Akick::OnAkickDel, source, ci, ci->GetAkick(i)); + EventManager::Get()->Dispatch(&Event::Akick::OnAkickDel, source, ci, ci->GetAkick(i)); delete ci->GetAkick(i); @@ -520,10 +528,8 @@ class CommandCSAKick : public Command source.Reply(_("The autokick list of \002{0}\002 has been cleared."), ci->GetName()); } - EventHandlers<Event::Akick> &akickevents; - public: - CommandCSAKick(Module *creator, EventHandlers<Event::Akick> &events) : Command(creator, "chanserv/akick", 2, 4), akickevents(events) + CommandCSAKick(Module *creator) : Command(creator, "chanserv/akick", 2, 4) { this->SetDesc(_("Maintain the AutoKick list")); this->SetSyntax(_("\037channel\037 ADD {\037nick\037 | \037mask\037} [\037reason\037]")); @@ -665,13 +671,12 @@ class CSAKick : public Module , public EventHook<Event::CheckKick> { CommandCSAKick commandcsakick; - EventHandlers<Event::Akick> akickevents; AutoKickType akick_type; public: CSAKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandcsakick(this, akickevents) - , akickevents(this) + , EventHook<Event::CheckKick>(this) + , commandcsakick(this) , akick_type(this) { } diff --git a/modules/chanserv/clone.cpp b/modules/chanserv/clone.cpp index 0cc1b2739..06b5c1a2b 100644 --- a/modules/chanserv/clone.cpp +++ b/modules/chanserv/clone.cpp @@ -15,6 +15,9 @@ class CommandCSClone : public Command { + ServiceReference<BadWords> badwords; + +#warning "levels hasnt been merged" #if 0 void CopyLevels(CommandSource &source, ChannelInfo *ci, ChannelInfo *target_ci) { @@ -88,7 +91,7 @@ public: if (what.empty()) { target_ci->Delete(); - target_ci = ChanServ::channel.Create(); + target_ci = Serialize::New<ChanServ::Channel *>(); target_ci->SetName(target); ChanServ::registered_channel_map& map = ChanServ::service->GetChannels(); map[target_ci->GetName()] = target_ci; @@ -115,9 +118,11 @@ public: target_ci->SetLastTopicTime(target_ci->c->topic_time); } else + { target_ci->SetLastTopicSetter(source.service->nick); + } - Event::OnChanRegistered(&Event::ChanRegistered::OnChanRegistered, target_ci); + EventManager::Get()->Dispatch(&Event::ChanRegistered::OnChanRegistered, target_ci); source.Reply(_("All settings from \002{0}\002 have been cloned to \002{0}\002."), channel, target); } @@ -134,7 +139,7 @@ public: { ChanServ::ChanAccess *taccess = ci->GetAccess(i); - if (access_max && target_ci->GetDeepAccessCount() >= access_max) + if (access_max && target_ci->GetAccessCount() >= access_max) break; if (masks.count(taccess->Mask())) diff --git a/modules/chanserv/drop.cpp b/modules/chanserv/drop.cpp index cb2036694..bbda47dbf 100644 --- a/modules/chanserv/drop.cpp +++ b/modules/chanserv/drop.cpp @@ -14,10 +14,8 @@ class CommandCSDrop : public Command { - EventHandlers<Event::ChanDrop> &onchandrop; - public: - CommandCSDrop(Module *creator, EventHandlers<Event::ChanDrop> &event) : Command(creator, "chanserv/drop", 1, 2), onchandrop(event) + CommandCSDrop(Module *creator) : Command(creator, "chanserv/drop", 1, 2) { this->SetDesc(_("Cancel the registration of a channel")); this->SetSyntax(_("\037channel\037 \037channel\037")); @@ -52,7 +50,7 @@ class CommandCSDrop : public Command return; } - EventReturn MOD_RESULT = this->onchandrop(&Event::ChanDrop::OnChanDrop, source, ci); + EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::ChanDrop::OnChanDrop, source, ci); if (MOD_RESULT == EVENT_STOP) return; @@ -87,12 +85,10 @@ class CommandCSDrop : public Command class CSDrop : public Module { CommandCSDrop commandcsdrop; - EventHandlers<Event::ChanDrop> onchandrop; public: CSDrop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandcsdrop(this, onchandrop) - , onchandrop(this) + , commandcsdrop(this) { } diff --git a/modules/chanserv/entrymsg.cpp b/modules/chanserv/entrymsg.cpp index ac46809fd..6abd6706a 100644 --- a/modules/chanserv/entrymsg.cpp +++ b/modules/chanserv/entrymsg.cpp @@ -14,6 +14,12 @@ class EntryMsgImpl : public EntryMsg { + friend class EntryMsgType; + + ChanServ::Channel *channel = nullptr; + Anope::string creator, message; + time_t when = 0; + public: EntryMsgImpl(Serialize::TypeBase *type) : EntryMsg(type) { } EntryMsgImpl(Serialize::TypeBase *type, Serialize::ID id) : EntryMsg(type, id) { } @@ -38,11 +44,11 @@ class EntryMsgType : public Serialize::Type<EntryMsgImpl> Serialize::Field<EntryMsgImpl, Anope::string> creator, message; Serialize::Field<EntryMsgImpl, time_t> when; - EntryMsgType(Module *me) : Serialize::Type<EntryMsgImpl>(me, "EntryMsg") - , chan(this, "chan", true) - , creator(this, "creator") - , message(this, "message") - , when(this, "when") + EntryMsgType(Module *me) : Serialize::Type<EntryMsgImpl>(me) + , chan(this, "chan", &EntryMsgImpl::channel, true) + , creator(this, "creator", &EntryMsgImpl::creator) + , message(this, "message", &EntryMsgImpl::message) + , when(this, "when", &EntryMsgImpl::when) { } }; @@ -92,7 +98,7 @@ class CommandEntryMessage : public Command private: void DoList(CommandSource &source, ChanServ::Channel *ci) { - std::vector<EntryMsg *> messages = ci->GetRefs<EntryMsg *>(entrymsg); + std::vector<EntryMsg *> messages = ci->GetRefs<EntryMsg *>(); if (messages.empty()) { @@ -126,15 +132,15 @@ class CommandEntryMessage : public Command void DoAdd(CommandSource &source, ChanServ::Channel *ci, const Anope::string &message) { - std::vector<EntryMsg *> messages = ci->GetRefs<EntryMsg *>(entrymsg); + std::vector<EntryMsg *> messages = ci->GetRefs<EntryMsg *>(); - if (messages.size() >= Config->GetModule(this->owner)->Get<unsigned>("maxentries")) + if (messages.size() >= Config->GetModule(this->GetOwner())->Get<unsigned>("maxentries")) { source.Reply(_("The entry message list for \002{0}\002 is full."), ci->GetName()); return; } - EntryMsg *msg = entrymsg.Create(); + EntryMsg *msg = Serialize::New<EntryMsg *>(); msg->SetChannel(ci); msg->SetCreator(source.GetNick()); msg->SetMessage(message); @@ -144,7 +150,7 @@ class CommandEntryMessage : public Command void DoDel(CommandSource &source, ChanServ::Channel *ci, const Anope::string &message) { - std::vector<EntryMsg *> messages = ci->GetRefs<EntryMsg *>(entrymsg); + std::vector<EntryMsg *> messages = ci->GetRefs<EntryMsg *>(); if (!message.is_pos_number_only()) source.Reply(("Entry message \002{0}\002 not found on channel \002{1}\002."), message, ci->GetName()); @@ -173,7 +179,7 @@ class CommandEntryMessage : public Command void DoClear(CommandSource &source, ChanServ::Channel *ci) { - for (EntryMsg *e : ci->GetRefs<EntryMsg *>(entrymsg)) + for (EntryMsg *e : ci->GetRefs<EntryMsg *>()) delete e; Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to remove all messages"; @@ -254,6 +260,7 @@ class CSEntryMessage : public Module public: CSEntryMessage(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::JoinChannel>(this) , commandentrymsg(this) , entrymsg_type(this) { @@ -262,7 +269,7 @@ class CSEntryMessage : public Module void OnJoinChannel(User *u, Channel *c) override { if (u && c && c->ci && u->server->IsSynced()) - for (EntryMsg *msg : c->ci->GetRefs<EntryMsg *>(entrymsg)) + for (EntryMsg *msg : c->ci->GetRefs<EntryMsg *>()) u->SendMessage(c->ci->WhoSends(), "[{0}] {1}", c->ci->GetName(), msg->GetMessage()); } }; diff --git a/modules/chanserv/cs_flags.old b/modules/chanserv/flags.cpp index 8bca8581f..cb6f68522 100644 --- a/modules/chanserv/cs_flags.old +++ b/modules/chanserv/flags.cpp @@ -5,25 +5,29 @@ * * Please read COPYING and README for further details. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. */ +/* Dependencies: anope_chanserv.main */ + #include "module.h" -#include "modules/cs_access.h" -#include "main/chanaccess.h" +#include "modules/chanserv.h" +#include "modules/chanserv/access.h" +#include "modules/chanserv/main/chanaccess.h" #include "main/chanaccesstype.h" static std::map<Anope::string, char> defaultFlags; -class FlagsChanAccess : public ChanAccessImpl +class FlagsChanAccessImpl : public FlagsChanAccess { + friend class FlagsChanAccessType; + + Anope::string flags; + public: - FlagsChanAccess(Serialize::TypeBase *type) : ChanAccessImpl(type) { } - FlagsChanAccess(Serialize::TypeBase *type, Serialize::ID id) : ChanAccessImpl(type, id) { } + using FlagsChanAccess::FlagsChanAccess; - Anope::string GetFlags(); - void SetFlags(const Anope::string &); + const Anope::string &GetFlags() override; + void SetFlags(const Anope::string &) override; bool HasPriv(const Anope::string &priv) override { @@ -43,7 +47,7 @@ class FlagsChanAccess : public ChanAccessImpl static Anope::string DetermineFlags(ChanServ::ChanAccess *access) { - if (access->GetSerializableType()->GetName() != "FlagsChanAccess") + if (access->GetSerializableType()->GetName() != NAME) return access->AccessSerialize(); std::set<char> buffer; @@ -59,20 +63,19 @@ class FlagsChanAccess : public ChanAccessImpl } }; -class FlagsChanAccessType : public Serialize::Type<FlagsChanAccess, ChanAccessType> +class FlagsChanAccessType : public ChanAccessType<FlagsChanAccessImpl> { public: - Serialize::Field<FlagsChanAccess, Anope::string> flags; - //Serialize::Field<FlagsChanAccess, std::set<char>>> flags; XXX? + Serialize::Field<FlagsChanAccessImpl, Anope::string> flags; - FlagsChanAccessType(Module *me) : Serialize::Type<FlagsChanAccess, ChanAccessType>(me, "FlagsChanAccess") - , flags(this, "flags") + FlagsChanAccessType(Module *me) : ChanAccessType<FlagsChanAccessImpl>(me) + , flags(this, "flags", &FlagsChanAccessImpl::flags) { - SetParent(ChanServ::chanaccess); + Serialize::SetParent(FlagsChanAccess::NAME, ChanServ::ChanAccess::NAME); } }; -Anope::string FlagsChanAccess::GetFlags() +const Anope::string &FlagsChanAccess::GetFlags() { return Get(&FlagsChanAccessType::flags); } @@ -169,7 +172,7 @@ class CommandCSFlags : public Command } current = access; - Anope::string cur_flags = FlagsChanAccess::DetermineFlags(access); + Anope::string cur_flags = FlagsChanAccessImpl::DetermineFlags(access); for (unsigned j = cur_flags.length(); j > 0; --j) current_flags.insert(cur_flags[j - 1]); break; @@ -177,7 +180,7 @@ class CommandCSFlags : public Command } unsigned access_max = Config->GetModule("chanserv")->Get<unsigned>("accessmax", "1024"); - if (access_max && ci->GetDeepAccessCount() >= access_max) + if (access_max && ci->GetAccessCount() >= access_max) { source.Reply(_("Sorry, you can only have \002{0}\002 access entries on a channel, including access entries from other channels."), access_max); return; @@ -252,7 +255,7 @@ class CommandCSFlags : public Command { if (current != NULL) { - Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, current); + EventManager::Get()->Dispatch(&Event::AccessDel::OnAccessDel, ci, source, current); delete current; Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << mask; source.Reply(_("\002{0}\002 removed from the access list of \002{1}\002."), mask, ci->GetName()); @@ -264,7 +267,7 @@ class CommandCSFlags : public Command return; } - FlagsChanAccess *access = anope_dynamic_static_cast<FlagsChanAccess *>(flagschanaccess.Create()); + FlagsChanAccess *access = Serialize::New<FlagsChanAccess *>(); if (na) access->SetObj(na->GetAccount()); else if (targ_ci) @@ -279,7 +282,7 @@ class CommandCSFlags : public Command if (current != NULL) delete current; - Event::OnAccessAdd(&Event::AccessAdd::OnAccessAdd, ci, source, access); + EventManager::Get()->Dispatch(&Event::AccessAdd::OnAccessAdd, ci, source, access); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to modify " << mask << "'s flags to " << access->AccessSerialize(); if (p != NULL) @@ -311,7 +314,7 @@ class CommandCSFlags : public Command for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i) { ChanServ::ChanAccess *access = ci->GetAccess(i); - const Anope::string &flags = FlagsChanAccess::DetermineFlags(access); + const Anope::string &flags = FlagsChanAccessImpl::DetermineFlags(access); if (!arg.empty()) { @@ -365,7 +368,7 @@ class CommandCSFlags : public Command ci->ClearAccess(); - Event::OnAccessClear(&Event::AccessClear::OnAccessClear, ci, source); + EventManager::Get()->Dispatch(&Event::AccessClear::OnAccessClear, ci, source); source.Reply(_("The access list of \002{0}\002 has been cleared."), ci->GetName()); diff --git a/modules/chanserv/info.cpp b/modules/chanserv/info.cpp index 4f3895cc4..c48368598 100644 --- a/modules/chanserv/info.cpp +++ b/modules/chanserv/info.cpp @@ -14,10 +14,8 @@ class CommandCSInfo : public Command { - EventHandlers<Event::ChanInfo> &eventonchaninfo; - public: - CommandCSInfo(Module *creator, EventHandlers<Event::ChanInfo> &event) : Command(creator, "chanserv/info", 1, 2), eventonchaninfo(event) + CommandCSInfo(Module *creator) : Command(creator, "chanserv/info", 1, 2) { this->SetDesc(_("Lists information about the specified registered channel")); this->SetSyntax(_("\037channel\037")); @@ -63,7 +61,7 @@ class CommandCSInfo : public Command info[_("Ban type")] = stringify(ci->GetBanType()); } - this->eventonchaninfo(&Event::ChanInfo::OnChanInfo, source, ci, info, show_all); + EventManager::Get()->Dispatch(&Event::ChanInfo::OnChanInfo, source, ci, info, show_all); std::vector<Anope::string> replies; info.Process(replies); @@ -83,12 +81,10 @@ class CommandCSInfo : public Command class CSInfo : public Module { CommandCSInfo commandcsinfo; - EventHandlers<Event::ChanInfo> eventonchaninfo; public: CSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandcsinfo(this, eventonchaninfo) - , eventonchaninfo(this) + , commandcsinfo(this) { } diff --git a/modules/chanserv/list.cpp b/modules/chanserv/list.cpp index ad0460239..28ce5f7e6 100644 --- a/modules/chanserv/list.cpp +++ b/modules/chanserv/list.cpp @@ -16,6 +16,8 @@ class CommandCSList : public Command { + ServiceReference<ModeLocks> mlocks; + public: CommandCSList(Module *creator) : Command(creator, "chanserv/list", 1, 2) { @@ -68,7 +70,7 @@ class CommandCSList : public Command } Anope::string spattern = "#" + pattern; - unsigned listmax = Config->GetModule(this->owner)->Get<unsigned>("listmax", "50"); + unsigned listmax = Config->GetModule(this->GetOwner())->Get<unsigned>("listmax", "50"); source.Reply(_("List of entries matching \002{0}\002:"), pattern); @@ -194,7 +196,7 @@ class CommandCSSetPrivate : public Command return; } - EventReturn MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); + EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -240,10 +242,11 @@ class CSList : public Module CommandCSList commandcslist; CommandCSSetPrivate commandcssetprivate; - ExtensibleItem<bool> priv; // XXX + Serialize::Field<ChanServ::Channel, bool> priv; public: CSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ChanInfo>(this) , commandcslist(this) , commandcssetprivate(this) , priv(this, "CS_PRIVATE") diff --git a/modules/chanserv/log.cpp b/modules/chanserv/log.cpp index 43ed76291..b31d515f7 100644 --- a/modules/chanserv/log.cpp +++ b/modules/chanserv/log.cpp @@ -15,6 +15,12 @@ class LogSettingImpl : public LogSetting { + friend class LogSettingType; + + ChanServ::Channel *channel = nullptr; + Anope::string service_name, command_service, command_name, method, extra, creator; + time_t created = 0; + public: LogSettingImpl(Serialize::TypeBase *type) : LogSetting(type) { } LogSettingImpl(Serialize::TypeBase *type, Serialize::ID id) : LogSetting(type, id) { } @@ -51,15 +57,15 @@ class LogSettingType : public Serialize::Type<LogSettingImpl> Serialize::Field<LogSettingImpl, Anope::string> service_name, command_service, command_name, method, extra, creator; Serialize::Field<LogSettingImpl, time_t> created; - LogSettingType(Module *me) : Serialize::Type<LogSettingImpl>(me, "LogSetting") - , ci(this, "ci", true) - , service_name(this, "service_name") - , command_service(this, "command_service") - , command_name(this, "command_name") - , method(this, "method") - , extra(this, "extra") - , creator(this, "creator") - , created(this, "created") + LogSettingType(Module *me) : Serialize::Type<LogSettingImpl>(me) + , ci(this, "ci", &LogSettingImpl::channel, true) + , service_name(this, "service_name", &LogSettingImpl::service_name) + , command_service(this, "command_service", &LogSettingImpl::command_service) + , command_name(this, "command_name", &LogSettingImpl::command_name) + , method(this, "method", &LogSettingImpl::method) + , extra(this, "extra", &LogSettingImpl::extra) + , creator(this, "creator", &LogSettingImpl::creator) + , created(this, "created", &LogSettingImpl::created) { } }; @@ -173,7 +179,7 @@ public: if (params.size() == 1) { - std::vector<LogSetting *> ls = ci->GetRefs<LogSetting *>(logsetting); + std::vector<LogSetting *> ls = ci->GetRefs<LogSetting *>(); if (ls.empty()) { source.Reply(_("There currently are no logging configurations for \002{0}\002."), ci->GetName()); @@ -235,7 +241,7 @@ public: /* Get service name from command */ service_name = bi->commands[command_name].name; } - else if (ServiceReference<Command>("Command", command.lower())) + else if (ServiceReference<Command>(command.lower())) { /* This is the service name, don't use any specific command */ service_name = command; @@ -263,7 +269,7 @@ public: bool override = !source.AccessFor(ci).HasPriv("SET"); - std::vector<LogSetting *> ls = ci->GetRefs<LogSetting *>(logsetting); + std::vector<LogSetting *> ls = ci->GetRefs<LogSetting *>(); for (unsigned i = ls.size(); i > 0; --i) { LogSetting *log = ls[i - 1]; @@ -286,7 +292,7 @@ public: } } - LogSetting *log = logsetting.Create(); + LogSetting *log = Serialize::New<LogSetting *>(); log->SetChannel(ci); log->SetServiceName(service_name); if (bi) @@ -335,6 +341,7 @@ class CSLog : public Module { CommandCSLog commandcslog; LogSettingType logtype; + ServiceReference<MemoServ::MemoServService> memoserv; struct LogDefault { @@ -345,6 +352,8 @@ class CSLog : public Module public: CSLog(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ChanRegistered>(this) + , EventHook<Event::Log>(this) , commandcslog(this) , logtype(this) { @@ -379,7 +388,7 @@ class CSLog : public Module { LogDefault &d = defaults[i]; - LogSetting *log = logsetting.Create(); + LogSetting *log = Serialize::New<LogSetting *>(); log->SetChannel(ci); if (!d.service.empty()) @@ -408,13 +417,13 @@ class CSLog : public Module if (l->type != LOG_COMMAND || l->u == NULL || l->c == NULL || l->ci == NULL || !Me || !Me->IsSynced()) return; - std::vector<LogSetting *> ls = l->ci->GetRefs<LogSetting *>(logsetting); + std::vector<LogSetting *> ls = l->ci->GetRefs<LogSetting *>(); for (unsigned i = 0; i < ls.size(); ++i) { LogSetting *log = ls[i]; /* wrong command */ - if (log->GetServiceName() != l->c->name) + if (log->GetServiceName() != l->c->GetName()) continue; /* if a command name is given check the service and the command */ @@ -430,14 +439,15 @@ class CSLog : public Module Anope::string buffer = l->u->nick + " used " + l->source->command.upper() + " " + l->buf.str(); - if (log->GetMethod().equals_ci("MEMO") && MemoServ::service && l->ci->WhoSends() != NULL) - MemoServ::service->Send(l->ci->WhoSends()->nick, l->ci->GetName(), buffer, true); + if (log->GetMethod().equals_ci("MEMO") && memoserv && l->ci->WhoSends() != NULL) + memoserv->Send(l->ci->WhoSends()->nick, l->ci->GetName(), buffer, true); else if (l->source->c) /* Sending a channel message or notice in response to a fantasy command */; else if (log->GetMethod().equals_ci("MESSAGE") && l->ci->c) { IRCD->SendPrivmsg(l->ci->WhoSends(), log->GetExtra() + l->ci->c->name, "%s", buffer.c_str()); - //l->ci->WhoSends()->lastmsg = Anope::CurTime; XXX +#warning "fix idletimes" + //l->ci->WhoSends()->lastmsg = Anope::CurTime; } else if (log->GetMethod().equals_ci("NOTICE") && l->ci->c) IRCD->SendNotice(l->ci->WhoSends(), log->GetExtra() + l->ci->c->name, "%s", buffer.c_str()); diff --git a/modules/chanserv/main/chanaccess.cpp b/modules/chanserv/main/chanaccess.cpp index 1601260c2..4d70fb30b 100644 --- a/modules/chanserv/main/chanaccess.cpp +++ b/modules/chanserv/main/chanaccess.cpp @@ -1,65 +1,65 @@ #include "module.h" -#include "chanaccess.h" +#include "modules/chanserv/main/chanaccess.h" #include "chanaccesstype.h" ChanServ::Channel *ChanAccessImpl::GetChannel() { - return Get(&ChanAccessType::ci); + return Get(&ChanAccessType<ChanServ::ChanAccess>::ci); } void ChanAccessImpl::SetChannel(ChanServ::Channel *ci) { - Object::Set(&ChanAccessType::ci, ci); + Object::Set(&ChanAccessType<ChanServ::ChanAccess>::ci, ci); } Anope::string ChanAccessImpl::GetCreator() { - return Get(&ChanAccessType::creator); + return Get(&ChanAccessType<ChanServ::ChanAccess>::creator); } void ChanAccessImpl::SetCreator(const Anope::string &c) { - Object::Set(&ChanAccessType::creator, c); + Object::Set(&ChanAccessType<ChanServ::ChanAccess>::creator, c); } time_t ChanAccessImpl::GetLastSeen() { - return Get(&ChanAccessType::last_seen); + return Get(&ChanAccessType<ChanServ::ChanAccess>::last_seen); } void ChanAccessImpl::SetLastSeen(const time_t &t) { - Object::Set(&ChanAccessType::last_seen, t); + Object::Set(&ChanAccessType<ChanServ::ChanAccess>::last_seen, t); } time_t ChanAccessImpl::GetCreated() { - return Get(&ChanAccessType::created); + return Get(&ChanAccessType<ChanServ::ChanAccess>::created); } void ChanAccessImpl::SetCreated(const time_t &t) { - Object::Set(&ChanAccessType::created, t); + Object::Set(&ChanAccessType<ChanServ::ChanAccess>::created, t); } Anope::string ChanAccessImpl::GetMask() { - return Get(&ChanAccessType::mask); + return Get(&ChanAccessType<ChanServ::ChanAccess>::mask); } void ChanAccessImpl::SetMask(const Anope::string &n) { - Object::Set(&ChanAccessType::mask, n); + Object::Set(&ChanAccessType<ChanServ::ChanAccess>::mask, n); } Serialize::Object *ChanAccessImpl::GetObj() { - return Get(&ChanAccessType::obj); + return Get(&ChanAccessType<ChanServ::ChanAccess>::obj); } void ChanAccessImpl::SetObj(Serialize::Object *o) { - Object::Set(&ChanAccessType::obj, o); + Object::Set(&ChanAccessType<ChanServ::ChanAccess>::obj, o); } Anope::string ChanAccessImpl::Mask() @@ -72,13 +72,13 @@ Anope::string ChanAccessImpl::Mask() NickServ::Account *ChanAccessImpl::GetAccount() { - if (!GetObj() || GetObj()->GetSerializableType() != NickServ::account) + if (!GetObj() || GetObj()->GetSerializableType()->GetName() != NickServ::Account::NAME) return nullptr; return anope_dynamic_static_cast<NickServ::Account *>(GetObj()); } -bool ChanAccessImpl::Matches(const User *u, NickServ::Account *acc, Path &p) +bool ChanAccessImpl::Matches(const User *u, NickServ::Account *acc) { if (this->GetAccount()) return this->GetAccount() == acc; @@ -93,35 +93,9 @@ bool ChanAccessImpl::Matches(const User *u, NickServ::Account *acc, Path &p) } if (acc) - for (NickServ::Nick *na : acc->GetRefs<NickServ::Nick *>(NickServ::nick)) + for (NickServ::Nick *na : acc->GetRefs<NickServ::Nick *>()) if (Anope::Match(na->GetNick(), this->Mask())) return true; - if (IRCD->IsChannelValid(this->Mask())) - { - ChanServ::Channel *tci = ChanServ::Find(this->Mask()); - if (tci) - { - for (unsigned i = 0; i < tci->GetAccessCount(); ++i) - { - ChanServ::ChanAccess *a = tci->GetAccess(i); - std::pair<ChanServ::ChanAccess *, ChanServ::ChanAccess *> pair = std::make_pair(this, a); - - std::pair<Set::iterator, Set::iterator> range = p.first.equal_range(this); - for (; range.first != range.second; ++range.first) - if (range.first->first == pair.first && range.first->second == pair.second) - goto cont; - - p.first.insert(pair); - if (a->Matches(u, acc, p)) - p.second.insert(pair); - - cont:; - } - - return p.second.count(this) > 0; - } - } - return false; } diff --git a/modules/chanserv/main/chanaccess.h b/modules/chanserv/main/chanaccess.h deleted file mode 100644 index bb65f79c5..000000000 --- a/modules/chanserv/main/chanaccess.h +++ /dev/null @@ -1,30 +0,0 @@ - -class ChanAccessImpl : public ChanServ::ChanAccess -{ - public: - ChanAccessImpl(Serialize::TypeBase *type) : ChanServ::ChanAccess(type) { } - ChanAccessImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::ChanAccess(type, id) { } - - ChanServ::Channel *GetChannel() override; - void SetChannel(ChanServ::Channel *ci) override; - - Anope::string GetCreator() override; - void SetCreator(const Anope::string &c) override; - - time_t GetLastSeen() override; - void SetLastSeen(const time_t &t) override; - - time_t GetCreated() override; - void SetCreated(const time_t &t) override; - - Anope::string GetMask() override; - void SetMask(const Anope::string &) override; - - Serialize::Object *GetObj() override; - void SetObj(Serialize::Object *) override; - - Anope::string Mask() override; - NickServ::Account *GetAccount() override; - - bool Matches(const User *u, NickServ::Account *acc, Path &p) override; -}; diff --git a/modules/chanserv/main/chanaccesstype.h b/modules/chanserv/main/chanaccesstype.h index ca8dc1b79..f679669f1 100644 --- a/modules/chanserv/main/chanaccesstype.h +++ b/modules/chanserv/main/chanaccesstype.h @@ -1,6 +1,9 @@ -class ChanAccessType : public Serialize::AbstractType +template<typename T> +class ChanAccessType : public Serialize::Type<T> { + static_assert(std::is_base_of<ChanServ::ChanAccess, T>::value, ""); + public: Serialize::ObjectField<ChanServ::ChanAccess, ChanServ::Channel *> ci; Serialize::Field<ChanServ::ChanAccess, Anope::string> mask; @@ -9,13 +12,13 @@ class ChanAccessType : public Serialize::AbstractType Serialize::Field<ChanServ::ChanAccess, time_t> last_seen; Serialize::Field<ChanServ::ChanAccess, time_t> created; - ChanAccessType(Module *me, const Anope::string &name) : Serialize::AbstractType(me, name) - , ci(this, "ci", true) - , mask(this, "mask") - , obj(this, "obj", true) - , creator(this, "creator") - , last_seen(this, "last_seen") - , created(this, "created") + ChanAccessType(Module *me) : Serialize::Type<T>(me) + , ci(this, "ci", &ChanServ::ChanAccess::channel, true) + , mask(this, "mask", &ChanServ::ChanAccess::mask) + , obj(this, "obj", &ChanServ::ChanAccess::object, true) + , creator(this, "creator", &ChanServ::ChanAccess::creator) + , last_seen(this, "last_seen", &ChanServ::ChanAccess::last_seen) + , created(this, "created", &ChanServ::ChanAccess::created) { } }; diff --git a/modules/chanserv/main/channel.cpp b/modules/chanserv/main/channel.cpp index 7190b8bd9..490a0306f 100644 --- a/modules/chanserv/main/channel.cpp +++ b/modules/chanserv/main/channel.cpp @@ -14,13 +14,6 @@ #include "channeltype.h" #include "modules/chanserv/akick.h" -ChannelImpl::ChannelImpl(Serialize::TypeBase *type, const Anope::string &chname) : ChanServ::Channel(type) -{ - SetName(chname); - SetTimeRegistered(Anope::CurTime); - SetLastUsed(Anope::CurTime); -} - ChannelImpl::~ChannelImpl() { ChanServ::registered_channel_map& map = ChanServ::service->GetChannels(); @@ -29,7 +22,7 @@ ChannelImpl::~ChannelImpl() void ChannelImpl::Delete() { - Event::OnDelChan(&Event::DelChan::OnDelChan, this); + EventManager::Get()->Dispatch(&Event::DelChan::OnDelChan, this); Log(LOG_DEBUG) << "Deleting channel " << this->GetName(); @@ -165,7 +158,7 @@ void ChannelImpl::SetBot(ServiceBot *bi) MemoServ::MemoInfo *ChannelImpl::GetMemos() { - return GetRef<MemoServ::MemoInfo *>(MemoServ::memoinfo); + return GetRef<MemoServ::MemoInfo *>(); } void ChannelImpl::SetFounder(NickServ::Account *nc) @@ -190,7 +183,7 @@ NickServ::Account *ChannelImpl::GetSuccessor() ChanServ::ChanAccess *ChannelImpl::GetAccess(unsigned index) { - std::vector<ChanServ::ChanAccess *> a = GetRefs<ChanServ::ChanAccess *>(ChanServ::chanaccess); + std::vector<ChanServ::ChanAccess *> a = GetRefs<ChanServ::ChanAccess *>(); return a.size() > index ? a[index] : nullptr; } @@ -217,7 +210,7 @@ ChanServ::AccessGroup ChannelImpl::AccessFor(const User *u, bool updateLastUsed) for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i) { ChanServ::ChanAccess *a = this->GetAccess(i); - if (a->Matches(u, u->Account(), group.path)) + if (a->Matches(u, u->Account())) group.push_back(a); } @@ -244,7 +237,7 @@ ChanServ::AccessGroup ChannelImpl::AccessFor(NickServ::Account *nc, bool updateL for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i) { ChanServ::ChanAccess *a = this->GetAccess(i); - if (a->Matches(NULL, nc, group.path)) + if (a->Matches(NULL, nc)) group.push_back(a); } @@ -259,45 +252,18 @@ ChanServ::AccessGroup ChannelImpl::AccessFor(NickServ::Account *nc, bool updateL unsigned ChannelImpl::GetAccessCount() { - return GetRefs<ChanServ::ChanAccess *>(ChanServ::chanaccess).size(); -} - -unsigned ChannelImpl::GetDeepAccessCount() const -{ - return 0; -#if 0 - ChanServ::ChanAccess::Path path; - for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i) - { - ChanServ::ChanAccess *a = this->GetAccess(i); - a->Matches(NULL, NULL, path); - } - - unsigned count = this->GetAccessCount(); - std::set<const ChanServ::Channel *> channels; - channels.insert(this); - for (ChanServ::ChanAccess::Set::iterator it = path.first.begin(); it != path.first.end(); ++it) - { - const ChanServ::Channel *ci = it->first->GetChannel(); - if (!channels.count(ci)) - { - channels.count(ci); - count += ci->GetAccessCount(); - } - } - return count; -#endif + return GetRefs<ChanServ::ChanAccess *>().size(); } void ChannelImpl::ClearAccess() { - for (ChanServ::ChanAccess *a : GetRefs<ChanServ::ChanAccess *>(ChanServ::chanaccess)) + for (ChanServ::ChanAccess *a : GetRefs<ChanServ::ChanAccess *>()) a->Delete(); } AutoKick *ChannelImpl::AddAkick(const Anope::string &user, NickServ::Account *akicknc, const Anope::string &reason, time_t t, time_t lu) { - AutoKick *ak = ::autokick.Create(); + AutoKick *ak = Serialize::New<AutoKick *>(); ak->SetChannel(this); ak->SetAccount(akicknc); ak->SetReason(reason); @@ -310,7 +276,7 @@ AutoKick *ChannelImpl::AddAkick(const Anope::string &user, NickServ::Account *ak AutoKick *ChannelImpl::AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t, time_t lu) { - AutoKick *ak = ::autokick.Create(); + AutoKick *ak = Serialize::New<AutoKick *>(); ak->SetChannel(this); ak->SetMask(mask); ak->SetReason(reason); @@ -323,25 +289,25 @@ AutoKick *ChannelImpl::AddAkick(const Anope::string &user, const Anope::string & AutoKick *ChannelImpl::GetAkick(unsigned index) { - std::vector<AutoKick *> a = GetRefs<AutoKick *>(autokick); + std::vector<AutoKick *> a = GetRefs<AutoKick *>(); return a.size() > index ? a[index] : nullptr; } unsigned ChannelImpl::GetAkickCount() { - std::vector<AutoKick *> t = GetRefs<AutoKick *>(autokick); + std::vector<AutoKick *> t = GetRefs<AutoKick *>(); return t.size(); } void ChannelImpl::ClearAkick() { - for (AutoKick *ak : GetRefs<AutoKick *>(autokick)) + for (AutoKick *ak : GetRefs<AutoKick *>()) ak->Delete(); } int16_t ChannelImpl::GetLevel(const Anope::string &priv) { - for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>(ChanServ::level)) + for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>()) if (l->GetName() == priv) return l->GetLevel(); @@ -357,7 +323,7 @@ int16_t ChannelImpl::GetLevel(const Anope::string &priv) void ChannelImpl::SetLevel(const Anope::string &priv, int16_t level) { - for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>(ChanServ::level)) + for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>()) if (l->GetName() == priv) { l->SetLevel(level); @@ -371,7 +337,7 @@ void ChannelImpl::SetLevel(const Anope::string &priv, int16_t level) return; } - ChanServ::Level *l = ChanServ::level.Create(); + ChanServ::Level *l = Serialize::New<ChanServ::Level *>(); l->SetChannel(this); l->SetName(priv); l->SetLevel(level); @@ -379,7 +345,7 @@ void ChannelImpl::SetLevel(const Anope::string &priv, int16_t level) void ChannelImpl::RemoveLevel(const Anope::string &priv) { - for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>(ChanServ::level)) + for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>()) if (l->GetName() == priv) { l->Delete(); @@ -389,7 +355,7 @@ void ChannelImpl::RemoveLevel(const Anope::string &priv) void ChannelImpl::ClearLevels() { - for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>(ChanServ::level)) + for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>()) l->Delete(); } diff --git a/modules/chanserv/main/channel.h b/modules/chanserv/main/channel.h index 86e42a8f9..801891821 100644 --- a/modules/chanserv/main/channel.h +++ b/modules/chanserv/main/channel.h @@ -2,10 +2,20 @@ class ChannelImpl : public ChanServ::Channel { + friend class ChannelType; + + NickServ::Account *founder = nullptr, *successor = nullptr; + Anope::string name, desc; + time_t time_registered = 0, last_used = 0; + Anope::string last_topic, last_topic_setter; + time_t last_topic_time = 0; + int16_t bantype = 0; + time_t banexpire = 0; + BotInfo *bi = nullptr; + public: ChannelImpl(Serialize::TypeBase *type) : ChanServ::Channel(type) { } ChannelImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::Channel(type, id) { } - ChannelImpl(Serialize::TypeBase *type, const Anope::string &chname); ~ChannelImpl(); void Delete() override; @@ -44,16 +54,17 @@ class ChannelImpl : public ChanServ::Channel MemoServ::MemoInfo *GetMemos() override; - bool IsFounder(const User *user) override; void SetFounder(NickServ::Account *nc) override; NickServ::Account *GetFounder() override; + void SetSuccessor(NickServ::Account *nc) override; NickServ::Account *GetSuccessor() override; + + bool IsFounder(const User *user) override; ChanServ::ChanAccess *GetAccess(unsigned index) /*const*/ override; ChanServ::AccessGroup AccessFor(const User *u, bool = true) override; ChanServ::AccessGroup AccessFor(NickServ::Account *nc, bool = true) override; unsigned GetAccessCount()/* const*/ override; - unsigned GetDeepAccessCount() const override; void ClearAccess() override; AutoKick* AddAkick(const Anope::string &user, NickServ::Account *akicknc, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0) override; AutoKick* AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0) override; diff --git a/modules/chanserv/main/channeltype.cpp b/modules/chanserv/main/channeltype.cpp index 4143285a8..0c65b1bb1 100644 --- a/modules/chanserv/main/channeltype.cpp +++ b/modules/chanserv/main/channeltype.cpp @@ -1,29 +1,29 @@ #include "module.h" #include "channeltype.h" -ChannelType::ChannelType(Module *me) : Serialize::Type<ChannelImpl>(me, "ChannelInfo") - , name(this, "name") - , desc(this, "desc") - , time_registered(this, "time_registered") - , last_used(this, "last_used") - , last_topic(this, "last_topic") - , last_topic_setter(this, "last_topic_setter") - , last_topic_time(this, "last_topic_time") - , bantype(this, "bantype") - , banexpire(this, "banexpire") - , founder(this, "founder") - , successor(this, "successor") - , bi(this, "bi") +ChannelType::ChannelType(Module *me) : Serialize::Type<ChannelImpl>(me) + , name(this, "name", &ChannelImpl::name) + , desc(this, "desc", &ChannelImpl::desc) + , time_registered(this, "time_registered", &ChannelImpl::time_registered) + , last_used(this, "last_used", &ChannelImpl::last_used) + , last_topic(this, "last_topic", &ChannelImpl::last_topic) + , last_topic_setter(this, "last_topic_setter", &ChannelImpl::last_topic_setter) + , last_topic_time(this, "last_topic_time", &ChannelImpl::last_topic_time) + , bantype(this, "bantype", &ChannelImpl::bantype) + , banexpire(this, "banexpire", &ChannelImpl::banexpire) + , founder(this, "founder", &ChannelImpl::founder) + , successor(this, "successor", &ChannelImpl::successor) + , bi(this, "bi", &ChannelImpl::bi) { } -void ChannelType::Name::SetField(ChanServ::Channel *c, const Anope::string &value) +void ChannelType::Name::SetField(ChannelImpl *c, const Anope::string &value) { ChanServ::registered_channel_map& map = ChanServ::service->GetChannels(); map.erase(GetField(c)); - Serialize::Field<ChanServ::Channel, Anope::string>::SetField(c, value); + Serialize::Field<ChannelImpl, Anope::string>::SetField(c, value); map[value] = c; } @@ -31,7 +31,7 @@ void ChannelType::Name::SetField(ChanServ::Channel *c, const Anope::string &valu ChanServ::Channel *ChannelType::FindChannel(const Anope::string &chan) { Serialize::ID id; - EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializeFind, this, &this->name, chan, id); + EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeFind, this, &this->name, chan, id); if (result == EVENT_ALLOW) return RequireID(id); diff --git a/modules/chanserv/main/channeltype.h b/modules/chanserv/main/channeltype.h index 7bc22a8f6..06d6410f8 100644 --- a/modules/chanserv/main/channeltype.h +++ b/modules/chanserv/main/channeltype.h @@ -4,29 +4,29 @@ class ChannelType : public Serialize::Type<ChannelImpl> { public: /* Channel name */ - struct Name : Serialize::Field<ChanServ::Channel, Anope::string> + struct Name : Serialize::Field<ChannelImpl, Anope::string> { - using Serialize::Field<ChanServ::Channel, Anope::string>::Field; + using Serialize::Field<ChannelImpl, Anope::string>::Field; - void SetField(ChanServ::Channel *c, const Anope::string &value) override; + void SetField(ChannelImpl *c, const Anope::string &value) override; } name; - Serialize::Field<ChanServ::Channel, Anope::string> desc; - Serialize::Field<ChanServ::Channel, time_t> time_registered; - Serialize::Field<ChanServ::Channel, time_t> last_used; + Serialize::Field<ChannelImpl, Anope::string> desc; + Serialize::Field<ChannelImpl, time_t> time_registered; + Serialize::Field<ChannelImpl, time_t> last_used; - Serialize::Field<ChanServ::Channel, Anope::string> last_topic; - Serialize::Field<ChanServ::Channel, Anope::string> last_topic_setter; - Serialize::Field<ChanServ::Channel, time_t> last_topic_time; + Serialize::Field<ChannelImpl, Anope::string> last_topic; + Serialize::Field<ChannelImpl, Anope::string> last_topic_setter; + Serialize::Field<ChannelImpl, time_t> last_topic_time; - Serialize::Field<ChanServ::Channel, int16_t> bantype; - Serialize::Field<ChanServ::Channel, time_t> banexpire; + Serialize::Field<ChannelImpl, int16_t> bantype; + Serialize::Field<ChannelImpl, time_t> banexpire; /* Channel founder */ - Serialize::ObjectField<ChanServ::Channel, NickServ::Account *> founder; + Serialize::ObjectField<ChannelImpl, NickServ::Account *> founder; /* Who gets the channel if the founder nick is dropped or expires */ - Serialize::ObjectField<ChanServ::Channel, NickServ::Account *> successor; + Serialize::ObjectField<ChannelImpl, NickServ::Account *> successor; - Serialize::ObjectField<ChanServ::Channel, BotInfo *> bi; + Serialize::ObjectField<ChannelImpl, BotInfo *> bi; ChannelType(Module *); diff --git a/modules/chanserv/main/chanserv.cpp b/modules/chanserv/main/chanserv.cpp index 9336b7c53..f579ec0ae 100644 --- a/modules/chanserv/main/chanserv.cpp +++ b/modules/chanserv/main/chanserv.cpp @@ -20,7 +20,7 @@ #include "leveltype.h" #include "modetype.h" #include "chanaccesstype.h" -#include "chanaccess.h" +#include "modules/chanserv/main/chanaccess.h" class ChanServCore : public Module , public ChanServ::ChanServService @@ -31,7 +31,6 @@ class ChanServCore : public Module , public EventHook<Event::DelChan> , public EventHook<Event::Help> , public EventHook<Event::CheckModes> - , public EventHook<Event::CreateChan> , public EventHook<Event::CanSet> , public EventHook<Event::ChannelSync> , public EventHook<Event::Log> @@ -47,30 +46,48 @@ class ChanServCore : public Module Reference<ServiceBot> ChanServ; std::vector<Anope::string> defaults; ExtensibleItem<bool> inhabit; - ExtensibleRef<bool> persist;//XXX? bool always_lower; - EventHandlers<ChanServ::Event::PreChanExpire> OnPreChanExpire; - EventHandlers<ChanServ::Event::ChanExpire> OnChanExpire; std::vector<ChanServ::Privilege> Privileges; ChanServ::registered_channel_map registered_channels; ChannelType channel_type; - ChanAccessType chanaccess_type; +// ChanAccessType chanaccess_type; LevelType level_type; CSModeType mode_type; public: ChanServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) , ChanServService(this) + , EventHook<Event::ChannelCreate>(this) + , EventHook<Event::BotDelete>(this) + , EventHook<Event::BotPrivmsg>(this) + , EventHook<Event::DelCore>(this) + , EventHook<Event::DelChan>(this) + , EventHook<Event::Help>(this) + , EventHook<Event::CheckModes>(this) + , EventHook<Event::CanSet>(this) + , EventHook<Event::ChannelSync>(this) + , EventHook<Event::Log>(this) + , EventHook<Event::ExpireTick>(this) + , EventHook<Event::CheckDelete>(this) + , EventHook<Event::PreUplinkSync>(this) + , EventHook<Event::ChanRegistered>(this) + , EventHook<Event::JoinChannel>(this) + , EventHook<Event::ChannelModeSet>(this) + , EventHook<Event::ChanInfo>(this) + , EventHook<Event::SetCorrectModes>(this) , inhabit(this, "inhabit") - , persist("PERSIST") , always_lower(false) - , OnPreChanExpire(this) - , OnChanExpire(this) , channel_type(this) - , chanaccess_type(this, "ChanAccess") +// , chanaccess_type(this) , level_type(this) , mode_type(this) { + ChanServ::service = this; + } + + ~ChanServCore() + { + ChanServ::service = nullptr; } ChanServ::Channel *Find(const Anope::string &name) override @@ -143,7 +160,7 @@ class ChanServCore : public Module if (inhabit.HasExt(c)) return; - new ChanServTimer(ChanServ, inhabit, this->owner, c); + new ChanServTimer(ChanServ, inhabit, this, c); } void AddPrivilege(ChanServ::Privilege p) override @@ -265,7 +282,7 @@ class ChanServCore : public Module void OnDelCore(NickServ::Account *nc) override { unsigned int max_reg = Config->GetModule(this)->Get<unsigned int>("maxregistered"); - for (ChanServ::Channel *ci : nc->GetRefs<ChanServ::Channel *>(ChanServ::channel)) + for (ChanServ::Channel *ci : nc->GetRefs<ChanServ::Channel *>()) { if (ci->GetFounder() == nc) { @@ -336,7 +353,7 @@ class ChanServCore : public Module { /* remove access entries that are this channel */ - for (ChanServ::Channel *c : ci->GetRefs<ChanServ::Channel *>(ChanServ::channel)) + for (ChanServ::Channel *c : ci->GetRefs<ChanServ::Channel *>()) { for (unsigned j = 0; j < c->GetAccessCount(); ++j) { @@ -412,13 +429,6 @@ class ChanServCore : public Module } } - void OnCreateChan(ChanServ::Channel *ci) override - { - /* Set default chan flags */ - for (unsigned i = 0; i < defaults.size(); ++i) - ci->SetS<bool>(defaults[i].upper(), true); - } - EventReturn OnCanSet(User *u, const ChannelMode *cm) override { if (Config->GetModule(this)->Get<Anope::string>("nomlock").find(cm->mchar) != Anope::string::npos @@ -429,7 +439,7 @@ class ChanServCore : public Module void OnChannelSync(Channel *c) override { - bool perm = c->HasMode("PERM") || (c->ci && persist && persist->HasExt(c->ci)); + bool perm = c->HasMode("PERM") || (c->ci && c->ci->HasFieldS("PERSIST")); if (!perm && !c->botchannel && (c->users.empty() || (c->users.size() == 1 && c->users.begin()->second->user->server == Me))) { this->Hold(c); @@ -466,12 +476,12 @@ class ChanServCore : public Module expire = true; } - this->OnPreChanExpire(&ChanServ::Event::PreChanExpire::OnPreChanExpire, ci, expire); + EventManager::Get()->Dispatch(&ChanServ::Event::PreChanExpire::OnPreChanExpire, ci, expire); if (expire) { ::Log(LOG_NORMAL, "chanserv/expire", ChanServ) << "Expiring channel " << ci->GetName() << " (founder: " << (ci->GetFounder() ? ci->GetFounder()->GetDisplay() : "(none)") << ")"; - this->OnChanExpire(&ChanServ::Event::ChanExpire::OnChanExpire, ci); + EventManager::Get()->Dispatch(&ChanServ::Event::ChanExpire::OnChanExpire, ci); delete ci; } } @@ -488,12 +498,10 @@ class ChanServCore : public Module void OnPreUplinkSync(Server *serv) override { - if (!persist) - return; /* Find all persistent channels and create them, as we are about to finish burst to our uplink */ for (ChanServ::Channel *ci : channel_type.List<ChanServ::Channel *>()) { - if (persist->HasExt(ci)) + if (ci->HasFieldS("PERSIST")) { bool c; ci->c = Channel::FindOrCreate(ci->GetName(), c, ci->GetTimeRegistered()); @@ -521,13 +529,17 @@ class ChanServCore : public Module void OnChanRegistered(ChanServ::Channel *ci) override { - if (!persist || !ci->c) + /* Set default chan flags */ + for (unsigned i = 0; i < defaults.size(); ++i) + ci->SetS<bool>(defaults[i].upper(), true); + + if (!ci->c) return; /* Mark the channel as persistent */ if (ci->c->HasMode("PERM")) - persist->Set(ci, true); + ci->SetS("PERSIST", true); /* Persist may be in def cflags, set it here */ - else if (persist->HasExt(ci)) + else if (ci->HasFieldS("PERSIST")) ci->c->SetMode(NULL, "PERM"); } diff --git a/modules/chanserv/main/level.h b/modules/chanserv/main/level.h index 4521fceef..6c6397270 100644 --- a/modules/chanserv/main/level.h +++ b/modules/chanserv/main/level.h @@ -1,6 +1,12 @@ class LevelImpl : public ChanServ::Level { + friend class LevelType; + + ChanServ::Channel *channel = nullptr; + Anope::string name; + int level = 0; + public: LevelImpl(Serialize::TypeBase *type) : ChanServ::Level(type) { } LevelImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::Level(type, id) { } diff --git a/modules/chanserv/main/leveltype.h b/modules/chanserv/main/leveltype.h index 12e4c132f..ad6962f42 100644 --- a/modules/chanserv/main/leveltype.h +++ b/modules/chanserv/main/leveltype.h @@ -7,10 +7,10 @@ class LevelType : public Serialize::Type<LevelImpl> Serialize::Field<LevelImpl, Anope::string> name; Serialize::Field<LevelImpl, int> level; - LevelType(Module *creator) : Serialize::Type<LevelImpl>(creator, "Level") - , channel(this, "channel", true) - , name(this, "name") - , level(this, "level") + LevelType(Module *creator) : Serialize::Type<LevelImpl>(creator) + , channel(this, "channel", &LevelImpl::channel, true) + , name(this, "name", &LevelImpl::name) + , level(this, "level", &LevelImpl::level) { } }; diff --git a/modules/chanserv/main/mode.h b/modules/chanserv/main/mode.h index cd94e5ad1..8923a18ae 100644 --- a/modules/chanserv/main/mode.h +++ b/modules/chanserv/main/mode.h @@ -1,6 +1,11 @@ class ModeImpl : public ChanServ::Mode { + friend class CSModeType; + + ChanServ::Channel *channel = nullptr; + Anope::string mode, param; + public: ModeImpl(Serialize::TypeBase *type) : ChanServ::Mode(type) { } ModeImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::Mode(type, id) { } diff --git a/modules/chanserv/main/modetype.h b/modules/chanserv/main/modetype.h index b30c0491f..b03764e32 100644 --- a/modules/chanserv/main/modetype.h +++ b/modules/chanserv/main/modetype.h @@ -6,10 +6,10 @@ class CSModeType : public Serialize::Type<ModeImpl> Serialize::ObjectField<ModeImpl, ChanServ::Channel *> channel; Serialize::Field<ModeImpl, Anope::string> mode, param; - CSModeType(Module *creator) : Serialize::Type<ModeImpl>(creator, "CSKeepMode") - , channel(this, "channel", true) - , mode(this, "mode") - , param(this, "param") + CSModeType(Module *creator) : Serialize::Type<ModeImpl>(creator) + , channel(this, "channel", &ModeImpl::channel, true) + , mode(this, "mode", &ModeImpl::mode) + , param(this, "param", &ModeImpl::param) { } }; diff --git a/modules/chanserv/mode.cpp b/modules/chanserv/mode.cpp index eb1350e5a..529f02727 100644 --- a/modules/chanserv/mode.cpp +++ b/modules/chanserv/mode.cpp @@ -13,10 +13,15 @@ #include "modules/chanserv/mode.h" #include "modules/chanserv/info.h" -static EventHandlers<Event::MLockEvents> *events; - class ModeLockImpl : public ModeLock { + friend class ModeLockType; + + ChanServ::Channel *channel = nullptr; + bool set = false; + Anope::string name, param, setter; + time_t created = 0; + public: ModeLockImpl(Serialize::TypeBase *type) : ModeLock(type) { } ModeLockImpl(Serialize::TypeBase *type, Serialize::ID id) : ModeLock(type, id) { } @@ -48,13 +53,13 @@ class ModeLockType : public Serialize::Type<ModeLockImpl> Serialize::Field<ModeLockImpl, Anope::string> name, param, setter; Serialize::Field<ModeLockImpl, time_t> created; - ModeLockType(Module *me) : Serialize::Type<ModeLockImpl>(me, "ModeLock") - , ci(this, "ci", true) - , set(this, "set") - , name(this, "name") - , param(this, "param") - , setter(this, "setter") - , created(this, "created") + ModeLockType(Module *me) : Serialize::Type<ModeLockImpl>(me) + , ci(this, "ci", &ModeLockImpl::channel, true) + , set(this, "set", &ModeLockImpl::set) + , name(this, "name", &ModeLockImpl::name) + , param(this, "param", &ModeLockImpl::param) + , setter(this, "setter", &ModeLockImpl::setter) + , created(this, "created", &ModeLockImpl::created) { } }; @@ -129,14 +134,14 @@ class ModeLocksImpl : public ModeLocks if (!mode) return false; - for (ModeLock *ml : ci->GetRefs<ModeLock *>(modelock)) + for (ModeLock *ml : ci->GetRefs<ModeLock *>()) if (ml->GetName() == mode->name && ml->GetSet() == status && ml->GetParam() == param) return true; return false; } - bool SetMLock(ChanServ::Channel *ci, ChannelMode *mode, bool status, const Anope::string ¶m, Anope::string setter, time_t created = Anope::CurTime) override + bool SetMLock(ChanServ::Channel *ci, ChannelMode *mode, bool status, const Anope::string ¶m = "", Anope::string setter = "", time_t created = Anope::CurTime) override { if (!mode) return false; @@ -146,16 +151,15 @@ class ModeLocksImpl : public ModeLocks if (setter.empty()) setter = ci->GetFounder() ? ci->GetFounder()->GetDisplay() : "Unknown"; - ModeLock *ml = modelock.Create(); + ModeLock *ml = Serialize::New<ModeLock *>(); ml->SetChannel(ci); ml->SetSet(status); - ml->SetName(name); + ml->SetName(mode->name); ml->SetParam(param); ml->SetSetter(setter); ml->SetCreated(created); - EventReturn MOD_RESULT; - MOD_RESULT = (*events)(&Event::MLockEvents::OnMLock, ci, ml); + EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::MLockEvents::OnMLock, ci, ml); if (MOD_RESULT == EVENT_STOP) { delete ml; @@ -170,7 +174,7 @@ class ModeLocksImpl : public ModeLocks if (!mode) return false; - for (ModeLock *m : ci->GetRefs<ModeLockImpl *>(modelock)) + for (ModeLock *m : ci->GetRefs<ModeLockImpl *>()) if (m->GetName() == mode->name) { // For list or status modes, we must check the parameter @@ -178,8 +182,7 @@ class ModeLocksImpl : public ModeLocks if (m->GetParam() != param) continue; - EventReturn MOD_RESULT; - MOD_RESULT = (*events)(&Event::MLockEvents::OnUnMLock, ci, m); + EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::MLockEvents::OnUnMLock, ci, m); if (MOD_RESULT == EVENT_STOP) break; @@ -192,19 +195,19 @@ class ModeLocksImpl : public ModeLocks void ClearMLock(ChanServ::Channel *ci) override { - for (ModeLock *m : ci->GetRefs<ModeLock *>(modelock)) + for (ModeLock *m : ci->GetRefs<ModeLock *>()) delete m; } ModeList GetMLock(ChanServ::Channel *ci) const override { - return ci->GetRefs<ModeLock *>(modelock); + return ci->GetRefs<ModeLock *>(); } std::list<ModeLock *> GetModeLockList(ChanServ::Channel *ci, const Anope::string &name) override { std::list<ModeLock *> mlist; - for (ModeLock *m : ci->GetRefs<ModeLock *>(modelock)) + for (ModeLock *m : ci->GetRefs<ModeLock *>()) if (m->GetName() == name) mlist.push_back(m); return mlist; @@ -212,7 +215,7 @@ class ModeLocksImpl : public ModeLocks ModeLock *GetMLock(ChanServ::Channel *ci, const Anope::string &mname, const Anope::string ¶m = "") override { - for (ModeLock *m : ci->GetRefs<ModeLock *>(modelock)) + for (ModeLock *m : ci->GetRefs<ModeLock *>()) if (m->GetName() == mname && m->GetParam() == param) return m; @@ -223,7 +226,7 @@ class ModeLocksImpl : public ModeLocks { Anope::string pos = "+", neg = "-", params; - for (ModeLock *ml : ci->GetRefs<ModeLock *>(modelock)) + for (ModeLock *ml : ci->GetRefs<ModeLock *>()) { ChannelMode *cm = ModeManager::FindChannelModeByName(ml->GetName()); @@ -250,6 +253,8 @@ class ModeLocksImpl : public ModeLocks class CommandCSMode : public Command { + ServiceReference<ModeLocks> mlocks; + bool CanSet(CommandSource &source, ChanServ::Channel *ci, ChannelMode *cm, bool self) { if (!ci || !cm || cm->type != MODE_STATUS) @@ -321,7 +326,7 @@ class CommandCSMode : public Command source.Reply(_("Missing parameter for mode \002{0}\002."), cm->mchar); else if (cm->type == MODE_LIST && ci->c && IRCD->GetMaxListFor(ci->c) && ci->c->HasMode(cm->name) >= IRCD->GetMaxListFor(ci->c)) source.Reply(_("List for mode \002{0}\002 is full."), cm->mchar); - else if (ci->GetRefs<ModeLock *>(modelock).size() >= Config->GetModule(this->owner)->Get<unsigned>("max", "32")) + else if (ci->GetRefs<ModeLock *>().size() >= Config->GetModule(this->GetOwner())->Get<unsigned>("max", "32")) source.Reply(_("The mode lock list of \002{0}\002 is full."), ci->GetName()); else { @@ -854,17 +859,16 @@ class CSMode : public Module ModeLocksImpl modelock; ModeLockType modelock_type; - EventHandlers<Event::MLockEvents> modelockevents; - public: CSMode(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::CheckModes>(this) + , EventHook<Event::ChanRegistered>(this) + , EventHook<Event::ChanInfo>(this) , commandcsmode(this) , commandcsmodes(this) , modelock(this) , modelock_type(this) - , modelockevents(this) { - events = &modelockevents; } void OnReload(Configuration::Conf *conf) override @@ -896,7 +900,7 @@ class CSMode : public Module if (!c || !c->ci) return; - ModeLocks::ModeList locks = mlocks->GetMLock(c->ci); + ModeLocks::ModeList locks = modelock.GetMLock(c->ci); for (ModeLock *ml : locks) { ChannelMode *cm = ModeManager::FindChannelModeByName(ml->GetName()); @@ -980,7 +984,7 @@ class CSMode : public Module continue; } - mlocks->SetMLock(ci, cm, add, param); + modelock.SetMLock(ci, cm, add, param); } } } @@ -990,7 +994,7 @@ class CSMode : public Module if (!show_hidden) return; - const Anope::string &m = mlocks->GetMLockAsString(ci, true); + const Anope::string &m = modelock.GetMLockAsString(ci, true); if (!m.empty()) info[_("Mode lock")] = m; } diff --git a/modules/chanserv/register.cpp b/modules/chanserv/register.cpp index eb2832074..f342ba43b 100644 --- a/modules/chanserv/register.cpp +++ b/modules/chanserv/register.cpp @@ -88,12 +88,19 @@ class CommandCSRegister : public Command return; } - if (!ChanServ::service) + ci = Serialize::New<ChanServ::Channel *>(); + if (ci == nullptr) return; - ci = ChanServ::channel.Create(); + ci->SetName(chan); ci->SetFounder(nc); ci->SetDesc(chdesc); + ci->SetTimeRegistered(Anope::CurTime); + ci->SetLastUsed(Anope::CurTime); + ci->SetBanType(2); + + ci->c = c; // XXX? this isnt set on reconstrubted objects? + c->ci = ci; if (c && !c->topic.empty()) { @@ -102,7 +109,9 @@ class CommandCSRegister : public Command ci->SetLastTopicTime(c->topic_time); } else + { ci->SetLastTopicSetter(source.service->nick); + } Log(LOG_COMMAND, source, this, ci); source.Reply(_("Channel \002{0}\002 registered under your account: \002{1}\002"), chan, nc->GetDisplay()); @@ -114,7 +123,7 @@ class CommandCSRegister : public Command if (u) c->SetCorrectModes(u, true); - Event::OnChanRegistered(&Event::ChanRegistered::OnChanRegistered, ci); + EventManager::Get()->Dispatch(&Event::ChanRegistered::OnChanRegistered, ci); } } diff --git a/modules/chanserv/seen.cpp b/modules/chanserv/seen.cpp index b97ffe238..7a5cd80c1 100644 --- a/modules/chanserv/seen.cpp +++ b/modules/chanserv/seen.cpp @@ -10,6 +10,7 @@ */ +#warning "this is disabled" #if 0 #include "module.h" diff --git a/modules/chanserv/set.cpp b/modules/chanserv/set.cpp index a56afa141..b4af25831 100644 --- a/modules/chanserv/set.cpp +++ b/modules/chanserv/set.cpp @@ -17,6 +17,8 @@ class CommandCSSet : public Command { + ServiceReference<ModeLocks> mlocks; + public: CommandCSSet(Module *creator) : Command(creator, "chanserv/set", 2, 3) { @@ -45,7 +47,7 @@ class CommandCSSet : public Command const CommandInfo &info = it->second; if (c_name.find_ci(this_name + " ") == 0) { - ServiceReference<Command> c("Command", info.name); + ServiceReference<Command> c(info.name); // XXX dup if (!c) @@ -95,7 +97,7 @@ class CommandCSSetAutoOp : public Command return; } - EventReturn MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); + EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -155,7 +157,7 @@ class CommandCSSetBanType : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -222,7 +224,7 @@ class CommandCSSetDescription : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -280,7 +282,7 @@ class CommandCSSetFounder : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -349,7 +351,7 @@ class CommandCSSetKeepModes : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -367,7 +369,7 @@ class CommandCSSetKeepModes : public Command if (ci->c) for (const std::pair<Anope::string, Anope::string> &p : ci->c->GetModes()) { - ChanServ::Mode *mode = ChanServ::mode.Create(); + ChanServ::Mode *mode = Serialize::New<ChanServ::Mode *>(); mode->SetChannel(ci); mode->SetMode(p.first); mode->SetParam(p.second); @@ -378,7 +380,7 @@ class CommandCSSetKeepModes : public Command Log(source.AccessFor(ci).HasPriv("SET") ? LOG_COMMAND : LOG_OVERRIDE, source, this, ci) << "to disable keep modes"; ci->UnsetS<bool>("CS_KEEP_MODES"); source.Reply(_("Keep modes for \002{0}\002 is now \002off\002."), ci->GetName()); - for (ChanServ::Mode *m : ci->GetRefs<ChanServ::Mode *>(ChanServ::mode)) + for (ChanServ::Mode *m : ci->GetRefs<ChanServ::Mode *>()) m->Delete(); } else @@ -420,7 +422,7 @@ class CommandCSSetPeace : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -464,6 +466,8 @@ inline static Anope::string BotModes() class CommandCSSetPersist : public Command { + ServiceReference<ModeLocks> mlocks; + public: CommandCSSetPersist(Module *creator, const Anope::string &cname = "chanserv/set/persist") : Command(creator, cname, 2, 2) { @@ -490,7 +494,7 @@ class CommandCSSetPersist : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -632,7 +636,7 @@ class CommandCSSetRestricted : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -693,7 +697,7 @@ class CommandCSSetSecure : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -755,7 +759,7 @@ class CommandCSSetSecureFounder : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -821,7 +825,7 @@ class CommandCSSetSecureOps : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -883,7 +887,7 @@ class CommandCSSetSignKick : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -956,7 +960,7 @@ class CommandCSSetSuccessor : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -1065,7 +1069,7 @@ class CommandCSSetNoexpire : public Command }; class CSSet : public Module - , public EventHook<Event::CreateChan> + , public EventHook<Event::ChanRegistered> , public EventHook<Event::ChannelSync> , public EventHook<Event::CheckKick> , public EventHook<Event::DelChan> @@ -1101,18 +1105,28 @@ class CSSet : public Module public: CSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - - , noautoop(this, ChanServ::channel, "NOAUTOOP") - , peace(this, ChanServ::channel, "PEACE") - , securefounder(this, ChanServ::channel, "SECUREFOUNDER") - , restricted(this, ChanServ::channel, "RESTRICTED") - , secure(this, ChanServ::channel, "CS_SECURE") - , secureops(this, ChanServ::channel, "SECUREOPS") - , signkick(this, ChanServ::channel, "SIGNKICK") - , signkick_level(this, ChanServ::channel, "SIGNKICK_LEVEL") - , noexpire(this, ChanServ::channel, "CS_NO_EXPIRE") - , keep_modes(this, ChanServ::channel, "CS_KEEP_MODES") - , persist(this, ChanServ::channel, "PERSIST") + , EventHook<Event::ChanRegistered>(this) + , EventHook<Event::ChannelSync>(this) + , EventHook<Event::CheckKick>(this) + , EventHook<Event::DelChan>(this) + , EventHook<Event::ChannelModeSet>(this) + , EventHook<Event::ChannelModeUnset>(this) + , EventHook<Event::JoinChannel>(this) + , EventHook<Event::SetCorrectModes>(this) + , EventHook<ChanServ::Event::PreChanExpire>(this) + , EventHook<Event::ChanInfo>(this) + + , noautoop(this, "NOAUTOOP") + , peace(this, "PEACE") + , securefounder(this, "SECUREFOUNDER") + , restricted(this, "RESTRICTED") + , secure(this, "CS_SECURE") + , secureops(this, "SECUREOPS") + , signkick(this, "SIGNKICK") + , signkick_level(this, "SIGNKICK_LEVEL") + , noexpire(this, "CS_NO_EXPIRE") + , keep_modes(this, "CS_KEEP_MODES") + , persist(this, "PERSIST") , commandcsset(this) , commandcssetautoop(this) @@ -1139,7 +1153,7 @@ class CSSet : public Module persist_lower_ts = conf->GetModule(this)->Get<bool>("persist_lower_ts"); } - void OnCreateChan(ChanServ::Channel *ci) override + void OnChanRegistered(ChanServ::Channel *ci) override { ci->SetBanType(Config->GetModule(this)->Get<int>("defbantype", "2")); } @@ -1147,7 +1161,7 @@ class CSSet : public Module void OnChannelSync(Channel *c) override { if (c->ci && keep_modes.HasExt(c->ci)) - for (ChanServ::Mode *m : c->ci->GetRefs<ChanServ::Mode *>(ChanServ::mode)) + for (ChanServ::Mode *m : c->ci->GetRefs<ChanServ::Mode *>()) c->SetMode(c->ci->WhoSends(), m->GetMode(), m->GetParam()); } @@ -1177,12 +1191,15 @@ class CSSet : public Module if (mode->name == "PERM") persist.Set(c->ci, true); - if (mode->type != MODE_STATUS && !c->syncing && Me->IsSynced() && ChanServ::mode && (!inhabit || !inhabit->HasExt(c))) + if (mode->type != MODE_STATUS && !c->syncing && Me->IsSynced() && (!inhabit || !inhabit->HasExt(c))) { - ChanServ::Mode *m = ChanServ::mode.Create(); - m->SetChannel(c->ci); - m->SetMode(mode->name); - m->SetParam(param); + ChanServ::Mode *m = Serialize::New<ChanServ::Mode *>(); + if (m != nullptr) + { + m->SetChannel(c->ci); + m->SetMode(mode->name); + m->SetParam(param); + } } } @@ -1198,7 +1215,7 @@ class CSSet : public Module } if (c->ci && mode->type != MODE_STATUS && !c->syncing && Me->IsSynced() && (!inhabit || !inhabit->HasExt(c))) - for (ChanServ::Mode *m : c->ci->GetRefs<ChanServ::Mode *>(ChanServ::mode)) + for (ChanServ::Mode *m : c->ci->GetRefs<ChanServ::Mode *>()) if (m->GetMode() == mode->name && m->GetParam().equals_ci(param)) m->Delete(); diff --git a/modules/chanserv/set_misc.cpp b/modules/chanserv/set_misc.cpp index 71087138a..af7c52650 100644 --- a/modules/chanserv/set_misc.cpp +++ b/modules/chanserv/set_misc.cpp @@ -17,6 +17,11 @@ static Anope::map<Anope::string> descriptions; class CSMiscDataImpl : public CSMiscData { + friend class CSMiscDataType; + + ChanServ::Channel *channel = nullptr; + Anope::string name, data; + public: CSMiscDataImpl(Serialize::TypeBase *type) : CSMiscData(type) { } CSMiscDataImpl(Serialize::TypeBase *type, Serialize::ID id) : CSMiscData(type, id) { } @@ -37,10 +42,10 @@ class CSMiscDataType : public Serialize::Type<CSMiscDataImpl> Serialize::ObjectField<CSMiscDataImpl, ChanServ::Channel *> owner; Serialize::Field<CSMiscDataImpl, Anope::string> name, data; - CSMiscDataType(Module *me) : Serialize::Type<CSMiscDataImpl>(me, "CSMiscData") - , owner(this, "owner", true) - , name(this, "name") - , data(this, "data") + CSMiscDataType(Module *me) : Serialize::Type<CSMiscDataImpl>(me) + , owner(this, "owner", &CSMiscDataImpl::channel, true) + , name(this, "name", &CSMiscDataImpl::name) + , data(this, "data", &CSMiscDataImpl::data) { } }; @@ -110,7 +115,7 @@ class CommandCSSetMisc : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -123,7 +128,7 @@ class CommandCSSetMisc : public Command Anope::string scommand = GetAttribute(source.command); /* remove existing */ - for (CSMiscData *data : ci->GetRefs<CSMiscData *>(csmiscdata)) + for (CSMiscData *data : ci->GetRefs<CSMiscData *>()) if (data->GetName() == scommand) { data->Delete(); @@ -132,7 +137,7 @@ class CommandCSSetMisc : public Command if (!param.empty()) { - CSMiscData *data = csmiscdata.Create(); + CSMiscData *data = Serialize::New<CSMiscData *>(); data->SetChannel(ci); data->SetName(scommand); data->SetData(param); @@ -175,6 +180,7 @@ class CSSetMisc : public Module public: CSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ChanInfo>(this) , commandcssetmisc(this) , type(this) { @@ -203,7 +209,7 @@ class CSSetMisc : public Module void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool) override { - for (CSMiscData *data : ci->GetRefs<CSMiscData *>(csmiscdata)) + for (CSMiscData *data : ci->GetRefs<CSMiscData *>()) info[data->GetName()] = data->GetData(); } }; diff --git a/modules/chanserv/statusupdate.cpp b/modules/chanserv/statusupdate.cpp index e2e37c60d..354664e3e 100644 --- a/modules/chanserv/statusupdate.cpp +++ b/modules/chanserv/statusupdate.cpp @@ -13,6 +13,8 @@ class StatusUpdate : public Module { public: StatusUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::AccessAdd>(this) + , EventHook<Event::AccessDel>(this) { } @@ -24,8 +26,7 @@ class StatusUpdate : public Module { User *user = it->second->user; - ChanServ::ChanAccess::Path p; - if (user->server != Me && access->Matches(user, user->Account(), p)) + if (user->server != Me && access->Matches(user, user->Account())) { ChanServ::AccessGroup ag = ci->AccessFor(user); @@ -48,8 +49,7 @@ class StatusUpdate : public Module { User *user = it->second->user; - ChanServ::ChanAccess::Path p; - if (user->server != Me && access->Matches(user, user->Account(), p)) + if (user->server != Me && access->Matches(user, user->Account())) { ChanServ::AccessGroup ag = ci->AccessFor(user); diff --git a/modules/chanserv/suspend.cpp b/modules/chanserv/suspend.cpp index 44259f341..dbfcafa3f 100644 --- a/modules/chanserv/suspend.cpp +++ b/modules/chanserv/suspend.cpp @@ -17,6 +17,12 @@ class CSSuspendInfoImpl : public CSSuspendInfo { + friend class CSSuspendType; + + ChanServ::Channel *channel = nullptr; + Anope::string by, reason; + time_t when = 0, expires = 0; + public: CSSuspendInfoImpl(Serialize::TypeBase *type) : CSSuspendInfo(type) { } CSSuspendInfoImpl(Serialize::TypeBase *type, Serialize::ID id) : CSSuspendInfo(type, id) { } @@ -44,12 +50,12 @@ class CSSuspendType : public Serialize::Type<CSSuspendInfoImpl> Serialize::Field<CSSuspendInfoImpl, Anope::string> by, reason; Serialize::Field<CSSuspendInfoImpl, time_t> when, expires; - CSSuspendType(Module *me) : Serialize::Type<CSSuspendInfoImpl>(me, "CSSuspendInfo") - , channel(this, "chan", true) - , by(this, "by") - , reason(this, "reason") - , when(this, "time") - , expires(this, "expires") + CSSuspendType(Module *me) : Serialize::Type<CSSuspendInfoImpl>(me) + , channel(this, "chan", &CSSuspendInfoImpl::channel, true) + , by(this, "by", &CSSuspendInfoImpl::by) + , reason(this, "reason", &CSSuspendInfoImpl::reason) + , when(this, "time", &CSSuspendInfoImpl::when) + , expires(this, "expires", &CSSuspendInfoImpl::expires) { } }; @@ -106,9 +112,8 @@ void CSSuspendInfoImpl::SetExpires(const time_t &e) class CommandCSSuspend : public Command { - EventHandlers<Event::ChanSuspend> &onchansuspend; public: - CommandCSSuspend(Module *creator, EventHandlers<Event::ChanSuspend> &event) : Command(creator, "chanserv/suspend", 2, 3), onchansuspend(event) + CommandCSSuspend(Module *creator) : Command(creator, "chanserv/suspend", 2, 3) { this->SetDesc(_("Prevent a channel from being used preserving channel data and settings")); this->SetSyntax(_("\037channel\037 [+\037expiry\037] [\037reason\037]")); @@ -119,7 +124,7 @@ class CommandCSSuspend : public Command const Anope::string &chan = params[0]; Anope::string expiry = params[1]; Anope::string reason = params.size() > 2 ? params[2] : ""; - time_t expiry_secs = Config->GetModule(this->owner)->Get<time_t>("expire"); + time_t expiry_secs = Config->GetModule(this->GetOwner())->Get<time_t>("expire"); if (!expiry.empty() && expiry[0] != '+') { @@ -147,14 +152,14 @@ class CommandCSSuspend : public Command return; } - CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>(cssuspendinfo); + CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>(); if (si) { source.Reply(_("\002{0}\002 is already suspended."), ci->GetName()); return; } - si = cssuspendinfo.Create(); + si = Serialize::New<CSSuspendInfo *>(); si->SetChannel(ci); si->SetBy(source.GetNick()); si->SetReason(reason); @@ -180,7 +185,7 @@ class CommandCSSuspend : public Command Log(LOG_ADMIN, source, this, ci) << "(" << (!reason.empty() ? reason : "No reason") << "), expires on " << (expiry_secs ? Anope::strftime(Anope::CurTime + expiry_secs) : "never"); source.Reply(_("Channel \002{0}\002 is now suspended."), ci->GetName()); - this->onchansuspend(&Event::ChanSuspend::OnChanSuspend, ci); + EventManager::Get()->Dispatch(&Event::ChanSuspend::OnChanSuspend, ci); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -194,10 +199,8 @@ class CommandCSSuspend : public Command class CommandCSUnSuspend : public Command { - EventHandlers<Event::ChanUnsuspend> &onchanunsuspend; - public: - CommandCSUnSuspend(Module *creator, EventHandlers<Event::ChanUnsuspend> &event) : Command(creator, "chanserv/unsuspend", 1, 1), onchanunsuspend(event) + CommandCSUnSuspend(Module *creator) : Command(creator, "chanserv/unsuspend", 1, 1) { this->SetDesc(_("Releases a suspended channel")); this->SetSyntax(_("\037channel\037")); @@ -217,7 +220,7 @@ class CommandCSUnSuspend : public Command return; } - CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>(cssuspendinfo); + CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>(); if (!si) { source.Reply(_("Channel \002{0}\002 isn't suspended."), ci->GetName()); @@ -230,7 +233,7 @@ class CommandCSUnSuspend : public Command source.Reply(_("Channel \002%s\002 is now released."), ci->GetName().c_str()); - this->onchanunsuspend(&Event::ChanUnsuspend::OnChanUnsuspend, ci); + EventManager::Get()->Dispatch(&Event::ChanUnsuspend::OnChanUnsuspend, ci); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -248,8 +251,6 @@ class CSSuspend : public Module { CommandCSSuspend commandcssuspend; CommandCSUnSuspend commandcsunsuspend; - EventHandlers<Event::ChanSuspend> onchansuspend; - EventHandlers<Event::ChanUnsuspend> onchanunsuspend; std::vector<Anope::string> show; CSSuspendType cst; @@ -268,17 +269,19 @@ class CSSuspend : public Module public: CSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandcssuspend(this, onchansuspend) - , commandcsunsuspend(this, onchanunsuspend) - , onchansuspend(this) - , onchanunsuspend(this) + , EventHook<Event::ChanInfo>(this) + , EventHook<ChanServ::Event::PreChanExpire>(this) + , EventHook<Event::CheckKick>(this) + , EventHook<Event::ChanDrop>(this) + , commandcssuspend(this) + , commandcsunsuspend(this) , cst(this) { } void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool show_hidden) override { - CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>(cssuspendinfo); + CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>(); if (!si) return; @@ -296,7 +299,7 @@ class CSSuspend : public Module void OnPreChanExpire(ChanServ::Channel *ci, bool &expire) override { - CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>(cssuspendinfo); + CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>(); if (!si) return; @@ -316,7 +319,7 @@ class CSSuspend : public Module EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) override { - if (u->HasMode("OPER") || !c->ci || !c->ci->GetRef<CSSuspendInfo *>(cssuspendinfo)) + if (u->HasMode("OPER") || !c->ci || !c->ci->GetRef<CSSuspendInfo *>()) return EVENT_CONTINUE; reason = Language::Translate(u, _("This channel may not be used.")); @@ -325,7 +328,7 @@ class CSSuspend : public Module EventReturn OnChanDrop(CommandSource &source, ChanServ::Channel *ci) override { - CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>(cssuspendinfo); + CSSuspendInfo *si = ci->GetRef<CSSuspendInfo *>(); if (si && !source.HasCommand("chanserv/drop")) { source.Reply(_("Channel \002{0}\002 is currently suspended."), ci->GetName()); diff --git a/modules/chanserv/topic.cpp b/modules/chanserv/topic.cpp index aab3f8dbf..6559b4d25 100644 --- a/modules/chanserv/topic.cpp +++ b/modules/chanserv/topic.cpp @@ -42,7 +42,7 @@ class CommandCSSetKeepTopic : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, param); if (MOD_RESULT == EVENT_STOP) return; @@ -90,7 +90,7 @@ class CommandCSTopic : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, "topiclock on"); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, "topiclock on"); if (MOD_RESULT == EVENT_STOP) return; @@ -107,7 +107,7 @@ class CommandCSTopic : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, "topiclock off"); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, "topiclock off"); if (MOD_RESULT == EVENT_STOP) return; @@ -211,10 +211,15 @@ class CSTopic : public Module CommandCSTopic commandcstopic; CommandCSSetKeepTopic commandcssetkeeptopic; - /*Serializable*/ExtensibleItem<bool> topiclock, keeptopic; + Serialize::Field<ChanServ::Channel, bool> topiclock, keeptopic; + + ServiceReference<ModeLocks> mlocks; public: CSTopic(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ChannelSync>(this) + , EventHook<Event::TopicUpdated>(this) + , EventHook<Event::ChanInfo>(this) , commandcstopic(this) , commandcssetkeeptopic(this) , topiclock(this, "TOPICLOCK") diff --git a/modules/chanserv/unban.cpp b/modules/chanserv/unban.cpp index 73391ac30..3cd4ba3e2 100644 --- a/modules/chanserv/unban.cpp +++ b/modules/chanserv/unban.cpp @@ -36,7 +36,7 @@ class CommandCSUnban : public Command unsigned count = 0; - for (ChanServ::Channel *ci : source.GetAccount()->GetRefs<ChanServ::Channel *>(ChanServ::channel)) + for (ChanServ::Channel *ci : source.GetAccount()->GetRefs<ChanServ::Channel *>()) { if (!ci->c || !source.AccessFor(ci).HasPriv("UNBAN")) continue; diff --git a/modules/chanserv/cs_xop.old b/modules/chanserv/xop.cpp index 8c133697a..149676e73 100644 --- a/modules/chanserv/cs_xop.old +++ b/modules/chanserv/xop.cpp @@ -5,14 +5,14 @@ * * Please read COPYING and README for further details. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. */ +/* Dependencies: anope_chanserv.main */ #include "module.h" -#include "modules/cs_access.h" -#include "main/chanaccess.h" +#include "modules/chanserv.h" +#include "modules/chanserv/access.h" +#include "modules/chanserv/main/chanaccess.h" #include "main/chanaccesstype.h" namespace @@ -21,14 +21,17 @@ namespace std::map<Anope::string, std::vector<Anope::string> > permissions; } -class XOPChanAccess : public ChanAccessImpl +class XOPChanAccessImpl : public XOPChanAccess { + friend class XOPChanAccessType; + + Anope::string type; + public: - XOPChanAccess(Serialize::TypeBase *type) : ChanAccessImpl(type) { } - XOPChanAccess(Serialize::TypeBase *type, Serialize::ID id) : ChanAccessImpl(type, id) { } + using XOPChanAccess::XOPChanAccess; - Anope::string GetType(); - void SetType(const Anope::string &); + const Anope::string &GetType() override; + void SetType(const Anope::string &) override; bool HasPriv(const Anope::string &priv) override { @@ -53,7 +56,7 @@ class XOPChanAccess : public ChanAccessImpl static Anope::string DetermineLevel(ChanServ::ChanAccess *access) { - if (access->GetSerializableType()->GetName() == "XOPChanAccess") + if (access->GetSerializableType()->GetName() == NAME) { XOPChanAccess *xaccess = anope_dynamic_static_cast<XOPChanAccess *>(access); return xaccess->GetType(); @@ -84,19 +87,19 @@ class XOPChanAccess : public ChanAccessImpl }; -class XOPChanAccessType : public Serialize::Type<XOPChanAccess, ChanAccessType> +class XOPChanAccessType : public ChanAccessType<XOPChanAccessImpl> { public: - Serialize::Field<XOPChanAccess, Anope::string> type; + Serialize::Field<XOPChanAccessImpl, Anope::string> type; - XOPChanAccessType(Module *me) : Serialize::Type<XOPChanAccess, ChanAccessType>(me, "XOPChanAccess") - , type(this, "type") + XOPChanAccessType(Module *me) : ChanAccessType<XOPChanAccessImpl>(me) + , type(this, "type", &XOPChanAccessImpl::type) { - SetParent(ChanServ::chanaccess); + Serialize::SetParent(XOPChanAccess::NAME, ChanServ::ChanAccess::NAME); } }; -Anope::string XOPChanAccess::GetType() +const Anope::string &XOPChanAccess::GetType() { return Get(&XOPChanAccessType::type); } @@ -125,16 +128,12 @@ class CommandCSXOP : public Command return; } - XOPChanAccess tmp_access(NULL); - tmp_access.SetChannel(ci); - tmp_access.SetType(source.command.upper()); - ChanServ::AccessGroup access = source.AccessFor(ci); ChanServ::ChanAccess *highest = access.Highest(); bool override = false; std::vector<Anope::string>::iterator cmd_it = std::find(order.begin(), order.end(), source.command.upper()), - access_it = highest ? std::find(order.begin(), order.end(), XOPChanAccess::DetermineLevel(highest)) : order.end(); + access_it = highest ? std::find(order.begin(), order.end(), XOPChanAccessImpl::DetermineLevel(highest)) : order.end(); if (!access.founder && (!access.HasPriv("ACCESS_CHANGE") || cmd_it <= access_it)) { @@ -217,13 +216,13 @@ class CommandCSXOP : public Command } unsigned access_max = Config->GetModule("chanserv")->Get<unsigned>("accessmax", "1024"); - if (access_max && ci->GetDeepAccessCount() >= access_max) + if (access_max && ci->GetAccessCount() >= access_max) { source.Reply(_("Sorry, you can only have %d access entries on a channel, including access entries from other channels."), access_max); return; } - XOPChanAccess *acc = anope_dynamic_static_cast<XOPChanAccess *>(xopchanaccess.Create()); + XOPChanAccess *acc = Serialize::New<XOPChanAccess *>(); if (na) acc->SetObj(na->GetAccount()); else if (targ_ci) @@ -237,7 +236,7 @@ class CommandCSXOP : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to add " << mask; - Event::OnAccessAdd(&Event::AccessAdd::OnAccessAdd, ci, source, acc); + EventManager::Get()->Dispatch(&Event::AccessAdd::OnAccessAdd, ci, source, acc); source.Reply(_("\002%s\002 added to %s %s list."), acc->Mask(), ci->GetName().c_str(), source.command.c_str()); } @@ -281,7 +280,7 @@ class CommandCSXOP : public Command } std::vector<Anope::string>::iterator cmd_it = std::find(order.begin(), order.end(), source.command.upper()), - access_it = highest ? std::find(order.begin(), order.end(), XOPChanAccess::DetermineLevel(highest)) : order.end(); + access_it = highest ? std::find(order.begin(), order.end(), XOPChanAccessImpl::DetermineLevel(highest)) : order.end(); if (!mask.equals_ci(nc->GetDisplay()) && !access.founder && (!access.HasPriv("ACCESS_CHANGE") || cmd_it <= access_it)) { @@ -317,7 +316,7 @@ class CommandCSXOP : public Command else nicks = caccess->Mask(); - Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, caccess); + EventManager::Get()->Dispatch(&Event::AccessDel::OnAccessDel, ci, source, caccess); delete caccess; }, [&]() @@ -350,7 +349,7 @@ class CommandCSXOP : public Command source.Reply(_("\002%s\002 deleted from %s %s list."), a->Mask().c_str(), ci->GetName().c_str(), source.command.c_str()); - Event::OnAccessDel(&Event::AccessDel::OnAccessDel, ci, source, a); + EventManager::Get()->Dispatch(&Event::AccessDel::OnAccessDel, ci, source, a); delete a; return; @@ -467,7 +466,7 @@ class CommandCSXOP : public Command delete access; } - Event::OnAccessClear(&Event::AccessClear::OnAccessClear, ci, source); + EventManager::Get()->Dispatch(&Event::AccessClear::OnAccessClear, ci, source); source.Reply(_("Channel %s %s list has been cleared."), ci->GetName().c_str(), source.command.c_str()); } diff --git a/modules/database/CMakeLists.txt b/modules/database/CMakeLists.txt index cd225a94d..9a236d6d0 100644 --- a/modules/database/CMakeLists.txt +++ b/modules/database/CMakeLists.txt @@ -1 +1,2 @@ build_modules(${CMAKE_CURRENT_SOURCE_DIR}) +build_modules_dependencies(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/modules/database/flatfile.cpp b/modules/database/flatfile.cpp index 122134960..b250be294 100644 --- a/modules/database/flatfile.cpp +++ b/modules/database/flatfile.cpp @@ -80,6 +80,8 @@ class DBFlatFile : public Module public: DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) + , EventHook<Event::LoadDatabase>(this) + , EventHook<Event::SaveDatabase>(this) , last_day(0) , loaded(false) { @@ -182,8 +184,9 @@ class DBFlatFile : public Module f << "OBJECT " << s_type->GetName() << "\n"; f << "ID " << object->id << "\n"; - for (Serialize::FieldBase *field : s_type->fields) - f << "DATA " << field->GetName() << " " << field->SerializeToString(object) << "\n"; + for (Serialize::FieldBase *field : s_type->GetFields()) + if (field->HasFieldS(object)) // for ext + f << "DATA " << field->serialize_name << " " << field->SerializeToString(object) << "\n"; f << "END\n"; } } diff --git a/modules/database/old.cpp b/modules/database/old.cpp index 27fb3565d..5e94cde02 100644 --- a/modules/database/old.cpp +++ b/modules/database/old.cpp @@ -8,6 +8,8 @@ * Based on the original code of Services by Andy Church. */ +/* Dependencies: anope_chanserv.access */ + #include "module.h" #include "modules/operserv/session.h" #include "modules/botserv/kick.h" @@ -159,6 +161,8 @@ enum static void process_mlock(ChanServ::Channel *ci, uint32_t lock, bool status, uint32_t *limit, Anope::string *key) { + ServiceReference<ModeLocks> mlocks; + if (!mlocks) return; @@ -463,7 +467,7 @@ static void LoadNicks() READ(read_string(buffer, f)); - NickServ::Account *nc = NickServ::account.Create(); + NickServ::Account *nc = Serialize::New<NickServ::Account *>(); nc->SetDisplay(buffer); const Anope::string settings[] = { "killprotect", "kill_quick", "ns_secure", "ns_private", "hide_email", @@ -532,9 +536,9 @@ static void LoadNicks() nc->SetS<bool>("HIDE_STATUS", true); if (u32 & OLD_NI_SUSPENDED) { - if (nssuspendinfo) + NSSuspendInfo *si = Serialize::New<NSSuspendInfo *>(); + if (si) { - NSSuspendInfo *si = nssuspendinfo.Create(); si->SetAccount(nc); } } @@ -594,9 +598,9 @@ static void LoadNicks() { READ(read_string(buffer, f)); - if (nsaccess) + NickAccess *a = Serialize::New<NickAccess *>(); + if (a) { - NickAccess *a = nsaccess.Create(); a->SetAccount(nc); a->SetMask(buffer); } @@ -610,7 +614,7 @@ static void LoadNicks() mi->SetMemoMax(i16); for (int16_t j = 0; j < i16; ++j) { - MemoServ::Memo *m = MemoServ::service ? MemoServ::service->CreateMemo() : nullptr; + MemoServ::Memo *m = Serialize::New<MemoServ::Memo *>(); READ(read_uint32(&u32, f)); uint16_t flags; READ(read_uint16(&flags, f)); @@ -664,28 +668,26 @@ static void LoadNicks() if (tmpu16 & OLD_NS_VERBOTEN) { - if (!forbiddata) + if (nc->GetDisplay().find_first_of("?*") != Anope::string::npos) { delete nc; continue; } - if (nc->GetDisplay().find_first_of("?*") != Anope::string::npos) + ForbidData *d = Serialize::New<ForbidData *>(); + if (d) { - delete nc; - continue; + d->SetMask(nc->GetDisplay()); + d->SetCreator(last_usermask); + d->SetReason(last_realname); + d->SetType(FT_NICK); } - - ForbidData *d = forbiddata.Create(); - d->SetMask(nc->GetDisplay()); - d->SetCreator(last_usermask); - d->SetReason(last_realname); - d->SetType(FT_NICK); + delete nc; continue; } - NickServ::Nick *na = NickServ::nick.Create(); + NickServ::Nick *na = Serialize::New<NickServ::Nick *>(); na->SetNick(nick); na->SetAccount(nc); na->SetLastUsermask(last_usermask); @@ -756,9 +758,8 @@ static void LoadBots() READ(read_int16(&chancount, f)); ServiceBot *bi = ServiceBot::Find(nick, true); - //XXX - // if (!bi) - // bi = new ServiceBot(nick, user, host, real); + if (!bi) + bi = new ServiceBot(nick, user, host, real); bi->bi->SetCreated(created); if (flags & OLD_BI_PRIVATE) @@ -772,10 +773,13 @@ static void LoadBots() static void LoadChannels() { - if (!ChanServ::service) + ServiceReference<BadWords> badwords; + ServiceReference<ChanServ::ChanServService> chanserv; + + if (!chanserv) return; - ServiceReference<ForbidService> forbid("ForbidService", "forbid"); + ServiceReference<ForbidService> forbid; dbFILE *f = open_db_read("ChanServ", "chan.db", 16); if (f == NULL) return; @@ -786,7 +790,7 @@ static void LoadChannels() Anope::string buffer; char namebuf[64]; READ(read_buffer(namebuf, f)); - ChanServ::Channel *ci = ChanServ::channel.Create(); + ChanServ::Channel *ci = Serialize::New<ChanServ::Channel *>(); ci->SetName(namebuf); const Anope::string settings[] = { "keeptopic", "peace", "cs_private", "restricted", "cs_secure", "secureops", "securefounder", @@ -860,9 +864,9 @@ static void LoadChannels() READ(read_string(forbidreason, f)); if (tmpu32 & OLD_CI_SUSPENDED) { - if (cssuspendinfo) + CSSuspendInfo *si = Serialize::New<CSSuspendInfo *>(); + if (si) { - CSSuspendInfo *si = cssuspendinfo.Create(); si->SetChannel(ci); si->SetBy(forbidby); } @@ -903,13 +907,11 @@ static void LoadChannels() if (xop) { - if (xopchanaccess) - access = xopchanaccess.Create(); + access = Serialize::New<XOPChanAccess *>(); } else { - if (accesschanaccess) - access = accesschanaccess.Create(); + access = Serialize::New<AccessChanAccess *>(); } if (access) @@ -998,7 +1000,7 @@ static void LoadChannels() { READ(read_uint32(&tmpu32, f)); READ(read_uint16(&tmpu16, f)); - MemoServ::Memo *m = MemoServ::service ? MemoServ::service->CreateMemo() : nullptr; + MemoServ::Memo *m = Serialize::New<MemoServ::Memo *>(); READ(read_int32(&tmp32, f)); if (m) m->SetTime(tmp32); @@ -1015,9 +1017,9 @@ static void LoadChannels() READ(read_string(buffer, f)); if (!buffer.empty()) { - if (entrymsg) + EntryMsg *e = Serialize::New<EntryMsg *>(); + if (e) { - EntryMsg *e = entrymsg.Create(); e->SetChannel(ci); e->SetCreator("Unknown"); e->SetMessage(buffer); @@ -1129,23 +1131,21 @@ static void LoadChannels() if (forbid_chan) { - if (!forbiddata) + if (ci->GetName().find_first_of("?*") != Anope::string::npos) { delete ci; continue; } - if (ci->GetName().find_first_of("?*") != Anope::string::npos) + ForbidData *d = Serialize::New<ForbidData *>(); + if (d) { - delete ci; - continue; + d->SetMask(ci->GetName()); + d->SetCreator(forbidby); + d->SetReason(forbidreason); + d->SetType(FT_CHAN); } - - ForbidData *d = forbiddata.Create(); - d->SetMask(ci->GetName()); - d->SetCreator(forbidby); - d->SetReason(forbidreason); - d->SetType(FT_CHAN); + delete ci; continue; } @@ -1198,8 +1198,14 @@ static void LoadOper() if (!akill) continue; - XLine *x = new XLine(user + "@" + host, by, expires, reason, XLineManager::GenerateUID()); + XLine *x = Serialize::New<XLine *>(); + x->SetMask(user + "@" + host); + x->SetBy(by); + x->SetExpires(expires); + x->SetReason(reason); + x->SetID(XLineManager::GenerateUID()); x->SetCreated(seton); + akill->AddXLine(x); } @@ -1218,8 +1224,14 @@ static void LoadOper() if (!snline) continue; - XLine *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID()); + XLine *x = Serialize::New<XLine *>(); + x->SetMask(mask); + x->SetBy(by); + x->SetExpires(expires); + x->SetReason(reason); + x->SetID(XLineManager::GenerateUID()); x->SetCreated(seton); + snline->AddXLine(x); } @@ -1238,8 +1250,14 @@ static void LoadOper() if (!sqline) continue; - XLine *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID()); + XLine *x = Serialize::New<XLine *>(); + x->SetMask(mask); + x->SetBy(by); + x->SetExpires(expires); + x->SetReason(reason); + x->SetID(XLineManager::GenerateUID()); x->SetCreated(seton); + sqline->AddXLine(x); } @@ -1258,8 +1276,14 @@ static void LoadOper() if (!szline) continue; - XLine *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID()); + XLine *x = Serialize::New<XLine *>(); + x->SetMask(mask); + x->SetBy(by); + x->SetExpires(expires); + x->SetReason(reason); + x->SetID(XLineManager::GenerateUID()); x->SetCreated(seton); + szline->AddXLine(x); } @@ -1268,9 +1292,6 @@ static void LoadOper() static void LoadExceptions() { - if (!session_service) - return; - dbFILE *f = open_db_read("OperServ", "exception.db", 9); if (f == NULL) return; @@ -1291,9 +1312,9 @@ static void LoadExceptions() READ(read_int32(&time, f)); READ(read_int32(&expires, f)); - if (exception && session_service) + Exception *e = Serialize::New<Exception *>(); + if (e) { - Exception *e = exception.Create(); e->SetMask(mask); e->SetLimit(limit); e->SetWho(who); @@ -1308,9 +1329,6 @@ static void LoadExceptions() static void LoadNews() { - if (!newsitem) - return; - dbFILE *f = open_db_read("OperServ", "news.db", 9); if (f == NULL) @@ -1322,7 +1340,10 @@ static void LoadNews() for (int16_t i = 0; i < n; i++) { int16_t type; - NewsItem *ni = newsitem.Create(); + NewsItem *ni = Serialize::New<NewsItem *>(); + + if (!ni) + break; READ(read_int16(&type, f)); @@ -1362,11 +1383,13 @@ class DBOld : public Module , public EventHook<Event::LoadDatabase> , public EventHook<Event::UplinkSync> { - ExtensibleItem<uint32_t> mlock_on, mlock_off, mlock_limit; + ExtensibleItem<uint32_t> mlock_on, mlock_off, mlock_limit; // XXX these are no longer required because of confmodes ExtensibleItem<Anope::string> mlock_key; public: DBOld(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) + , EventHook<Event::LoadDatabase>(this) + , EventHook<Event::UplinkSync>(this) , mlock_on(this, "mlock_on") , mlock_off(this, "mlock_off") , mlock_limit(this, "mlock_limit") @@ -1424,5 +1447,10 @@ class DBOld : public Module } }; +template<> void ModuleInfo<DBOld>(ModuleDef *def) +{ + def->Depends("chanserv.access"); +} + MODULE_INIT(DBOld) diff --git a/modules/database/redis.cpp b/modules/database/redis.cpp index 72f25a16e..bb5103b4c 100644 --- a/modules/database/redis.cpp +++ b/modules/database/redis.cpp @@ -65,6 +65,8 @@ class DatabaseRedis : public Module ServiceReference<Provider> redis; DatabaseRedis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) + , EventHook<Event::LoadDatabase>(this) + , EventHook<Event::SerializeEvents>(this) , sl(this) { me = this; @@ -73,7 +75,7 @@ class DatabaseRedis : public Module void OnReload(Configuration::Conf *conf) override { Configuration::Block *block = conf->GetModule(this); - this->redis = ServiceReference<Provider>("Redis::Provider", block->Get<Anope::string>("engine", "redis/main")); + this->redis = ServiceReference<Provider>(block->Get<Anope::string>("engine", "redis/main")); } EventReturn OnLoadDatabase() override @@ -136,7 +138,7 @@ class DatabaseRedis : public Module redis->StartTransaction(); const Anope::string &old = field->SerializeToString(object); - args = { "SREM", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->GetName() + ":" + old, stringify(object->id) }; + args = { "SREM", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + old, stringify(object->id) }; redis->SendCommand(nullptr, args); // add object to type set @@ -144,15 +146,15 @@ class DatabaseRedis : public Module redis->SendCommand(nullptr, args); // add key to key set - args = { "SADD", "keys:" + stringify(object->id), field->GetName() }; + args = { "SADD", "keys:" + stringify(object->id), field->serialize_name }; redis->SendCommand(nullptr, args); // set value - args = { "SET", "values:" + stringify(object->id) + ":" + field->GetName(), value }; + args = { "SET", "values:" + stringify(object->id) + ":" + field->serialize_name, value }; redis->SendCommand(nullptr, args); // lookup - args = { "SADD", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->GetName() + ":" + value, stringify(object->id) }; + args = { "SADD", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + value, stringify(object->id) }; redis->SendCommand(nullptr, args); redis->CommitTransaction(); @@ -172,11 +174,11 @@ class DatabaseRedis : public Module redis->StartTransaction(); const Anope::string &old = field->SerializeToString(object); - args = { "SREM", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->GetName() + ":" + old, stringify(object->id) }; + args = { "SREM", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + old, stringify(object->id) }; redis->SendCommand(nullptr, args); // remove field from set - args = { "SREM", "keys:" + stringify(object->id), field->GetName() }; + args = { "SREM", "keys:" + stringify(object->id), field->serialize_name }; redis->SendCommand(nullptr, args); redis->CommitTransaction(); @@ -219,17 +221,17 @@ class DatabaseRedis : public Module redis->StartTransaction(); - for (Serialize::FieldBase *field : obj->GetSerializableType()->fields) + for (Serialize::FieldBase *field : obj->GetSerializableType()->GetFields()) { Anope::string value = field->SerializeToString(obj); - args = { "SREM", "lookup:" + obj->GetSerializableType()->GetName() + ":" + field->GetName() + ":" + value, stringify(obj->id) }; + args = { "SREM", "lookup:" + obj->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + value, stringify(obj->id) }; redis->SendCommand(nullptr, args); - args = { "DEL", "values:" + stringify(obj->id) + ":" + field->GetName() }; + args = { "DEL", "values:" + stringify(obj->id) + ":" + field->serialize_name }; redis->SendCommand(nullptr, args); - args = { "SREM", "keys:" + stringify(obj->id), field->GetName() }; + args = { "SREM", "keys:" + stringify(obj->id), field->serialize_name }; redis->SendCommand(nullptr, args); } @@ -308,7 +310,7 @@ void ObjectLoader::OnResult(const Reply &r) void FieldLoader::OnResult(const Reply &r) { - Log(LOG_DEBUG_2) << "redis: Setting field " << field->GetName() << " of object #" << obj->id << " of type " << obj->GetSerializableType()->GetName() << " to " << r.bulk; + Log(LOG_DEBUG_2) << "redis: Setting field " << field->serialize_name << " of object #" << obj->id << " of type " << obj->GetSerializableType()->GetName() << " to " << r.bulk; field->UnserializeFromString(obj, r.bulk); delete this; @@ -366,7 +368,7 @@ void SubscriptionListener::OnResult(const Reply &r) return; } - Log(LOG_DEBUG_2) << "redis: Setting field " << field->GetName() << " of object #" << obj->id << " of type " << obj->GetSerializableType()->GetName() << " to " << value; + Log(LOG_DEBUG_2) << "redis: Setting field " << field->serialize_name << " of object #" << obj->id << " of type " << obj->GetSerializableType()->GetName() << " to " << value; field->UnserializeFromString(obj, value); } else if (command == "create") diff --git a/modules/database/sql.cpp b/modules/database/sql.cpp index fed0050e4..2d1a61afa 100644 --- a/modules/database/sql.cpp +++ b/modules/database/sql.cpp @@ -11,11 +11,26 @@ class DBMySQL : public Module, public Pipe bool inited = false; Anope::string prefix; ServiceReference<Provider> SQL; + std::unordered_multimap<Serialize::Object *, Serialize::FieldBase *> cache; + + void CacheMiss(Serialize::Object *object, Serialize::FieldBase *field) + { + cache.insert(std::make_pair(object, field)); + } + + bool IsCacheMiss(Serialize::Object *object, Serialize::FieldBase *field) + { + auto range = cache.equal_range(object); + for (auto it = range.first; it != range.second; ++it) + if (it->second == field) + return true; + return false; + } Result Run(const Query &query) { if (!SQL) - ;//XXX + return Result(); if (!inited) { @@ -24,6 +39,8 @@ class DBMySQL : public Module, public Pipe SQL->RunQuery(q); } + Log(LOG_DEBUG_2) << query.Unsafe(); + return SQL->RunQuery(query); } @@ -50,6 +67,7 @@ class DBMySQL : public Module, public Pipe public: DBMySQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) + , EventHook<Event::SerializeEvents>(this) { } @@ -57,12 +75,13 @@ class DBMySQL : public Module, public Pipe { Commit(); Serialize::Clear(); + cache.clear(); } void OnReload(Configuration::Conf *conf) override { Configuration::Block *block = conf->GetModule(this); - this->SQL = ServiceReference<Provider>("SQL::Provider", block->Get<Anope::string>("engine")); + this->SQL = ServiceReference<Provider>(block->Get<Anope::string>("engine")); this->prefix = block->Get<Anope::string>("prefix", "anope_db_"); inited = false; } @@ -94,13 +113,13 @@ class DBMySQL : public Module, public Pipe for (Query &q : SQL->CreateTable(prefix, type->GetName())) Run(q); - for (Query &q : SQL->AlterTable(prefix, type->GetName(), field->GetName(), false)) + for (Query &q : SQL->AlterTable(prefix, type->GetName(), field->serialize_name, false)) Run(q); - for (const Query &q : SQL->CreateIndex(prefix + type->GetName(), field->GetName())) + for (const Query &q : SQL->CreateIndex(prefix + type->GetName(), field->serialize_name)) Run(q); - Query query("SELECT `id` FROM `" + prefix + type->GetName() + "` WHERE `" + field->GetName() + "` = @value@"); + Query query("SELECT `id` FROM `" + prefix + type->GetName() + "` WHERE `" + field->serialize_name + "` = @value@"); query.SetValue("value", value); Result res = Run(query); if (res.Rows()) @@ -120,14 +139,14 @@ class DBMySQL : public Module, public Pipe { StartTransaction(); - Query query = "SELECT `" + field->GetName() + "` FROM `" + prefix + object->GetSerializableType()->GetName() + "` WHERE `id` = @id@"; + Query query = "SELECT `" + field->serialize_name + "` FROM `" + prefix + object->GetSerializableType()->GetName() + "` WHERE `id` = @id@"; query.SetValue("id", object->id); Result res = Run(query); if (res.Rows() == 0) return false; - v = res.GetValue(0, field->GetName()); + v = res.GetValue(0, field->serialize_name); return true; } @@ -136,9 +155,12 @@ class DBMySQL : public Module, public Pipe { SQL::Result::Value v; + if (IsCacheMiss(object, field)) + return EVENT_CONTINUE; + if (!GetValue(object, field, v)) { - field->CacheMiss(object); + CacheMiss(object, field); return EVENT_CONTINUE; } @@ -175,7 +197,7 @@ class DBMySQL : public Module, public Pipe Result res = Run(query); for (int i = 0; i < res.Rows(); ++i) { - Serialize::ID id = convertTo<Serialize::ID>(res.Get(i, "id")); + Serialize::ID id = convertTo<Serialize::ID>(res.Get(i, "id")); // object edge is on if (id == object->id) { @@ -184,11 +206,26 @@ class DBMySQL : public Module, public Pipe Anope::string f = res.Get(i, "field"); id = convertTo<Serialize::ID>(res.Get(i, "other_id")); - //XXX sanity checks Serialize::FieldBase *obj_field = object->GetSerializableType()->GetField(f); + if (obj_field == nullptr) + { + Log(LOG_DEBUG) << "Unable to find field " << f << " on " << object->GetSerializableType()->GetName(); + continue; + } Serialize::TypeBase *obj_type = Serialize::TypeBase::Find(t); + if (obj_type == nullptr) + { + Log(LOG_DEBUG) << "Unable to find type " << t; + continue; + } + Serialize::Object *other = obj_type->Require(id); + if (other == nullptr) + { + Log(LOG_DEBUG) << "Unable to require id " << id << " type " << obj_type->GetName(); + continue; + } edges.emplace_back(other, obj_field, true); } @@ -198,10 +235,26 @@ class DBMySQL : public Module, public Pipe Anope::string t = res.Get(i, "type"); Anope::string f = res.Get(i, "field"); - //XXX sanity checks Serialize::TypeBase *obj_type = Serialize::TypeBase::Find(t); + if (obj_type == nullptr) + { + Log(LOG_DEBUG) << "Unable to find type " << t; + continue; + } + Serialize::FieldBase *obj_field = obj_type->GetField(f); + if (obj_field == nullptr) + { + Log(LOG_DEBUG) << "Unable to find field " << f << " on " << obj_type->GetName(); + continue; + } + Serialize::Object *other = obj_type->Require(id); + if (other == nullptr) + { + Log(LOG_DEBUG) << "Unable to require id " << id << " type " << obj_type->GetName(); + continue; + } // other type, other field, edges.emplace_back(other, obj_field, false); @@ -227,8 +280,8 @@ class DBMySQL : public Module, public Pipe { StartTransaction(); - Query query = "SELECT `" + field->GetName() + "`,j1.type AS " + field->GetName() + "_type FROM `" + prefix + object->GetSerializableType()->GetName() + "` " - "JOIN `" + prefix + "objects` AS j1 ON " + prefix + object->GetSerializableType()->GetName() + "." + field->GetName() + " = j1.id " + Query query = "SELECT `" + field->serialize_name + "`,j1.type AS " + field->serialize_name + "_type FROM `" + prefix + object->GetSerializableType()->GetName() + "` " + "JOIN `" + prefix + "objects` AS j1 ON " + prefix + object->GetSerializableType()->GetName() + "." + field->serialize_name + " = j1.id " "WHERE " + prefix + object->GetSerializableType()->GetName() + ".id = @id@"; query.SetValue("id", object->id); Result res = Run(query); @@ -236,10 +289,10 @@ class DBMySQL : public Module, public Pipe if (res.Rows() == 0) return EVENT_CONTINUE; - type = res.Get(0, field->GetName() + "_type"); + type = res.Get(0, field->serialize_name + "_type"); try { - value = convertTo<Serialize::ID>(res.Get(0, field->GetName())); + value = convertTo<Serialize::ID>(res.Get(0, field->serialize_name)); } catch (const ConvertException &ex) { @@ -260,15 +313,15 @@ class DBMySQL : public Module, public Pipe for (Query &q : SQL->CreateTable(prefix, object->GetSerializableType()->GetName())) Run(q); - for (Query &q : SQL->AlterTable(prefix, object->GetSerializableType()->GetName(), field->GetName(), is_object)) + for (Query &q : SQL->AlterTable(prefix, object->GetSerializableType()->GetName(), field->serialize_name, is_object)) Run(q); Query q; q.SetValue("id", object->id); if (value) - q.SetValue(field->GetName(), *value); + q.SetValue(field->serialize_name, *value); else - q.SetNull(field->GetName()); + q.SetNull(field->serialize_name); for (Query &q2 : SQL->Replace(prefix + object->GetSerializableType()->GetName(), q, { "id" })) Run(q2); @@ -294,7 +347,7 @@ class DBMySQL : public Module, public Pipe DoSet(object, field, true, &v); Query query; - query.SetValue("field", field->GetName()); + query.SetValue("field", field->serialize_name); query.SetValue("id", object->id); query.SetValue("other_id", value->id); @@ -307,7 +360,7 @@ class DBMySQL : public Module, public Pipe Query query("DELETE FROM `" + prefix + "edges` WHERE `id` = @id@ AND `field` = @field@"); query.SetValue("id", object->id); - query.SetValue("field", field->GetName()); + query.SetValue("field", field->serialize_name); Run(query); } @@ -317,18 +370,16 @@ class DBMySQL : public Module, public Pipe EventReturn OnSerializeUnset(Serialize::Object *object, Serialize::FieldBase *field) override { DoSet(object, field, false, nullptr); - field->CacheMiss(object); return EVENT_STOP; } EventReturn OnSerializeUnsetSerializable(Serialize::Object *object, Serialize::FieldBase *field) override { DoSet(object, field, true, nullptr); - field->CacheMiss(object); Query query("DELETE FROM `" + prefix + "edges` WHERE `id` = @id@ AND `field` = @field@"); query.SetValue("id", object->id); - query.SetValue("field", field->GetName()); + query.SetValue("field", field->serialize_name); Run(query); return EVENT_STOP; @@ -343,6 +394,9 @@ class DBMySQL : public Module, public Pipe EventReturn OnSerializableGetId(Serialize::ID &id) override { + if (!SQL) + return EVENT_CONTINUE; + StartTransaction(); id = SQL->GetID(prefix); diff --git a/modules/dns.cpp b/modules/dns.cpp index 1ea70a6ed..fe993c271 100644 --- a/modules/dns.cpp +++ b/modules/dns.cpp @@ -835,7 +835,7 @@ class MyManager : public Manager, public Timer } } - Event::OnDnsRequest(&Event::DnsRequest::OnDnsRequest, recv_packet, packet); + EventManager::Get()->Dispatch(&Event::DnsRequest::OnDnsRequest, recv_packet, packet); for (unsigned i = 0; i < recv_packet.questions.size(); ++i) { @@ -1028,6 +1028,7 @@ class ModuleDNS : public Module public: ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::ModuleUnload>(this) , manager(this) { diff --git a/modules/dnsbl.cpp b/modules/dnsbl.cpp index 49739a80c..7d60a9f45 100644 --- a/modules/dnsbl.cpp +++ b/modules/dnsbl.cpp @@ -10,8 +10,6 @@ using namespace DNS; -static ServiceReference<XLineManager> akills("XLineManager", "xlinemanager/sgline"); - struct Blacklist { struct Reply @@ -41,12 +39,13 @@ struct Blacklist class DNSBLResolver : public Request { + ServiceReference<XLineManager> &akills; Reference<User> user; Blacklist blacklist; bool add_to_akill; public: - DNSBLResolver(Module *c, User *u, const Blacklist &b, const Anope::string &host, bool add_akill) : Request(DNS::manager, c, host, QUERY_A, true), user(u), blacklist(b), add_to_akill(add_akill) { } + DNSBLResolver(ServiceReference<XLineManager> &a, Module *c, DNS::Manager *manager, User *u, const Blacklist &b, const Anope::string &host, bool add_akill) : Request(manager, c, host, QUERY_A, true), akills(a), user(u), blacklist(b), add_to_akill(add_akill) { } void OnLookupComplete(const Query *record) override { @@ -81,7 +80,7 @@ class DNSBLResolver : public Request ServiceBot *OperServ = Config->GetClient("OperServ"); Log(creator, "dnsbl", OperServ) << user->GetMask() << " (" << addr << ") appears in " << this->blacklist.name; - XLine *x = new XLine(xline); + XLine *x = Serialize::New<XLine *>(); x->SetMask("*@" + addr); x->SetBy(OperServ ? OperServ->nick : "m_dnsbl"); x->SetCreated(Anope::CurTime); @@ -105,14 +104,18 @@ class DNSBLResolver : public Request class ModuleDNSBL : public Module , public EventHook<Event::UserConnect> { + ServiceReference<DNS::Manager> manager; std::vector<Blacklist> blacklists; std::set<Anope::string> exempts; bool check_on_connect; bool check_on_netburst; bool add_to_akill; + ServiceReference<XLineManager> akill; public: ModuleDNSBL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR | EXTRA) + , EventHook<Event::UserConnect>(this) + , akill("sgline") { } @@ -158,7 +161,7 @@ class ModuleDNSBL : public Module void OnUserConnect(User *user, bool &exempt) override { - if (exempt || user->Quitting() || (!this->check_on_connect && !Me->IsSynced()) || !DNS::manager) + if (exempt || user->Quitting() || (!this->check_on_connect && !Me->IsSynced()) || !manager) return; if (!this->check_on_netburst && !user->server->IsSynced()) @@ -186,8 +189,8 @@ class ModuleDNSBL : public Module DNSBLResolver *res = NULL; try { - res = new DNSBLResolver(this, user, b, dnsbl_host, this->add_to_akill); - DNS::manager->Process(res); + res = new DNSBLResolver(akill, this, manager, user, b, dnsbl_host, this->add_to_akill); + manager->Process(res); } catch (const SocketException &ex) { diff --git a/modules/encryption/bcrypt.cpp b/modules/encryption/bcrypt.cpp index 74d729491..ed003f883 100644 --- a/modules/encryption/bcrypt.cpp +++ b/modules/encryption/bcrypt.cpp @@ -877,6 +877,8 @@ class EBCRYPT : public Module public: EBCRYPT(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR) + , EventHook<Event::Encrypt>(this) + , EventHook<Event::CheckAuthentication>(this) , rounds(10) { // Test a pre-calculated hash diff --git a/modules/encryption/md5.cpp b/modules/encryption/md5.cpp index a92f5a4f9..0bf3942ec 100644 --- a/modules/encryption/md5.cpp +++ b/modules/encryption/md5.cpp @@ -345,6 +345,8 @@ class EMD5 : public Module public: EMD5(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR) + , EventHook<Event::Encrypt>(this) + , EventHook<Event::CheckAuthentication>(this) , md5provider(this) { if (ModuleManager::FindFirstOf(ENCRYPTION) == this) diff --git a/modules/encryption/none.cpp b/modules/encryption/none.cpp index 8164534eb..c51bcb9ae 100644 --- a/modules/encryption/none.cpp +++ b/modules/encryption/none.cpp @@ -16,6 +16,9 @@ class ENone : public Module { public: ENone(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR) + , EventHook<Event::Encrypt>(this) + , EventHook<Event::Decrypt>(this) + , EventHook<Event::CheckAuthentication>(this) { } diff --git a/modules/encryption/old.cpp b/modules/encryption/old.cpp index 4e3e70f7d..fc4598887 100644 --- a/modules/encryption/old.cpp +++ b/modules/encryption/old.cpp @@ -12,12 +12,15 @@ #include "module.h" #include "modules/encryption.h" -static ServiceReference<Encryption::Provider> md5("Encryption::Provider", "md5"); - class OldMD5Provider : public Encryption::Provider { + ServiceReference<Encryption::Provider> md5; + public: - OldMD5Provider(Module *creator) : Encryption::Provider(creator, "oldmd5") { } + OldMD5Provider(Module *creator) : Encryption::Provider(creator, "oldmd5") + , md5("md5") + { + } Encryption::Context *CreateContext(Encryption::IV *iv) override { @@ -39,12 +42,16 @@ class EOld : public Module , public EventHook<Event::CheckAuthentication> { OldMD5Provider oldmd5provider; + ServiceReference<Encryption::Provider> md5; inline static char XTOI(char c) { return c > 9 ? c - 'A' + 10 : c - '0'; } public: EOld(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR) + , EventHook<Event::Encrypt>(this) + , EventHook<Event::CheckAuthentication>(this) , oldmd5provider(this) + , md5("md5") { if (ModuleManager::FindFirstOf(ENCRYPTION) == this) throw ModuleException("enc_old is deprecated and can not be used as a primary encryption method"); diff --git a/modules/encryption/sha1.cpp b/modules/encryption/sha1.cpp index a99bc834e..85fc9a5f2 100644 --- a/modules/encryption/sha1.cpp +++ b/modules/encryption/sha1.cpp @@ -200,6 +200,8 @@ class ESHA1 : public Module public: ESHA1(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR) + , EventHook<Event::Encrypt>(this) + , EventHook<Event::CheckAuthentication>(this) , sha1provider(this) { if (ModuleManager::FindFirstOf(ENCRYPTION) == this) diff --git a/modules/encryption/sha256.cpp b/modules/encryption/sha256.cpp index a138b3756..226cf0feb 100644 --- a/modules/encryption/sha256.cpp +++ b/modules/encryption/sha256.cpp @@ -275,6 +275,8 @@ class ESHA256 : public Module public: ESHA256(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, ENCRYPTION | VENDOR) + , EventHook<Event::Encrypt>(this) + , EventHook<Event::CheckAuthentication>(this) , sha256provider(this) { diff --git a/modules/extra/ldap_authentication.cpp b/modules/extra/ldap_authentication.cpp index dd63fd3fb..ac4b9dd4e 100644 --- a/modules/extra/ldap_authentication.cpp +++ b/modules/extra/ldap_authentication.cpp @@ -97,7 +97,7 @@ class IdentifyInterface : public LDAPInterface { na = new NickServ::Nick(ii->req->GetAccount(), new NickServ::Account(ii->req->GetAccount())); na->SetLastRealname(ii->user ? ii->user->realname : ii->req->GetAccount()); - NickServ::Event::OnNickRegister(&NickServ::Event::NickRegister::OnNickRegister, ii->user, na, ii->req->GetPassword());; + NickServ::EventManager::Get()->Dispatch(&NickServ::Event::NickRegister::OnNickRegister, ii->user, na, ii->req->GetPassword());; ServiceBot *NickServ = Config->GetClient("NickServ"); if (ii->user && NickServ) ii->user->SendMessage(NickServ, _("Your account \002%s\002 has been successfully created."), na->GetNick().c_str()); diff --git a/modules/extra/mysql.cpp b/modules/extra/mysql.cpp index 843a2ba0a..11a5e1f15 100644 --- a/modules/extra/mysql.cpp +++ b/modules/extra/mysql.cpp @@ -182,6 +182,7 @@ class ModuleSQL : public Module DispatcherThread *DThread; ModuleSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::ModuleUnload>(this) { me = this; @@ -526,9 +527,9 @@ void MySQLService::Connect() bool connect = mysql_real_connect(this->sql, this->server.c_str(), this->user.c_str(), this->password.c_str(), this->database.c_str(), this->port, NULL, CLIENT_MULTI_RESULTS); if (!connect) - throw SQL::Exception("Unable to connect to MySQL service " + this->name + ": " + mysql_error(this->sql)); + throw SQL::Exception("Unable to connect to MySQL service " + this->GetName() + ": " + mysql_error(this->sql)); - Log(LOG_DEBUG) << "Successfully connected to MySQL service " << this->name << " at " << this->server << ":" << this->port; + Log(LOG_DEBUG) << "Successfully connected to MySQL service " << this->GetName() << " at " << this->server << ":" << this->port; } diff --git a/modules/extra/sasl_dh-aes.cpp b/modules/extra/sasl_dh-aes.cpp index dd06d118b..b4920aeb4 100644 --- a/modules/extra/sasl_dh-aes.cpp +++ b/modules/extra/sasl_dh-aes.cpp @@ -161,7 +161,7 @@ class DHAES : public Mechanism return Err(sess, pubkey); SASL::IdentifyRequest* req = new SASL::IdentifyRequest(this->owner, m.source, username, password); - Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); + EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); req->Dispatch(); BN_free(pubkey); diff --git a/modules/extra/sasl_dh-blowfish.cpp b/modules/extra/sasl_dh-blowfish.cpp index f6e4b27b3..e3e0eb4f9 100644 --- a/modules/extra/sasl_dh-blowfish.cpp +++ b/modules/extra/sasl_dh-blowfish.cpp @@ -171,7 +171,7 @@ class DHBS : public Mechanism return Err(sess, pubkey); SASL::IdentifyRequest* req = new SASL::IdentifyRequest(this->owner, m.source, username, password); - Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); + EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); req->Dispatch(); BN_free(pubkey); diff --git a/modules/extra/sql_authentication.cpp b/modules/extra/sql_authentication.cpp index 1c2dbe729..a7d5b206f 100644 --- a/modules/extra/sql_authentication.cpp +++ b/modules/extra/sql_authentication.cpp @@ -43,7 +43,7 @@ class SQLAuthenticationResult : public SQL::Interface if (na == NULL) { na = new NickServ::Nick(req->GetAccount(), new NickServ::Account(req->GetAccount())); - NickServ::Event::OnNickRegister(&NickServ::Event::NickRegister::OnNickRegister, user, na, ""); + NickServ::EventManager::Get()->Dispatch(&NickServ::Event::NickRegister::OnNickRegister, user, na, ""); if (user && NickServ) user->SendMessage(NickServ, _("Your account \002%s\002 has been successfully created."), na->GetNick().c_str()); } diff --git a/modules/extra/stats/chanstats.cpp b/modules/extra/stats/chanstats.cpp index 687c077b5..65a198449 100644 --- a/modules/extra/stats/chanstats.cpp +++ b/modules/extra/stats/chanstats.cpp @@ -20,7 +20,7 @@ class CommandCSSetChanstats : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetChannelOption(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetChannelOption::OnSetChannelOption, source, this, ci, params[1]); if (MOD_RESULT == EVENT_STOP) return; @@ -73,7 +73,7 @@ class CommandNSSetChanstats : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, na->GetAccount(), param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, na->GetAccount(), param); if (MOD_RESULT == EVENT_STOP) return; diff --git a/modules/fantasy.cpp b/modules/fantasy.cpp index 3730f7e70..1a9127beb 100644 --- a/modules/fantasy.cpp +++ b/modules/fantasy.cpp @@ -77,7 +77,7 @@ class CommandBSSetFantasy : public Command "Note that users wanting to use fantaisist\n" "commands MUST have enough access for both\n" "the FANTASIA and the command they are executing."), - Config->GetModule(this->owner)->Get<Anope::string>("fantasycharacter", "!").c_str()); + Config->GetModule(this->GetOwner())->Get<Anope::string>("fantasycharacter", "!").c_str()); return true; } }; @@ -90,15 +90,12 @@ class Fantasy : public Module CommandBSSetFantasy commandbssetfantasy; - EventHandlers<Event::BotFantasy> OnBotFantasy; - EventHandlers<Event::BotNoFantasyAccess> OnBotNoFantasyAccess; - public: Fantasy(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , fantasy(this, ChanServ::channel, "BS_FANTASY") + , EventHook<Event::Privmsg>(this) + , EventHook<Event::ServiceBotEvent>(this) + , fantasy(this, "BS_FANTASY") , commandbssetfantasy(this) - , OnBotFantasy(this) - , OnBotNoFantasyAccess(this) { } @@ -156,7 +153,7 @@ class Fantasy : public Module return; const CommandInfo &info = it->second; - ServiceReference<Command> cmd("Command", info.name); + ServiceReference<Command> cmd(info.name); if (!cmd) { Log(LOG_DEBUG) << "Fantasy command " << it->first << " exists for non-existent service " << info.name << "!"; @@ -194,11 +191,11 @@ class Fantasy : public Module EventReturn MOD_RESULT; if (has_fantasia) { - MOD_RESULT = this->OnBotFantasy(&Event::BotFantasy::OnBotFantasy, source, cmd, c->ci, params); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotFantasy::OnBotFantasy, source, cmd, c->ci, params); } else { - MOD_RESULT = this->OnBotNoFantasyAccess(&Event::BotNoFantasyAccess::OnBotNoFantasyAccess, source, cmd, c->ci, params); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotNoFantasyAccess::OnBotNoFantasyAccess, source, cmd, c->ci, params); } if (MOD_RESULT == EVENT_STOP || !has_fantasia) @@ -207,7 +204,7 @@ class Fantasy : public Module if (MOD_RESULT != EVENT_ALLOW && !info.permission.empty() && !source.HasCommand(info.permission)) return; - MOD_RESULT = Event::OnPreCommand(&Event::PreCommand::OnPreCommand, source, cmd, params); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::PreCommand::OnPreCommand, source, cmd, params); if (MOD_RESULT == EVENT_STOP) return; @@ -215,7 +212,7 @@ class Fantasy : public Module cmd->Execute(source, params); if (!nc_reference) source.nc = NULL; - Event::OnPostCommand(&Event::PostCommand::OnPostCommand, source, cmd, params); + EventManager::Get()->Dispatch(&Event::PostCommand::OnPostCommand, source, cmd, params); } void OnServiceBot(CommandSource &source, ServiceBot *bi, ChanServ::Channel *ci, InfoFormatter &info) override diff --git a/modules/global/global.cpp b/modules/global/global.cpp index d6106b2be..9461dff75 100644 --- a/modules/global/global.cpp +++ b/modules/global/global.cpp @@ -14,6 +14,8 @@ class CommandGLGlobal : public Command { + ServiceReference<Global::GlobalService> service; + public: CommandGLGlobal(Module *creator) : Command(creator, "global/global", 1, 1) { @@ -25,14 +27,14 @@ class CommandGLGlobal : public Command { const Anope::string &msg = params[0]; - if (!Global::service) + if (!service) { source.Reply("No global reference, is global loaded?"); return; } Log(LOG_ADMIN, source, this); - Global::service->SendGlobal(NULL, source.GetNick(), msg); + service->SendGlobal(NULL, source.GetNick(), msg); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/global/main/global.cpp b/modules/global/main/global.cpp index f31605acb..57905c1d7 100644 --- a/modules/global/main/global.cpp +++ b/modules/global/main/global.cpp @@ -32,6 +32,10 @@ class GlobalCore : public Module public: GlobalCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , EventHook<Event::Restart>(this) + , EventHook<Event::Shutdown>(this) + , EventHook<Event::NewServer>(this) + , EventHook<Event::Help>(this) , GlobalService(this) { } diff --git a/modules/greet.cpp b/modules/greet.cpp index 69039849c..26834afa5 100644 --- a/modules/greet.cpp +++ b/modules/greet.cpp @@ -101,7 +101,7 @@ class CommandNSSetGreet : public Command } NickServ::Account *nc = na->GetAccount(); - EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -170,8 +170,11 @@ class Greet : public Module public: Greet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , bs_greet(this, ChanServ::channel, "BS_GREET") - , ns_greet(this, NickServ::account, "greet") + , EventHook<Event::JoinChannel>(this) + , EventHook<Event::NickInfo>(this) + , EventHook<Event::ServiceBotEvent>(this) + , bs_greet(this, "BS_GREET") + , ns_greet(this, "greet") , commandbssetgreet(this) , commandnssetgreet(this) , commandnssasetgreet(this) diff --git a/modules/help.cpp b/modules/help.cpp index debb25837..0e544dc1e 100644 --- a/modules/help.cpp +++ b/modules/help.cpp @@ -26,10 +26,8 @@ class CommandHelp : public Command return NULL; } - EventHandlers<Event::Help> &onhelp; - public: - CommandHelp(Module *creator, EventHandlers<Event::Help> &event) : Command(creator, "generic/help", 0), onhelp(event) + CommandHelp(Module *creator) : Command(creator, "generic/help", 0) { this->SetDesc(_("Displays this list and give information about commands")); this->AllowUnregistered(true); @@ -37,7 +35,7 @@ class CommandHelp : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - EventReturn MOD_RESULT = this->onhelp(&Event::Help::OnPreHelp, source, params); + EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::Help::OnPreHelp, source, params); if (MOD_RESULT == EVENT_STOP) return; @@ -70,7 +68,7 @@ class CommandHelp : public Command if (cmd != it->first && map.count(cmd)) continue; - ServiceReference<Command> c("Command", info.name); + ServiceReference<Command> c(info.name); if (!c) continue; @@ -133,7 +131,7 @@ class CommandHelp : public Command const CommandInfo &info = it->second; - ServiceReference<Command> c("Command", info.name); + ServiceReference<Command> c(info.name); if (!c) continue; @@ -176,19 +174,17 @@ class CommandHelp : public Command source.Reply(_("No help available for \002{0}\002."), params[0]); } - this->onhelp(&Event::Help::OnPostHelp, source, params); + EventManager::Get()->Dispatch(&Event::Help::OnPostHelp, source, params); } }; class Help : public Module { CommandHelp commandhelp; - EventHandlers<Event::Help> onhelp; public: Help(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandhelp(this, onhelp) - , onhelp(this) + , commandhelp(this) { } diff --git a/modules/helpchan.cpp b/modules/helpchan.cpp index 3897b2b5a..11ec4247d 100644 --- a/modules/helpchan.cpp +++ b/modules/helpchan.cpp @@ -12,6 +12,7 @@ class HelpChannel : public Module { public: HelpChannel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::ChannelModeSet>(this) { } diff --git a/modules/hostserv/del.cpp b/modules/hostserv/del.cpp index 0830cd5b5..37823b1b7 100644 --- a/modules/hostserv/del.cpp +++ b/modules/hostserv/del.cpp @@ -14,10 +14,8 @@ class CommandHSDel : public Command { - EventHandlers<Event::DeleteVhost> &OnDeleteVhost; - public: - CommandHSDel(Module *creator, EventHandlers<Event::DeleteVhost> &onDeleteVhost) : Command(creator, "hostserv/del", 1, 1), OnDeleteVhost(onDeleteVhost) + CommandHSDel(Module *creator) : Command(creator, "hostserv/del", 1, 1) { this->SetDesc(_("Delete the vhost of another user")); this->SetSyntax(_("\037user\037")); @@ -37,7 +35,7 @@ class CommandHSDel : public Command } Log(LOG_ADMIN, source, this) << "for user " << na->GetNick(); - this->OnDeleteVhost(&Event::DeleteVhost::OnDeleteVhost, na); + EventManager::Get()->Dispatch(&Event::DeleteVhost::OnDeleteVhost, na); na->RemoveVhost(); source.Reply(_("Vhost for \002{0}\002 has been removed."), na->GetNick()); } @@ -51,10 +49,8 @@ class CommandHSDel : public Command class CommandHSDelAll : public Command { - EventHandlers<Event::DeleteVhost> &ondeletevhost; - public: - CommandHSDelAll(Module *creator, EventHandlers<Event::DeleteVhost> &event) : Command(creator, "hostserv/delall", 1, 1), ondeletevhost(event) + CommandHSDelAll(Module *creator) : Command(creator, "hostserv/delall", 1, 1) { this->SetDesc(_("Delete the vhost for all nicks in a group")); this->SetSyntax(_("\037group\037")); @@ -73,10 +69,10 @@ class CommandHSDelAll : public Command return; } - this->ondeletevhost(&Event::DeleteVhost::OnDeleteVhost, na); + EventManager::Get()->Dispatch(&Event::DeleteVhost::OnDeleteVhost, na); NickServ::Account *nc = na->GetAccount(); - for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>(NickServ::nick)) + for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>()) na2->RemoveVhost(); Log(LOG_ADMIN, source, this) << "for all nicks in group " << nc->GetDisplay(); source.Reply(_("Vhosts for group \002{0}\002 have been removed."), nc->GetDisplay()); @@ -93,13 +89,11 @@ class HSDel : public Module { CommandHSDel commandhsdel; CommandHSDelAll commandhsdelall; - EventHandlers<Event::DeleteVhost> ondeletevhost; public: HSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandhsdel(this, ondeletevhost) - , commandhsdelall(this, ondeletevhost) - , ondeletevhost(this) + , commandhsdel(this) + , commandhsdelall(this) { if (!IRCD || !IRCD->CanSetVHost) throw ModuleException("Your IRCd does not support vhosts"); diff --git a/modules/hostserv/group.cpp b/modules/hostserv/group.cpp index 3aff66e27..01e8ad722 100644 --- a/modules/hostserv/group.cpp +++ b/modules/hostserv/group.cpp @@ -26,10 +26,10 @@ class CommandHSGroup : public Command return; setting = true; - for (NickServ::Nick *nick : na->GetAccount()->GetRefs<NickServ::Nick *>(NickServ::nick)) + for (NickServ::Nick *nick : na->GetAccount()->GetRefs<NickServ::Nick *>()) { nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); - Event::OnSetVhost(&Event::SetVhost::OnSetVhost, nick); + EventManager::Get()->Dispatch(&Event::SetVhost::OnSetVhost, nick); } setting = false; } @@ -84,6 +84,8 @@ class HSGroup : public Module public: HSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::SetVhost>(this) + , EventHook<Event::NickGroup>(this) , commandhsgroup(this) { if (!IRCD || !IRCD->CanSetVHost) diff --git a/modules/hostserv/list.cpp b/modules/hostserv/list.cpp index 738f9f1bd..e77d8d9fa 100644 --- a/modules/hostserv/list.cpp +++ b/modules/hostserv/list.cpp @@ -53,7 +53,7 @@ class CommandHSList : public Command } } - unsigned display_counter = 0, listmax = Config->GetModule(this->owner)->Get<unsigned>("listmax", "50"); + unsigned display_counter = 0, listmax = Config->GetModule(this->GetOwner())->Get<unsigned>("listmax", "50"); ListFormatter list(source.GetAccount()); list.AddColumn(_("Number")).AddColumn(_("Nick")).AddColumn(_("Vhost")).AddColumn(_("Creator")).AddColumn(_("Created")); diff --git a/modules/hostserv/main/hostserv.cpp b/modules/hostserv/main/hostserv.cpp index 8fdfa560e..345d2cf97 100644 --- a/modules/hostserv/main/hostserv.cpp +++ b/modules/hostserv/main/hostserv.cpp @@ -25,6 +25,11 @@ class HostServCore : public Module public: HostServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , EventHook<Event::UserLogin>(this) + , EventHook<Event::NickUpdate>(this) + , EventHook<Event::Help>(this) + , EventHook<Event::SetVhost>(this) + , EventHook<Event::DeleteVhost>(this) { if (!IRCD || !IRCD->CanSetVHost) throw ModuleException("Your IRCd does not support vhosts"); diff --git a/modules/hostserv/request.cpp b/modules/hostserv/request.cpp index 8a064a84c..25f3de12b 100644 --- a/modules/hostserv/request.cpp +++ b/modules/hostserv/request.cpp @@ -1,7 +1,7 @@ /* * * - * (C) 2003-2014 Anope Team + * (C) 2003-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. @@ -11,11 +11,17 @@ #include "module.h" #include "modules/memoserv.h" -static void req_send_memos(Module *me, CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost); - class HostRequest : public Serialize::Object { + friend class HostRequestType; + + NickServ::Nick *na = nullptr; + Anope::string ident, host; + time_t time = 0; + public: + static constexpr const char *const NAME = "hostrequest"; + HostRequest(Serialize::TypeBase *type) : Serialize::Object(type) { } HostRequest(Serialize::TypeBase *type, Serialize::ID id) : Serialize::Object(type, id) { } @@ -39,11 +45,11 @@ class HostRequestType : public Serialize::Type<HostRequest> Serialize::Field<HostRequest, Anope::string> ident, host; Serialize::Field<HostRequest, time_t> time; - HostRequestType(Module *me) : Serialize::Type<HostRequest>(me, "HostRequest") - , na(this, "na", true) - , ident(this, "ident") - , host(this, "host") - , time(this, "time") + HostRequestType(Module *me) : Serialize::Type<HostRequest>(me) + , na(this, "na", &HostRequest::na, true) + , ident(this, "ident", &HostRequest::ident) + , host(this, "host", &HostRequest::host) + , time(this, "time", &HostRequest::time) { } }; @@ -88,10 +94,32 @@ void HostRequest::SetTime(const time_t &t) Set(&HostRequestType::time, t); } -static Serialize::TypeReference<HostRequest> hostrequest("HostRequest"); - class CommandHSRequest : public Command { + ServiceReference<MemoServ::MemoServService> memoserv; + + void SendMemos(CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost) + { + Anope::string host; + + if (!vIdent.empty()) + host = vIdent + "@" + vHost; + else + host = vHost; + + if (Config->GetModule(GetOwner())->Get<bool>("memooper") && memoserv) + for (Oper *o : Serialize::GetObjects<Oper *>()) + { + NickServ::Nick *na = NickServ::FindNick(o->GetName()); + if (!na) + continue; + + Anope::string message = Anope::printf(_("[auto memo] vHost \002%s\002 has been requested by %s."), host.c_str(), source.GetNick().c_str()); + + memoserv->Send(source.service->nick, na->GetNick(), message, true); + } + } + public: CommandHSRequest(Module *creator) : Command(creator, "hostserv/request", 1, 1) { @@ -174,21 +202,21 @@ class CommandHSRequest : public Command } time_t send_delay = Config->GetModule("memoserv")->Get<time_t>("senddelay"); - if (Config->GetModule(this->owner)->Get<bool>("memooper") && send_delay > 0 && u && u->lastmemosend + send_delay > Anope::CurTime) + if (Config->GetModule(this->GetOwner())->Get<bool>("memooper") && send_delay > 0 && u && u->lastmemosend + send_delay > Anope::CurTime) { source.Reply(_("Please wait %d seconds before requesting a new vHost."), send_delay); u->lastmemosend = Anope::CurTime; return; } - HostRequest *req = hostrequest.Create(); + HostRequest *req = Serialize::New<HostRequest *>(); req->SetNick(na); req->SetIdent(user); req->SetHost(host); req->SetTime(Anope::CurTime); source.Reply(_("Your vhost has been requested.")); - req_send_memos(owner, source, user, host); + this->SendMemos(source, user, host); Log(LOG_COMMAND, source, this) << "to request new vhost " << (!user.empty() ? user + "@" : "") << host; } @@ -201,6 +229,8 @@ class CommandHSRequest : public Command class CommandHSActivate : public Command { + ServiceReference<MemoServ::MemoServService> memoserv; + public: CommandHSActivate(Module *creator) : Command(creator, "hostserv/activate", 1, 1) { @@ -233,10 +263,10 @@ class CommandHSActivate : public Command } na->SetVhost(req->GetIdent(), req->GetHost(), source.GetNick(), req->GetTime()); - Event::OnSetVhost(&Event::SetVhost::OnSetVhost, na); + EventManager::Get()->Dispatch(&Event::SetVhost::OnSetVhost, na); - if (Config->GetModule(this->owner)->Get<bool>("memouser") && MemoServ::service) - MemoServ::service->Send(source.service->nick, na->GetNick(), _("[auto memo] Your requested vHost has been approved."), true); + if (Config->GetModule(this->GetOwner())->Get<bool>("memouser") && memoserv) + memoserv->Send(source.service->nick, na->GetNick(), _("[auto memo] Your requested vHost has been approved."), true); source.Reply(_("Vhost for \002{0}\002 has been activated."), na->GetNick()); Log(LOG_COMMAND, source, this) << "for " << na->GetNick() << " for vhost " << (!req->GetIdent().empty() ? req->GetIdent() + "@" : "") << req->GetHost(); @@ -246,7 +276,7 @@ class CommandHSActivate : public Command bool OnHelp(CommandSource &source, const Anope::string &subcommand) override { source.Reply(_("Activate the requested vhost for the given user.")); - if (Config->GetModule(this->owner)->Get<bool>("memouser")) + if (Config->GetModule(this->GetOwner())->Get<bool>("memouser")) source.Reply(_("A memo informing the user will also be sent.")); return true; @@ -255,6 +285,8 @@ class CommandHSActivate : public Command class CommandHSReject : public Command { + ServiceReference<MemoServ::MemoServService> memoserv; + public: CommandHSReject(Module *creator) : Command(creator, "hostserv/reject", 1, 2) { @@ -289,7 +321,7 @@ class CommandHSReject : public Command req->Delete(); - if (Config->GetModule(this->owner)->Get<bool>("memouser") && MemoServ::service) + if (Config->GetModule(this->GetOwner())->Get<bool>("memouser") && memoserv) { Anope::string message; if (!reason.empty()) @@ -297,7 +329,7 @@ class CommandHSReject : public Command else message = _("[auto memo] Your requested vHost has been rejected."); - MemoServ::service->Send(source.service->nick, nick, Language::Translate(source.GetAccount(), message.c_str()), true); + memoserv->Send(source.service->nick, nick, Language::Translate(source.GetAccount(), message.c_str()), true); } source.Reply(_("Vhost for \002{0}\002 has been rejected."), na->GetNick()); @@ -307,7 +339,7 @@ class CommandHSReject : public Command bool OnHelp(CommandSource &source, const Anope::string &subcommand) override { source.Reply(_("Reject the requested vhost for the given user.")); - if (Config->GetModule(this->owner)->Get<bool>("memouser")) + if (Config->GetModule(this->GetOwner())->Get<bool>("memouser")) source.Reply(_("A memo informing the user will also be sent, which includes the reason for the rejection if supplied.")); return true; @@ -325,12 +357,12 @@ class CommandHSWaiting : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { unsigned counter = 0; - unsigned display_counter = 0, listmax = Config->GetModule(this->owner)->Get<unsigned>("listmax"); + unsigned display_counter = 0, listmax = Config->GetModule(this->GetOwner())->Get<unsigned>("listmax"); ListFormatter list(source.GetAccount()); list.AddColumn(_("Number")).AddColumn(_("Nick")).AddColumn(_("Vhost")).AddColumn(_("Created")); - for (HostRequest *hr : Serialize::GetObjects<HostRequest *>(hostrequest)) + for (HostRequest *hr : Serialize::GetObjects<HostRequest *>()) { if (!listmax || display_counter < listmax) { @@ -388,27 +420,4 @@ class HSRequest : public Module } }; -static void req_send_memos(Module *me, CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost) -{ - Anope::string host; - std::list<std::pair<Anope::string, Anope::string> >::iterator it, it_end; - - if (!vIdent.empty()) - host = vIdent + "@" + vHost; - else - host = vHost; - - if (Config->GetModule(me)->Get<bool>("memooper") && MemoServ::service) - for (Oper *o : Serialize::GetObjects<Oper *>(operblock)) - { - NickServ::Nick *na = NickServ::FindNick(o->GetName()); - if (!na) - continue; - - Anope::string message = Anope::printf(_("[auto memo] vHost \002%s\002 has been requested by %s."), host.c_str(), source.GetNick().c_str()); - - MemoServ::service->Send(source.service->nick, na->GetNick(), message, true); - } -} - MODULE_INIT(HSRequest) diff --git a/modules/hostserv/set.cpp b/modules/hostserv/set.cpp index a86afead4..e7f42e630 100644 --- a/modules/hostserv/set.cpp +++ b/modules/hostserv/set.cpp @@ -86,7 +86,7 @@ class CommandHSSet : public Command Log(LOG_ADMIN, source, this) << "to set the vhost of " << na->GetNick() << " to " << (!user.empty() ? user + "@" : "") << host; na->SetVhost(user, host, source.GetNick()); - Event::OnSetVhost(&Event::SetVhost::OnSetVhost, na); + EventManager::Get()->Dispatch(&Event::SetVhost::OnSetVhost, na); if (!user.empty()) source.Reply(_("Vhost for \002{0}\002 set to \002{0}\002@\002{1}\002."), nick, user, host); else @@ -107,7 +107,7 @@ class CommandHSSetAll : public Command if (!na || !na->HasVhost()) return; - for (NickServ::Nick *nick : na->GetAccount()->GetRefs<NickServ::Nick *>(NickServ::nick)) + for (NickServ::Nick *nick : na->GetAccount()->GetRefs<NickServ::Nick *>()) nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); } @@ -184,7 +184,7 @@ class CommandHSSetAll : public Command na->SetVhost(user, host, source.GetNick()); this->Sync(na); - Event::OnSetVhost(&Event::SetVhost::OnSetVhost, na); + EventManager::Get()->Dispatch(&Event::SetVhost::OnSetVhost, na); if (!user.empty()) source.Reply(_("Vhost for group \002{0}\002 set to \002{1}\002@\002{2}\002."), nick.c_str(), user.c_str(), host.c_str()); else diff --git a/modules/httpd.cpp b/modules/httpd.cpp index 1627ef133..ea0327316 100644 --- a/modules/httpd.cpp +++ b/modules/httpd.cpp @@ -340,7 +340,7 @@ class HTTPD : public Module std::map<Anope::string, MyHTTPProvider *> providers; public: HTTPD(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) - , sslref("SSLService", "ssl") + , EventHook<Event::ModuleLoad>(this) { } @@ -445,10 +445,10 @@ class HTTPD : public Module HTTPProvider *p = it->second; ++it; - if (existing.count(p->name) == 0) + if (existing.count(p->GetName()) == 0) { - Log(this) << "Removing HTTP server " << p->name; - this->providers.erase(p->name); + Log(this) << "Removing HTTP server " << p->GetName(); + this->providers.erase(p->GetName()); delete p; } } diff --git a/modules/memoserv/cancel.cpp b/modules/memoserv/cancel.cpp index e3da82581..fe61fe18c 100644 --- a/modules/memoserv/cancel.cpp +++ b/modules/memoserv/cancel.cpp @@ -32,7 +32,7 @@ class CommandMSCancel : public Command const Anope::string &nname = params[0]; bool ischan, isregistered; - MemoServ::MemoInfo *mi = MemoServ::service->GetMemoInfo(name, ischan, isregistered, false); + MemoServ::MemoInfo *mi = MemoServ::service->GetMemoInfo(nname, ischan, isregistered, false); if (!isregistered) { @@ -57,8 +57,7 @@ class CommandMSCancel : public Command MemoServ::Memo *m = memos[i]; if (m->GetUnread() && source.nc->GetDisplay().equals_ci(m->GetSender())) { - if (MemoServ::Event::OnMemoDel) - MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ischan ? ci->GetName() : na->GetAccount()->GetDisplay(), mi, m); + EventManager::Get()->Dispatch(&MemoServ::Event::MemoDel::OnMemoDel, ischan ? ci->GetName() : na->GetAccount()->GetDisplay(), mi, m); mi->Del(i); source.Reply(_("Your last memo to \002{0}\002 has been cancelled."), nname); return; diff --git a/modules/memoserv/del.cpp b/modules/memoserv/del.cpp index 79af11adc..dffa3c8cd 100644 --- a/modules/memoserv/del.cpp +++ b/modules/memoserv/del.cpp @@ -81,8 +81,7 @@ class CommandMSDel : public Command if (!number || number > memos.size()) return; - if (MemoServ::Event::OnMemoDel) - MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->GetName() : source.nc->GetDisplay(), mi, mi->GetMemo(number - 1)); + EventManager::Get()->Dispatch(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->GetName() : source.nc->GetDisplay(), mi, mi->GetMemo(number - 1)); mi->Del(number - 1); source.Reply(_("Memo \002{0}\002 has been deleted."), number); @@ -92,8 +91,7 @@ class CommandMSDel : public Command else if (numstr.equals_ci("LAST")) { /* Delete last memo. */ - if (MemoServ::Event::OnMemoDel) - MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->GetName() : source.nc->GetDisplay(), mi, mi->GetMemo(memos.size() - 1)); + EventManager::Get()->Dispatch(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->GetName() : source.nc->GetDisplay(), mi, mi->GetMemo(memos.size() - 1)); mi->Del(memos.size() - 1); source.Reply(_("Memo \002{0}\002 has been deleted."), memos.size() + 1); } @@ -103,8 +101,7 @@ class CommandMSDel : public Command std::for_each(memos.begin(), memos.end(), [&](MemoServ::Memo *m) { - if (MemoServ::Event::OnMemoDel) - MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->GetName() : source.nc->GetDisplay(), mi, m); + EventManager::Get()->Dispatch(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->GetName() : source.nc->GetDisplay(), mi, m); delete m; }); if (!chan.empty()) diff --git a/modules/memoserv/ignore.cpp b/modules/memoserv/ignore.cpp index c454444ea..7dad842cf 100644 --- a/modules/memoserv/ignore.cpp +++ b/modules/memoserv/ignore.cpp @@ -66,7 +66,7 @@ class CommandMSIgnore : public Command if (command.equals_ci("ADD") && !param.empty()) { - if (ignores.size() >= Config->GetModule(this->owner)->Get<unsigned>("max", "32")) + if (ignores.size() >= Config->GetModule(this->GetOwner())->Get<unsigned>("max", "32")) { source.Reply(_("Sorry, the memo ignore list for \002{0}\002 is full."), channel); return; @@ -79,7 +79,7 @@ class CommandMSIgnore : public Command return; } - MemoServ::Ignore *ign = MemoServ::service->CreateIgnore(); + MemoServ::Ignore *ign = Serialize::New<MemoServ::Ignore *>(); ign->SetMemoInfo(mi); ign->SetMask(param); diff --git a/modules/memoserv/main/ignore.h b/modules/memoserv/main/ignore.h index c98b44adf..0147cc2be 100644 --- a/modules/memoserv/main/ignore.h +++ b/modules/memoserv/main/ignore.h @@ -2,6 +2,11 @@ class IgnoreImpl : public MemoServ::Ignore { + friend class IgnoreType; + + MemoServ::MemoInfo *memoinfo = nullptr; + Anope::string mask; + public: IgnoreImpl(Serialize::TypeBase *type) : MemoServ::Ignore(type) { } IgnoreImpl(Serialize::TypeBase *type, Serialize::ID id) : MemoServ::Ignore(type, id) { } diff --git a/modules/memoserv/main/ignoretype.cpp b/modules/memoserv/main/ignoretype.cpp index 375f83272..015925b5f 100644 --- a/modules/memoserv/main/ignoretype.cpp +++ b/modules/memoserv/main/ignoretype.cpp @@ -1,9 +1,9 @@ #include "module.h" #include "ignoretype.h" -IgnoreType::IgnoreType(Module *me) : Serialize::Type<IgnoreImpl>(me, "MemoIgnore") - , mi(this, "mi", true) - , mask(this, "mask") +IgnoreType::IgnoreType(Module *me) : Serialize::Type<IgnoreImpl>(me) + , mi(this, "mi", &IgnoreImpl::memoinfo, true) + , mask(this, "mask", &IgnoreImpl::mask) { } diff --git a/modules/memoserv/main/memo.h b/modules/memoserv/main/memo.h index 1a230c1e9..c0000259a 100644 --- a/modules/memoserv/main/memo.h +++ b/modules/memoserv/main/memo.h @@ -2,11 +2,16 @@ class MemoImpl : public MemoServ::Memo { + friend class MemoType; + + MemoServ::MemoInfo *memoinfo = nullptr; + Anope::string text, sender; + time_t time = 0; + bool unread = false, receipt = false; + public: MemoImpl(Serialize::TypeBase *type) : MemoServ::Memo(type) { } MemoImpl(Serialize::TypeBase *type, Serialize::ID id) : MemoServ::Memo(type, id) { } - //using MemoServ::Memo::Memo; -// MemoImpl(); ~MemoImpl(); MemoServ::MemoInfo *GetMemoInfo() override; diff --git a/modules/memoserv/main/memoinfo.cpp b/modules/memoserv/main/memoinfo.cpp index 45d95533e..5f3b4cccc 100644 --- a/modules/memoserv/main/memoinfo.cpp +++ b/modules/memoserv/main/memoinfo.cpp @@ -53,11 +53,11 @@ void MemoInfoImpl::SetMemoMax(const int16_t &i) std::vector<MemoServ::Memo *> MemoInfoImpl::GetMemos() { - return GetRefs<MemoServ::Memo *>(MemoServ::memo); + return GetRefs<MemoServ::Memo *>(); } std::vector<MemoServ::Ignore *> MemoInfoImpl::GetIgnores() { - return GetRefs<MemoServ::Ignore *>(MemoServ::ignore); + return GetRefs<MemoServ::Ignore *>(); } diff --git a/modules/memoserv/main/memoinfo.h b/modules/memoserv/main/memoinfo.h index 22ea0734f..42f5483ac 100644 --- a/modules/memoserv/main/memoinfo.h +++ b/modules/memoserv/main/memoinfo.h @@ -2,6 +2,11 @@ class MemoInfoImpl : public MemoServ::MemoInfo { + friend class MemoInfoType; + + Serialize::Object *owner = nullptr; + int16_t memomax = 0; + public: MemoInfoImpl(Serialize::TypeBase *type) : MemoServ::MemoInfo(type) { } MemoInfoImpl(Serialize::TypeBase *type, Serialize::ID id) : MemoServ::MemoInfo(type, id) { } diff --git a/modules/memoserv/main/memoinfotype.cpp b/modules/memoserv/main/memoinfotype.cpp index 7eb3af72c..ff387e883 100644 --- a/modules/memoserv/main/memoinfotype.cpp +++ b/modules/memoserv/main/memoinfotype.cpp @@ -1,9 +1,9 @@ #include "module.h" #include "memoinfotype.h" -MemoInfoType::MemoInfoType(Module *me) : Serialize::Type<MemoInfoImpl>(me, "MemoInfo") - , owner(this, "owner", true) - , memomax(this, "memomax") +MemoInfoType::MemoInfoType(Module *me) : Serialize::Type<MemoInfoImpl>(me) + , owner(this, "owner", &MemoInfoImpl::owner, true) + , memomax(this, "memomax", &MemoInfoImpl::memomax) { } diff --git a/modules/memoserv/main/memoserv.cpp b/modules/memoserv/main/memoserv.cpp index ed3939ef7..79344b25e 100644 --- a/modules/memoserv/main/memoserv.cpp +++ b/modules/memoserv/main/memoserv.cpp @@ -14,16 +14,13 @@ #include "modules/help.h" #include "modules/botserv/bot.h" #include "modules/memoserv.h" -//#include "memoinfo.h" -//#include "memo.h" -//#include "ignore.h" #include "memotype.h" #include "memoinfotype.h" #include "ignoretype.h" class MemoServCore : public Module, public MemoServ::MemoServService - , public EventHook<Event::NickCoreCreate> - , public EventHook<Event::CreateChan> + , public EventHook<NickServ::Event::NickRegister> + , public EventHook<Event::ChanRegistered> , public EventHook<Event::BotDelete> , public EventHook<Event::NickIdentify> , public EventHook<Event::JoinChannel> @@ -32,8 +29,6 @@ class MemoServCore : public Module, public MemoServ::MemoServService , public EventHook<Event::Help> { Reference<ServiceBot> MemoServ; - EventHandlers<MemoServ::Event::MemoSend> onmemosend; - EventHandlers<MemoServ::Event::MemoDel> onmemodel; MemoInfoType memoinfo_type; MemoType memo_type; @@ -62,8 +57,16 @@ class MemoServCore : public Module, public MemoServ::MemoServService public: MemoServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) , MemoServ::MemoServService(this) - , onmemosend(this) - , onmemodel(this) + + , EventHook<NickServ::Event::NickRegister>(this) + , EventHook<Event::ChanRegistered>(this) + , EventHook<Event::BotDelete>(this) + , EventHook<Event::NickIdentify>(this) + , EventHook<Event::JoinChannel>(this) + , EventHook<Event::UserAway>(this) + , EventHook<Event::NickUpdate>(this) + , EventHook<Event::Help>(this) + , memoinfo_type(this) , memo_type(this) , ignore_type(this) @@ -95,14 +98,14 @@ class MemoServCore : public Module, public MemoServ::MemoServService if (sender != NULL) sender->lastmemosend = Anope::CurTime; - MemoServ::Memo *m = new MemoImpl(&memo_type); + MemoServ::Memo *m = Serialize::New<MemoServ::Memo *>(); m->SetMemoInfo(mi); m->SetSender(source); m->SetTime(Anope::CurTime); m->SetText(message); m->SetUnread(true); - this->onmemosend(&MemoServ::Event::MemoSend::OnMemoSend, source, target, mi, m); + EventManager::Get()->Dispatch(&MemoServ::Event::MemoSend::OnMemoSend, source, target, mi, m); if (ischan) { @@ -160,16 +163,6 @@ class MemoServCore : public Module, public MemoServ::MemoServService } } - MemoServ::Memo *CreateMemo() override - { - return new MemoImpl(&memo_type); - } - - MemoServ::Ignore *CreateIgnore() override - { - return new IgnoreImpl(&ignore_type); - } - MemoServ::MemoInfo *GetMemoInfo(const Anope::string &target, bool &is_registered, bool &ischan, bool create) override { if (!target.empty() && target[0] == '#') @@ -181,7 +174,7 @@ class MemoServCore : public Module, public MemoServ::MemoServService is_registered = true; if (create && !ci->GetMemos()) { - MemoServ::MemoInfo *mi = new MemoInfoImpl(&memoinfo_type); + MemoServ::MemoInfo *mi = Serialize::New<MemoServ::MemoInfo *>(); mi->SetOwner(ci); } return ci->GetMemos(); @@ -198,7 +191,7 @@ class MemoServCore : public Module, public MemoServ::MemoServService is_registered = true; if (create && !na->GetAccount()->GetMemos()) { - MemoServ::MemoInfo *mi = new MemoInfoImpl(&memoinfo_type); + MemoServ::MemoInfo *mi = Serialize::New<MemoServ::MemoInfo *>(); mi->SetOwner(na->GetAccount()); } return na->GetAccount()->GetMemos(); @@ -224,16 +217,16 @@ class MemoServCore : public Module, public MemoServ::MemoServService MemoServ = bi; } - void OnNickCoreCreate(NickServ::Account *nc) override + void OnNickRegister(User *, NickServ::Nick *na, const Anope::string &) override { - MemoServ::MemoInfo *mi = new MemoInfoImpl(&memoinfo_type); - mi->SetOwner(mi); + MemoServ::MemoInfo *mi = Serialize::New<MemoServ::MemoInfo *>(); + mi->SetOwner(na->GetAccount()); mi->SetMemoMax(Config->GetModule(this)->Get<int>("maxmemos")); } - void OnCreateChan(ChanServ::Channel *ci) override + void OnChanRegistered(ChanServ::Channel *ci) override { - MemoServ::MemoInfo *mi = new MemoInfoImpl(&memoinfo_type); + MemoServ::MemoInfo *mi = Serialize::New<MemoServ::MemoInfo *>(); mi->SetOwner(ci); mi->SetMemoMax(Config->GetModule(this)->Get<int>("maxmemos")); } diff --git a/modules/memoserv/main/memotype.cpp b/modules/memoserv/main/memotype.cpp index c9144bbaa..57cf3ba31 100644 --- a/modules/memoserv/main/memotype.cpp +++ b/modules/memoserv/main/memotype.cpp @@ -1,13 +1,13 @@ #include "module.h" #include "memotype.h" -MemoType::MemoType(Module *me) : Serialize::Type<MemoImpl>(me, "Memo") - , mi(this, "mi", true) - , time(this, "time") - , sender(this, "sender") - , text(this, "text") - , unread(this, "unread") - , receipt(this, "receipt") +MemoType::MemoType(Module *me) : Serialize::Type<MemoImpl>(me) + , mi(this, "mi", &MemoImpl::memoinfo, true) + , time(this, "time", &MemoImpl::time) + , sender(this, "sender", &MemoImpl::sender) + , text(this, "text", &MemoImpl::text) + , unread(this, "unread", &MemoImpl::unread) + , receipt(this, "receipt", &MemoImpl::receipt) { } diff --git a/modules/memoserv/rsend.cpp b/modules/memoserv/rsend.cpp index 16f6105fa..887c87cc6 100644 --- a/modules/memoserv/rsend.cpp +++ b/modules/memoserv/rsend.cpp @@ -23,6 +23,7 @@ class CommandMSRSend : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { +#warning "this is completely disabled" #if 0 if (!MemoServ::service) return; @@ -44,7 +45,7 @@ class CommandMSRSend : public Command return; } - if (Config->GetModule(this->owner)->Get<bool>("operonly") && !source.IsServicesOper()) + if (Config->GetModule(this->GetOwner())->Get<bool>("operonly") && !source.IsServicesOper()) source.Reply(_("Access denied. This command is for operators only.")); else { diff --git a/modules/memoserv/set.cpp b/modules/memoserv/set.cpp index c924d0ea0..361ebeba3 100644 --- a/modules/memoserv/set.cpp +++ b/modules/memoserv/set.cpp @@ -301,11 +301,11 @@ class MSSet : public Module public: MSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) , commandmsset(this) - , memo_signon(this, NickServ::account, "MEMO_SIGNON") - , memo_receive(this, NickServ::account, "MEMO_RECEIVE") - , memo_mail(this, NickServ::account, "MEMO_MAIL") - , memo_hardmax_nick(this, NickServ::account, "MEMO_HARDMAX") - , memo_hardmax_channel(this, ChanServ::channel, "MEMO_HARDMAX") + , memo_signon(this, "MEMO_SIGNON") + , memo_receive(this, "MEMO_RECEIVE") + , memo_mail(this, "MEMO_MAIL") + , memo_hardmax_nick(this, "MEMO_HARDMAX") + , memo_hardmax_channel(this, "MEMO_HARDMAX") { } diff --git a/modules/nickserv/access.cpp b/modules/nickserv/access.cpp index 0e405484c..f29b98904 100644 --- a/modules/nickserv/access.cpp +++ b/modules/nickserv/access.cpp @@ -15,6 +15,11 @@ class NickAccessImpl : public NickAccess { + friend class NickAccessType; + + NickServ::Account *account = nullptr; + Anope::string mask; + public: NickAccessImpl(Serialize::TypeBase *type) : NickAccess(type) { } NickAccessImpl(Serialize::TypeBase *type, Serialize::ID id) : NickAccess(type, id) { } @@ -32,9 +37,9 @@ class NickAccessType : public Serialize::Type<NickAccessImpl> Serialize::ObjectField<NickAccessImpl, NickServ::Account *> account; Serialize::Field<NickAccessImpl, Anope::string> mask; - NickAccessType(Module *creator) : Serialize::Type<NickAccessImpl>(creator, "NSAccess") - , account(this, "account", true) - , mask(this, "mask") + NickAccessType(Module *creator) : Serialize::Type<NickAccessImpl>(creator) + , account(this, "account", &NickAccessImpl::account, true) + , mask(this, "mask", &NickAccessImpl::mask) { } }; @@ -76,11 +81,11 @@ class CommandNSAccess : public Command return; } - std::vector<NickAccess *> access = nc->GetRefs<NickAccess *>(nsaccess); + std::vector<NickAccess *> access = nc->GetRefs<NickAccess *>(); - if (access.size() >= Config->GetModule(this->owner)->Get<unsigned>("accessmax", "32")) + if (access.size() >= Config->GetModule(this->GetOwner())->Get<unsigned>("accessmax", "32")) { - source.Reply(_("Sorry, the maximum of \002{0}\002 access entries has been reached."), Config->GetModule(this->owner)->Get<unsigned>("accessmax")); + source.Reply(_("Sorry, the maximum of \002{0}\002 access entries has been reached."), Config->GetModule(this->GetOwner())->Get<unsigned>("accessmax")); return; } @@ -91,7 +96,7 @@ class CommandNSAccess : public Command return; } - NickAccess *a = nsaccess.Create(); + NickAccess *a = Serialize::New<NickAccess *>(); a->SetAccount(nc); a->SetMask(mask); @@ -113,7 +118,7 @@ class CommandNSAccess : public Command return; } - for (NickAccess *a : nc->GetRefs<NickAccess *>(nsaccess)) + for (NickAccess *a : nc->GetRefs<NickAccess *>()) if (a->GetMask().equals_ci(mask)) { a->Delete(); @@ -128,7 +133,7 @@ class CommandNSAccess : public Command void DoList(CommandSource &source, NickServ::Account *nc, const Anope::string &mask) { - std::vector<NickAccess *> access = nc->GetRefs<NickAccess *>(nsaccess); + std::vector<NickAccess *> access = nc->GetRefs<NickAccess *>(); if (access.empty()) { source.Reply(_("The access list of \002{0}\002 is empty."), nc->GetDisplay()); @@ -236,6 +241,7 @@ class NSAccess : public Module public: NSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<NickServ::Event::NickRegister>(this) , commandnsaccess(this) , nick_type(this) { @@ -245,11 +251,12 @@ class NSAccess : public Module { if (u && Config->GetModule(this)->Get<bool>("addaccessonreg")) { - NickAccess *a = nsaccess.Create(); + NickAccess *a = Serialize::New<NickAccess *>(); a->SetAccount(na->GetAccount()); a->SetMask(u->Mask()); - //XXX? -// source.Reply(_("\002{0}\002 has been registered under your hostmask: \002{1}\002"), u_nick, na->GetAccount()->GetAccess(0)); + + u->SendMessage(Config->GetClient("NickServ"), + _("\002{0}\002 has been registered under your hostmask: \002{1}\002"), na->GetNick(), a->GetMask()); } } }; diff --git a/modules/nickserv/ajoin.cpp b/modules/nickserv/ajoin.cpp index 0b074a84a..fc5e9b198 100644 --- a/modules/nickserv/ajoin.cpp +++ b/modules/nickserv/ajoin.cpp @@ -14,6 +14,11 @@ class AutoJoinImpl : public AutoJoin { + friend class AutoJoinType; + + NickServ::Account *account = nullptr; + Anope::string channel, key; + public: AutoJoinImpl(Serialize::TypeBase *type) : AutoJoin(type) { } AutoJoinImpl(Serialize::TypeBase *type, Serialize::ID id) : AutoJoin(type, id) { } @@ -34,10 +39,10 @@ class AutoJoinType : public Serialize::Type<AutoJoinImpl> Serialize::ObjectField<AutoJoinImpl, NickServ::Account *> owner; Serialize::Field<AutoJoinImpl, Anope::string> channel, key; - AutoJoinType(Module *me) : Serialize::Type<AutoJoinImpl>(me, "AutoJoin") - , owner(this, "owner", true) - , channel(this, "channel") - , key(this, "key") + AutoJoinType(Module *me) : Serialize::Type<AutoJoinImpl>(me) + , owner(this, "owner", &AutoJoinImpl::account, true) + , channel(this, "channel", &AutoJoinImpl::channel) + , key(this, "key", &AutoJoinImpl::key) { } }; @@ -76,7 +81,7 @@ class CommandNSAJoin : public Command { void DoList(CommandSource &source, NickServ::Account *nc) { - std::vector<AutoJoin *> channels = nc->GetRefs<AutoJoin *>(autojoin); + std::vector<AutoJoin *> channels = nc->GetRefs<AutoJoin *>(); if (channels.empty()) { @@ -107,7 +112,7 @@ class CommandNSAJoin : public Command void DoAdd(CommandSource &source, NickServ::Account *nc, const Anope::string &chans, const Anope::string &keys) { - std::vector<AutoJoin *> channels = nc->GetRefs<AutoJoin *>(autojoin); + std::vector<AutoJoin *> channels = nc->GetRefs<AutoJoin *>(); Anope::string addedchans; Anope::string alreadyadded; @@ -123,9 +128,9 @@ class CommandNSAJoin : public Command if (channels[i]->GetChannel().equals_ci(chan)) break; - if (channels.size() >= Config->GetModule(this->owner)->Get<unsigned>("ajoinmax")) + if (channels.size() >= Config->GetModule(this->GetOwner())->Get<unsigned>("ajoinmax")) { - source.Reply(_("Sorry, the maximum of \002{0}\002 auto join entries has been reached."), Config->GetModule(this->owner)->Get<unsigned>("ajoinmax")); + source.Reply(_("Sorry, the maximum of \002{0}\002 auto join entries has been reached."), Config->GetModule(this->GetOwner())->Get<unsigned>("ajoinmax")); return; } @@ -143,7 +148,7 @@ class CommandNSAJoin : public Command continue; } - AutoJoin *entry = autojoin.Create(); + AutoJoin *entry = Serialize::New<AutoJoin *>(); entry->SetOwner(nc); entry->SetChannel(chan); entry->SetKey(key); @@ -174,7 +179,7 @@ class CommandNSAJoin : public Command void DoDel(CommandSource &source, NickServ::Account *nc, const Anope::string &chans) { - std::vector<AutoJoin *> channels = nc->GetRefs<AutoJoin *>(autojoin); + std::vector<AutoJoin *> channels = nc->GetRefs<AutoJoin *>(); Anope::string delchans; Anope::string notfoundchans; commasepstream sep(chans); @@ -282,6 +287,7 @@ class NSAJoin : public Module public: NSAJoin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::UserLogin>(this) , commandnsajoin(this) , ajtype(this) { @@ -297,7 +303,7 @@ class NSAJoin : public Module if (!NickServ) return; - std::vector<AutoJoin *> channels = u->Account()->GetRefs<AutoJoin *>(autojoin); + std::vector<AutoJoin *> channels = u->Account()->GetRefs<AutoJoin *>(); if (channels.empty()) return; diff --git a/modules/nickserv/alist.cpp b/modules/nickserv/alist.cpp index e4aaff38b..f80af7cb1 100644 --- a/modules/nickserv/alist.cpp +++ b/modules/nickserv/alist.cpp @@ -47,7 +47,7 @@ class CommandNSAList : public Command list.AddColumn(_("Number")).AddColumn(_("Channel")).AddColumn(_("Access")).AddColumn(_("Description")); - std::vector<ChanServ::Channel *> chans = nc->GetRefs<ChanServ::Channel *>(ChanServ::channel); + std::vector<ChanServ::Channel *> chans = nc->GetRefs<ChanServ::Channel *>(); std::sort(chans.begin(), chans.end(), ChannelSort); for (ChanServ::Channel *ci : chans) { diff --git a/modules/nickserv/cert.cpp b/modules/nickserv/cert.cpp index 23487f305..6df85aacd 100644 --- a/modules/nickserv/cert.cpp +++ b/modules/nickserv/cert.cpp @@ -14,7 +14,6 @@ #include "modules/nickserv.h" static Anope::hash_map<NickServ::Account *> certmap; -static EventHandlers<Event::NickCertEvents> *events; class CertServiceImpl : public CertService { @@ -31,7 +30,7 @@ class CertServiceImpl : public CertService bool Matches(User *u, NickServ::Account *nc) override { - std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>(certentry); + std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>(); return !u->fingerprint.empty() && FindCert(cl, u->fingerprint); } @@ -46,6 +45,11 @@ class CertServiceImpl : public CertService class NSCertEntryImpl : public NSCertEntry { + friend class NSCertEntryType; + + NickServ::Account *account = nullptr; + Anope::string cert; + public: NSCertEntryImpl(Serialize::TypeBase *type) : NSCertEntry(type) { } NSCertEntryImpl(Serialize::TypeBase *type, Serialize::ID id) : NSCertEntry(type, id) { } @@ -95,9 +99,9 @@ class NSCertEntryType : public Serialize::Type<NSCertEntryImpl> } } mask; - NSCertEntryType(Module *me) : Serialize::Type<NSCertEntryImpl>(me, "NSCertEntry") - , nc(this, "nc", true) - , mask(this, "mask") + NSCertEntryType(Module *me) : Serialize::Type<NSCertEntryImpl>(me) + , nc(this, "nc", &NSCertEntryImpl::account, true) + , mask(this, "mask", &NSCertEntryImpl::cert) { } }; @@ -141,8 +145,8 @@ class CommandNSCert : public Command void DoAdd(CommandSource &source, NickServ::Account *nc, Anope::string certfp) { - std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>(certentry); - unsigned max = Config->GetModule(this->owner)->Get<unsigned>("max", "5"); + std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>(); + unsigned max = Config->GetModule(this->GetOwner())->Get<unsigned>("max", "5"); if (cl.size() >= max) { @@ -175,9 +179,11 @@ class CommandNSCert : public Command return; } - NSCertEntry *e = certentry.Create(); + NSCertEntry *e = Serialize::New<NSCertEntry *>(); e->SetAccount(nc); e->SetCert(certfp); + + // XXX fire events Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to ADD certificate fingerprint " << certfp << " to " << nc->GetDisplay(); source.Reply(_("\002{0}\002 added to the certificate list of \002{1}\002."), certfp, nc->GetDisplay()); @@ -185,7 +191,7 @@ class CommandNSCert : public Command void DoDel(CommandSource &source, NickServ::Account *nc, Anope::string certfp) { - std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>(certentry); + std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>(); if (certfp.empty()) { @@ -215,7 +221,7 @@ class CommandNSCert : public Command void DoList(CommandSource &source, NickServ::Account *nc) { - std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>(certentry); + std::vector<NSCertEntry *> cl = nc->GetRefs<NSCertEntry *>(); if (cl.empty()) { @@ -309,18 +315,15 @@ class NSCert : public Module CommandNSCert commandnscert; CertServiceImpl cs; - EventHandlers<Event::NickCertEvents> onnickservevents; - public: NSCert(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::Fingerprint>(this) + , EventHook<NickServ::Event::NickValidate>(this) , commandnscert(this) , cs(this) - , onnickservevents(this) { if (!IRCD || !IRCD->CanCertFP) throw ModuleException("Your IRCd does not support ssl client certificates"); - - events = &onnickservevents; } void OnFingerprint(User *u) override diff --git a/modules/nickserv/drop.cpp b/modules/nickserv/drop.cpp index e1eba9a3c..e45f1e2ea 100644 --- a/modules/nickserv/drop.cpp +++ b/modules/nickserv/drop.cpp @@ -14,10 +14,8 @@ class CommandNSDrop : public Command { - EventHandlers<Event::NickDrop> &onnickdrop; - public: - CommandNSDrop(Module *creator, EventHandlers<Event::NickDrop> &event) : Command(creator, "nickserv/drop", 1, 1), onnickdrop(event) + CommandNSDrop(Module *creator) : Command(creator, "nickserv/drop", 1, 1) { this->SetSyntax(_("\037nickname\037")); this->SetDesc(_("Cancel the registration of a nickname")); @@ -54,7 +52,7 @@ class CommandNSDrop : public Command return; } - this->onnickdrop(&Event::NickDrop::OnNickDrop, source, na); + EventManager::Get()->Dispatch(&Event::NickDrop::OnNickDrop, source, na); Log(!is_mine ? LOG_ADMIN : LOG_COMMAND, source, this) << "to drop nickname " << na->GetNick() << " (group: " << na->GetAccount()->GetDisplay() << ") (email: " << (!na->GetAccount()->GetEmail().empty() ? na->GetAccount()->GetEmail() : "none") << ")"; na->Delete(); @@ -77,12 +75,10 @@ class CommandNSDrop : public Command class NSDrop : public Module { CommandNSDrop commandnsdrop; - EventHandlers<Event::NickDrop> onnickdrop; public: NSDrop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandnsdrop(this, onnickdrop) - , onnickdrop(this) + , commandnsdrop(this) { } diff --git a/modules/nickserv/group.cpp b/modules/nickserv/group.cpp index 3a50d0306..5c9fb326f 100644 --- a/modules/nickserv/group.cpp +++ b/modules/nickserv/group.cpp @@ -15,14 +15,13 @@ class NSGroupRequestListener : public NickServ::IdentifyRequestListener { - EventHandlers<Event::NickGroup> &onnickgroup; CommandSource source; Command *cmd; Anope::string nick; Reference<NickServ::Nick> target; public: - NSGroupRequestListener(EventHandlers<Event::NickGroup> &event, CommandSource &src, Command *c, const Anope::string &n, NickServ::Nick *targ) : onnickgroup(event), source(src), cmd(c), nick(n), target(targ) { } + NSGroupRequestListener(CommandSource &src, Command *c, const Anope::string &n, NickServ::Nick *targ) : source(src), cmd(c), nick(n), target(targ) { } void OnSuccess(NickServ::IdentifyRequest *) override { @@ -34,11 +33,11 @@ class NSGroupRequestListener : public NickServ::IdentifyRequestListener /* If the nick is already registered, drop it. */ if (na) { - Event::OnChangeCoreDisplay(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, na->GetAccount(), u->nick); + EventManager::Get()->Dispatch(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, na->GetAccount(), u->nick); delete na; } - na = NickServ::nick.Create(); + na = Serialize::New<NickServ::Nick *>(); na->SetNick(nick); na->SetAccount(target->GetAccount()); na->SetLastUsermask(u->GetIdent() + "@" + u->GetDisplayedHost()); @@ -47,7 +46,7 @@ class NSGroupRequestListener : public NickServ::IdentifyRequestListener na->SetTimeRegistered(Anope::CurTime); u->Login(target->GetAccount()); - this->onnickgroup(&Event::NickGroup::OnNickGroup, u, target); + EventManager::Get()->Dispatch(&Event::NickGroup::OnNickGroup, u, target); Log(LOG_COMMAND, source, cmd) << "to make " << nick << " join group of " << target->GetNick() << " (" << target->GetAccount()->GetDisplay() << ") (email: " << (!target->GetAccount()->GetEmail().empty() ? target->GetAccount()->GetEmail() : "none") << ")"; source.Reply(_("You are now in the group of \002{0}\002."), target->GetNick()); @@ -69,10 +68,10 @@ class NSGroupRequestListener : public NickServ::IdentifyRequestListener class CommandNSGroup : public Command { - EventHandlers<Event::NickGroup> &onnickgroup; - + ServiceReference<CertService> certservice; + public: - CommandNSGroup(Module *creator, EventHandlers<Event::NickGroup> &event) : Command(creator, "nickserv/group", 0, 2), onnickgroup(event) + CommandNSGroup(Module *creator) : Command(creator, "nickserv/group", 0, 2) { this->SetDesc(_("Join a group")); this->SetSyntax(_("\037[target]\037 \037[password]\037")); @@ -115,7 +114,7 @@ class CommandNSGroup : public Command } if (Config->GetModule("nickserv")->Get<bool>("restrictopernicks")) - for (Oper *o : Serialize::GetObjects<Oper *>(operblock)) + for (Oper *o : Serialize::GetObjects<Oper *>()) { if (!u->HasMode("OPER") && u->nick.find_ci(o->GetName()) != Anope::string::npos) { @@ -127,7 +126,7 @@ class CommandNSGroup : public Command NickServ::Nick *target, *na = NickServ::FindNick(u->nick); const Anope::string &guestnick = Config->GetModule("nickserv")->Get<Anope::string>("guestnickprefix", "Guest"); time_t reg_delay = Config->GetModule("nickserv")->Get<time_t>("regdelay"); - unsigned maxaliases = Config->GetModule(this->owner)->Get<unsigned>("maxaliases"); + unsigned maxaliases = Config->GetModule(this->GetOwner())->Get<unsigned>("maxaliases"); if (!(target = NickServ::FindNick(nick))) { source.Reply(_("\002{0}\002 isn't registered."), nick); @@ -147,7 +146,7 @@ class CommandNSGroup : public Command return; } - if (na && Config->GetModule(this->owner)->Get<bool>("nogroupchange")) + if (na && Config->GetModule(this->GetOwner())->Get<bool>("nogroupchange")) { source.Reply(_("Your nick is already registered.")); return; @@ -165,13 +164,13 @@ class CommandNSGroup : public Command return; } - if (na && Config->GetModule(this->owner)->Get<bool>("nogroupchange")) + if (na && Config->GetModule(this->GetOwner())->Get<bool>("nogroupchange")) { source.Reply(_("You are already registered.")); return; } - if (maxaliases && target->GetAccount()->GetRefs<NickServ::Nick *>(NickServ::nick).size() >= maxaliases && !target->GetAccount()->IsServicesOper()) + if (maxaliases && target->GetAccount()->GetRefs<NickServ::Nick *>().size() >= maxaliases && !target->GetAccount()->IsServicesOper()) { source.Reply(_("There are too many nicknames in your group.")); return; @@ -194,13 +193,13 @@ class CommandNSGroup : public Command if (ok == false && !pass.empty()) { - NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSGroupRequestListener(onnickgroup, source, this, u->nick, target), owner, target->GetAccount()->GetDisplay(), pass); - Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req); + NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSGroupRequestListener(source, this, u->nick, target), this->GetOwner(), target->GetAccount()->GetDisplay(), pass); + EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req); req->Dispatch(); } else { - NSGroupRequestListener req(onnickgroup, source, this, u->nick, target); + NSGroupRequestListener req(source, this, u->nick, target); if (ok) req.OnSuccess(nullptr); @@ -238,7 +237,7 @@ class CommandNSUngroup : public Command Anope::string nick = !params.empty() ? params[0] : ""; NickServ::Nick *na = NickServ::FindNick(!nick.empty() ? nick : u->nick); - if (u->Account()->GetRefs<NickServ::Nick *>(NickServ::nick).size() == 1) + if (u->Account()->GetRefs<NickServ::Nick *>().size() == 1) { source.Reply(_("Your nickname is not grouped to anything, so you can't ungroup it.")); return; @@ -260,9 +259,9 @@ class CommandNSUngroup : public Command NickServ::Account *oldcore = na->GetAccount(); if (na->GetNick().equals_ci(oldcore->GetDisplay())) - oldcore->SetDisplay(oldcore->GetRef<NickServ::Nick *>(NickServ::nick)); + oldcore->SetDisplay(oldcore->GetRef<NickServ::Nick *>()); - NickServ::Account *nc = NickServ::account.Create(); + NickServ::Account *nc = Serialize::New<NickServ::Account *>(); nc->SetDisplay(na->GetNick()); na->SetAccount(nc); @@ -319,7 +318,7 @@ class CommandNSGList : public Command list.AddColumn(_("Nick")).AddColumn(_("Expires")); time_t nickserv_expire = Config->GetModule("nickserv")->Get<time_t>("expire", "21d"), unconfirmed_expire = Config->GetModule("nickserv")->Get<time_t>("unconfirmedexpire", "1d"); - for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>(NickServ::nick)) + for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>()) { Anope::string expires; if (na2->HasFieldS("NS_NO_EXPIRE")) @@ -368,14 +367,11 @@ class NSGroup : public Module CommandNSUngroup commandnsungroup; CommandNSGList commandnsglist; - EventHandlers<Event::NickGroup> onnickgroup; - public: NSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandnsgroup(this, onnickgroup) + , commandnsgroup(this) , commandnsungroup(this) , commandnsglist(this) - , onnickgroup(this) { if (Config->GetModule("nickserv")->Get<bool>("nonicknameownership")) throw ModuleException(modname + " can not be used with options:nonicknameownership enabled"); diff --git a/modules/nickserv/identify.cpp b/modules/nickserv/identify.cpp index 122378d8a..a9b1f9284 100644 --- a/modules/nickserv/identify.cpp +++ b/modules/nickserv/identify.cpp @@ -89,15 +89,15 @@ class CommandNSIdentify : public Command return; } - unsigned int maxlogins = Config->GetModule(this->owner)->Get<unsigned int>("maxlogins"); + unsigned int maxlogins = Config->GetModule(this->GetOwner())->Get<unsigned int>("maxlogins"); if (na && maxlogins && na->GetAccount()->users.size() >= maxlogins) { source.Reply(_("Account \002{0}\002 has already reached the maximum number of simultaneous logins ({1})."), na->GetAccount()->GetDisplay(), maxlogins); return; } - NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSIdentifyRequestListener(source, this), owner, na ? na->GetAccount()->GetDisplay() : nick, pass); - Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, u, req); + NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSIdentifyRequestListener(source, this), this->GetOwner(), na ? na->GetAccount()->GetDisplay() : nick, pass); + EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, u, req); req->Dispatch(); } diff --git a/modules/nickserv/info.cpp b/modules/nickserv/info.cpp index 0bc712ac9..02be72f2b 100644 --- a/modules/nickserv/info.cpp +++ b/modules/nickserv/info.cpp @@ -15,10 +15,8 @@ class CommandNSInfo : public Command { - EventHandlers<Event::NickInfo> &onnickinfo; - public: - CommandNSInfo(Module *creator, EventHandlers<Event::NickInfo> &event) : Command(creator, "nickserv/info", 0, 2), onnickinfo(event) + CommandNSInfo(Module *creator) : Command(creator, "nickserv/info", 0, 2) { this->SetDesc(_("Displays information about a given nickname")); this->SetSyntax(_("[\037nickname\037]")); @@ -60,7 +58,7 @@ class CommandNSInfo : public Command source.Reply(_("\002{0}\002 has not confirmed their account."), na->GetNick()); if (na->GetAccount()->IsServicesOper() && (show_hidden || !na->GetAccount()->HasFieldS("HIDE_STATUS"))) - source.Reply(_("\002{0}\002 is a Services Operator of type \002{0}\002."), na->GetNick(), na->GetAccount()->o->GetType()->GetName()); + source.Reply(_("\002{0}\002 is a Services Operator of type \002{1}\002."), na->GetNick(), na->GetAccount()->o->GetType()->GetName()); InfoFormatter info(source.nc); @@ -112,7 +110,7 @@ class CommandNSInfo : public Command } } - this->onnickinfo(&Event::NickInfo::OnNickInfo, source, na, info, show_hidden); + EventManager::Get()->Dispatch(&Event::NickInfo::OnNickInfo, source, na, info, show_hidden); std::vector<Anope::string> replies; info.Process(replies); @@ -161,7 +159,7 @@ class CommandNSSetHide : public Command } NickServ::Account *nc = na->GetAccount(); - EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -259,20 +257,17 @@ class NSInfo : public Module CommandNSSetHide commandnssethide; CommandNSSASetHide commandnssasethide; - EventHandlers<Event::NickInfo> onnickinfo; - Serialize::Field<NickServ::Account, bool> hide_email, hide_usermask, hide_status, hide_quit; public: NSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandnsinfo(this, onnickinfo) + , commandnsinfo(this) , commandnssethide(this) , commandnssasethide(this) - , onnickinfo(this) - , hide_email(this, NickServ::account, "HIDE_EMAIL") - , hide_usermask(this, NickServ::account, "HIDE_MASK") - , hide_status(this, NickServ::account, "HIDE_STATUS") - , hide_quit(this, NickServ::account, "HIDE_QUIT") + , hide_email(this, "HIDE_EMAIL") + , hide_usermask(this, "HIDE_MASK") + , hide_status(this, "HIDE_STATUS") + , hide_quit(this, "HIDE_QUIT") { } diff --git a/modules/nickserv/list.cpp b/modules/nickserv/list.cpp index 53a3a9394..c6758d583 100644 --- a/modules/nickserv/list.cpp +++ b/modules/nickserv/list.cpp @@ -31,7 +31,7 @@ class CommandNSList : public Command bool is_servadmin = source.HasCommand("nickserv/list"); int count = 0, from = 0, to = 0; bool suspended, nsnoexpire, unconfirmed; - unsigned listmax = Config->GetModule(this->owner)->Get<unsigned>("listmax", "50"); + unsigned listmax = Config->GetModule(this->GetOwner())->Get<unsigned>("listmax", "50"); suspended = nsnoexpire = unconfirmed = false; @@ -200,7 +200,7 @@ class CommandNSSetPrivate : public Command } NickServ::Account *nc = na->GetAccount(); - EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -270,10 +270,11 @@ class NSList : public Module public: NSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::NickInfo>(this) , commandnslist(this) , commandnssetprivate(this) , commandnssasetprivate(this) - , priv(this, NickServ::account, "NS_PRIVATE") + , priv(this, "NS_PRIVATE") { } diff --git a/modules/nickserv/logout.cpp b/modules/nickserv/logout.cpp index 9bcb543fc..2afc65124 100644 --- a/modules/nickserv/logout.cpp +++ b/modules/nickserv/logout.cpp @@ -46,6 +46,7 @@ class CommandNSLogout : public Command return; } +#warning "revalidate" #if 0 if (!nick.empty() && !param.empty() && param.equals_ci("REVALIDATE") && NickServ::service) NickServ::service->Validate(u2); @@ -64,7 +65,7 @@ class CommandNSLogout : public Command u2->Logout(); /* Send out an event */ - Event::OnNickLogout(&Event::NickLogout::OnNickLogout, u2); + EventManager::Get()->Dispatch(&Event::NickLogout::OnNickLogout, u2); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/nickserv/main/account.cpp b/modules/nickserv/main/account.cpp index d74154d97..bfde7f15b 100644 --- a/modules/nickserv/main/account.cpp +++ b/modules/nickserv/main/account.cpp @@ -22,7 +22,7 @@ AccountImpl::~AccountImpl() void AccountImpl::Delete() { - Event::OnDelCore(&Event::DelCore::OnDelCore, this); + EventManager::Get()->Dispatch(&Event::DelCore::OnDelCore, this); for (unsigned i = users.size(); i > 0; --i) users[i - 1]->Logout(); @@ -72,7 +72,7 @@ void AccountImpl::SetLanguage(const Anope::string &lang) MemoServ::MemoInfo *AccountImpl::GetMemos() { - return GetRef<MemoServ::MemoInfo *>(MemoServ::memoinfo); + return GetRef<MemoServ::MemoInfo *>(); } void AccountImpl::SetDisplay(NickServ::Nick *na) @@ -80,7 +80,7 @@ void AccountImpl::SetDisplay(NickServ::Nick *na) if (na->GetAccount() != this || na->GetNick() == this->GetDisplay()) return; - Event::OnChangeCoreDisplay(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, this, na->GetNick()); + EventManager::Get()->Dispatch(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, this, na->GetNick()); NickServ::nickcore_map& map = NickServ::service->GetAccountMap(); @@ -109,7 +109,7 @@ bool AccountImpl::IsOnAccess(User *u) if (!u->GetCloakedHost().empty()) buf3 = u->GetIdent() + "@" + u->GetCloakedHost(); - for (NickAccess *access : GetRefs<NickAccess *>(nsaccess)) + for (NickAccess *access : GetRefs<NickAccess *>()) { Anope::string a = access->GetMask(); if (Anope::Match(buf, a) || (!buf2.empty() && Anope::Match(buf2, a)) || (!buf3.empty() && Anope::Match(buf3, a))) @@ -121,7 +121,7 @@ bool AccountImpl::IsOnAccess(User *u) unsigned int AccountImpl::GetChannelCount() { unsigned int i = 0; - for (ChanServ::Channel *c : GetRefs<ChanServ::Channel *>(ChanServ::channel)) + for (ChanServ::Channel *c : GetRefs<ChanServ::Channel *>()) if (c->GetFounder() == this) ++i; return i; diff --git a/modules/nickserv/main/account.h b/modules/nickserv/main/account.h index 584548563..69edce0db 100644 --- a/modules/nickserv/main/account.h +++ b/modules/nickserv/main/account.h @@ -2,6 +2,10 @@ class AccountImpl : public NickServ::Account { + friend class AccountType; + + Anope::string display, password, email, language; + public: AccountImpl(Serialize::TypeBase *type) : NickServ::Account(type) { } AccountImpl(Serialize::TypeBase *type, Serialize::ID id) : NickServ::Account(type, id) { } diff --git a/modules/nickserv/main/accounttype.cpp b/modules/nickserv/main/accounttype.cpp index 3dad436b4..4f2c59d80 100644 --- a/modules/nickserv/main/accounttype.cpp +++ b/modules/nickserv/main/accounttype.cpp @@ -1,12 +1,11 @@ #include "module.h" #include "accounttype.h" -//#include "account.h" -AccountType::AccountType(Module *me) : Serialize::Type<AccountImpl>(me, "NickCore") - , display(this, "display") - , pass(this, "pass") - , email(this, "email") - , language(this, "language") +AccountType::AccountType(Module *me) : Serialize::Type<AccountImpl>(me) + , display(this, "display", &AccountImpl::display) + , pass(this, "pass", &AccountImpl::password) + , email(this, "email", &AccountImpl::email) + , language(this, "language", &AccountImpl::language) { } @@ -29,7 +28,7 @@ void AccountType::Display::SetField(AccountImpl *acc, const Anope::string &disp) NickServ::Account *AccountType::FindAccount(const Anope::string &acc) { Serialize::ID id; - EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializeFind, this, &this->display, acc, id); + EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeFind, this, &this->display, acc, id); if (result == EVENT_ALLOW) return RequireID(id); diff --git a/modules/nickserv/main/identifyrequest.cpp b/modules/nickserv/main/identifyrequest.cpp index 4fc2f9989..3d014965b 100644 --- a/modules/nickserv/main/identifyrequest.cpp +++ b/modules/nickserv/main/identifyrequest.cpp @@ -49,3 +49,14 @@ void IdentifyRequestImpl::Dispatch() else dispatched = true; } + +void IdentifyRequestImpl::Unload(Module *m) +{ + if (this->GetOwner() != m) + return; + + if (!success) + l->OnFail(this); + delete this; +} + diff --git a/modules/nickserv/main/identifyrequest.h b/modules/nickserv/main/identifyrequest.h index e74d3129e..03857da96 100644 --- a/modules/nickserv/main/identifyrequest.h +++ b/modules/nickserv/main/identifyrequest.h @@ -10,4 +10,5 @@ class IdentifyRequestImpl : public NickServ::IdentifyRequest void Release(Module *m) override; void Success(Module *m) override; void Dispatch() override; + void Unload(Module *); }; diff --git a/modules/nickserv/main/mode.h b/modules/nickserv/main/mode.h index 9fc4c331e..df72e1823 100644 --- a/modules/nickserv/main/mode.h +++ b/modules/nickserv/main/mode.h @@ -1,6 +1,11 @@ class ModeImpl : public NickServ::Mode { + friend class NSModeType; + + NickServ::Account *account = nullptr; + Anope::string mode; + public: ModeImpl(Serialize::TypeBase *type) : NickServ::Mode(type) { } ModeImpl(Serialize::TypeBase *type, Serialize::ID id) : NickServ::Mode(type, id) { } diff --git a/modules/nickserv/main/modetype.h b/modules/nickserv/main/modetype.h index 0c4aefecc..5796614d4 100644 --- a/modules/nickserv/main/modetype.h +++ b/modules/nickserv/main/modetype.h @@ -6,9 +6,9 @@ class NSModeType : public Serialize::Type<ModeImpl> Serialize::ObjectField<ModeImpl, NickServ::Account *> account; Serialize::Field<ModeImpl, Anope::string> mode; - NSModeType(Module *creator) : Serialize::Type<ModeImpl>(creator, "NSKeepMode") - , account(this, "account", true) - , mode(this, "mode") + NSModeType(Module *creator) : Serialize::Type<ModeImpl>(creator) + , account(this, "account", &ModeImpl::account, true) + , mode(this, "mode", &ModeImpl::mode) { } }; diff --git a/modules/nickserv/main/nick.cpp b/modules/nickserv/main/nick.cpp index 0ac55ff93..95cef63da 100644 --- a/modules/nickserv/main/nick.cpp +++ b/modules/nickserv/main/nick.cpp @@ -1,12 +1,10 @@ /* * - * (C) 2003-2014 Anope Team + * (C) 2003-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. * */ @@ -22,12 +20,12 @@ NickImpl::~NickImpl() void NickImpl::Delete() { - Event::OnDelNick(&Event::DelNick::OnDelNick, this); + EventManager::Get()->Dispatch(&Event::DelNick::OnDelNick, this); if (this->GetAccount()) { /* Next: see if our core is still useful. */ - std::vector<NickServ::Nick *> aliases = this->GetAccount()->GetRefs<NickServ::Nick *>(NickServ::nick); + std::vector<NickServ::Nick *> aliases = this->GetAccount()->GetRefs<NickServ::Nick *>(); auto it = std::find(aliases.begin(), aliases.end(), this); if (it != aliases.end()) diff --git a/modules/nickserv/main/nick.h b/modules/nickserv/main/nick.h index 043d7c052..fa8e7bcc5 100644 --- a/modules/nickserv/main/nick.h +++ b/modules/nickserv/main/nick.h @@ -1,6 +1,14 @@ class NickImpl : public NickServ::Nick { + friend class NickType; + + NickServ::Account *account = nullptr; + Anope::string nick, last_quit, last_realname, last_usermask, last_realhost; + time_t time_registered = 0, last_seen = 0; + Anope::string vhost_ident, vhost_host, vhost_creator; + time_t vhost_created = 0; + public: NickImpl(Serialize::TypeBase *type) : NickServ::Nick(type) { } NickImpl(Serialize::TypeBase *type, Serialize::ID id) : NickServ::Nick(type, id) { } diff --git a/modules/nickserv/main/nickserv.cpp b/modules/nickserv/main/nickserv.cpp index 85ac34b12..434e4324c 100644 --- a/modules/nickserv/main/nickserv.cpp +++ b/modules/nickserv/main/nickserv.cpp @@ -138,16 +138,12 @@ class NickServCore : public Module, public NickServ::NickServService , public EventHook<Event::ExpireTick> , public EventHook<Event::NickInfo> , public EventHook<Event::ModuleUnload> - , public EventHook<Event::NickCoreCreate> + , public EventHook<NickServ::Event::NickRegister> , public EventHook<Event::UserQuit> { Reference<ServiceBot> NickServ; std::vector<Anope::string> defaults; ExtensibleItem<bool> held, collided; - EventHandlers<NickServ::Event::PreNickExpire> onprenickexpire; - EventHandlers<NickServ::Event::NickExpire> onnickexpire; - EventHandlers<NickServ::Event::NickRegister> onnickregister; - EventHandlers<NickServ::Event::NickValidate> onnickvalidate; std::set<NickServ::IdentifyRequest *> identifyrequests; NickServ::nickalias_map NickList; NickServ::nickcore_map AccountList; @@ -173,21 +169,41 @@ class NickServCore : public Module, public NickServ::NickServService public: NickServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) , NickServ::NickServService(this) + + , EventHook<Event::Shutdown>(this) + , EventHook<Event::Restart>(this) + , EventHook<Event::UserLogin>(this) + , EventHook<Event::DelNick>(this) + , EventHook<Event::DelCore>(this) + , EventHook<Event::ChangeCoreDisplay>(this) + , EventHook<Event::NickIdentify>(this) + , EventHook<Event::NickGroup>(this) + , EventHook<Event::NickUpdate>(this) + , EventHook<Event::UserConnect>(this) + , EventHook<Event::PostUserLogoff>(this) + , EventHook<Event::ServerSync>(this) + , EventHook<Event::UserNickChange>(this) + , EventHook<Event::UserModeSet>(this) + , EventHook<Event::Help>(this) + , EventHook<Event::ExpireTick>(this) + , EventHook<Event::NickInfo>(this) + , EventHook<Event::ModuleUnload>(this) + , EventHook<NickServ::Event::NickRegister>(this) + , EventHook<Event::UserQuit>(this) + , held(this, "HELD") , collided(this, "COLLIDED") - , onprenickexpire(this) - , onnickexpire(this) - , onnickregister(this) - , onnickvalidate(this) , nick_type(this) , account_type(this) , mode_type(this) { + NickServ::service = this; } ~NickServCore() { OnShutdown(); + NickServ::service = nullptr; } void OnShutdown() override @@ -210,7 +226,7 @@ class NickServCore : public Module, public NickServ::NickServService if (!na) return; - EventReturn MOD_RESULT = this->onnickvalidate(&NickServ::Event::NickValidate::OnNickValidate, u, na); + EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&NickServ::Event::NickValidate::OnNickValidate, u, na); if (MOD_RESULT == EVENT_STOP) { this->Collide(u, na); @@ -412,7 +428,7 @@ class NickServCore : public Module, public NickServ::NickServService IRCD->SendLogout(user); user->RemoveMode(NickServ, "REGISTERED"); user->Logout(); - Event::OnNickLogout(&Event::NickLogout::OnNickLogout, user); + EventManager::Get()->Dispatch(&Event::NickLogout::OnNickLogout, user); } } @@ -588,11 +604,11 @@ class NickServCore : public Module, public NickServ::NickServService "nickname(s)."), NickServ->nick.c_str()); } - void OnNickCoreCreate(NickServ::Account *nc) override + void OnNickRegister(User *, NickServ::Nick *na, const Anope::string &) override { /* Set default flags */ for (unsigned i = 0; i < defaults.size(); ++i) - nc->SetS<bool>(defaults[i].upper(), true); + na->GetAccount()->SetS<bool>(defaults[i].upper(), true); } void OnUserQuit(User *u, const Anope::string &msg) override @@ -627,12 +643,12 @@ class NickServCore : public Module, public NickServ::NickServService if (nickserv_expire && Anope::CurTime - na->GetLastSeen() >= nickserv_expire) expire = true; - this->onprenickexpire(&NickServ::Event::PreNickExpire::OnPreNickExpire, na, expire); + EventManager::Get()->Dispatch(&NickServ::Event::PreNickExpire::OnPreNickExpire, na, expire); if (expire) { Log(LOG_NORMAL, "nickserv/expire", NickServ) << "Expiring nickname " << na->GetNick() << " (group: " << na->GetAccount()->GetDisplay() << ") (e-mail: " << (na->GetAccount()->GetEmail().empty() ? "none" : na->GetAccount()->GetEmail()) << ")"; - this->onnickexpire(&NickServ::Event::NickExpire::OnNickExpire, na); + EventManager::Get()->Dispatch(&NickServ::Event::NickExpire::OnNickExpire, na); delete na; } } @@ -657,27 +673,10 @@ class NickServCore : public Module, public NickServ::NickServService { for (std::set<NickServ::IdentifyRequest *>::iterator it = identifyrequests.begin(), it_end = identifyrequests.end(); it != it_end;) { - NickServ::IdentifyRequest *ir = *it; + IdentifyRequestImpl *ir = anope_dynamic_static_cast<IdentifyRequestImpl *>(*it); ++it; - ir->Release(m); -#if 0 - ir->holds.erase(m); - if (ir->holds.empty() && ir->dispatched) - { - if (!ir->success) - ir->OnFail(); - delete ir; - continue; - } - - if (ir->GetOwner() == m) - { - if (!ir->success) - ir->OnFail(); - delete ir; - } -#endif + ir->Unload(m); } } }; diff --git a/modules/nickserv/main/nicktype.cpp b/modules/nickserv/main/nicktype.cpp index 9607aaa2f..7d9b34ac1 100644 --- a/modules/nickserv/main/nicktype.cpp +++ b/modules/nickserv/main/nicktype.cpp @@ -1,19 +1,19 @@ #include "module.h" #include "nicktype.h" -NickType::NickType(Module *me) : Serialize::Type<NickImpl>(me, "NickAlias") - , nick(this, "nick") - , last_quit(this, "last_quit") - , last_realname(this, "last_realname") - , last_usermask(this, "last_usermask") - , last_realhost(this, "last_realhost") - , time_registered(this, "time_registered") - , last_seen(this, "last_seen") - , vhost_ident(this, "vhost_ident") - , vhost_host(this, "vhost_host") - , vhost_creator(this, "vhost_creator") - , vhost_created(this, "vhost_created") - , nc(this, "nc") +NickType::NickType(Module *me) : Serialize::Type<NickImpl>(me) + , nick(this, "nick", &NickImpl::nick) + , last_quit(this, "last_quit", &NickImpl::last_quit) + , last_realname(this, "last_realname", &NickImpl::last_realname) + , last_usermask(this, "last_usermask", &NickImpl::last_usermask) + , last_realhost(this, "last_realhost", &NickImpl::last_realhost) + , time_registered(this, "time_registered", &NickImpl::time_registered) + , last_seen(this, "last_seen", &NickImpl::last_seen) + , vhost_ident(this, "vhost_ident", &NickImpl::vhost_ident) + , vhost_host(this, "vhost_host", &NickImpl::vhost_host) + , vhost_creator(this, "vhost_creator", &NickImpl::vhost_creator) + , vhost_created(this, "vhost_created", &NickImpl::vhost_created) + , nc(this, "nc", &NickImpl::account) { } @@ -32,7 +32,7 @@ void NickType::Nick::SetField(NickImpl *na, const Anope::string &value) NickServ::Nick *NickType::FindNick(const Anope::string &n) { Serialize::ID id; - EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializeFind, this, &this->nick, n, id); + EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeFind, this, &this->nick, n, id); if (result == EVENT_ALLOW) return RequireID(id); diff --git a/modules/nickserv/maxemail.cpp b/modules/nickserv/maxemail.cpp index 38054f819..34f83741d 100644 --- a/modules/nickserv/maxemail.cpp +++ b/modules/nickserv/maxemail.cpp @@ -49,6 +49,7 @@ class NSMaxEmail : public Module public: NSMaxEmail(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::PreCommand>(this) { } @@ -57,17 +58,17 @@ class NSMaxEmail : public Module if (source.IsOper()) return EVENT_CONTINUE; - if (command->name == "nickserv/register") + if (command->GetName() == "nickserv/register") { if (this->CheckLimitReached(source, params.size() > 1 ? params[1] : "")) return EVENT_STOP; } - else if (command->name == "nickserv/set/email") + else if (command->GetName() == "nickserv/set/email") { if (this->CheckLimitReached(source, params.size() > 0 ? params[0] : "")) return EVENT_STOP; } - else if (command->name == "nickserv/ungroup" && source.GetAccount()) + else if (command->GetName() == "nickserv/ungroup" && source.GetAccount()) { if (this->CheckLimitReached(source, source.GetAccount()->GetEmail())) return EVENT_STOP; diff --git a/modules/nickserv/recover.cpp b/modules/nickserv/recover.cpp index c95d3f135..9a6ddd64e 100644 --- a/modules/nickserv/recover.cpp +++ b/modules/nickserv/recover.cpp @@ -124,6 +124,8 @@ class NSRecoverRequestListener : public NickServ::IdentifyRequestListener class CommandNSRecover : public Command { + ServiceReference<CertService> certservice; + public: CommandNSRecover(Module *creator) : Command(creator, "nickserv/recover", 1, 2) { @@ -170,8 +172,8 @@ class CommandNSRecover : public Command if (ok == false && !pass.empty()) { - NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSRecoverRequestListener(source, this, na->GetNick(), pass), owner, na->GetNick(), pass); - Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req); + NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSRecoverRequestListener(source, this, na->GetNick(), pass), GetOwner(), na->GetNick(), pass); + EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req); req->Dispatch(); } else @@ -204,6 +206,8 @@ class NSRecover : public Module public: NSRecover(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::UserNickChange>(this) + , EventHook<Event::JoinChannel>(this) , commandnsrecover(this) , recover(this, "recover") { diff --git a/modules/nickserv/register.cpp b/modules/nickserv/register.cpp index c7e6e5af2..e8255ca1a 100644 --- a/modules/nickserv/register.cpp +++ b/modules/nickserv/register.cpp @@ -44,8 +44,7 @@ class CommandNSConfirm : public Command } na->GetAccount()->UnsetS<bool>("UNCONFIRMED"); - if (NickServ::Event::OnNickConfirm) - NickServ::Event::OnNickConfirm(&NickServ::Event::NickConfirm::OnNickConfirm, source.GetUser(), na->GetAccount()); + EventManager::Get()->Dispatch(&NickServ::Event::NickConfirm::OnNickConfirm, source.GetUser(), na->GetAccount()); Log(LOG_ADMIN, source, this) << "to confirm nick " << na->GetNick() << " (" << na->GetAccount()->GetDisplay() << ")"; source.Reply(_("\002{0}\002 has been confirmed."), na->GetNick()); } @@ -59,12 +58,12 @@ class CommandNSConfirm : public Command } NickServ::Account *nc = source.nc; - nc->ShrinkOK<Anope::string>("passcode"); + nc->Shrink<Anope::string>("passcode"); Log(LOG_COMMAND, source, this) << "to confirm their email"; source.Reply(_("Your email address of \002{0}\002 has been confirmed."), source.nc->GetEmail()); nc->UnsetS<bool>("UNCONFIRMED"); - if (NickServ::Event::OnNickConfirm) - NickServ::Event::OnNickConfirm(&NickServ::Event::NickConfirm::OnNickConfirm, source.GetUser(), nc); + + EventManager::Get()->Dispatch(&NickServ::Event::NickConfirm::OnNickConfirm, source.GetUser(), nc); if (source.GetUser()) { @@ -115,7 +114,7 @@ class CommandNSRegister : public Command size_t nicklen = u_nick.length(); Anope::string pass = params[0]; Anope::string email = params.size() > 1 ? params[1] : ""; - const Anope::string &nsregister = Config->GetModule(this->owner)->Get<Anope::string>("registration"); + const Anope::string &nsregister = Config->GetModule(this->GetOwner())->Get<Anope::string>("registration"); if (Anope::ReadOnly) { @@ -129,7 +128,7 @@ class CommandNSRegister : public Command return; } - time_t nickregdelay = Config->GetModule(this->owner)->Get<time_t>("nickregdelay"); + time_t nickregdelay = Config->GetModule(this->GetOwner())->Get<time_t>("nickregdelay"); time_t reg_delay = Config->GetModule("nickserv")->Get<time_t>("regdelay"); if (u && !u->HasMode("OPER") && nickregdelay && Anope::CurTime - u->timestamp < nickregdelay) { @@ -162,11 +161,11 @@ class CommandNSRegister : public Command } if (Config->GetModule("nickserv")->Get<bool>("restrictopernicks")) - for (Oper *o : Serialize::GetObjects<Oper *>(operblock)) + for (Oper *o : Serialize::GetObjects<Oper *>()) { if (!source.IsOper() && u_nick.find_ci(o->GetName()) != Anope::string::npos) { - source.Reply(_("\002{0}\002 may not be registered."), u_nick); + source.Reply(_("\002{0}\002 may not be registered because it is too similar to an operator nick."), u_nick); return; } } @@ -210,12 +209,15 @@ class CommandNSRegister : public Command return; } - NickServ::Account *nc = NickServ::account.Create(); + NickServ::Account *nc = Serialize::New<NickServ::Account *>(); nc->SetDisplay(u_nick); - NickServ::Nick *na = NickServ::nick.Create(); + NickServ::Nick *na = Serialize::New<NickServ::Nick *>(); na->SetNick(u_nick); na->SetAccount(nc); + na->SetTimeRegistered(Anope::CurTime); + na->SetLastSeen(Anope::CurTime); + Anope::string epass; Anope::Encrypt(pass, epass); nc->SetPassword(epass); @@ -252,8 +254,7 @@ class CommandNSRegister : public Command } } - if (NickServ::Event::OnNickRegister) - NickServ::Event::OnNickRegister(&NickServ::Event::NickRegister::OnNickRegister, source.GetUser(), na, pass); + EventManager::Get()->Dispatch(&NickServ::Event::NickRegister::OnNickRegister, source.GetUser(), na, pass); if (u) { @@ -296,7 +297,7 @@ class CommandNSResend : public Command void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - if (!Config->GetModule(this->owner)->Get<Anope::string>("registration").equals_ci("mail")) + if (!Config->GetModule(this->GetOwner())->Get<Anope::string>("registration").equals_ci("mail")) { source.Reply(_("Access denied.")); return; @@ -316,7 +317,7 @@ class CommandNSResend : public Command return; } - if (Anope::CurTime < source.nc->lastmail + Config->GetModule(this->owner)->Get<time_t>("resenddelay")) + if (Anope::CurTime < source.nc->lastmail + Config->GetModule(this->GetOwner())->Get<time_t>("resenddelay")) { source.Reply(_("Cannot send mail now; please retry a little later.")); return; @@ -324,7 +325,7 @@ class CommandNSResend : public Command if (!SendRegmail(source.GetUser(), na, source.service)) { - Log(this->owner) << "Unable to resend registration verification code for " << source.GetNick(); + Log(this->GetOwner()) << "Unable to resend registration verification code for " << source.GetNick(); return; } @@ -335,7 +336,7 @@ class CommandNSResend : public Command bool OnHelp(CommandSource &source, const Anope::string &subcommand) override { - if (!Config->GetModule(this->owner)->Get<Anope::string>("registration").equals_ci("mail")) + if (!Config->GetModule(this->GetOwner())->Get<Anope::string>("registration").equals_ci("mail")) return false; source.Reply(_("This command will resend you the registration confirmation email.")); @@ -344,7 +345,7 @@ class CommandNSResend : public Command void OnServHelp(CommandSource &source) override { - if (Config->GetModule(this->owner)->Get<Anope::string>("registration").equals_ci("mail")) + if (Config->GetModule(this->GetOwner())->Get<Anope::string>("registration").equals_ci("mail")) Command::OnServHelp(source); } }; @@ -362,14 +363,16 @@ class NSRegister : public Module public: NSRegister(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::NickIdentify>(this) + , EventHook<NickServ::Event::PreNickExpire>(this) , commandnsregister(this) , commandnsconfirm(this) , commandnsrsend(this) - , unconfirmed(this, NickServ::account, "UNCONFIRMED") - , passcode(this, NickServ::account, "passcode") + , unconfirmed(this, "UNCONFIRMED") + , passcode(this, "passcode") { if (Config->GetModule(this)->Get<Anope::string>("registration").equals_ci("disable")) - throw ModuleException("Module " + this->name + " will not load with registration disabled."); + throw ModuleException("Module " + Module::name + " will not load with registration disabled."); } void OnNickIdentify(User *u) override diff --git a/modules/nickserv/resetpass.cpp b/modules/nickserv/resetpass.cpp index 3be5a4c06..4f8fa5136 100644 --- a/modules/nickserv/resetpass.cpp +++ b/modules/nickserv/resetpass.cpp @@ -67,6 +67,7 @@ class NSResetPass : public Module public: NSResetPass(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::PreCommand>(this) , commandnsresetpass(this), reset(this, "reset") { if (!Config->GetBlock("mail")->Get<bool>("usemail")) @@ -75,7 +76,7 @@ class NSResetPass : public Module EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> ¶ms) override { - if (command->name == "nickserv/confirm" && params.size() > 1) + if (command->GetName() == "nickserv/confirm" && params.size() > 1) { if (Anope::ReadOnly) { diff --git a/modules/nickserv/set.cpp b/modules/nickserv/set.cpp index 337bdab9d..93d2dcc57 100644 --- a/modules/nickserv/set.cpp +++ b/modules/nickserv/set.cpp @@ -1,12 +1,10 @@ /* NickServ core functions * - * (C) 2003-2014 Anope Team + * (C) 2003-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. */ #include "module.h" @@ -44,7 +42,7 @@ class CommandNSSet : public Command if (c_name.find_ci(this_name + " ") == 0) { - ServiceReference<Command> c("Command", info.name); + ServiceReference<Command> c(info.name); // XXX dup if (!c) continue; @@ -96,7 +94,7 @@ class CommandNSSASet : public Command if (c_name.find_ci(this_name + " ") == 0) { - ServiceReference<Command> command("Command", info.name); + ServiceReference<Command> command(info.name); if (command) { source.command = c_name; @@ -254,7 +252,7 @@ class CommandNSSetAutoOp : public Command NickServ::Account *nc = na->GetAccount(); EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -347,7 +345,7 @@ class CommandNSSetDisplay : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, user_na->GetAccount(), param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, user_na->GetAccount(), param); if (MOD_RESULT == EVENT_STOP) return; @@ -468,7 +466,7 @@ class CommandNSSetEmail : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -550,7 +548,7 @@ class CommandNSSetKeepModes : public Command NickServ::Account *nc = na->GetAccount(); EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -635,7 +633,7 @@ class CommandNSSetKill : public Command NickServ::Account *nc = na->GetAccount(); EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -657,7 +655,7 @@ class CommandNSSetKill : public Command } else if (param.equals_ci("IMMED")) { - if (Config->GetModule(this->owner)->Get<bool>("allowkillimmed")) + if (Config->GetModule(this->GetOwner())->Get<bool>("allowkillimmed")) { nc->SetS<bool>("KILLPROTECT",true); nc->UnsetS<bool>("KILL_QUICK"); @@ -749,7 +747,7 @@ class CommandNSSetLanguage : public Command NickServ::Account *nc = na->GetAccount(); EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -854,7 +852,7 @@ class CommandNSSetMessage : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -949,7 +947,7 @@ class CommandNSSetSecure : public Command NickServ::Account *nc = na->GetAccount(); EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -1105,10 +1103,16 @@ class NSSet : public Module /* email, passcode */ ExtensibleItem<std::pair<Anope::string, Anope::string > > ns_set_email; - EventHandlers<Event::SetNickOption> onsetnickoption; - public: NSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::PreCommand>(this) + , EventHook<Event::SetCorrectModes>(this) + , EventHook<NickServ::Event::PreNickExpire>(this) + , EventHook<Event::NickInfo>(this) + , EventHook<Event::UserModeSet>(this) + , EventHook<Event::UserModeUnset>(this) + , EventHook<Event::UserLogin>(this) + , commandnsset(this) , commandnssaset(this) , commandnssetautoop(this) @@ -1131,18 +1135,16 @@ class NSSet : public Module , commandnssasetsecure(this) , commandnssasetnoexpire(this) - , autoop(this, NickServ::account, "AUTOOP") - , keep_modes(this, NickServ::account, "NS_KEEP_MODES") - , killprotect(this, NickServ::account, "KILLPROTECT") - , kill_quick(this, NickServ::account, "KILL_QUICK") - , kill_immed(this, NickServ::account, "KILL_IMMED") - , message(this, NickServ::account, "MSG") - , secure(this, NickServ::account, "NS_SECURE") - , noexpire(this, NickServ::nick, "NS_NO_EXPIRE") + , autoop(this, "AUTOOP") + , keep_modes(this, "NS_KEEP_MODES") + , killprotect(this, "KILLPROTECT") + , kill_quick(this, "KILL_QUICK") + , kill_immed(this, "KILL_IMMED") + , message(this, "MSG") + , secure(this, "NS_SECURE") + , noexpire(this, "NS_NO_EXPIRE") , ns_set_email(this, "ns_set_email") - - , onsetnickoption(this) { } @@ -1151,7 +1153,7 @@ class NSSet : public Module { NickServ::Account *uac = source.nc; - if (command->name == "nickserv/confirm" && !params.empty() && uac) + if (command->GetName() == "nickserv/confirm" && !params.empty() && uac) { std::pair<Anope::string, Anope::string> *n = ns_set_email.Get(uac); if (n) @@ -1210,11 +1212,14 @@ class NSSet : public Module void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) override { - if (u->Account() && setter.GetUser() == u && NickServ::mode) + if (u->Account() && setter.GetUser() == u) { - NickServ::Mode *m = NickServ::mode.Create(); - m->SetAccount(u->Account()); - m->SetMode(mname); + NickServ::Mode *m = Serialize::New<NickServ::Mode *>(); + if (m != nullptr) + { + m->SetAccount(u->Account()); + m->SetMode(mname); + } } } @@ -1222,7 +1227,7 @@ class NSSet : public Module { if (u->Account() && setter.GetUser() == u) { - for (NickServ::Mode *m : u->Account()->GetRefs<NickServ::Mode *>(NickServ::mode)) + for (NickServ::Mode *m : u->Account()->GetRefs<NickServ::Mode *>()) if (m->GetMode() == mname) m->Delete(); } @@ -1231,7 +1236,7 @@ class NSSet : public Module void OnUserLogin(User *u) override { if (keep_modes.HasExt(u->Account())) - for (NickServ::Mode *mode : u->Account()->GetRefs<NickServ::Mode *>(NickServ::mode)) + for (NickServ::Mode *mode : u->Account()->GetRefs<NickServ::Mode *>()) { UserMode *um = ModeManager::FindUserModeByName(mode->GetMode()); /* if the null user can set the mode, then it's probably safe */ diff --git a/modules/nickserv/set_misc.cpp b/modules/nickserv/set_misc.cpp index 347ae034c..2c6ea317c 100644 --- a/modules/nickserv/set_misc.cpp +++ b/modules/nickserv/set_misc.cpp @@ -18,6 +18,11 @@ static Anope::map<Anope::string> descriptions; class NSMiscDataImpl : public NSMiscData { + friend class NSMiscDataType; + + NickServ::Account *account = nullptr; + Anope::string name, data; + public: NSMiscDataImpl(Serialize::TypeBase *type) : NSMiscData(type) { } NSMiscDataImpl(Serialize::TypeBase *type, Serialize::ID id) : NSMiscData(type, id) { } @@ -38,10 +43,10 @@ class NSMiscDataType : public Serialize::Type<NSMiscDataImpl> Serialize::ObjectField<NSMiscDataImpl, NickServ::Account *> owner; Serialize::Field<NSMiscDataImpl, Anope::string> name, data; - NSMiscDataType(Module *me) : Serialize::Type<NSMiscDataImpl>(me, "NSMiscData") - , owner(this, "nc", true) - , name(this, "name") - , data(this, "data") + NSMiscDataType(Module *me) : Serialize::Type<NSMiscDataImpl>(me) + , owner(this, "nc", &NSMiscDataImpl::account, true) + , name(this, "name", &NSMiscDataImpl::name) + , data(this, "data", &NSMiscDataImpl::data) { } }; @@ -108,14 +113,14 @@ class CommandNSSetMisc : public Command } NickServ::Account *nc = na->GetAccount(); - EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; Anope::string scommand = GetAttribute(source.command); /* remove existing */ - for (NSMiscData *data : nc->GetRefs<NSMiscData *>(nsmiscdata)) + for (NSMiscData *data : nc->GetRefs<NSMiscData *>()) if (data->GetName() == scommand) { data->Delete(); @@ -124,7 +129,7 @@ class CommandNSSetMisc : public Command if (!param.empty()) { - NSMiscData *data = nsmiscdata.Create(); + NSMiscData *data = Serialize::New<NSMiscData *>(); data->SetAccount(nc); data->SetName(scommand); data->SetData(param); @@ -186,6 +191,7 @@ class NSSetMisc : public Module public: NSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::NickInfo>(this) , commandnssetmisc(this) , commandnssasetmisc(this) , type(this) @@ -217,7 +223,7 @@ class NSSetMisc : public Module void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool) override { - for (NSMiscData *data : na->GetAccount()->GetRefs<NSMiscData *>(nsmiscdata)) + for (NSMiscData *data : na->GetAccount()->GetRefs<NSMiscData *>()) info[data->GetName()] = data->GetData(); } }; diff --git a/modules/nickserv/suspend.cpp b/modules/nickserv/suspend.cpp index b56e68f97..c33556e76 100644 --- a/modules/nickserv/suspend.cpp +++ b/modules/nickserv/suspend.cpp @@ -16,6 +16,12 @@ class NSSuspendInfoImpl : public NSSuspendInfo { + friend class NSSuspendType; + + NickServ::Account *account = nullptr; + Anope::string by, reason; + time_t when = 0, expires =0; + public: NSSuspendInfoImpl(Serialize::TypeBase *type) : NSSuspendInfo(type) { } NSSuspendInfoImpl(Serialize::TypeBase *type, Serialize::ID id) : NSSuspendInfo(type, id) { } @@ -43,12 +49,12 @@ class NSSuspendType : public Serialize::Type<NSSuspendInfoImpl> Serialize::Field<NSSuspendInfoImpl, Anope::string> by, reason; Serialize::Field<NSSuspendInfoImpl, time_t> when, expires; - NSSuspendType(Module *me) : Serialize::Type<NSSuspendInfoImpl>(me, "NSSuspendInfo") - , account(this, "nick", true) - , by(this, "by") - , reason(this, "reason") - , when(this, "time") - , expires(this, "expires") + NSSuspendType(Module *me) : Serialize::Type<NSSuspendInfoImpl>(me) + , account(this, "nick", &NSSuspendInfoImpl::account, true) + , by(this, "by", &NSSuspendInfoImpl::by) + , reason(this, "reason", &NSSuspendInfoImpl::reason) + , when(this, "when", &NSSuspendInfoImpl::when) + , expires(this, "expires", &NSSuspendInfoImpl::expires) { } }; @@ -105,10 +111,8 @@ void NSSuspendInfoImpl::SetExpires(const time_t &e) class CommandNSSuspend : public Command { - EventHandlers<Event::NickSuspend> &onnicksuspend; - public: - CommandNSSuspend(Module *creator, EventHandlers<Event::NickSuspend> &event) : Command(creator, "nickserv/suspend", 2, 3), onnicksuspend(event) + CommandNSSuspend(Module *creator) : Command(creator, "nickserv/suspend", 2, 3) { this->SetDesc(_("Suspend a given nick")); this->SetSyntax(_("\037account\037 [+\037expiry\037] [\037reason\037]")); @@ -120,7 +124,7 @@ class CommandNSSuspend : public Command const Anope::string &nick = params[0]; Anope::string expiry = params[1]; Anope::string reason = params.size() > 2 ? params[2] : ""; - time_t expiry_secs = Config->GetModule(this->owner)->Get<time_t>("suspendexpire"); + time_t expiry_secs = Config->GetModule(this->GetOwner())->Get<time_t>("suspendexpire"); if (Anope::ReadOnly) source.Reply(_("Services are in read-only mode. Any changes made may not persist.")); @@ -154,7 +158,7 @@ class CommandNSSuspend : public Command return; } - NSSuspendInfo *si = na->GetAccount()->GetRef<NSSuspendInfo *>(nssuspendinfo); + NSSuspendInfo *si = na->GetAccount()->GetRef<NSSuspendInfo *>(); if (!si) { source.Reply(_("\002%s\002 is already suspended."), na->GetAccount()->GetDisplay().c_str()); @@ -163,14 +167,14 @@ class CommandNSSuspend : public Command NickServ::Account *nc = na->GetAccount(); - si = nssuspendinfo.Create(); + si = Serialize::New<NSSuspendInfo *>(); si->SetAccount(nc); si->SetBy(source.GetNick()); si->SetReason(reason); si->SetWhen(Anope::CurTime); si->SetExpires(expiry_secs ? expiry_secs + Anope::CurTime : 0); - for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>(NickServ::nick)) + for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>()) { na2->SetLastQuit(reason); @@ -186,7 +190,7 @@ class CommandNSSuspend : public Command Log(LOG_ADMIN, source, this) << "for " << nick << " (" << (!reason.empty() ? reason : "No reason") << "), expires on " << (expiry_secs ? Anope::strftime(Anope::CurTime + expiry_secs) : "never"); source.Reply(_("\002{0}\002 is now suspended."), na->GetNick()); - this->onnicksuspend(&Event::NickSuspend::OnNickSuspend, na); + EventManager::Get()->Dispatch(&Event::NickSuspend::OnNickSuspend, na); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -199,10 +203,8 @@ class CommandNSSuspend : public Command class CommandNSUnSuspend : public Command { - EventHandlers<Event::NickUnsuspend> &onnickunsuspend; - public: - CommandNSUnSuspend(Module *creator, EventHandlers<Event::NickUnsuspend> &event) : Command(creator, "nickserv/unsuspend", 1, 1), onnickunsuspend(event) + CommandNSUnSuspend(Module *creator) : Command(creator, "nickserv/unsuspend", 1, 1) { this->SetDesc(_("Unsuspend a given nick")); this->SetSyntax(_("\037account\037")); @@ -222,7 +224,7 @@ class CommandNSUnSuspend : public Command return; } - NSSuspendInfo *si = na->GetAccount()->GetRef<NSSuspendInfo *>(nssuspendinfo); + NSSuspendInfo *si = na->GetAccount()->GetRef<NSSuspendInfo *>(); if (!si) { source.Reply(_("\002{0}\002 is not suspended."), na->GetNick()); @@ -235,7 +237,7 @@ class CommandNSUnSuspend : public Command source.Reply(_("\002{0}\002 is now released."), na->GetNick()); - this->onnickunsuspend(&Event::NickUnsuspend::OnNickUnsuspend, na); + EventManager::Get()->Dispatch(&Event::NickUnsuspend::OnNickUnsuspend, na); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -252,8 +254,6 @@ class NSSuspend : public Module { CommandNSSuspend commandnssuspend; CommandNSUnSuspend commandnsunsuspend; - EventHandlers<Event::NickSuspend> onnicksuspend; - EventHandlers<Event::NickUnsuspend> onnickunsuspend; std::vector<Anope::string> show; NSSuspendType nst; @@ -272,10 +272,11 @@ class NSSuspend : public Module public: NSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandnssuspend(this, onnicksuspend) - , commandnsunsuspend(this, onnickunsuspend) - , onnicksuspend(this) - , onnickunsuspend(this) + , EventHook<Event::NickInfo>(this) + , EventHook<NickServ::Event::PreNickExpire>(this) + , EventHook<NickServ::Event::NickValidate>(this) + , commandnssuspend(this) + , commandnsunsuspend(this) , nst(this) { } @@ -289,7 +290,7 @@ class NSSuspend : public Module void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool show_hidden) override { - NSSuspendInfo *s = na->GetAccount()->GetRef<NSSuspendInfo *>(nssuspendinfo); + NSSuspendInfo *s = na->GetAccount()->GetRef<NSSuspendInfo *>(); if (!s) return; @@ -307,7 +308,7 @@ class NSSuspend : public Module void OnPreNickExpire(NickServ::Nick *na, bool &expire) override { - NSSuspendInfo *s = na->GetAccount()->GetRef<NSSuspendInfo *>(nssuspendinfo); + NSSuspendInfo *s = na->GetAccount()->GetRef<NSSuspendInfo *>(); if (!s) return; @@ -327,7 +328,7 @@ class NSSuspend : public Module EventReturn OnNickValidate(User *u, NickServ::Nick *na) override { - NSSuspendInfo *s = na->GetAccount()->GetRef<NSSuspendInfo *>(nssuspendinfo); + NSSuspendInfo *s = na->GetAccount()->GetRef<NSSuspendInfo *>(); if (!s) return EVENT_CONTINUE; diff --git a/modules/nickserv/update.cpp b/modules/nickserv/update.cpp index 6781585d3..d4815b4cb 100644 --- a/modules/nickserv/update.cpp +++ b/modules/nickserv/update.cpp @@ -14,10 +14,8 @@ class CommandNSUpdate : public Command { - EventHandlers<Event::NickUpdate> &onnickupdate; - public: - CommandNSUpdate(Module *creator, EventHandlers<Event::NickUpdate> &event) : Command(creator, "nickserv/update", 0, 0), onnickupdate(event) + CommandNSUpdate(Module *creator) : Command(creator, "nickserv/update", 0, 0) { this->SetDesc(_("Updates your current status, i.e. it checks for new memos")); this->RequireUser(true); @@ -34,7 +32,7 @@ class CommandNSUpdate : public Command na->SetLastSeen(Anope::CurTime); } - this->onnickupdate(&Event::NickUpdate::OnNickUpdate, u); + EventManager::Get()->Dispatch(&Event::NickUpdate::OnNickUpdate, u); source.Reply(_("Status updated (memos, vhost, chmodes, flags).")); } @@ -53,12 +51,10 @@ class CommandNSUpdate : public Command class NSUpdate : public Module { CommandNSUpdate commandnsupdate; - EventHandlers<Event::NickUpdate> onnickupdate; public: NSUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandnsupdate(this, onnickupdate) - , onnickupdate(this) + , commandnsupdate(this) { } diff --git a/modules/operserv/akill.cpp b/modules/operserv/akill.cpp index 7f366e0c9..1f62b2f55 100644 --- a/modules/operserv/akill.cpp +++ b/modules/operserv/akill.cpp @@ -1,21 +1,18 @@ /* OperServ core functions * - * (C) 2003-2014 Anope Team + * (C) 2003-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. */ #include "module.h" -static ServiceReference<XLineManager> akills("XLineManager", "xlinemanager/sgline"); - class CommandOSAKill : public Command { - private: + ServiceReference<XLineManager> akills; + void DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { Anope::string expiry, mask; @@ -120,7 +117,12 @@ class CommandOSAKill : public Command return; } - XLine *x = new XLine(mask, source.GetNick(), expires, reason); + XLine *x = Serialize::New<XLine *>(); + x->SetMask(mask); + x->SetBy(source.GetNick()); + x->SetExpires(expires); + x->SetReason(reason); + if (Config->GetModule("operserv")->Get<bool>("akillids")) x->SetID(XLineManager::GenerateUID()); @@ -139,7 +141,7 @@ class CommandOSAKill : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnAddXLine(&Event::AddXLine::OnAddXLine, source, x, akills); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::AddXLine::OnAddXLine, source, x, akills); if (MOD_RESULT == EVENT_STOP) { delete x; @@ -212,7 +214,7 @@ class CommandOSAKill : public Command do { - Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, x, akills); + EventManager::Get()->Dispatch(&Event::DelXLine::OnDelXLine, source, x, akills); Log(LOG_ADMIN, source, this) << "to remove " << x->GetMask() << " from the list"; source.Reply(_("\002{0}\002 deleted from the akill list."), x->GetMask()); @@ -256,7 +258,7 @@ class CommandOSAKill : public Command unsigned int i = 0; for (XLine *x : akills->GetXLines()) { - if (mask.empty() || mask.equals_ci(x->GetMask()) || mask == x->id || Anope::Match(x->GetMask(), mask, false, true)) + if (mask.empty() || mask.equals_ci(x->GetMask()) || mask == x->GetID() || Anope::Match(x->GetMask(), mask, false, true)) { ListFormatter::ListEntry entry; entry["Number"] = stringify(++i); @@ -319,7 +321,7 @@ class CommandOSAKill : public Command { for (XLine *x : akills->GetXLines()) { - Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, x, akills); + EventManager::Get()->Dispatch(&Event::DelXLine::OnDelXLine, source, x, akills); x->Delete(); } @@ -331,6 +333,7 @@ class CommandOSAKill : public Command } public: CommandOSAKill(Module *creator) : Command(creator, "operserv/akill", 1, 2) + , akills("xlinemanager/sgline") { this->SetDesc(_("Manipulate the AKILL list")); this->SetSyntax(_("ADD [+\037expiry\037] \037mask\037 \037reason\037")); diff --git a/modules/operserv/chankill.cpp b/modules/operserv/chankill.cpp index 8d3773e9d..81f04583b 100644 --- a/modules/operserv/chankill.cpp +++ b/modules/operserv/chankill.cpp @@ -11,12 +11,13 @@ #include "module.h" -static ServiceReference<XLineManager> akills("XLineManager", "xlinemanager/sgline"); - class CommandOSChanKill : public Command { + ServiceReference<XLineManager> akills; + public: CommandOSChanKill(Module *creator) : Command(creator, "operserv/chankill", 2, 3) + , akills("xlinemanager/sgline") { this->SetDesc(_("AKILL all users on a specific channel")); this->SetSyntax(_("[+\037expiry\037] \037channel\037 \037reason\037")); @@ -83,7 +84,13 @@ class CommandOSChanKill : public Command if (uc->user->server == Me || uc->user->HasMode("OPER")) continue; - XLine *x = new XLine("*@" + uc->user->host, source.GetNick(), expires, realreason, XLineManager::GenerateUID()); + XLine *x = Serialize::New<XLine *>(); + x->SetMask("*@" + uc->user->host); + x->SetBy(source.GetNick()); + x->SetExpires(expires); + x->SetReason(realreason); + x->SetID(XLineManager::GenerateUID()); + akills->AddXLine(x); akills->OnMatch(uc->user, x); } diff --git a/modules/operserv/defcon.cpp b/modules/operserv/defcon.cpp index fc4a096c9..ba081eb06 100644 --- a/modules/operserv/defcon.cpp +++ b/modules/operserv/defcon.cpp @@ -107,11 +107,11 @@ static Timer *timeout; class DefConTimeout : public Timer { - EventHandlers<Event::DefconLevel> &eventdefcon; int level; + ServiceReference<Global::GlobalService> global; public: - DefConTimeout(EventHandlers<Event::DefconLevel> &ev, Module *mod, int newlevel) : Timer(mod, DConfig.timeout), eventdefcon(ev), level(newlevel) + DefConTimeout(Module *mod, int newlevel) : Timer(mod, DConfig.timeout), level(newlevel) { timeout = this; } @@ -126,18 +126,18 @@ class DefConTimeout : public Timer if (DConfig.defaultlevel != level) { DConfig.defaultlevel = level; - this->eventdefcon(&Event::DefconLevel::OnDefconLevel, level); + EventManager::Get()->Dispatch(&Event::DefconLevel::OnDefconLevel, level); Log(Config->GetClient("OperServ"), "operserv/defcon") << "Defcon level timeout, returning to level " << level; - if (DConfig.globalondefcon && Global::service) + if (DConfig.globalondefcon && global) { if (!DConfig.offmessage.empty()) - Global::service->SendGlobal(NULL, "", DConfig.offmessage); + global->SendGlobal(NULL, "", DConfig.offmessage); else - Global::service->SendGlobal(NULL, "", Anope::printf(Language::Translate(_("The Defcon level is now at: \002%d\002")), DConfig.defaultlevel)); + global->SendGlobal(NULL, "", Anope::printf(Language::Translate(_("The Defcon level is now at: \002%d\002")), DConfig.defaultlevel)); if (!DConfig.message.empty()) - Global::service->SendGlobal(NULL, "", DConfig.message); + global->SendGlobal(NULL, "", DConfig.message); } runDefCon(); @@ -147,6 +147,8 @@ class DefConTimeout : public Timer class CommandOSDefcon : public Command { + ServiceReference<Global::GlobalService> global; + void SendLevels(CommandSource &source) { if (DConfig.Check(DEFCON_NO_NEW_CHANNELS)) @@ -171,10 +173,8 @@ class CommandOSDefcon : public Command source.Reply(_("* No new memos sent")); } - EventHandlers<Event::DefconLevel> &ondefconlevel; - public: - CommandOSDefcon(Module *creator, EventHandlers<Event::DefconLevel> &event) : Command(creator, "operserv/defcon", 1, 1), ondefconlevel(event) + CommandOSDefcon(Module *creator) : Command(creator, "operserv/defcon", 1, 1) { this->SetDesc(_("Manipulate the DefCon system")); this->SetSyntax(_("[\0021\002|\0022\002|\0023\002|\0024\002|\0025\002]")); @@ -206,12 +206,12 @@ class CommandOSDefcon : public Command DConfig.defaultlevel = newLevel; - this->ondefconlevel(&Event::DefconLevel::OnDefconLevel, newLevel); + EventManager::Get()->Dispatch(&Event::DefconLevel::OnDefconLevel, newLevel); delete timeout; if (DConfig.timeout) - timeout = new DefConTimeout(this->ondefconlevel, this->module, 5); + timeout = new DefConTimeout(this->module, 5); source.Reply(_("Services are now at defcon \002{0}\002."), DConfig.defaultlevel); this->SendLevels(source); @@ -219,15 +219,15 @@ class CommandOSDefcon : public Command /* Global notice the user what is happening. Also any Message that the Admin would like to add. Set in config file. */ - if (DConfig.globalondefcon && Global::service) + if (DConfig.globalondefcon && global) { if (DConfig.defaultlevel == 5 && !DConfig.offmessage.empty()) - Global::service->SendGlobal(NULL, "", DConfig.offmessage); + global->SendGlobal(NULL, "", DConfig.offmessage); else if (DConfig.defaultlevel != 5) { - Global::service->SendGlobal(NULL, "", Anope::printf(_("The defcon level is now at \002%d\002"), DConfig.defaultlevel)); + global->SendGlobal(NULL, "", Anope::printf(_("The defcon level is now at \002%d\002"), DConfig.defaultlevel)); if (!DConfig.message.empty()) - Global::service->SendGlobal(NULL, "", DConfig.message); + global->SendGlobal(NULL, "", DConfig.message); } } @@ -254,7 +254,6 @@ class OSDefcon : public Module ServiceReference<SessionService> session_service; ServiceReference<XLineManager> akills; CommandOSDefcon commandosdefcon; - EventHandlers<Event::DefconLevel> ondefconlevel; void ParseModeString() { @@ -337,10 +336,14 @@ class OSDefcon : public Module public: OSDefcon(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , session_service("SessionService", "session") - , akills("XLineManager", "xlinemanager/sgline") - , commandosdefcon(this, ondefconlevel) - , ondefconlevel(this) + , EventHook<Event::ChannelModeSet>(this) + , EventHook<Event::ChannelModeUnset>(this) + , EventHook<Event::PreCommand>(this) + , EventHook<Event::UserConnect>(this) + , EventHook<Event::ChannelModeAdd>(this) + , EventHook<Event::ChannelSync>(this) + , akills("xlinemanager/sgline") + , commandosdefcon(this) { } @@ -463,7 +466,7 @@ class OSDefcon : public Module { return EVENT_STOP; } - else if (command->name == "nickserv/register" || command->name == "nickserv/group") + else if (command->GetName() == "nickserv/register" || command->GetName() == "nickserv/group") { if (DConfig.Check(DEFCON_NO_NEW_NICKS)) { @@ -471,7 +474,7 @@ class OSDefcon : public Module return EVENT_STOP; } } - else if (command->name == "chanserv/mode" && params.size() > 1 && params[1].equals_ci("LOCK")) + else if (command->GetName() == "chanserv/mode" && params.size() > 1 && params[1].equals_ci("LOCK")) { if (DConfig.Check(DEFCON_NO_MLOCK_CHANGE)) { @@ -479,7 +482,7 @@ class OSDefcon : public Module return EVENT_STOP; } } - else if (command->name == "chanserv/register") + else if (command->GetName() == "chanserv/register") { if (DConfig.Check(DEFCON_NO_NEW_CHANNELS)) { @@ -487,7 +490,7 @@ class OSDefcon : public Module return EVENT_STOP; } } - else if (command->name == "memoserv/send") + else if (command->GetName() == "memoserv/send") { if (DConfig.Check(DEFCON_NO_NEW_MEMOS)) { @@ -508,8 +511,11 @@ class OSDefcon : public Module if (DConfig.Check(DEFCON_AKILL_NEW_CLIENTS) && akills) { Log(OperServ, "operserv/defcon") << "DEFCON: adding akill for *@" << u->host; +#warning "xline allocated on stack" +#if 0 XLine x("*@" + u->host, OperServ ? OperServ->nick : "defcon", Anope::CurTime + DConfig.akillexpire, DConfig.akillreason, XLineManager::GenerateUID()); akills->Send(NULL, &x); +#endif } if (DConfig.Check(DEFCON_NO_NEW_CLIENTS) || DConfig.Check(DEFCON_AKILL_NEW_CLIENTS)) @@ -539,9 +545,12 @@ class OSDefcon : public Module ++session->hits; if (akills && DConfig.max_session_kill && session->hits >= DConfig.max_session_kill) { +#warning "xline allocated on stack" +#if 0 XLine x("*@" + session->addr.mask(), OperServ ? OperServ->nick : "", Anope::CurTime + DConfig.session_autokill_expiry, "Defcon session limit exceeded", XLineManager::GenerateUID()); akills->Send(NULL, &x); Log(OperServ, "akill/defcon") << "[DEFCON] Added a temporary AKILL for \002*@" << session->addr.mask() << "\002 due to excessive connections"; +#endif } else { diff --git a/modules/operserv/dns.cpp b/modules/operserv/dns.cpp index 1d714700d..2cf79d631 100644 --- a/modules/operserv/dns.cpp +++ b/modules/operserv/dns.cpp @@ -13,6 +13,10 @@ static std::map<Anope::string, std::list<time_t> > server_quit_times; class DNSZoneImpl : public DNSZone { + friend class DNSZoneType; + + Anope::string name; + public: DNSZoneImpl(Serialize::TypeBase *type) : DNSZone(type) { } DNSZoneImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSZone(type, id) { } @@ -22,7 +26,7 @@ class DNSZoneImpl : public DNSZone static DNSZone *Find(const Anope::string &name) { - for (DNSZone *zone : Serialize::GetObjects<DNSZone *>(dnszone)) + for (DNSZone *zone : Serialize::GetObjects<DNSZone *>()) if (zone->GetName().equals_ci(name)) return zone; return nullptr; @@ -34,8 +38,8 @@ class DNSZoneType : public Serialize::Type<DNSZoneImpl> public: Serialize::Field<DNSZoneImpl, Anope::string> name; - DNSZoneType(Module *creator) : Serialize::Type<DNSZoneImpl>(creator, "DNSZone") - , name(this, "name") + DNSZoneType(Module *creator) : Serialize::Type<DNSZoneImpl>(creator) + , name(this, "name", &DNSZoneImpl::name) { } }; @@ -52,6 +56,15 @@ void DNSZoneImpl::SetName(const Anope::string &name) class DNSServerImpl : public DNSServer { + friend class DNSServerType; + + ServiceReference<DNS::Manager> manager; + + DNSZone *zone = nullptr; + Anope::string name; + unsigned int limit = 0; + bool pooled = false; + /* is actually in the pool */ bool active = false; @@ -85,17 +98,17 @@ class DNSServerImpl : public DNSServer this->SetPool(p); active = p; - if (DNS::manager) + if (manager) { - DNS::manager->UpdateSerial(); + manager->UpdateSerial(); for (std::set<Anope::string, ci::less>::iterator it = zones.begin(), it_end = zones.end(); it != it_end; ++it) - DNS::manager->Notify(*it); + manager->Notify(*it); } } static DNSServerImpl *Find(const Anope::string &s) { - for (DNSServerImpl *server : Serialize::GetObjects<DNSServerImpl *>(dnsserver)) + for (DNSServerImpl *server : Serialize::GetObjects<DNSServerImpl *>()) if (server->GetName().equals_ci(s)) return server; return nullptr; @@ -110,11 +123,11 @@ class DNSServerType : public Serialize::Type<DNSServerImpl> Serialize::Field<DNSServerImpl, unsigned int> limit; Serialize::Field<DNSServerImpl, bool> pooled; - DNSServerType(Module *creator) : Serialize::Type<DNSServerImpl>(creator, "DNSServer") - , zone(this, "zone") - , name(this, "name") - , limit(this, "limit") - , pooled(this, "pooled") + DNSServerType(Module *creator) : Serialize::Type<DNSServerImpl>(creator) + , zone(this, "zone", &DNSServerImpl::zone) + , name(this, "name", &DNSServerImpl::name) + , limit(this, "limit", &DNSServerImpl::limit) + , pooled(this, "pooled", &DNSServerImpl::pooled) { } }; @@ -161,6 +174,11 @@ void DNSServerImpl::SetPool(const bool &p) class DNSZoneMembershipImpl : public DNSZoneMembership { + friend class DNSZoneMembershipType; + + DNSServer *server = nullptr; + DNSZone *zone = nullptr; + public: DNSZoneMembershipImpl(Serialize::TypeBase *type) : DNSZoneMembership(type) { } DNSZoneMembershipImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSZoneMembership(type, id) { } @@ -173,7 +191,7 @@ class DNSZoneMembershipImpl : public DNSZoneMembership static DNSZoneMembership *Find(DNSServer *server, DNSZone *zone) { - for (DNSZoneMembership *mem : Serialize::GetObjects<DNSZoneMembership *>(dnszonemembership)) + for (DNSZoneMembership *mem : Serialize::GetObjects<DNSZoneMembership *>()) if (mem->GetServer() == server && mem->GetZone() == zone) return mem; return nullptr; @@ -186,9 +204,9 @@ class DNSZoneMembershipType : public Serialize::Type<DNSZoneMembershipImpl> Serialize::ObjectField<DNSZoneMembershipImpl, DNSServer *> server; Serialize::ObjectField<DNSZoneMembershipImpl, DNSZone *> zone; - DNSZoneMembershipType(Module *creator) : Serialize::Type<DNSZoneMembershipImpl>(creator, "DNSZoneMembership") - , server(this, "server") - , zone(this, "zone") + DNSZoneMembershipType(Module *creator) : Serialize::Type<DNSZoneMembershipImpl>(creator) + , server(this, "server", &DNSZoneMembershipImpl::server) + , zone(this, "zone", &DNSZoneMembershipImpl::zone) { } }; @@ -215,6 +233,11 @@ void DNSZoneMembershipImpl::SetZone(DNSZone *z) class DNSIPImpl : public DNSIP { + friend class DNSIPType; + + DNSServer *server = nullptr; + Anope::string ip; + public: DNSIPImpl(Serialize::TypeBase *type) : DNSIP(type) { } DNSIPImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSIP(type, id) { } @@ -229,12 +252,12 @@ class DNSIPImpl : public DNSIP class DNSIPType : public Serialize::Type<DNSIPImpl> { public: - Serialize::ObjectField<DNSServerImpl, DNSServer *> server; - Serialize::Field<DNSServerImpl, Anope::string> ip; + Serialize::ObjectField<DNSIPImpl, DNSServer *> server; + Serialize::Field<DNSIPImpl, Anope::string> ip; - DNSIPType(Module *creator) : Serialize::Type<DNSIPImpl>(creator, "DNSIP") - , server(this, "server") - , ip(this, "ip") + DNSIPType(Module *creator) : Serialize::Type<DNSIPImpl>(creator) + , server(this, "server", &DNSIPImpl::server) + , ip(this, "ip", &DNSIPImpl::ip) { } }; @@ -261,9 +284,11 @@ void DNSIPImpl::SetIP(const Anope::string &ip) class CommandOSDNS : public Command { + ServiceReference<DNS::Manager> manager; + void DisplayPoolState(CommandSource &source) { - std::vector<DNSServerImpl *> servers = Serialize::GetObjects<DNSServerImpl *>(dnsserver); + std::vector<DNSServerImpl *> servers = Serialize::GetObjects<DNSServerImpl *>(); if (servers.empty()) { @@ -282,7 +307,7 @@ class CommandOSDNS : public Command entry["Limit"] = s->GetLimit() ? stringify(s->GetLimit()) : Language::Translate(source.GetAccount(), _("None")); Anope::string ip_str; - for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip)) + for (DNSIP *ip : s->GetRefs<DNSIP *>()) ip_str += ip->GetIP() + " "; ip_str.trim(); if (ip_str.empty()) @@ -305,7 +330,7 @@ class CommandOSDNS : public Command std::vector<Anope::string> replies; lf.Process(replies); - std::vector<DNSZone *> zones = Serialize::GetObjects<DNSZone *>(dnszone); + std::vector<DNSZone *> zones = Serialize::GetObjects<DNSZone *>(); if (!zones.empty()) { ListFormatter lf2(source.GetAccount()); @@ -317,7 +342,7 @@ class CommandOSDNS : public Command entry["Zone"] = z->GetName(); Anope::string server_str; - for (DNSServer *s : z->GetRefs<DNSServer *>(dnsserver)) + for (DNSServer *s : z->GetRefs<DNSServer *>()) server_str += s->GetName() + " "; server_str.trim(); @@ -351,7 +376,7 @@ class CommandOSDNS : public Command Log(LOG_ADMIN, source, this) << "to add zone " << zone; - DNSZone *z = dnszone.Create(); + DNSZone *z = Serialize::New<DNSZone *>(); z->SetName(zone); source.Reply(_("Added zone \002{0}\002."), zone); } @@ -372,13 +397,13 @@ class CommandOSDNS : public Command Log(LOG_ADMIN, source, this) << "to delete zone " << z->GetName(); - for (DNSZoneMembership *mem : z->GetRefs<DNSZoneMembership *>(dnszonemembership)) + for (DNSZoneMembership *mem : z->GetRefs<DNSZoneMembership *>()) mem->Delete(); - if (DNS::manager) + if (manager) { - DNS::manager->UpdateSerial(); - DNS::manager->Notify(z->GetName()); + manager->UpdateSerial(); + manager->Notify(z->GetName()); } source.Reply(_("Zone \002{0}\002 removed."), z->GetName()); @@ -415,14 +440,14 @@ class CommandOSDNS : public Command if (Anope::ReadOnly) source.Reply(_("Services are in read-only mode. Any changes made may not persist.")); - mem = dnszonemembership.Create(); + mem = Serialize::New<DNSZoneMembership *>(); mem->SetZone(z); mem->SetServer(s); - if (DNS::manager) + if (manager) { - DNS::manager->UpdateSerial(); - DNS::manager->Notify(zone); + manager->UpdateSerial(); + manager->Notify(zone); } Log(LOG_ADMIN, source, this) << "to add server " << s->GetName() << " to zone " << z->GetName(); @@ -440,7 +465,7 @@ class CommandOSDNS : public Command return; } - s = dnsserver.Create(); + s = Serialize::New<DNSServer *>(); s->SetName(params[1]); if (zone.empty()) { @@ -465,14 +490,14 @@ class CommandOSDNS : public Command Log(LOG_ADMIN, source, this) << "to add server " << s->GetName() << " to zone " << zone; - DNSZoneMembership *mem = dnszonemembership.Create(); + DNSZoneMembership *mem = Serialize::New<DNSZoneMembership *>(); mem->SetServer(s); mem->SetZone(z); - if (DNS::manager) + if (manager) { - DNS::manager->UpdateSerial(); - DNS::manager->Notify(z->GetName()); + manager->UpdateSerial(); + manager->Notify(z->GetName()); } } } @@ -509,10 +534,10 @@ class CommandOSDNS : public Command Log(LOG_ADMIN, source, this) << "to remove server " << s->GetName() << " from zone " << z->GetName(); - if (DNS::manager) + if (manager) { - DNS::manager->UpdateSerial(); - DNS::manager->Notify(z->GetName()); + manager->UpdateSerial(); + manager->Notify(z->GetName()); } mem->Delete(); @@ -526,14 +551,14 @@ class CommandOSDNS : public Command return; } - for (DNSZoneMembership *mem : s->GetRefs<DNSZoneMembership *>(dnszonemembership)) + for (DNSZoneMembership *mem : s->GetRefs<DNSZoneMembership *>()) mem->Delete(); if (Anope::ReadOnly) source.Reply(_("Services are in read-only mode. Any changes made may not persist.")); - if (DNS::manager) - DNS::manager->UpdateSerial(); + if (manager) + manager->UpdateSerial(); Log(LOG_ADMIN, source, this) << "to delete server " << s->GetName(); source.Reply(_("Removed server \002{0}\002."), s->GetName()); @@ -550,7 +575,7 @@ class CommandOSDNS : public Command return; } - for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip)) + for (DNSIP *ip : s->GetRefs<DNSIP *>()) if (params[2].equals_ci(ip->GetIP())) { source.Reply(_("IP \002{0}\002 already exists for \002{1}\002."), ip->GetIP(), s->GetName()); @@ -567,18 +592,18 @@ class CommandOSDNS : public Command if (Anope::ReadOnly) source.Reply(_("Services are in read-only mode. Any changes made may not persist.")); - DNSIP *ip = dnsip.Create(); + DNSIP *ip = Serialize::New<DNSIP *>(); ip->SetServer(s); ip->SetIP(params[2]); source.Reply(_("Added IP \002{0}\002 to \002{1}\002."), params[2], s->GetName()); Log(LOG_ADMIN, source, this) << "to add IP " << params[2] << " to " << s->GetName(); - if (s->Active() && DNS::manager) + if (s->Active() && manager) { - DNS::manager->UpdateSerial(); - for (DNSZone *zone : s->GetRefs<DNSZone *>(dnszone)) - DNS::manager->Notify(zone->GetName()); + manager->UpdateSerial(); + for (DNSZone *zone : s->GetRefs<DNSZone *>()) + manager->Notify(zone->GetName()); } } @@ -595,7 +620,7 @@ class CommandOSDNS : public Command if (Anope::ReadOnly) source.Reply(_("Services are in read-only mode. Any changes made may not persist.")); - for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip)) + for (DNSIP *ip : s->GetRefs<DNSIP *>()) if (params[2].equals_ci(ip->GetIP())) { ip->Delete(); @@ -603,17 +628,17 @@ class CommandOSDNS : public Command source.Reply(_("Removed IP \002{0}\002 from \002{1}\002."), params[2], s->GetName()); Log(LOG_ADMIN, source, this) << "to remove IP " << params[2] << " from " << s->GetName(); - if (s->GetRefs<DNSIP *>(dnsip).empty()) + if (s->GetRefs<DNSIP *>().empty()) { s->repool = 0; s->SetPool(false); } - if (s->Active() && DNS::manager) + if (s->Active() && manager) { - DNS::manager->UpdateSerial(); - for (DNSZone *zone : s->GetRefs<DNSZone *>(dnszone)) - DNS::manager->Notify(zone->GetName()); + manager->UpdateSerial(); + for (DNSZone *zone : s->GetRefs<DNSZone *>()) + manager->Notify(zone->GetName()); } return; @@ -677,7 +702,7 @@ class CommandOSDNS : public Command return; } - if (s->GetRefs<DNSIP *>(dnsip).empty()) + if (s->GetRefs<DNSIP *>().empty()) { source.Reply(_("Server \002{0}\002 has no configured IPs."), s->GetName()); return; @@ -791,32 +816,34 @@ class ModuleDNS : public Module DNSIPType iptype; CommandOSDNS commandosdns; - time_t ttl; - int user_drop_mark; - time_t user_drop_time; - time_t user_drop_readd_time; - bool remove_split_servers; - bool readd_connected_servers; + time_t ttl = 0; + int user_drop_mark = 0; + time_t user_drop_time = 0; + time_t user_drop_readd_time = 0; + bool remove_split_servers = 0; + bool readd_connected_servers = 0; - time_t last_warn; + time_t last_warn = 0; public: ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::NewServer>(this) + , EventHook<Event::ServerQuit>(this) + , EventHook<Event::UserConnect>(this) + , EventHook<Event::PreUserLogoff>(this) + , EventHook<Event::DnsRequest>(this) , zonetype(this) , servertype(this) , zonemembtype(this) , iptype(this) , commandosdns(this) - , last_warn(0) { -#if 0 - for (unsigned j = 0; j < dns_servers->size(); ++j) - { - DNSServer *s = dns_servers->at(j); - if (s->Pooled() && Server::Find(s->GetName(), true)) + /* enable active flag for linked servers */ + std::vector<DNSServerImpl *> servers = Serialize::GetObjects<DNSServerImpl *>(); + + for (DNSServerImpl *s : servers) + if (s->GetPooled() && Server::Find(s->GetName(), true)) s->SetActive(true); - } -#endif } ~ModuleDNS() @@ -841,7 +868,7 @@ class ModuleDNS : public Module if (!Me->IsSynced() || this->readd_connected_servers) { DNSServerImpl *dns = DNSServerImpl::Find(s->GetName()); - if (dns && dns->GetPooled() && !dns->Active() && !dns->GetRefs<DNSIP *>(dnsip).empty()) + if (dns && dns->GetPooled() && !dns->Active() && !dns->GetRefs<DNSIP *>().empty()) { dns->SetActive(true); Log(this) << "Pooling server " << s->GetName(); @@ -934,12 +961,12 @@ class ModuleDNS : public Module size_t answer_size = packet->answers.size(); if (zone) { - for (DNSServerImpl *s : zone->GetRefs<DNSServerImpl *>(dnsserver)) + for (DNSServerImpl *s : zone->GetRefs<DNSServerImpl *>()) { if (!s->Active()) continue; - for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip)) + for (DNSIP *ip : s->GetRefs<DNSIP *>()) { DNS::QueryType q_type = ip->GetIP().find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A; @@ -957,12 +984,12 @@ class ModuleDNS : public Module if (packet->answers.size() == answer_size) { /* Default zone */ - for (DNSServerImpl *s : Serialize::GetObjects<DNSServerImpl *>(dnsserver)) + for (DNSServerImpl *s : Serialize::GetObjects<DNSServerImpl *>()) { if (!s->Active()) continue; - for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip)) + for (DNSIP *ip : s->GetRefs<DNSIP *>()) { DNS::QueryType q_type = ip->GetIP().find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A; @@ -986,8 +1013,8 @@ class ModuleDNS : public Module } /* Something messed up, just return them all and hope one is available */ - for (DNSServer *s : Serialize::GetObjects<DNSServer *>(dnsserver)) - for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip)) + for (DNSServer *s : Serialize::GetObjects<DNSServer *>()) + for (DNSIP *ip : s->GetRefs<DNSIP *>()) { DNS::QueryType q_type = ip->GetIP().find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A; diff --git a/modules/operserv/forbid.cpp b/modules/operserv/forbid.cpp index 2375eddcd..6fb0172cf 100644 --- a/modules/operserv/forbid.cpp +++ b/modules/operserv/forbid.cpp @@ -16,6 +16,12 @@ class ForbidDataImpl : public ForbidData { + friend class ForbidDataType; + + Anope::string mask, creator, reason; + time_t created = 0, expires = 0; + ForbidType type = static_cast<ForbidType>(0); + public: ForbidDataImpl(Serialize::TypeBase *type) : ForbidData(type) { } ForbidDataImpl(Serialize::TypeBase *type, Serialize::ID id) : ForbidData(type, id) { } @@ -46,13 +52,13 @@ class ForbidDataType : public Serialize::Type<ForbidDataImpl> Serialize::Field<ForbidDataImpl, time_t> created, expires; Serialize::Field<ForbidDataImpl, ForbidType> type; - ForbidDataType(Module *me) : Serialize::Type<ForbidDataImpl>(me, "ForbidData") - , mask(this, "mask") - , creator(this, "creator") - , reason(this, "reason") - , created(this, "created") - , expires(this, "expires") - , type(this, "type") + ForbidDataType(Module *me) : Serialize::Type<ForbidDataImpl>(me) + , mask(this, "mask", &ForbidDataImpl::mask) + , creator(this, "creator", &ForbidDataImpl::creator) + , reason(this, "reason", &ForbidDataImpl::reason) + , created(this, "created", &ForbidDataImpl::created) + , expires(this, "expires", &ForbidDataImpl::expires) + , type(this, "type", &ForbidDataImpl::type) { } }; @@ -134,7 +140,7 @@ class MyForbidService : public ForbidService std::vector<ForbidData *> GetForbids() override { - for (ForbidData *d : Serialize::GetObjects<ForbidData *>(forbiddata)) + for (ForbidData *d : Serialize::GetObjects<ForbidData *>()) if (d->GetExpires() && !Anope::NoExpire && Anope::CurTime >= d->GetExpires()) { Anope::string ftype = "none"; @@ -148,15 +154,16 @@ class MyForbidService : public ForbidService Log(LOG_NORMAL, "expire/forbid", Config->GetClient("OperServ")) << "Expiring forbid for " << d->GetMask() << " type " << ftype; d->Delete(); } - return Serialize::GetObjects<ForbidData *>(forbiddata); + return Serialize::GetObjects<ForbidData *>(); } }; class CommandOSForbid : public Command { ServiceReference<ForbidService> fs; + public: - CommandOSForbid(Module *creator) : Command(creator, "operserv/forbid", 1, 5), fs("ForbidService", "forbid") + CommandOSForbid(Module *creator) : Command(creator, "operserv/forbid", 1, 5) { this->SetDesc(_("Forbid usage of nicknames, channels, and emails")); this->SetSyntax(_("ADD {NICK|CHAN|EMAIL|REGISTER} [+\037expiry\037] \037entry\037 \037reason\037")); @@ -242,7 +249,7 @@ class CommandOSForbid : public Command bool created = false; if (d == NULL) { - d = forbiddata.Create(); + d = Serialize::New<ForbidData *>(); created = true; } @@ -303,8 +310,11 @@ class CommandOSForbid : public Command if (IRCD->CanSQLineChannel && OperServ) { time_t inhabit = Config->GetModule("chanserv")->Get<time_t>("inhabit", "15s"); +#warning "xline allocated on stack" +#if 0 XLine x(c->name, OperServ->nick, Anope::CurTime + inhabit, d->GetReason()); IRCD->SendSQLine(NULL, &x); +#endif } else if (ChanServ::service) { @@ -460,6 +470,10 @@ class OSForbid : public Module public: OSForbid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::UserConnect>(this) + , EventHook<Event::UserNickChange>(this) + , EventHook<Event::CheckKick>(this) + , EventHook<Event::PreCommand>(this) , forbid_service(this) , type(this) , commandosforbid(this) @@ -491,8 +505,11 @@ class OSForbid : public Module if (IRCD->CanSQLineChannel) { time_t inhabit = Config->GetModule("chanserv")->Get<time_t>("inhabit", "15s"); +#warning "xline allocated on stack" +#if 0 XLine x(c->name, OperServ->nick, Anope::CurTime + inhabit, d->GetReason()); IRCD->SendSQLine(NULL, &x); +#endif } else if (ChanServ::service) { @@ -509,7 +526,7 @@ class OSForbid : public Module EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> ¶ms) override { - if (command->name == "nickserv/info" && params.size() > 0) + if (command->GetName() == "nickserv/info" && params.size() > 0) { ForbidData *d = this->forbid_service.FindForbid(params[0], FT_NICK); if (d != NULL) @@ -521,7 +538,7 @@ class OSForbid : public Module return EVENT_STOP; } } - else if (command->name == "chanserv/info" && params.size() > 0) + else if (command->GetName() == "chanserv/info" && params.size() > 0) { ForbidData *d = this->forbid_service.FindForbid(params[0], FT_CHAN); if (d != NULL) @@ -535,7 +552,7 @@ class OSForbid : public Module } else if (source.IsOper()) return EVENT_CONTINUE; - else if (command->name == "nickserv/register" && params.size() > 1) + else if (command->GetName() == "nickserv/register" && params.size() > 1) { ForbidData *d = this->forbid_service.FindForbid(source.GetNick(), FT_REGISTER); if (d != NULL) @@ -551,7 +568,7 @@ class OSForbid : public Module return EVENT_STOP; } } - else if (command->name == "nickserv/set/email" && params.size() > 0) + else if (command->GetName() == "nickserv/set/email" && params.size() > 0) { ForbidData *d = this->forbid_service.FindForbid(params[0], FT_EMAIL); if (d != NULL) @@ -560,7 +577,7 @@ class OSForbid : public Module return EVENT_STOP; } } - else if (command->name == "chanserv/register" && !params.empty()) + else if (command->GetName() == "chanserv/register" && !params.empty()) { ForbidData *d = this->forbid_service.FindForbid(params[0], FT_REGISTER); if (d != NULL) diff --git a/modules/operserv/ignore.cpp b/modules/operserv/ignore.cpp index 0aeab0718..ffd85e5e9 100644 --- a/modules/operserv/ignore.cpp +++ b/modules/operserv/ignore.cpp @@ -14,6 +14,11 @@ class IgnoreImpl : public Ignore { + friend class IgnoreType; + + Anope::string mask, creator, reason; + time_t time = 0; + public: IgnoreImpl(Serialize::TypeBase *type) : Ignore(type) { } IgnoreImpl(Serialize::TypeBase *type, Serialize::ID id) : Ignore(type, id) { } @@ -37,11 +42,11 @@ class IgnoreType : public Serialize::Type<IgnoreImpl> Serialize::Field<IgnoreImpl, Anope::string> mask, creator, reason; Serialize::Field<IgnoreImpl, time_t> time; - IgnoreType(Module *me) : Serialize::Type<IgnoreImpl>(me, "IgnoreData") - , mask(this, "mask") - , creator(this, "creator") - , reason(this, "reason") - , time(this, "time") + IgnoreType(Module *me) : Serialize::Type<IgnoreImpl>(me) + , mask(this, "mask", &IgnoreImpl::mask) + , creator(this, "creator", &IgnoreImpl::creator) + , reason(this, "reason", &IgnoreImpl::reason) + , time(this, "time", &IgnoreImpl::time) { } }; @@ -96,7 +101,7 @@ class OSIgnoreService : public IgnoreService Ignore *Find(const Anope::string &mask) override { User *u = User::Find(mask, true); - std::vector<Ignore *> ignores = Serialize::GetObjects<Ignore *>(ignoretype); + std::vector<Ignore *> ignores = Serialize::GetObjects<Ignore *>(); std::vector<Ignore *>::iterator ign = ignores.begin(), ign_end = ignores.end(); if (u) @@ -155,6 +160,8 @@ class OSIgnoreService : public IgnoreService class CommandOSIgnore : public Command { + ServiceReference<IgnoreService> ignore_service; + private: Anope::string RealMask(const Anope::string &mask) { @@ -216,7 +223,7 @@ class CommandOSIgnore : public Command if (Anope::ReadOnly) source.Reply(_("Services are in read-only mode. Any changes made may not persist.")); - Ignore *ign = ignoretype.Create(); + Ignore *ign = Serialize::New<Ignore *>(); ign->SetMask(mask); ign->SetCreator(source.GetNick()); ign->SetReason(reason); @@ -236,7 +243,7 @@ class CommandOSIgnore : public Command void DoList(CommandSource &source) { - std::vector<Ignore *> ignores = Serialize::GetObjects<Ignore *>(ignoretype); + std::vector<Ignore *> ignores = Serialize::GetObjects<Ignore *>(); for (Ignore *id : ignores) { @@ -247,7 +254,7 @@ class CommandOSIgnore : public Command } } - ignores = Serialize::GetObjects<Ignore *>(ignoretype); + ignores = Serialize::GetObjects<Ignore *>(); if (ignores.empty()) { source.Reply(_("Ignore list is empty.")); @@ -312,7 +319,7 @@ class CommandOSIgnore : public Command if (Anope::ReadOnly) source.Reply(_("Services are in read-only mode. Any changes made may not persist.")); - for (Ignore *ign : Serialize::GetObjects<Ignore *>(ignoretype)) + for (Ignore *ign : Serialize::GetObjects<Ignore *>()) ign->Delete(); Log(LOG_ADMIN, source, this) << "to CLEAR the list"; @@ -374,6 +381,7 @@ class OSIgnore : public Module public: OSIgnore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::BotPrivmsg>(this) , ignoretype(this) , osignoreservice(this) , commandosignore(this) diff --git a/modules/operserv/info.cpp b/modules/operserv/info.cpp index bb0eb8274..c1d625601 100644 --- a/modules/operserv/info.cpp +++ b/modules/operserv/info.cpp @@ -13,6 +13,12 @@ class OperInfoImpl : public OperInfo { + friend class OperInfoType; + + Serialize::Object *target = nullptr; + Anope::string info, creator; + time_t created = 0; + public: OperInfoImpl(Serialize::TypeBase *type) : OperInfo(type) { } OperInfoImpl(Serialize::TypeBase *type, Serialize::ID id) : OperInfo(type, id) { } @@ -37,11 +43,11 @@ class OperInfoType : public Serialize::Type<OperInfoImpl> Serialize::Field<OperInfoImpl, Anope::string> info, creator; Serialize::Field<OperInfoImpl, time_t> created; - OperInfoType(Module *c) : Serialize::Type<OperInfoImpl>(c, "OperInfo") - , target(this, "target", true) - , info(this, "info") - , creator(this, "adder") - , created(this, "created") + OperInfoType(Module *c) : Serialize::Type<OperInfoImpl>(c) + , target(this, "target", &OperInfoImpl::target, true) + , info(this, "info", &OperInfoImpl::info) + , creator(this, "adder", &OperInfoImpl::creator) + , created(this, "created", &OperInfoImpl::created) { } }; @@ -133,7 +139,7 @@ class CommandOSInfo : public Command return; } - std::vector<OperInfo *> oinfos = e->GetRefs<OperInfo *>(operinfo); + std::vector<OperInfo *> oinfos = e->GetRefs<OperInfo *>(); if (oinfos.size() >= Config->GetModule(this->module)->Get<unsigned int>("max", "10")) { source.Reply(_("The oper info list for \002{0}\002 is full."), target); @@ -147,7 +153,7 @@ class CommandOSInfo : public Command return; } - OperInfo *o = operinfo.Create(); + OperInfo *o = Serialize::New<OperInfo *>(); o->SetTarget(e); o->SetInfo(info); o->SetCreator(source.GetNick()); @@ -167,7 +173,7 @@ class CommandOSInfo : public Command return; } - std::vector<OperInfo *> oinfos = e->GetRefs<OperInfo *>(operinfo); + std::vector<OperInfo *> oinfos = e->GetRefs<OperInfo *>(); if (oinfos.empty()) { source.Reply(_("Oper info list for \002{0}\002 is empty."), target); @@ -193,7 +199,7 @@ class CommandOSInfo : public Command } else if (cmd.equals_ci("CLEAR")) { - std::vector<OperInfo *> oinfos = e->GetRefs<OperInfo *>(operinfo); + std::vector<OperInfo *> oinfos = e->GetRefs<OperInfo *>(); if (oinfos.empty()) { @@ -235,12 +241,14 @@ class OSInfo : public Module if (!source.IsOper()) return; - for (OperInfo *o : e->GetRefs<OperInfo *>(operinfo)) + for (OperInfo *o : e->GetRefs<OperInfo *>()) info[_("Oper Info")] = Anope::printf(_("(by %s on %s) %s"), o->GetCreator().c_str(), Anope::strftime(o->GetCreated(), source.GetAccount(), true).c_str(), o->GetInfo().c_str()); } public: OSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::NickInfo>(this) + , EventHook<Event::ChanInfo>(this) , commandosinfo(this) , oinfotype(this) { diff --git a/modules/operserv/login.cpp b/modules/operserv/login.cpp index 650c48e3d..fa4daf11d 100644 --- a/modules/operserv/login.cpp +++ b/modules/operserv/login.cpp @@ -100,7 +100,7 @@ class CommandOSLogout : public Command } Log(LOG_ADMIN, source, this); - u->ShrinkOK<bool>("os_login"); + u->Shrink<bool>("os_login"); source.Reply(_("You have been logged out.")); } @@ -125,6 +125,7 @@ class OSLogin : public Module public: OSLogin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::IsServicesOperEvent>(this) , commandoslogin(this) , commandoslogout(this) , os_login(this, "os_login") diff --git a/modules/operserv/logsearch.cpp b/modules/operserv/logsearch.cpp index 0fa425aba..543430c50 100644 --- a/modules/operserv/logsearch.cpp +++ b/modules/operserv/logsearch.cpp @@ -89,7 +89,7 @@ class CommandOSLogSearch : public Command Log(LOG_ADMIN, source, this) << "for " << search_string; - const Anope::string &logfile_name = Config->GetModule(this->owner)->Get<Anope::string>("logname"); + const Anope::string &logfile_name = Config->GetModule(this->GetOwner())->Get<Anope::string>("logname"); std::list<Anope::string> matches; for (int d = days - 1; d >= 0; --d) { diff --git a/modules/operserv/main/operserv.cpp b/modules/operserv/main/operserv.cpp index 0a4f1b692..40c392ea7 100644 --- a/modules/operserv/main/operserv.cpp +++ b/modules/operserv/main/operserv.cpp @@ -13,15 +13,6 @@ #include "modules/help.h" #include "modules/nickserv.h" -class SGlineType : public XLineType -{ - public: - SGlineType(Module *creator) : XLineType(creator, "SGLine") - { - SetParent(xline); - } -}; - class SGLineManager : public XLineManager { public: @@ -74,15 +65,6 @@ class SGLineManager : public XLineManager } }; -class SQlineType : public XLineType -{ - public: - SQlineType(Module *creator) : XLineType(creator, "SQLine") - { - SetParent(xline); - } -}; - class SQLineManager : public XLineManager { public: @@ -152,15 +134,6 @@ class SQLineManager : public XLineManager } }; -class SNlineType : public XLineType -{ - public: - SNlineType(Module *creator) : XLineType(creator, "SNLine") - { - SetParent(xline); - } -}; - class SNLineManager : public XLineManager { public: @@ -211,20 +184,23 @@ class OperServCore : public Module , public EventHook<Event::Log> { Reference<ServiceBot> OperServ; - SGlineType sgtype; SGLineManager sglines; - SQlineType sqtype; SQLineManager sqlines; - SNlineType sntype; SNLineManager snlines; public: OperServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) - , sgtype(this) + , EventHook<Event::BotPrivmsg>(this) + , EventHook<Event::ServerQuit>(this) + , EventHook<Event::UserModeSet>(this) + , EventHook<Event::UserModeUnset>(this) + , EventHook<Event::UserConnect>(this) + , EventHook<Event::UserNickChange>(this) + , EventHook<Event::CheckKick>(this) + , EventHook<Event::Help>(this) + , EventHook<Event::Log>(this) , sglines(this) - , sqtype(this) , sqlines(this) - , sntype(this) , snlines(this) { @@ -250,11 +226,11 @@ class OperServCore : public Module const Anope::string &osnick = conf->GetModule(this)->Get<Anope::string>("client"); if (osnick.empty()) - throw ConfigException(this->name + ": <client> must be defined"); + throw ConfigException(Module::name + ": <client> must be defined"); ServiceBot *bi = ServiceBot::Find(osnick, true); if (!bi) - throw ConfigException(this->name + ": no bot named " + osnick); + throw ConfigException(Module::name + ": no bot named " + osnick); OperServ = bi; } diff --git a/modules/operserv/modinfo.cpp b/modules/operserv/modinfo.cpp index f3c6db00f..8fc76d3d7 100644 --- a/modules/operserv/modinfo.cpp +++ b/modules/operserv/modinfo.cpp @@ -31,16 +31,15 @@ class CommandOSModInfo : public Command { source.Reply(_("Module: \002{0}\002 Version: \002{1}\002 Author: \002{2}\002 Loaded: \002{3}\002"), m->name, !m->version.empty() ? m->version : "?", !m->author.empty() ? m->author : "Unknown", Anope::strftime(m->created, source.GetAccount())); if (Anope::Debug) - source.Reply(_(" Loaded at: {0}"), Anope::printf("%o", m->handle)); + source.Reply(_(" Loaded at: {0}"), Anope::printf("0x%x", m->handle)); - std::vector<Anope::string> servicekeys = Service::GetServiceKeys("Command"); - for (unsigned i = 0; i < servicekeys.size(); ++i) + std::vector<Command *> commands = ServiceManager::Get()->FindServices<Command *>(); + for (Command *c : commands) { - ServiceReference<Command> c("Command", servicekeys[i]); - if (!c || c->owner != m) + if (c->GetOwner() != m) continue; - source.Reply(_(" Providing service: \002{0}\002"), c->name); + source.Reply(_(" Providing service: \002{0}\002"), c->GetName()); for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { @@ -55,9 +54,9 @@ class CommandOSModInfo : public Command { const Anope::string &c_name = cit->first; const CommandInfo &info = cit->second; - if (info.name != c->name) + if (info.name != c->GetName()) continue; - source.Reply(_(" Command \002{0}\002 on \002{1}\002 is linked to \002{2}\002"), c_name, bi->nick, c->name); + source.Reply(_(" Command \002{0}\002 on \002{1}\002 is linked to \002{2}\002"), c_name, bi->nick, c->GetName()); } } } diff --git a/modules/operserv/module.cpp b/modules/operserv/module.cpp index 14bc897e3..311757bc0 100644 --- a/modules/operserv/module.cpp +++ b/modules/operserv/module.cpp @@ -137,7 +137,7 @@ class CommandOSModUnLoad : public Command return; } - Log(this->owner) << "Trying to unload module [" << mname << "]"; + Log(this->GetOwner()) << "Trying to unload module [" << mname << "]"; ModuleReturn status = ModuleManager::UnloadModule(m, source.GetUser()); diff --git a/modules/operserv/news.cpp b/modules/operserv/news.cpp index c14103f2e..8180c3b3d 100644 --- a/modules/operserv/news.cpp +++ b/modules/operserv/news.cpp @@ -1,12 +1,10 @@ /* OperServ core functions * - * (C) 2003-2014 Anope Team + * (C) 2003-2016 Anope Team * Contact us at info@anope.org * * Please read COPYING and README for further details. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. */ #include "module.h" @@ -67,6 +65,12 @@ static struct NewsMessages class NewsItemImpl : public NewsItem { + friend class NewsItemType; + + NewsType type; + Anope::string text, who; + time_t time = 0; + public: NewsItemImpl(Serialize::TypeBase *type) : NewsItem(type) { } NewsItemImpl(Serialize::TypeBase *type, Serialize::ID id) : NewsItem(type, id) { } @@ -92,11 +96,11 @@ class NewsItemType : public Serialize::Type<NewsItemImpl> Serialize::Field<NewsItemImpl, Anope::string> who; Serialize::Field<NewsItemImpl, time_t> time; - NewsItemType(Module *me) : Serialize::Type<NewsItemImpl>(me, "NewsItem") - , type(this, "type") - , text(this, "text") - , who(this, "who") - , time(this, "time") + NewsItemType(Module *me) : Serialize::Type<NewsItemImpl>(me) + , type(this, "type", &NewsItemImpl::type) + , text(this, "text", &NewsItemImpl::text) + , who(this, "who", &NewsItemImpl::who) + , time(this, "time", &NewsItemImpl::time) { } }; @@ -154,7 +158,7 @@ class NewsBase : public Command protected: void DoList(CommandSource &source, NewsType ntype, const char **msgs) { - std::vector<NewsItem *> list = Serialize::GetObjects<NewsItem *>(newsitem); + std::vector<NewsItem *> list = Serialize::GetObjects<NewsItem *>(); if (list.empty()) { @@ -200,7 +204,7 @@ class NewsBase : public Command if (Anope::ReadOnly) source.Reply(_("Services are in read-only mode. Any changes made may not persist.")); - NewsItem *ni = newsitem.Create(); + NewsItem *ni = Serialize::New<NewsItem *>(); ni->SetNewsType(ntype); ni->SetText(text); ni->SetTime(Anope::CurTime); @@ -213,7 +217,7 @@ class NewsBase : public Command void DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms, NewsType ntype, const char **msgs) { const Anope::string &text = params.size() > 1 ? params[1] : ""; - std::vector<NewsItem *> list = Serialize::GetObjects<NewsItem *>(newsitem); + std::vector<NewsItem *> list = Serialize::GetObjects<NewsItem *>(); if (text.empty()) { @@ -304,7 +308,7 @@ class CommandOSLogonNews : public NewsBase source.Reply(_("Edits or displays the list of logon news messages. When a user connects to the network, these messages will be sent to them." " However, no more than \002{0}\002 messages will be sent in order to avoid flooding the user." " If there are more news messages, only the most recent will be sent."), - Config->GetModule(this->owner)->Get<unsigned>("newscount", "3")); + Config->GetModule(this->GetOwner())->Get<unsigned>("newscount", "3")); return true; } }; @@ -328,7 +332,7 @@ class CommandOSOperNews : public NewsBase " When a user opers up (with the /OPER command), these messages will be sent to them." " However, no more than \002{0}\002 messages will be sent in order to avoid flooding the user." " If there are more news messages, only the most recent will be sent."), - Config->GetModule(this->owner)->Get<unsigned>("newscount", "3")); + Config->GetModule(this->GetOwner())->Get<unsigned>("newscount", "3")); return true; } }; @@ -369,7 +373,7 @@ class OSNews : public Module void DisplayNews(User *u, NewsType Type) { - std::vector<NewsItem *> list = Serialize::GetObjects<NewsItem *>(newsitem); + std::vector<NewsItem *> list = Serialize::GetObjects<NewsItem *>(); if (list.empty()) return; @@ -426,6 +430,8 @@ class OSNews : public Module public: OSNews(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::UserModeSet>(this) + , EventHook<Event::UserConnect>(this) , newsitemtype(this) , commandoslogonnews(this) , commandosopernews(this) diff --git a/modules/operserv/noop.cpp b/modules/operserv/noop.cpp index a12bef6a2..d2711b7f4 100644 --- a/modules/operserv/noop.cpp +++ b/modules/operserv/noop.cpp @@ -52,7 +52,7 @@ class CommandOSNOOP : public Command } else if (cmd.equals_ci("REVOKE")) { - s->ShrinkOK<Anope::string>("noop"); + s->Shrink<Anope::string>("noop"); IRCD->SendSVSNOOP(s, false); Log(LOG_ADMIN, source, this) << "REVOKE on " << s->GetName(); source.Reply(_("All O:lines of \002{0}\002 have been reset."), s->GetName()); @@ -77,6 +77,7 @@ class OSNOOP : public Module public: OSNOOP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::UserModeSet>(this) , commandosnoop(this) , noop(this, "noop") { diff --git a/modules/operserv/oper.cpp b/modules/operserv/oper.cpp index 923137013..780c71903 100644 --- a/modules/operserv/oper.cpp +++ b/modules/operserv/oper.cpp @@ -79,7 +79,7 @@ class CommandOSOper : public Command na->GetAccount()->o = nullptr; } - Oper *o = operblock.Create(); + Oper *o = Serialize::New<Oper *>(); o->SetName(na->GetAccount()->GetDisplay()); o->SetType(ot); o->SetRequireOper(true); diff --git a/modules/operserv/reload.cpp b/modules/operserv/reload.cpp index 217194e18..1d3d041d4 100644 --- a/modules/operserv/reload.cpp +++ b/modules/operserv/reload.cpp @@ -35,7 +35,7 @@ class CommandOSReload : public Command } catch (const ConfigException &ex) { - Log(this->owner) << "Error reloading configuration file: " << ex.GetReason(); + Log(this->GetOwner()) << "Error reloading configuration file: " << ex.GetReason(); source.Reply(_("Error reloading configuration file: {0}"), ex.GetReason()); } } diff --git a/modules/operserv/session.cpp b/modules/operserv/session.cpp index 0c20e6d7a..31944e9b6 100644 --- a/modules/operserv/session.cpp +++ b/modules/operserv/session.cpp @@ -33,12 +33,16 @@ namespace /* Number of bits to use when comparing session IPs */ unsigned ipv4_cidr; unsigned ipv6_cidr; - - EventHandlers<Event::Exception> *events; } class ExceptionImpl : public Exception { + friend class ExceptionType; + + Anope::string mask, who, reason; + unsigned int limit = 0; + time_t time = 0, expires = 0; + public: ExceptionImpl(Serialize::TypeBase *type) : Exception(type) { } ExceptionImpl(Serialize::TypeBase *type, Serialize::ID id) : Exception(type, id) { } @@ -69,13 +73,13 @@ class ExceptionType : public Serialize::Type<ExceptionImpl> Serialize::Field<ExceptionImpl, unsigned int> limit; Serialize::Field<ExceptionImpl, time_t> time, expires; - ExceptionType(Module *me) : Serialize::Type<ExceptionImpl>(me, "Exception") - , mask(this, "mask") - , who(this, "who") - , reason(this, "reason") - , limit(this, "limit") - , time(this, "time") - , expires(this, "expires") + ExceptionType(Module *me) : Serialize::Type<ExceptionImpl>(me) + , mask(this, "mask", &ExceptionImpl::mask) + , who(this, "who", &ExceptionImpl::who) + , reason(this, "reason", &ExceptionImpl::reason) + , limit(this, "limit", &ExceptionImpl::limit) + , time(this, "time", &ExceptionImpl::time) + , expires(this, "expires", &ExceptionImpl::expires) { } }; @@ -149,7 +153,7 @@ class MySessionService : public SessionService Exception *FindException(User *u) override { - for (Exception *e : Serialize::GetObjects<Exception *>(exception)) + for (Exception *e : Serialize::GetObjects<Exception *>()) { if (Anope::Match(u->host, e->GetMask()) || Anope::Match(u->ip.addr(), e->GetMask())) return e; @@ -162,7 +166,7 @@ class MySessionService : public SessionService Exception *FindException(const Anope::string &host) override { - for (Exception *e : Serialize::GetObjects<Exception *>(exception)) + for (Exception *e : Serialize::GetObjects<Exception *>()) { if (Anope::Match(host, e->GetMask())) return e; @@ -211,6 +215,8 @@ class MySessionService : public SessionService class CommandOSSession : public Command { + ServiceReference<SessionService> session_service; + private: void DoList(CommandSource &source, const std::vector<Anope::string> ¶ms) { @@ -319,7 +325,7 @@ class CommandOSException : public Command { static void DoDel(CommandSource &source, Exception *e) { - (*events)(&Event::Exception::OnExceptionDel, source, e); + EventManager::Get()->Dispatch(&Event::Exception::OnExceptionDel, source, e); e->Delete(); } @@ -382,7 +388,7 @@ class CommandOSException : public Command return; } - for (Exception *e : Serialize::GetObjects<Exception *>(exception)) + for (Exception *e : Serialize::GetObjects<Exception *>()) if (e->GetMask().equals_ci(mask)) { if (e->GetLimit() != limit) @@ -395,7 +401,7 @@ class CommandOSException : public Command return; } - Exception *e = exception.Create(); + Exception *e = Serialize::New<Exception *>(); e->SetMask(mask); e->SetLimit(limit); e->SetReason(reason); @@ -404,7 +410,7 @@ class CommandOSException : public Command e->SetExpires(expires); EventReturn MOD_RESULT; - MOD_RESULT = (*events)(&Event::Exception::OnExceptionAdd, e); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::Exception::OnExceptionAdd, e); if (MOD_RESULT == EVENT_STOP) return; @@ -432,7 +438,7 @@ class CommandOSException : public Command NumberList(mask, true, [&](unsigned int number) { - std::vector<Exception *> exceptions = Serialize::GetObjects<Exception *>(exception); + std::vector<Exception *> exceptions = Serialize::GetObjects<Exception *>(); if (!number || number > exceptions.size()) return; @@ -456,7 +462,7 @@ class CommandOSException : public Command else { bool found = false; - for (Exception *e : Serialize::GetObjects<Exception *>(exception)) + for (Exception *e : Serialize::GetObjects<Exception *>()) if (mask.equals_ci(e->GetMask())) { Log(LOG_ADMIN, source, this) << "to remove the session limit exception for " << mask; @@ -476,7 +482,7 @@ class CommandOSException : public Command void ProcessList(CommandSource &source, const std::vector<Anope::string> ¶ms, ListFormatter &list) { const Anope::string &mask = params.size() > 1 ? params[1] : ""; - std::vector<Exception *> exceptions = Serialize::GetObjects<Exception *>(exception); + std::vector<Exception *> exceptions = Serialize::GetObjects<Exception *>(); if (exceptions.empty()) { @@ -621,24 +627,20 @@ class OSSession : public Module CommandOSSession commandossession; CommandOSException commandosexception; ServiceReference<XLineManager> akills; - EventHandlers<Event::Exception> exceptionevents; ExceptionType etype; public: OSSession(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , EventHook<Event::UserConnect>(EventHook<Event::UserConnect>::Priority::FIRST) - , EventHook<Event::UserQuit>(EventHook<Event::UserQuit>::Priority::FIRST) - , EventHook<Event::ExpireTick>(EventHook<Event::ExpireTick>::Priority::FIRST) + , EventHook<Event::UserConnect>(this, EventHook<Event::UserConnect>::Priority::FIRST) + , EventHook<Event::UserQuit>(this, EventHook<Event::UserQuit>::Priority::FIRST) + , EventHook<Event::ExpireTick>(this, EventHook<Event::ExpireTick>::Priority::FIRST) , ss(this) , commandossession(this) , commandosexception(this) - , akills("XLineManager", "xlinemanager/sgline") - , exceptionevents(this) + , akills("xlinemanager/sgline") , etype(this) { this->SetPermanent(true); - - events = &exceptionevents; } void OnReload(Configuration::Conf *conf) override @@ -658,7 +660,7 @@ class OSSession : public Module ipv6_cidr = block->Get<unsigned>("session_ipv6_cidr", "128"); if (ipv4_cidr > 32 || ipv6_cidr > 128) - throw ConfigException(this->name + ": session CIDR value out of range"); + throw ConfigException(Module::name + ": session CIDR value out of range"); } void OnUserConnect(User *u, bool &exempt) override @@ -708,9 +710,16 @@ class OSSession : public Module const Anope::string &akillmask = "*@" + session->addr.mask(); if (max_session_kill && session->hits >= max_session_kill && akills && !akills->HasEntry(akillmask)) { - XLine *x = new XLine(akillmask, OperServ ? OperServ->nick : "", Anope::CurTime + session_autokill_expiry, "Session limit exceeded", XLineManager::GenerateUID()); + XLine *x = Serialize::New<XLine *>(); + x->SetMask(akillmask); + x->SetBy(OperServ ? OperServ->nick : ""); + x->SetExpires(Anope::CurTime + session_autokill_expiry); + x->SetReason("Session limit exceeded"); + x->SetID(XLineManager::GenerateUID()); + akills->AddXLine(x); akills->Send(NULL, x); + Log(OperServ, "akill/session") << "Added a temporary AKILL for \002" << akillmask << "\002 due to excessive connections"; } else @@ -753,7 +762,7 @@ class OSSession : public Module if (Anope::NoExpire) return; - for (Exception *e : Serialize::GetObjects<Exception *>(exception)) + for (Exception *e : Serialize::GetObjects<Exception *>()) { if (!e->GetExpires() || e->GetExpires() > Anope::CurTime) continue; diff --git a/modules/operserv/set.cpp b/modules/operserv/set.cpp index 45515fa4b..432480ffb 100644 --- a/modules/operserv/set.cpp +++ b/modules/operserv/set.cpp @@ -74,7 +74,7 @@ class CommandOSSet : public Command * * Rob **/ - bool super_admin = Config->GetModule(this->owner)->Get<bool>("superadmin"); + bool super_admin = Config->GetModule(this->GetOwner())->Get<bool>("superadmin"); if (!super_admin) source.Reply(_("Super admin can not be set because it is not enabled in the configuration.")); else if (setting.equals_ci("ON")) diff --git a/modules/operserv/stats.cpp b/modules/operserv/stats.cpp index 025fe566c..0fc5e9ae1 100644 --- a/modules/operserv/stats.cpp +++ b/modules/operserv/stats.cpp @@ -11,32 +11,58 @@ #include "module.h" #include "modules/operserv/session.h" +#include "modules/operserv/stats.h" -#if 0 -struct Stats : Serialize::Object +class StatsImpl : public Stats { - static Stats *me; + friend class StatsType; - Stats() : Serialize::Object("Stats") - { - me = this; - } + unsigned int maxusercnt = 0; + time_t maxusertime = 0; - void Serialize(Serialize::Data &data) const override - { - data["maxusercnt"] << MaxUserCount; - data["maxusertime"] << MaxUserTime; - } + public: + + using Stats::Stats; + + unsigned int GetMaxUserCount(); + void SetMaxUserCount(unsigned int i); + + time_t GetMaxUserTime(); + void SetMaxUserTime(time_t t); +}; + +class StatsType : public Serialize::Type<StatsImpl> +{ + public: + Serialize::Field<StatsImpl, unsigned int> maxusercount; + Serialize::Field<StatsImpl, time_t> maxusertime; - static Serializable* Unserialize(Serializable *obj, Serialize::Data &data) + StatsType(Module *me) : Serialize::Type<StatsImpl>(me) + , maxusercount(this, "maxusercount", &StatsImpl::maxusercnt) + , maxusertime(this, "maxusertime", &StatsImpl::maxusertime) { - data["maxusercnt"] >> MaxUserCount; - data["maxusertime"] >> MaxUserTime; - return me; } }; -Stats *Stats::me; +unsigned int StatsImpl::GetMaxUserCount() +{ + return Get(&StatsType::maxusercount); +} + +void StatsImpl::SetMaxUserCount(unsigned int i) +{ + Set(&StatsType::maxusercount, i); +} + +time_t StatsImpl::GetMaxUserTime() +{ + return Get(&StatsType::maxusertime); +} + +void StatsImpl::SetMaxUserTime(time_t t) +{ + Set(&StatsType::maxusertime, t); +} /** * Count servers connected to server s @@ -60,6 +86,8 @@ static int stats_count_servers(Server *s) class CommandOSStats : public Command { ServiceReference<XLineManager> akills, snlines, sqlines; + ServiceReference<SessionService> session_service; + private: void DoStatsAkill(CommandSource &source) { @@ -128,16 +156,19 @@ class CommandOSStats : public Command void DoStatsReset(CommandSource &source) { - MaxUserCount = UserListByNick.size(); + Stats *stats = Serialize::GetObject<Stats *>(); + stats->SetMaxUserCount(UserListByNick.size()); source.Reply(_("Statistics reset.")); return; } void DoStatsUptime(CommandSource &source) { + Stats *stats = Serialize::GetObject<Stats *>(); time_t uptime = Anope::CurTime - Anope::StartTime; + source.Reply(_("Current users: \002{0}\002 (\002{1}\002 ops)"), UserListByNick.size(), OperCount); - source.Reply(_("Maximum users: \002{0}\002 ({1})"), MaxUserCount, Anope::strftime(MaxUserTime, source.GetAccount())); + source.Reply(_("Maximum users: \002{0}\002 ({1})"), stats->GetMaxUserCount(), Anope::strftime(stats->GetMaxUserTime(), source.GetAccount())); source.Reply(_("Services up \002{0}\002."), Anope::Duration(uptime, source.GetAccount())); } @@ -195,8 +226,10 @@ class CommandOSStats : public Command } public: - CommandOSStats(Module *creator) : Command(creator, "operserv/stats", 0, 1), - akills("XLineManager", "xlinemanager/sgline"), snlines("XLineManager", "xlinemanager/snline"), sqlines("XLineManager", "xlinemanager/sqline") + CommandOSStats(Module *creator) : Command(creator, "operserv/stats", 0, 1) + , akills("sgline") + , snlines("snline") + , sqlines("sqline") { this->SetDesc(_("Show status of Services and network")); this->SetSyntax("[AKILL | HASH | UPLINK | UPTIME | ALL | RESET]"); @@ -245,27 +278,42 @@ class CommandOSStats : public Command }; class OSStats : public Module + , public EventHook<Event::UserConnect> { CommandOSStats commandosstats; - //Serialize::TypeBase stats_type; - Stats stats_saver; + StatsType stats_type; + + Stats *GetStats() + { + Stats *stats = Serialize::GetObject<Stats *>(); + if (stats) + return stats; + else + return Serialize::New<Stats *>(); + } public: OSStats(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::UserConnect>(this) , commandosstats(this) -// , stats_type("Stats", Stats::Unserialize) + , stats_type(this) { - } -#if 0 void OnUserConnect(User *u, bool &exempt) override { - if (UserListByNick.size() == MaxUserCount && Anope::CurTime == MaxUserTime) - stats_saver.QueueUpdate(); + Stats *stats = GetStats(); + + if (stats && UserListByNick.size() > stats->GetMaxUserCount()) + { + stats->SetMaxUserCount(UserListByNick.size()); + stats->SetMaxUserTime(Anope::CurTime); + + Server *sserver = u->server; + if (sserver && sserver->IsSynced()) + Log(this, "maxusers") << "connected - new maximum user count: " << UserListByNick.size(); + } } -#endif }; MODULE_INIT(OSStats) -#endif diff --git a/modules/operserv/sxline.cpp b/modules/operserv/sxline.cpp index 61c95bc45..c1be6ad5b 100644 --- a/modules/operserv/sxline.cpp +++ b/modules/operserv/sxline.cpp @@ -71,7 +71,7 @@ class CommandOSSXLineBase : public Command return; } - Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, x, this->xlm()); + EventManager::Get()->Dispatch(&Event::DelXLine::OnDelXLine, source, x, this->xlm()); x->Delete(); source.Reply(_("\002{0}\002 deleted from the {1} list."), mask, source.command); @@ -118,7 +118,7 @@ class CommandOSSXLineBase : public Command unsigned int i = 0; for (XLine *x : this->xlm()->GetXLines()) { - if (mask.empty() || mask.equals_ci(x->GetMask()) || mask == x->id || Anope::Match(x->GetMask(), mask, false, true)) + if (mask.empty() || mask.equals_ci(x->GetMask()) || mask == x->GetID() || Anope::Match(x->GetMask(), mask, false, true)) { ListFormatter::ListEntry entry; entry["Number"] = stringify(i + 1); @@ -163,7 +163,7 @@ class CommandOSSXLineBase : public Command void OnClear(CommandSource &source) { - Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, nullptr, this->xlm()); + EventManager::Get()->Dispatch(&Event::DelXLine::OnDelXLine, source, nullptr, this->xlm()); for (XLine *x : this->xlm()->GetXLines()) x->Delete(); @@ -307,7 +307,12 @@ class CommandOSSNLine : public CommandOSSXLineBase return; } - XLine *x = new XLine(mask, source.GetNick(), expires, reason); + XLine *x = Serialize::New<XLine *>(); + x->SetMask(mask); + x->SetBy(source.GetNick()); + x->SetExpires(expires); + x->SetReason(reason); + if (Config->GetModule("operserv")->Get<bool>("akillids")) x->SetID(XLineManager::GenerateUID()); @@ -326,7 +331,7 @@ class CommandOSSNLine : public CommandOSSXLineBase } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnAddXLine(&Event::AddXLine::OnAddXLine, source, x, this->xlm()); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::AddXLine::OnAddXLine, source, x, this->xlm()); if (MOD_RESULT == EVENT_STOP) { delete x; @@ -358,7 +363,8 @@ class CommandOSSNLine : public CommandOSSXLineBase ServiceReference<XLineManager> snlines; public: - CommandOSSNLine(Module *creator) : CommandOSSXLineBase(creator, "operserv/snline"), snlines("XLineManager", "xlinemanager/snline") + CommandOSSNLine(Module *creator) : CommandOSSXLineBase(creator, "operserv/snline") + , snlines("xlinemanager/snline") { this->SetSyntax(_("ADD [+\037expiry\037] \037mask\037:\037reason\037")); this->SetSyntax(_("DEL {\037mask\037 | \037entry-num\037 | \037list\037 | \037id\037}")); @@ -512,7 +518,12 @@ class CommandOSSQLine : public CommandOSSXLineBase return; } - XLine *x = new XLine(mask, source.GetNick(), expires, reason); + XLine *x = Serialize::New<XLine *>(); + x->SetMask(mask); + x->SetBy(source.GetNick()); + x->SetExpires(expires); + x->SetReason(reason); + if (Config->GetModule("operserv")->Get<bool>("akillids")) x->SetID(XLineManager::GenerateUID()); @@ -531,7 +542,7 @@ class CommandOSSQLine : public CommandOSSXLineBase } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnAddXLine(&Event::AddXLine::OnAddXLine, source, x, this->xlm()); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::AddXLine::OnAddXLine, source, x, this->xlm()); if (MOD_RESULT == EVENT_STOP) { delete x; @@ -589,7 +600,8 @@ class CommandOSSQLine : public CommandOSSXLineBase ServiceReference<XLineManager> sqlines; public: - CommandOSSQLine(Module *creator) : CommandOSSXLineBase(creator, "operserv/sqline"), sqlines("XLineManager", "xlinemanager/sqline") + CommandOSSQLine(Module *creator) : CommandOSSXLineBase(creator, "operserv/sqline") + , sqlines("xlinemanager/sqline") { this->SetSyntax(_("ADD [+\037expiry\037] \037mask\037 \037reason\037")); this->SetSyntax(_("DEL {\037mask\037 | \037entry-num\037 | \037list\037 | \037id\037}")); diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index c320f3a3e..c7e5c45f1 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -192,24 +192,24 @@ class BahamutIRCdProto : public IRCDProto { /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (x->manager->Check(it->second, x)) + if (x->GetManager()->Check(it->second, x)) this->SendAkill(it->second, x); return; } XLine *old = x; - if (old->manager->HasEntry("*@" + u->host)) + if (old->GetManager()->HasEntry("*@" + u->host)) return; /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ - x = new XLine(xline); + x = Serialize::New<XLine *>(); x->SetMask("*@" + u->host); x->SetBy(old->GetBy()); x->SetExpires(old->GetExpires()); x->SetReason(old->GetReason()); x->SetID(old->GetID()); - old->manager->AddXLine(x); + old->GetManager()->AddXLine(x); Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->GetMask() << " because " << u->GetMask() << "#" << u->realname << " matches " << old->GetMask(); } @@ -509,6 +509,7 @@ class ProtoBahamut : public Module public: ProtoBahamut(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>(this) , ircd_proto(this) , message_away(this) , message_capab(this) diff --git a/modules/protocol/charybdis.cpp b/modules/protocol/charybdis.cpp index fc59a7214..c37e8aab0 100644 --- a/modules/protocol/charybdis.cpp +++ b/modules/protocol/charybdis.cpp @@ -176,7 +176,7 @@ struct IRCDMessageEncap : IRCDMessage if (params[1] == "CERTFP") { u->fingerprint = params[2]; - Event::OnFingerprint(&Event::Fingerprint::OnFingerprint, u); + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); } /* * Received: :42X ENCAP * SASL 42XAAAAAH * S PLAIN diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index b5c524530..65ea4a565 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -149,7 +149,7 @@ class HybridProto : public IRCDProto * Find users that match and ban them. */ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (x->manager->Check(it->second, x)) + if (x->GetManager()->Check(it->second, x)) this->SendAkill(it->second, x); return; @@ -157,13 +157,18 @@ class HybridProto : public IRCDProto XLine *old = x; - if (old->manager->HasEntry("*@" + u->host)) + if (old->GetManager()->HasEntry("*@" + u->host)) return; /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ - XLine *xl = new XLine("*@" + u->host, old->GetBy(), old->GetExpires(), old->GetReason(), old->id); - - old->manager->AddXLine(xl); + XLine *xl = Serialize::New<XLine *>(); + xl->SetMask("*@" + u->host); + xl->SetBy(old->GetBy()); + xl->SetExpires(old->GetExpires()); + xl->SetReason(old->GetReason()); + xl->SetID(old->GetID()); + + old->GetManager()->AddXLine(xl); x = xl; Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->GetMask() << " because " << u->GetMask() << "#" @@ -277,14 +282,19 @@ class HybridProto : public IRCDProto void SendSVSHold(const Anope::string &nick, time_t t) override { +#if 0 XLine x(nick, Me->GetName(), Anope::CurTime + t, "Being held for registered user"); this->SendSQLine(NULL, &x); +#endif } +#warning "xline on stack" void SendSVSHoldDel(const Anope::string &nick) override { +#if 0 XLine x(nick); this->SendSQLineDel(&x); +#endif } void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) override @@ -579,7 +589,7 @@ struct IRCDMessageCertFP: IRCDMessage User *u = source.GetUser(); u->fingerprint = params[0]; - Event::OnFingerprint(&Event::Fingerprint::OnFingerprint, u); + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); } }; @@ -627,6 +637,7 @@ class ProtoHybrid : public Module public: ProtoHybrid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>(this) , ircd_proto(this) , message_away(this) , message_capab(this) diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index f4c8bcf37..ae9cc700f 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -174,19 +174,23 @@ class InspIRCd20Proto : public IRCDProto { /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (x->manager->Check(it->second, x)) + if (x->GetManager()->Check(it->second, x)) this->SendAkill(it->second, x); return; } XLine *old = x; - if (old->manager->HasEntry("*@" + u->host)) + if (old->GetManager()->HasEntry("*@" + u->host)) return; /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ - x = new XLine("*@" + u->host, old->GetBy(), old->GetExpires(), old->GetReason(), old->GetID()); - old->manager->AddXLine(x); + x = Serialize::New<XLine *>(); + x->SetMask("*@" + u->host); + x->SetBy(old->GetBy()); + x->SetExpires(old->GetExpires()); + x->SetReason(old->GetReason()); + old->GetManager()->AddXLine(x); Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->GetMask() << " because " << u->GetMask() << "#" << u->realname << " matches " << old->GetMask(); } @@ -645,14 +649,14 @@ struct IRCDMessageCapab : Message::Capab ChannelMode *cm = ModeManager::FindChannelModeByChar(modechar[0]); if (cm == nullptr) { - Log(owner) << "Warning: Uplink has unknown channel mode " << modename << "=" << modechar; + Log(this->GetOwner()) << "Warning: Uplink has unknown channel mode " << modename << "=" << modechar; continue; } char modesymbol = cm->type == MODE_STATUS ? (anope_dynamic_static_cast<ChannelModeStatus *>(cm))->symbol : 0; if (symbol != modesymbol) { - Log(owner) << "Warning: Channel mode " << modename << " has a misconfigured status character"; + Log(this->GetOwner()) << "Warning: Channel mode " << modename << " has a misconfigured status character"; continue; } } @@ -676,7 +680,7 @@ struct IRCDMessageCapab : Message::Capab UserMode *um = ModeManager::FindUserModeByChar(modechar[0]); if (um == nullptr) { - Log(owner) << "Warning: Uplink has unknown user mode " << modename << "=" << modechar; + Log(this->GetOwner()) << "Warning: Uplink has unknown user mode " << modename << "=" << modechar; continue; } } @@ -992,7 +996,7 @@ struct IRCDMessageMetadata : IRCDMessage { u->fingerprint = data.substr(pos1, pos2 - pos1); } - Event::OnFingerprint(&Event::Fingerprint::OnFingerprint, u); + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); } } // We deliberately ignore non-bursting servers to avoid pseudoserver fights @@ -1246,6 +1250,8 @@ struct IRCDMessageTime : IRCDMessage struct IRCDMessageUID : IRCDMessage { + ServiceReference<SASL::Service> sasl; + IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } /* @@ -1270,7 +1276,7 @@ struct IRCDMessageUID : IRCDMessage modes += " " + params[i]; NickServ::Nick *na = NULL; - if (SASL::sasl) + if (sasl) for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();) { SASLUser &u = *it; @@ -1302,6 +1308,7 @@ class ProtoInspIRCd20 : public Module { InspIRCd20Proto ircd_proto; ExtensibleItem<bool> ssl; + ServiceReference<ModeLocks> mlocks; /* Core message handlers */ Message::Away message_away; @@ -1349,6 +1356,13 @@ class ProtoInspIRCd20 : public Module public: ProtoInspIRCd20(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>(this) + , EventHook<Event::ChannelSync>(this) + , EventHook<Event::ChanRegistered>(this) + , EventHook<Event::DelChan>(this) + , EventHook<Event::MLockEvents>(this) + , EventHook<Event::SetChannelOption>(this) + , ircd_proto(this) , ssl(this, "ssl") , message_away(this) @@ -1489,7 +1503,7 @@ class ProtoInspIRCd20 : public Module EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChanServ::Channel *ci, const Anope::string &setting) override { - if (cmd->name == "chanserv/topic" && ci->c) + if (cmd->GetName() == "chanserv/topic" && ci->c) { if (setting == "topiclock on") SendChannelMetadata(ci->c, "topiclock", "1"); diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp index b80f600e3..271466a42 100644 --- a/modules/protocol/ngircd.cpp +++ b/modules/protocol/ngircd.cpp @@ -357,7 +357,7 @@ struct IRCDMessageMetadata : IRCDMessage else if (params[1].equals_cs("certfp")) { u->fingerprint = params[2]; - Event::OnFingerprint(&Event::Fingerprint::OnFingerprint, u); + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); } else if (params[1].equals_cs("cloakhost")) { @@ -634,6 +634,7 @@ class ProtongIRCd : public Module public: ProtongIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>(this) , ircd_proto(this) , message_capab(this) , message_error(this) diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index 027fa2a14..efa521377 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -13,12 +13,13 @@ static Anope::string UplinkSID; -static ServiceReference<IRCDProto> hybrid("IRCDProto", "hybrid"); - class PlexusProto : public IRCDProto { + ServiceReference<IRCDProto> hybrid; // XXX use moddeps + inheritance here + public: PlexusProto(Module *creator) : IRCDProto(creator, "hybrid-7.2.3+plexus-3.0.1") + , hybrid("hybrid") { DefaultPseudoclientModes = "+oiU"; CanSVSNick = true; @@ -204,7 +205,7 @@ struct IRCDMessageEncap : IRCDMessage if (u) { u->fingerprint = params[3]; - Event::OnFingerprint(&Event::Fingerprint::OnFingerprint, u); + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); } } return; @@ -366,8 +367,8 @@ class ProtoPlexus : public Module m_hybrid = ModuleManager::FindModule("hybrid"); if (!m_hybrid) throw ModuleException("Unable to find hybrid"); - if (!hybrid) - throw ModuleException("No protocol interface for hybrid"); +// if (!hybrid) +// throw ModuleException("No protocol interface for hybrid"); } ~ProtoPlexus() diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index 9e1ea0710..54f085a3e 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -13,12 +13,12 @@ static Anope::string UplinkSID; -static ServiceReference<IRCDProto> hybrid("IRCDProto", "hybrid"); - class RatboxProto : public IRCDProto { + ServiceReference<IRCDProto> hybrid; // XXX public: RatboxProto(Module *creator) : IRCDProto(creator, "Ratbox 3.0+") + , hybrid("hybrid") { DefaultPseudoclientModes = "+oiS"; CanSNLine = true; @@ -282,8 +282,8 @@ class ProtoRatbox : public Module m_hybrid = ModuleManager::FindModule("hybrid"); if (!m_hybrid) throw ModuleException("Unable to find hybrid"); - if (!hybrid) - throw ModuleException("No protocol interface for hybrid"); +// if (!hybrid) +// throw ModuleException("No protocol interface for hybrid"); } ~ProtoRatbox() diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp index 3bb8ab93a..327f1c32e 100644 --- a/modules/protocol/unreal.cpp +++ b/modules/protocol/unreal.cpp @@ -12,6 +12,7 @@ #include "module.h" #include "modules/chanserv/mode.h" #include "modules/sasl.h" +#include "modules/operserv/stats.h" class UnrealIRCdProto : public IRCDProto { @@ -89,19 +90,25 @@ class UnrealIRCdProto : public IRCDProto { /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (x->manager->Check(it->second, x)) + if (x->GetManager()->Check(it->second, x)) this->SendAkill(it->second, x); return; } XLine *old = x; - if (old->manager->HasEntry("*@" + u->host)) + if (old->GetManager()->HasEntry("*@" + u->host)) return; /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ - XLine *xl = new XLine("*@" + u->host, old->GetBy(), old->GetExpires(), old->GetReason(), old->GetID()); - old->manager->AddXLine(xl); + XLine *xl = Serialize::New<XLine *>(); + xl->SetMask("*@" + u->host); + xl->SetBy(old->GetBy()); + xl->SetExpires(old->GetExpires()); + xl->SetReason(old->GetReason()); + xl->SetID(old->GetID()); + + old->GetManager()->AddXLine(xl); x = xl; Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->GetMask() << " because " << u->GetMask() << "#" << u->realname << " matches " << old->GetMask(); @@ -693,7 +700,8 @@ struct IRCDMessageNetInfo : IRCDMessage void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { - UplinkSocket::Message() << "NETINFO " << MaxUserCount << " " << Anope::CurTime << " " << convertTo<int>(params[2]) << " " << params[3] << " 0 0 0 :" << params[7]; + Stats *stats = Serialize::GetObject<Stats *>(); + UplinkSocket::Message() << "NETINFO " << (stats ? stats->GetMaxUserCount() : 0) << " " << Anope::CurTime << " " << convertTo<int>(params[2]) << " " << params[3] << " 0 0 0 :" << params[7]; } }; @@ -792,12 +800,14 @@ struct IRCDMessagePong : IRCDMessage struct IRCDMessageSASL : IRCDMessage { + ServiceReference<SASL::Service> sasl; + IRCDMessageSASL(Module *creator) : IRCDMessage(creator, "SASL", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { size_t p = params[1].find('!'); - if (!SASL::sasl || p == Anope::string::npos) + if (!sasl || p == Anope::string::npos) return; SASL::Message m; @@ -807,7 +817,7 @@ struct IRCDMessageSASL : IRCDMessage m.data = params[3]; m.ext = params.size() > 4 ? params[4] : ""; - SASL::sasl->ProcessMessage(m); + sasl->ProcessMessage(m); } }; @@ -1006,6 +1016,7 @@ class ProtoUnreal : public Module , public EventHook<Event::MLockEvents> { UnrealIRCdProto ircd_proto; + ServiceReference<ModeLocks> mlocks; /* Core message handlers */ Message::Away message_away; @@ -1049,11 +1060,11 @@ class ProtoUnreal : public Module public: ProtoUnreal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) - , EventHook<Event::UserNickChange>(EventHook<Event::UserNickChange>::Priority::FIRST) - , EventHook<Event::ChannelSync>(EventHook<Event::ChannelSync>::Priority::FIRST) - , EventHook<Event::ChanRegistered>(EventHook<Event::ChanRegistered>::Priority::FIRST) - , EventHook<Event::DelChan>(EventHook<Event::DelChan>::Priority::FIRST) - , EventHook<Event::MLockEvents>(EventHook<Event::MLockEvents>::Priority::FIRST) + , EventHook<Event::UserNickChange>(this, EventHook<Event::UserNickChange>::Priority::FIRST) + , EventHook<Event::ChannelSync>(this, EventHook<Event::ChannelSync>::Priority::FIRST) + , EventHook<Event::ChanRegistered>(this, EventHook<Event::ChanRegistered>::Priority::FIRST) + , EventHook<Event::DelChan>(this, EventHook<Event::DelChan>::Priority::FIRST) + , EventHook<Event::MLockEvents>(this, EventHook<Event::MLockEvents>::Priority::FIRST) , ircd_proto(this) , message_away(this) , message_capab(this, "PROTOCTL") diff --git a/modules/proxyscan.cpp b/modules/proxyscan.cpp deleted file mode 100644 index 398e021db..000000000 --- a/modules/proxyscan.cpp +++ /dev/null @@ -1,380 +0,0 @@ -/* - * (C) 2003-2014 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - */ - -#include "module.h" - -struct ProxyCheck -{ - std::set<Anope::string, ci::less> types; - std::vector<unsigned short> ports; - time_t duration; - Anope::string reason; -}; - -static Anope::string ProxyCheckString; -static Anope::string target_ip; -static unsigned short target_port; -static bool add_to_akill; - -class ProxyCallbackListener : public ListenSocket -{ - class ProxyCallbackClient : public ClientSocket, public BufferedSocket - { - public: - ProxyCallbackClient(ListenSocket *l, int f, const sockaddrs &a) : Socket(f, l->IsIPv6()), ClientSocket(l, a), BufferedSocket() - { - } - - void OnAccept() override - { - this->Write(ProxyCheckString); - } - - bool ProcessWrite() override - { - return !BufferedSocket::ProcessWrite() || this->write_buffer.empty() ? false : true; - } - }; - - public: - ProxyCallbackListener(const Anope::string &b, int p) : Socket(-1, b.find(':') != Anope::string::npos), ListenSocket(b, p, false) - { - } - - ClientSocket *OnAccept(int fd, const sockaddrs &addr) override - { - return new ProxyCallbackClient(this, fd, addr); - } -}; - -class ProxyConnect : public ConnectionSocket -{ - static ServiceReference<XLineManager> akills; - - public: - static std::set<ProxyConnect *> proxies; - - ProxyCheck proxy; - unsigned short port; - time_t created; - - ProxyConnect(ProxyCheck &p, unsigned short po) : Socket(-1), ConnectionSocket(), proxy(p), - port(po), created(Anope::CurTime) - { - proxies.insert(this); - } - - ~ProxyConnect() - { - proxies.erase(this); - } - - virtual void OnConnect() override = 0; - virtual const Anope::string GetType() const = 0; - - protected: - void Ban() - { - Anope::string reason = this->proxy.reason; - - reason = reason.replace_all_cs("%t", this->GetType()); - reason = reason.replace_all_cs("%i", this->conaddr.addr()); - reason = reason.replace_all_cs("%p", stringify(this->conaddr.port())); - - ServiceBot *OperServ = Config->GetClient("OperServ"); - Log(OperServ) << "PROXYSCAN: Open " << this->GetType() << " proxy found on " << this->conaddr.addr() << ":" << this->conaddr.port() << " (" << reason << ")"; - - XLine *x = new XLine("*@" + this->conaddr.addr(), OperServ ? OperServ->nick : "", Anope::CurTime + this->proxy.duration, reason, XLineManager::GenerateUID()); - if (add_to_akill && akills) - { - akills->AddXLine(x); - akills->Send(NULL, x); - } - else - { - if (IRCD->CanSZLine) - IRCD->SendSZLine(NULL, x); - else - IRCD->SendAkill(NULL, x); - delete x; - } - } -}; -ServiceReference<XLineManager> ProxyConnect::akills("XLineManager", "xlinemanager/sgline"); -std::set<ProxyConnect *> ProxyConnect::proxies; - -class HTTPProxyConnect : public ProxyConnect, public BufferedSocket -{ - public: - HTTPProxyConnect(ProxyCheck &p, unsigned short po) : Socket(-1), ProxyConnect(p, po), BufferedSocket() - { - } - - void OnConnect() override - { - this->Write("CONNECT %s:%d HTTP/1.0", target_ip.c_str(), target_port); - this->Write("Content-length: 0"); - this->Write("Connection: close"); - this->Write(""); - } - - const Anope::string GetType() const override - { - return "HTTP"; - } - - bool ProcessRead() override - { - bool b = BufferedSocket::ProcessRead(); - if (this->GetLine() == ProxyCheckString) - { - this->Ban(); - return false; - } - return b; - } -}; - -class SOCKS5ProxyConnect : public ProxyConnect, public BinarySocket -{ - public: - SOCKS5ProxyConnect(ProxyCheck &p, unsigned short po) : Socket(-1), ProxyConnect(p, po), BinarySocket() - { - } - - void OnConnect() override - { - sockaddrs target_addr; - char buf[4 + sizeof(target_addr.sa4.sin_addr.s_addr) + sizeof(target_addr.sa4.sin_port)]; - int ptr = 0; - target_addr.pton(AF_INET, target_ip, target_port); - if (!target_addr.valid()) - return; - - buf[ptr++] = 5; // Version - buf[ptr++] = 1; // # of methods - buf[ptr++] = 0; // No authentication - - this->Write(buf, ptr); - - ptr = 1; - buf[ptr++] = 1; // Connect - buf[ptr++] = 0; // Reserved - buf[ptr++] = 1; // IPv4 - memcpy(buf + ptr, &target_addr.sa4.sin_addr.s_addr, sizeof(target_addr.sa4.sin_addr.s_addr)); - ptr += sizeof(target_addr.sa4.sin_addr.s_addr); - memcpy(buf + ptr, &target_addr.sa4.sin_port, sizeof(target_addr.sa4.sin_port)); - ptr += sizeof(target_addr.sa4.sin_port); - - this->Write(buf, ptr); - } - - const Anope::string GetType() const override - { - return "SOCKS5"; - } - - bool Read(const char *buffer, size_t l) override - { - if (l >= ProxyCheckString.length() && !strncmp(buffer, ProxyCheckString.c_str(), ProxyCheckString.length())) - { - this->Ban(); - return false; - } - return true; - } -}; - -class ModuleProxyScan : public Module - , public EventHook<Event::UserConnect> -{ - Anope::string listen_ip; - unsigned short listen_port; - Anope::string con_notice, con_source; - std::vector<ProxyCheck> proxyscans; - - ProxyCallbackListener *listener; - - class ConnectionTimeout : public Timer - { - public: - ConnectionTimeout(Module *c, long timeout) : Timer(c, timeout, Anope::CurTime, true) - { - } - - void Tick(time_t) override - { - for (std::set<ProxyConnect *>::iterator it = ProxyConnect::proxies.begin(), it_end = ProxyConnect::proxies.end(); it != it_end;) - { - ProxyConnect *p = *it; - ++it; - - if (p->created + this->GetSecs() < Anope::CurTime) - delete p; - } - } - } connectionTimeout; - - public: - ModuleProxyScan(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) - , connectionTimeout(this, 5) - { - - - this->listener = NULL; - } - - ~ModuleProxyScan() - { - for (std::set<ProxyConnect *>::iterator it = ProxyConnect::proxies.begin(), it_end = ProxyConnect::proxies.end(); it != it_end;) - { - ProxyConnect *p = *it; - ++it; - delete p; - } - - for (std::map<int, Socket *>::const_iterator it = SocketEngine::Sockets.begin(), it_end = SocketEngine::Sockets.end(); it != it_end;) - { - Socket *s = it->second; - ++it; - - ClientSocket *cs = dynamic_cast<ClientSocket *>(s); - if (cs != NULL && cs->ls == this->listener) - delete s; - } - - delete this->listener; - } - - void OnReload(Configuration::Conf *conf) override - { - Configuration::Block *config = Config->GetModule(this); - - Anope::string s_target_ip = config->Get<Anope::string>("target_ip"); - if (s_target_ip.empty()) - throw ConfigException(this->name + " target_ip may not be empty"); - - int s_target_port = config->Get<int>("target_port", "-1"); - if (s_target_port <= 0) - throw ConfigException(this->name + " target_port may not be empty and must be a positive number"); - - Anope::string s_listen_ip = config->Get<Anope::string>("listen_ip"); - if (s_listen_ip.empty()) - throw ConfigException(this->name + " listen_ip may not be empty"); - - int s_listen_port = config->Get<int>("listen_port", "-1"); - if (s_listen_port <= 0) - throw ConfigException(this->name + " listen_port may not be empty and must be a positive number"); - - target_ip = s_target_ip; - target_port = s_target_port; - this->listen_ip = s_listen_ip; - this->listen_port = s_listen_port; - this->con_notice = config->Get<Anope::string>("connect_notice"); - this->con_source = config->Get<Anope::string>("connect_source"); - add_to_akill = config->Get<bool>("add_to_akill", "true"); - this->connectionTimeout.SetSecs(config->Get<time_t>("timeout", "5s")); - - ProxyCheckString = Config->GetBlock("networkinfo")->Get<Anope::string>("networkname") + " proxy check"; - delete this->listener; - this->listener = NULL; - try - { - this->listener = new ProxyCallbackListener(this->listen_ip, this->listen_port); - } - catch (const SocketException &ex) - { - throw ConfigException("m_proxyscan: " + ex.GetReason()); - } - - this->proxyscans.clear(); - for (int i = 0; i < config->CountBlock("proxyscan"); ++i) - { - Configuration::Block *block = config->GetBlock("proxyscan", i); - ProxyCheck p; - Anope::string token; - - commasepstream sep(block->Get<Anope::string>("type")); - while (sep.GetToken(token)) - { - if (!token.equals_ci("HTTP") && !token.equals_ci("SOCKS5")) - continue; - p.types.insert(token); - } - if (p.types.empty()) - continue; - - commasepstream sep2(block->Get<Anope::string>("port")); - while (sep2.GetToken(token)) - { - try - { - unsigned short port = convertTo<unsigned short>(token); - p.ports.push_back(port); - } - catch (const ConvertException &) { } - } - if (p.ports.empty()) - continue; - - p.duration = block->Get<time_t>("time", "4h"); - p.reason = block->Get<Anope::string>("reason"); - if (p.reason.empty()) - continue; - - this->proxyscans.push_back(p); - } - } - - void OnUserConnect(User *user, bool &exempt) override - { - if (exempt || user->Quitting() || !Me->IsSynced() || !user->server->IsSynced()) - return; - - /* At this time we only support IPv4 */ - if (!user->ip.valid() || user->ip.sa.sa_family != AF_INET) - /* User doesn't have a valid IPv4 IP (ipv6/spoof/etc) */ - return; - - if (!this->con_notice.empty() && !this->con_source.empty()) - { - ServiceBot *bi = ServiceBot::Find(this->con_source, true); - if (bi) - user->SendMessage(bi, this->con_notice); - } - - for (unsigned i = this->proxyscans.size(); i > 0; --i) - { - ProxyCheck &p = this->proxyscans[i - 1]; - - for (std::set<Anope::string, ci::less>::iterator it = p.types.begin(), it_end = p.types.end(); it != it_end; ++it) - { - for (unsigned k = 0; k < p.ports.size(); ++k) - { - try - { - ProxyConnect *con = NULL; - if (it->equals_ci("HTTP")) - con = new HTTPProxyConnect(p, p.ports[k]); - else if (it->equals_ci("SOCKS5")) - con = new SOCKS5ProxyConnect(p, p.ports[k]); - else - continue; - con->Connect(user->ip.addr(), p.ports[k]); - } - catch (const SocketException &ex) - { - Log(LOG_DEBUG) << "m_proxyscan: " << ex.GetReason(); - } - } - } - } - } -}; - -MODULE_INIT(ModuleProxyScan) - diff --git a/modules/redis.cpp b/modules/redis.cpp index 81c958f7c..14da3cae5 100644 --- a/modules/redis.cpp +++ b/modules/redis.cpp @@ -265,7 +265,7 @@ RedisSocket::~RedisSocket() void RedisSocket::OnConnect() { - Log() << "redis: Successfully connected to " << provider->name << (this == this->provider->sub ? " (sub)" : ""); + Log() << "redis: Successfully connected to " << provider->GetName() << (this == this->provider->sub ? " (sub)" : ""); this->provider->SendCommand(NULL, "CLIENT SETNAME Anope"); this->provider->SendCommand(NULL, "SELECT " + stringify(provider->db)); @@ -273,7 +273,7 @@ void RedisSocket::OnConnect() void RedisSocket::OnError(const Anope::string &error) { - Log() << "redis: Error on " << provider->name << (this == this->provider->sub ? " (sub)" : "") << ": " << error; + Log() << "redis: Error on " << provider->GetName() << (this == this->provider->sub ? " (sub)" : "") << ": " << error; } size_t RedisSocket::ParseReply(Reply &r, const char *buffer, size_t l) @@ -504,6 +504,7 @@ class ModuleRedis : public Module public: ModuleRedis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) + , EventHook<Event::ModuleUnload>(this) { } @@ -546,7 +547,7 @@ class ModuleRedis : public Module Provider *p = it->second; ++it; - if (std::find(new_services.begin(), new_services.end(), p->name) == new_services.end()) + if (std::find(new_services.begin(), new_services.end(), p->GetName()) == new_services.end()) delete it->second; } } diff --git a/modules/sasl.cpp b/modules/sasl.cpp index 174e86ab0..6fe68ce3e 100644 --- a/modules/sasl.cpp +++ b/modules/sasl.cpp @@ -15,13 +15,13 @@ using namespace SASL; class Plain : public Mechanism { public: - Plain(Module *o) : Mechanism(o, "PLAIN") { } + Plain(SASL::Service *s, Module *o) : Mechanism(s, o, "PLAIN") { } void ProcessMessage(Session *sess, const SASL::Message &m) override { if (m.type == "S") { - sasl->SendMessage(sess, "C", "+"); + GetService()->SendMessage(sess, "C", "+"); } else if (m.type == "C") { @@ -31,7 +31,7 @@ class Plain : public Mechanism size_t p = decoded.find('\0'); if (p == Anope::string::npos) { - sasl->Fail(sess); + GetService()->Fail(sess); delete sess; return; } @@ -40,7 +40,7 @@ class Plain : public Mechanism p = decoded.find('\0'); if (p == Anope::string::npos) { - sasl->Fail(sess); + GetService()->Fail(sess); delete sess; return; } @@ -50,13 +50,13 @@ class Plain : public Mechanism if (!NickServ::service || acc.empty() || pass.empty() || !IRCD->IsNickValid(acc) || pass.find_first_of("\r\n") != Anope::string::npos) { - sasl->Fail(sess); + GetService()->Fail(sess); delete sess; return; } - NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new IdentifyRequestListener(m.source), this->owner, acc, pass); - Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); + NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new IdentifyRequestListener(GetService(), m.source), this->GetOwner(), acc, pass); + EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); req->Dispatch(); } } @@ -70,11 +70,12 @@ class External : public Mechanism { Anope::string cert; - Session(Mechanism *m, const Anope::string &u) : SASL::Session(m, u) { } + Session(SASL::Service *s, Mechanism *m, const Anope::string &u) : SASL::Session(s, m, u) { } }; public: - External(Module *o) : Mechanism(o, "EXTERNAL"), certs("CertService", "certs") + External(SASL::Service *s, Module *o) : Mechanism(s, o, "EXTERNAL") + , certs("certs") { if (!IRCD || !IRCD->CanCertFP) throw ModuleException("No CertFP"); @@ -82,7 +83,7 @@ class External : public Mechanism Session* CreateSession(const Anope::string &uid) override { - return new Session(this, uid); + return new Session(this->GetService(), this, uid); } void ProcessMessage(SASL::Session *sess, const SASL::Message &m) override @@ -93,13 +94,13 @@ class External : public Mechanism { mysess->cert = m.ext; - sasl->SendMessage(sess, "C", "+"); + GetService()->SendMessage(sess, "C", "+"); } else if (m.type == "C") { if (!certs) { - sasl->Fail(sess); + GetService()->Fail(sess); delete sess; return; } @@ -107,13 +108,13 @@ class External : public Mechanism NickServ::Account *nc = certs->FindAccountFromCert(mysess->cert); if (!nc || nc->HasFieldS("NS_SUSPENDED")) { - sasl->Fail(sess); + GetService()->Fail(sess); delete sess; return; } Log(Config->GetClient("NickServ")) << "A user identified to account " << nc->GetDisplay() << " using SASL EXTERNAL"; - sasl->Succeed(sess, nc); + GetService()->Succeed(sess, nc); delete sess; } } @@ -149,13 +150,13 @@ class SASLService : public SASL::Service, public Timer if (m.type == "S") { - ServiceReference<Mechanism> mech("SASL::Mechanism", m.data); + ServiceReference<Mechanism> mech(m.data); if (!mech) { - Session tmp(NULL, m.source); + Session tmp(this, NULL, m.source); - sasl->SendMechs(&tmp); - sasl->Fail(&tmp); + this->SendMechs(&tmp); + this->Fail(&tmp); return; } @@ -175,7 +176,7 @@ class SASLService : public SASL::Service, public Timer Anope::string GetAgent() override { - Anope::string agent = Config->GetModule(Service::owner)->Get<Anope::string>("agent", "NickServ"); + Anope::string agent = Config->GetModule(Service::GetOwner())->Get<Anope::string>("agent", "NickServ"); ServiceBot *bi = Config->GetClient(agent); if (bi) agent = bi->GetUID(); @@ -233,10 +234,11 @@ class SASLService : public SASL::Service, public Timer void SendMechs(Session *session) override { - std::vector<Anope::string> mechs = Service::GetServiceKeys("SASL::Mechanism"); + std::vector<Mechanism *> mechs = ServiceManager::Get()->FindServices<Mechanism *>(); + Anope::string buf; for (unsigned j = 0; j < mechs.size(); ++j) - buf += "," + mechs[j]; + buf += "," + mechs[j]->GetName(); this->SendMessage(session, "M", buf.empty() ? "" : buf.substr(1)); } @@ -258,22 +260,55 @@ class SASLService : public SASL::Service, public Timer } }; +void IdentifyRequestListener::OnSuccess(NickServ::IdentifyRequest *req) +{ + NickServ::Nick *na = NickServ::FindNick(req->GetAccount()); + if (!na || na->GetAccount()->HasFieldS("NS_SUSPENDED")) + return OnFail(req); + + Session *s = service->GetSession(uid); + if (s) + { + Log(Config->GetClient("NickServ")) << "A user identified to account " << req->GetAccount() << " using SASL"; + service->Succeed(s, na->GetAccount()); + delete s; + } +} + +void IdentifyRequestListener::OnFail(NickServ::IdentifyRequest *req) +{ + Session *s = service->GetSession(uid); + if (s) + { + service->Fail(s); + delete s; + } + + Anope::string accountstatus; + NickServ::Nick *na = NickServ::FindNick(req->GetAccount()); + if (!na) + accountstatus = "nonexistent "; + else if (na->GetAccount()->HasFieldS("NS_SUSPENDED")) + accountstatus = "suspended "; + + Log(Config->GetClient("NickServ")) << "A user failed to identify for " << accountstatus << "account " << req->GetAccount() << " using SASL"; +} + class ModuleSASL : public Module { SASLService sasl; Plain plain; - External *external; + External *external = nullptr; public: ModuleSASL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) , sasl(this) - , plain(this) - , external(NULL) + , plain(&sasl, this) { try { - external = new External(this); + external = new External(&sasl, this); } catch (ModuleException &) { } } diff --git a/modules/webcpanel/pages/chanserv/access.cpp b/modules/webcpanel/pages/chanserv/access.cpp index e5d268dee..535df595f 100644 --- a/modules/webcpanel/pages/chanserv/access.cpp +++ b/modules/webcpanel/pages/chanserv/access.cpp @@ -105,11 +105,11 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s replacements["CREATORS"] = HTTPUtils::Escape(access->GetCreator()); } - if (Service::FindService("Command", "chanserv/access")) + if (ServiceManager::Get()->FindService("Command", "chanserv/access")) replacements["PROVIDERS"] = "chanserv/access"; - if (Service::FindService("Command", "chanserv/xop")) + if (ServiceManager::Get()->FindService("Command", "chanserv/xop")) replacements["PROVIDERS"] = "chanserv/xop"; - if (Service::FindService("Command", "chanserv/flags")) + if (ServiceManager::Get()->FindService("Command", "chanserv/flags")) replacements["PROVIDERS"] = "chanserv/flags"; Page.Serve(server, page_name, client, message, reply, replacements); diff --git a/modules/webcpanel/pages/chanserv/drop.cpp b/modules/webcpanel/pages/chanserv/drop.cpp index c546c0af5..b4eea6641 100644 --- a/modules/webcpanel/pages/chanserv/drop.cpp +++ b/modules/webcpanel/pages/chanserv/drop.cpp @@ -31,7 +31,7 @@ bool WebCPanel::ChanServ::Drop::OnRequest(HTTPProvider *server, const Anope::str replacements["MESSAGES"] = "Invalid Confirmation"; } - for (::ChanServ::Channel *ci : na->GetAccount()->GetRefs<::ChanServ::Channel *>(::ChanServ::channel)) + for (::ChanServ::Channel *ci : na->GetAccount()->GetRefs<::ChanServ::Channel *>()) if ((ci->HasFieldS("SECUREFOUNDER") ? ci->AccessFor(na->GetAccount()).founder : ci->AccessFor(na->GetAccount()).HasPriv("FOUNDER")) || (na->GetAccount()->IsServicesOper() && na->GetAccount()->o->GetType()->HasCommand("chanserv/drop"))) { replacements["CHANNEL_NAMES"] = ci->GetName(); diff --git a/modules/webcpanel/pages/chanserv/utils.cpp b/modules/webcpanel/pages/chanserv/utils.cpp index cf00de9d0..746097881 100644 --- a/modules/webcpanel/pages/chanserv/utils.cpp +++ b/modules/webcpanel/pages/chanserv/utils.cpp @@ -23,7 +23,7 @@ namespace ChanServ void BuildChanList(::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { - std::vector<::ChanServ::Channel *> chans = na->GetAccount()->GetRefs<::ChanServ::Channel *>(::ChanServ::channel); + std::vector<::ChanServ::Channel *> chans = na->GetAccount()->GetRefs<::ChanServ::Channel *>(); std::sort(chans.begin(), chans.end(), ChannelSort); for (::ChanServ::Channel *ci : chans) diff --git a/modules/webcpanel/pages/hostserv/request.cpp b/modules/webcpanel/pages/hostserv/request.cpp index 522806a9f..5ff2d228f 100644 --- a/modules/webcpanel/pages/hostserv/request.cpp +++ b/modules/webcpanel/pages/hostserv/request.cpp @@ -28,7 +28,7 @@ bool WebCPanel::HostServ::Request::OnRequest(HTTPProvider *server, const Anope:: else replacements["VHOST"] = na->GetVhostHost(); } - if (ServiceReference<Command>("Command", "hostserv/request")) + if (ServiceReference<Command>("hostserv/request")) replacements["CAN_REQUEST"] = "YES"; TemplateFileServer page("hostserv/request.html"); page.Serve(server, page_name, client, message, reply, replacements); diff --git a/modules/webcpanel/pages/index.cpp b/modules/webcpanel/pages/index.cpp index 551b73a0e..f40b029b4 100644 --- a/modules/webcpanel/pages/index.cpp +++ b/modules/webcpanel/pages/index.cpp @@ -94,7 +94,7 @@ bool WebCPanel::Index::OnRequest(HTTPProvider *server, const Anope::string &page // XXX Rate limit check. ::NickServ::IdentifyRequest *req = ::NickServ::service->CreateIdentifyRequest(new WebpanelRequest(reply, message, server, page_name, client, replacements), me, user, pass); - Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); + EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); req->Dispatch(); return false; } diff --git a/modules/webcpanel/pages/logout.cpp b/modules/webcpanel/pages/logout.cpp index b5f97258e..648b277cc 100644 --- a/modules/webcpanel/pages/logout.cpp +++ b/modules/webcpanel/pages/logout.cpp @@ -13,8 +13,8 @@ WebCPanel::Logout::Logout(const Anope::string &u) : WebPanelProtectedPage("", u) bool WebCPanel::Logout::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { - na->ShrinkOK<Anope::string>("webcpanel_id"); - na->ShrinkOK<Anope::string>("webcpanel_ip"); + na->Shrink<Anope::string>("webcpanel_id"); + na->Shrink<Anope::string>("webcpanel_ip"); reply.error = HTTP_FOUND; reply.headers["Location"] = Anope::string("http") + (server->IsSSL() ? "s" : "") + "://" + message.headers["Host"] + "/"; diff --git a/modules/webcpanel/pages/nickserv/access.cpp b/modules/webcpanel/pages/nickserv/access.cpp index 51472058d..986dfb635 100644 --- a/modules/webcpanel/pages/nickserv/access.cpp +++ b/modules/webcpanel/pages/nickserv/access.cpp @@ -31,7 +31,7 @@ bool WebCPanel::NickServ::Access::OnRequest(HTTPProvider *server, const Anope::s WebPanel::RunCommand(na->GetAccount()->GetDisplay(), na->GetAccount(), "NickServ", "nickserv/access", params, replacements); } - for (NickAccess *a : na->GetAccount()->GetRefs<NickAccess *>(nsaccess)) + for (NickAccess *a : na->GetAccount()->GetRefs<NickAccess *>()) replacements["ACCESS"] = a->GetMask(); TemplateFileServer page("nickserv/access.html"); diff --git a/modules/webcpanel/pages/nickserv/alist.cpp b/modules/webcpanel/pages/nickserv/alist.cpp index 105f1c117..26e4b6ffb 100644 --- a/modules/webcpanel/pages/nickserv/alist.cpp +++ b/modules/webcpanel/pages/nickserv/alist.cpp @@ -18,7 +18,7 @@ WebCPanel::NickServ::Alist::Alist(const Anope::string &cat, const Anope::string bool WebCPanel::NickServ::Alist::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { - std::vector<::ChanServ::Channel *> chans = na->GetAccount()->GetRefs<::ChanServ::Channel *>(::ChanServ::channel); + std::vector<::ChanServ::Channel *> chans = na->GetAccount()->GetRefs<::ChanServ::Channel *>(); std::sort(chans.begin(), chans.end(), ChannelSort); int chan_count = 0; diff --git a/modules/webcpanel/pages/nickserv/cert.cpp b/modules/webcpanel/pages/nickserv/cert.cpp index 436725b04..cdf23a1b3 100644 --- a/modules/webcpanel/pages/nickserv/cert.cpp +++ b/modules/webcpanel/pages/nickserv/cert.cpp @@ -1,8 +1,9 @@ /* - * (C) 2003-2014 Anope Team + * (C) 2003-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. + * */ #include "../../webcpanel.h" @@ -31,7 +32,7 @@ bool WebCPanel::NickServ::Cert::OnRequest(HTTPProvider *server, const Anope::str WebPanel::RunCommand(na->GetAccount()->GetDisplay(), na->GetAccount(), "NickServ", "nickserv/cert", params, replacements); } - std::vector<NSCertEntry *> cl = na->GetAccount()->GetRefs<NSCertEntry *>(certentry); + std::vector<NSCertEntry *> cl = na->GetAccount()->GetRefs<NSCertEntry *>(); for (NSCertEntry *e : cl) replacements["CERTS"] = e->GetCert(); diff --git a/modules/webcpanel/pages/nickserv/info.cpp b/modules/webcpanel/pages/nickserv/info.cpp index b3c743ed3..efbf1a425 100644 --- a/modules/webcpanel/pages/nickserv/info.cpp +++ b/modules/webcpanel/pages/nickserv/info.cpp @@ -34,7 +34,7 @@ bool WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::str const Anope::string &post_greet = HTTPUtils::URLDecode(message.post_data["greet"].replace_all_cs("+", " ")); if (post_greet.empty()) - na->GetAccount()->ShrinkOK<Anope::string>("greet"); + na->GetAccount()->Shrink<Anope::string>("greet"); else if (!greet || post_greet != *greet) na->GetAccount()->Extend<Anope::string>("greet", post_greet); diff --git a/modules/webcpanel/pages/operserv/akill.cpp b/modules/webcpanel/pages/operserv/akill.cpp index 58b68b0b2..950ed2bd9 100644 --- a/modules/webcpanel/pages/operserv/akill.cpp +++ b/modules/webcpanel/pages/operserv/akill.cpp @@ -7,15 +7,12 @@ #include "../../webcpanel.h" -WebCPanel::OperServ::Akill::Akill(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u) +WebCPanel::OperServ::Akill::Akill(const Anope::string &cat, const Anope::string &u) : WebPanelProtectedPage(cat, u), akills("xlinemanager/sgline") { } bool WebCPanel::OperServ::Akill::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, ::NickServ::Nick *na, TemplateFileServer::Replacements &replacements) { - - static ServiceReference<XLineManager> akills("XLineManager","xlinemanager/sgline"); - if (!na->GetAccount()->o || !na->GetAccount()->o->GetType()->HasCommand("operserv/akill")) { replacements["NOACCESS"]; diff --git a/modules/webcpanel/pages/operserv/akill.h b/modules/webcpanel/pages/operserv/akill.h index 7367f593f..5ad75eaeb 100644 --- a/modules/webcpanel/pages/operserv/akill.h +++ b/modules/webcpanel/pages/operserv/akill.h @@ -13,6 +13,8 @@ namespace OperServ class Akill : public WebPanelProtectedPage { + ServiceReference<XLineManager> akills; + public: Akill(const Anope::string &cat, const Anope::string &u); diff --git a/modules/webcpanel/webcpanel.cpp b/modules/webcpanel/webcpanel.cpp index 5da56a6d4..14889c97d 100644 --- a/modules/webcpanel/webcpanel.cpp +++ b/modules/webcpanel/webcpanel.cpp @@ -78,7 +78,7 @@ class ModuleWebCPanel : public Module template_base = Anope::DataDir + "/modules/webcpanel/templates/" + template_name; page_title = block->Get<Anope::string>("title", "Anope IRC Services"); - provider = ServiceReference<HTTPProvider>("HTTPProvider", provider_name); + provider = ServiceReference<HTTPProvider>(provider_name); if (!provider) throw ModuleException("Unable to find HTTPD provider. Is m_httpd loaded?"); @@ -250,7 +250,7 @@ namespace WebPanel { void RunCommand(const Anope::string &user, NickServ::Account *nc, const Anope::string &service, const Anope::string &c, std::vector<Anope::string> ¶ms, TemplateFileServer::Replacements &r, const Anope::string &key) { - ServiceReference<Command> cmd("Command", c); + ServiceReference<Command> cmd(c); if (!cmd) { r[key] = "Unable to find command " + c; @@ -286,7 +286,7 @@ namespace WebPanel void RunCommandWithName(NickServ::Account *nc, const Anope::string &service, const Anope::string &c, const Anope::string &cmdname, std::vector<Anope::string> ¶ms, TemplateFileServer::Replacements &r, const Anope::string &key) { - ServiceReference<Command> cmd("Command", c); + ServiceReference<Command> cmd(c); if (!cmd) { r[key] = "Unable to find command " + c; diff --git a/modules/webcpanel/webcpanel.h b/modules/webcpanel/webcpanel.h index 8e77b975a..23350ae32 100644 --- a/modules/webcpanel/webcpanel.h +++ b/modules/webcpanel/webcpanel.h @@ -31,7 +31,9 @@ struct Section class Panel : public Section, public Service { public: - Panel(Module *c, const Anope::string &n) : Service(c, "Panel", n) { } + static constexpr const char *NAME = "panel"; + + Panel(Module *c, const Anope::string &n) : Service(c, NAME, "") { } std::vector<Section> sections; @@ -74,6 +76,7 @@ class WebPanelPage : public HTTPPage class WebPanelProtectedPage : public WebPanelPage { Anope::string category; + ServiceReference<Panel> panel; public: WebPanelProtectedPage(const Anope::string &cat, const Anope::string &u, const Anope::string &ct = "text/html") : WebPanelPage(u, ct), category(cat) @@ -82,7 +85,6 @@ class WebPanelProtectedPage : public WebPanelPage bool OnRequest(HTTPProvider *provider, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) override final { - ServiceReference<Panel> panel("Panel", "webcpanel"); NickServ::Nick *na; if (!panel || !(na = panel->GetNickFromSession(client, message))) diff --git a/modules/xmlrpc.cpp b/modules/xmlrpc.cpp index 4dbfa0497..928929904 100644 --- a/modules/xmlrpc.cpp +++ b/modules/xmlrpc.cpp @@ -191,6 +191,7 @@ class MyXMLRPCServiceInterface : public XMLRPCServiceInterface, public HTTPPage class ModuleXMLRPC : public Module { ServiceReference<HTTPProvider> httpref; + public: MyXMLRPCServiceInterface xmlrpcinterface; @@ -210,9 +211,12 @@ class ModuleXMLRPC : public Module { if (httpref) httpref->UnregisterPage(&xmlrpcinterface); - this->httpref = ServiceReference<HTTPProvider>("HTTPProvider", conf->GetModule(this)->Get<Anope::string>("server", "httpd/main")); + + this->httpref = ServiceReference<HTTPProvider>(conf->GetModule(this)->Get<Anope::string>("server", "httpd/main")); + if (!httpref) throw ConfigException("Unable to find http reference, is m_httpd loaded?"); + httpref->RegisterPage(&xmlrpcinterface); } }; diff --git a/modules/xmlrpc_main.cpp b/modules/xmlrpc_main.cpp index af0253028..a812b1fba 100644 --- a/modules/xmlrpc_main.cpp +++ b/modules/xmlrpc_main.cpp @@ -1,5 +1,6 @@ #include "module.h" #include "modules/xmlrpc.h" +#include "modules/operserv/stats.h" static Module *me; @@ -117,7 +118,7 @@ class MyXMLRPCEvent : public XMLRPCEvent else { NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new XMLRPCIdentifyRequest(request, client, iface), me, username, password); - Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); + EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, nullptr, req); req->Dispatch(); return false; } @@ -127,6 +128,8 @@ class MyXMLRPCEvent : public XMLRPCEvent void DoStats(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) { + Stats *stats = Serialize::GetObject<Stats *>(); + request.reply("uptime", stringify(Anope::CurTime - Anope::StartTime)); request.reply("uplinkname", Me->GetLinks().front()->GetName()); { @@ -138,7 +141,7 @@ class MyXMLRPCEvent : public XMLRPCEvent request.reply("uplinkcapab", buf); } request.reply("usercount", stringify(UserListByNick.size())); - request.reply("maxusercount", stringify(MaxUserCount)); + request.reply("maxusercount", stringify(stats ? stats->GetMaxUserCount() : 0)); request.reply("channelcount", stringify(ChannelList.size())); } @@ -258,7 +261,7 @@ class ModuleXMLRPCMain : public Module MyXMLRPCEvent stats; public: - ModuleXMLRPCMain(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), xmlrpc("XMLRPCServiceInterface", "xmlrpc") + ModuleXMLRPCMain(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR) { me = this; |
