summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-12-29 23:34:47 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-12-29 23:34:47 +0000
commit5e9a6b9186a8cbaaf65ae7d9cd9c0c033c91b497 (patch)
tree5e90ee569ad974e0affe96d02b3470345eb74192 /src
parentb848ca14335adcb924acb7977d93e0d76b9437b7 (diff)
Add counter system for umodes to get rid of some O(n)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6163 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/helperfuncs.cpp26
-rw-r--r--src/mode.cpp7
-rw-r--r--src/modes/umode_i.cpp6
-rw-r--r--src/modes/umode_o.cpp5
-rw-r--r--src/modes/umode_s.cpp6
-rw-r--r--src/modes/umode_w.cpp7
6 files changed, 41 insertions, 16 deletions
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index fdbeb613f..84cc52df5 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -308,28 +308,24 @@ int InspIRCd::RegisteredUserCount()
return clientlist->size() - this->UnregisteredUserCount();
}
-int InspIRCd::InvisibleUserCount()
+int InspIRCd::ModeCount(const char mode)
{
- int c = 0;
+ ModeHandler* mh = this->Modes->GetHandler(mode, MODETYPE_USER);
- for (user_hash::const_iterator i = clientlist->begin(); i != clientlist->end(); i++)
- {
- c += ((i->second->registered == REG_ALL) && (i->second->modes[UM_INVISIBLE]));
- }
+ if (mh)
+ return mh->GetCount();
+ else
+ return 0;
+}
- return c;
+int InspIRCd::InvisibleUserCount()
+{
+ return ModeCount('i');
}
int InspIRCd::OperCount()
{
- int c = 0;
-
- for (user_hash::const_iterator i = clientlist->begin(); i != clientlist->end(); i++)
- {
- if (*(i->second->oper))
- c++;
- }
- return c;
+ return ModeCount('o');
}
int InspIRCd::UnregisteredUserCount()
diff --git a/src/mode.cpp b/src/mode.cpp
index dfa846364..68d7e0bd0 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -53,7 +53,7 @@
#include "modes/umode_n.h"
ModeHandler::ModeHandler(InspIRCd* Instance, char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly, char mprefix)
- : ServerInstance(Instance), mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), oper(operonly), prefix(mprefix)
+ : ServerInstance(Instance), mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), oper(operonly), prefix(mprefix), count(0)
{
}
@@ -71,6 +71,11 @@ unsigned int ModeHandler::GetPrefixRank()
return 0;
}
+unsigned int ModeHandler::GetCount()
+{
+ return 0;
+}
+
ModeType ModeHandler::GetModeType()
{
return m_type;
diff --git a/src/modes/umode_i.cpp b/src/modes/umode_i.cpp
index 73d7293a8..e3f81c529 100644
--- a/src/modes/umode_i.cpp
+++ b/src/modes/umode_i.cpp
@@ -31,9 +31,15 @@ ModeAction ModeUserInvisible::OnModeChange(userrec* source, userrec* dest, chanr
if (dest->modes[UM_INVISIBLE] != adding)
{
dest->modes[UM_INVISIBLE] = adding;
+ this->count += (adding ? 1: -1);
return MODEACTION_ALLOW;
}
/* Allow the change */
return MODEACTION_DENY;
}
+
+unsigned int GetCount()
+{
+ return count;
+}
diff --git a/src/modes/umode_o.cpp b/src/modes/umode_o.cpp
index b121df908..6d785f26e 100644
--- a/src/modes/umode_o.cpp
+++ b/src/modes/umode_o.cpp
@@ -42,3 +42,8 @@ ModeAction ModeUserOperator::OnModeChange(userrec* source, userrec* dest, chanre
return MODEACTION_ALLOW;
}
+
+unsigned int GetCount()
+{
+ return ServerInstance->all_opers.size();
+}
diff --git a/src/modes/umode_s.cpp b/src/modes/umode_s.cpp
index 9a78f3241..36b830b91 100644
--- a/src/modes/umode_s.cpp
+++ b/src/modes/umode_s.cpp
@@ -31,9 +31,15 @@ ModeAction ModeUserServerNotice::OnModeChange(userrec* source, userrec* dest, ch
if (dest->modes[UM_SERVERNOTICE] != adding)
{
dest->modes[UM_SERVERNOTICE] = adding;
+ this->count += (adding ? 1: -1);
return MODEACTION_ALLOW;
}
/* Allow the change */
return MODEACTION_DENY;
}
+
+unsigned int GetCount()
+{
+ return count;
+}
diff --git a/src/modes/umode_w.cpp b/src/modes/umode_w.cpp
index f9608bf0b..eba24778a 100644
--- a/src/modes/umode_w.cpp
+++ b/src/modes/umode_w.cpp
@@ -31,9 +31,16 @@ ModeAction ModeUserWallops::OnModeChange(userrec* source, userrec* dest, chanrec
if (dest->modes[UM_WALLOPS] != adding)
{
dest->modes[UM_WALLOPS] = adding;
+ this->count += (adding ? 1: -1);
return MODEACTION_ALLOW;
}
/* Allow the change */
return MODEACTION_DENY;
}
+
+unsigned int GetCount()
+{
+ return count;
+}
+