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/chanserv | |
| 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/chanserv')
32 files changed, 512 insertions, 523 deletions
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, t |
