summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-11-04 16:23:06 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-11-04 16:23:06 +0000
commit02ce802257b0c1213d4c54cce4cbbd0708db6919 (patch)
treecf911da2ea9d19932995a78906f45a39424df05d /src
parent2facf72164bcf6ddef3b865ee729e6918cd06fd0 (diff)
Bring back Prioritize (needs to occur after module load) with a different declaration
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8499 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/modules.cpp70
-rw-r--r--src/modules/m_auditorium.cpp21
2 files changed, 78 insertions, 13 deletions
diff --git a/src/modules.cpp b/src/modules.cpp
index f0d52d331..ae6767765 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -192,7 +192,7 @@ void Module::OnText(User*, void*, int, const std::string&, char, CUList&) { }
ModuleManager::ModuleManager(InspIRCd* Ins) : ModCount(0), Instance(Ins)
{
for (int n = I_BEGIN + 1; n != I_END; ++n)
- EventHandlers.push_back(std::list<Module*>());
+ EventHandlers.push_back(std::vector<Module*>());
}
ModuleManager::~ModuleManager()
@@ -231,6 +231,70 @@ void ModuleManager::DetachAll(Module* mod)
Detach((Implementation)n, mod);
}
+bool ModuleManager::SetPriority(Module* mod, Implementation i, PriorityState s, Module** modules, size_t sz)
+{
+ size_t swap_pos;
+ size_t source;
+ bool swap = true;
+
+ for (size_t x = 0; x != EventHandlers[i].size(); ++x)
+ {
+ if (EventHandlers[i][x] == mod)
+ {
+ source = x;
+ break;
+ }
+ }
+
+ switch (s)
+ {
+ case PRIO_DONTCARE:
+ swap = false;
+ break;
+ case PRIO_FIRST:
+ swap_pos = 0;
+ break;
+ case PRIO_LAST:
+ if (EventHandlers[i].empty())
+ swap_pos = 0;
+ else
+ swap_pos = EventHandlers[i].size() - 1;
+ break;
+ case PRIO_AFTER:
+ {
+ /* Find the latest possible position */
+ swap_pos = 0;
+ for (size_t x = 0; x != EventHandlers[i].size(); ++x)
+ {
+ for (size_t n = 0; n < sz; ++n)
+ {
+ if ((modules[n]) && (EventHandlers[i][x] == modules[n]) && (x >= swap_pos))
+ swap_pos = x;
+ }
+ }
+ }
+ break;
+ case PRIO_BEFORE:
+ {
+ swap_pos = EventHandlers[i].size() - 1;
+ for (size_t x = 0; x != EventHandlers[i].size(); ++x)
+ {
+ for (size_t n = 0; n < sz; ++n)
+ {
+ if ((modules[n]) && (EventHandlers[i][x] == modules[n]) && (x <= swap_pos))
+ swap_pos = x;
+ }
+ }
+ }
+ break;
+ }
+
+ if (swap)
+ std::swap(EventHandlers[i][swap_pos], EventHandlers[i][source]);
+
+ return true;
+}
+
const char* ModuleManager::LastError()
{
return MODERR;
@@ -359,6 +423,10 @@ bool ModuleManager::Load(const char* filename)
this->ModCount++;
FOREACH_MOD_I(Instance,I_OnLoadModule,OnLoadModule(modules[this->ModCount],filename_str));
+
+ for (int n = 0; n != this->ModCount+1; ++n)
+ modules[n]->Prioritize();
+
Instance->BuildISupport();
return true;
}
diff --git a/src/modules/m_auditorium.cpp b/src/modules/m_auditorium.cpp
index a686d7444..173b13311 100644
--- a/src/modules/m_auditorium.cpp
+++ b/src/modules/m_auditorium.cpp
@@ -55,8 +55,11 @@ class ModuleAuditorium : public Module
{
aum = new AuditoriumMode(ServerInstance);
if (!ServerInstance->AddMode(aum))
- throw ModuleException("Could not add new modes!");
+ throw ModuleException("Could not add new modes!")
OnRehash(NULL, "");
+
+ Implements eventlist[] = { I_OnUserJoin, I_OnUserPart, I_OnUserKick, I_OnUserQuit, I_OnUserList, I_OnRehash };
+ Me->Modules->Attach(eventlist, this, sizeof(eventlist));
}
virtual ~ModuleAuditorium()
@@ -65,16 +68,15 @@ class ModuleAuditorium : public Module
DELETE(aum);
}
- virtual void OnRehash(User* user, const std::string &parameter)
+ void Prioritize()
{
- ConfigReader conf(ServerInstance);
- ShowOps = conf.ReadFlag("auditorium", "showops", 0);
+ ServerInstance->Modules->SetPriority(this, I_OnUserList, PRIO_BEFORE, &(ServerInstance->Modules->Find("m_namesx.so")));
}
- Priority Prioritize()
+ virtual void OnRehash(User* user, const std::string &parameter)
{
- /* To ensure that we get priority over namesx for names list generation on +u channels */
- return (Priority)ServerInstance->Modules->PriorityBefore("m_namesx.so");
+ ConfigReader conf(ServerInstance);
+ ShowOps = conf.ReadFlag("auditorium", "showops", 0);
}
virtual Version GetVersion()
@@ -82,11 +84,6 @@ class ModuleAuditorium : public Module
return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
}
- void Implements(char* List)
- {
- List[I_OnUserJoin] = List[I_OnUserPart] = List[I_OnUserKick] = List[I_OnUserQuit] = List[I_OnUserList] = List[I_OnRehash] = 1;
- }
-
virtual int OnUserList(User* user, Channel* Ptr, CUList* &nameslist)
{
if (Ptr->IsModeSet('u'))