diff options
-rw-r--r-- | include/inspircd.h | 4 | ||||
-rw-r--r-- | include/mode.h | 7 | ||||
-rw-r--r-- | include/modes/umode_i.h | 1 | ||||
-rw-r--r-- | include/modes/umode_o.h | 1 | ||||
-rw-r--r-- | include/modes/umode_s.h | 1 | ||||
-rw-r--r-- | include/modes/umode_w.h | 1 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 26 | ||||
-rw-r--r-- | src/mode.cpp | 7 | ||||
-rw-r--r-- | src/modes/umode_i.cpp | 6 | ||||
-rw-r--r-- | src/modes/umode_o.cpp | 5 | ||||
-rw-r--r-- | src/modes/umode_s.cpp | 6 | ||||
-rw-r--r-- | src/modes/umode_w.cpp | 7 |
12 files changed, 56 insertions, 16 deletions
diff --git a/include/inspircd.h b/include/inspircd.h index d3d424384..006e8092e 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -494,6 +494,10 @@ class InspIRCd : public classbase void AddGlobalClone(userrec* user); + /** Number of users with a certain mode set on them + */ + int ModeCount(const char mode); + /** Get the time offset in seconds * @return The current time delta (in seconds) */ diff --git a/include/mode.h b/include/mode.h index b3c580e6c..62374be6c 100644 --- a/include/mode.h +++ b/include/mode.h @@ -132,6 +132,10 @@ class ModeHandler : public Extensible */ char prefix; + /** Number of items with this mode set on them + */ + static unsigned int count; + public: /** * The constructor for ModeHandler initalizes the mode handler. @@ -164,6 +168,9 @@ class ModeHandler : public Extensible * value for this mode prefix. */ char GetPrefix(); + /** Get number of items with this mode set on them + */ + virtual unsigned int GetCount(); /** * Get the 'value' of this modes prefix. * determines which to display when there are multiple. diff --git a/include/modes/umode_i.h b/include/modes/umode_i.h index c8e33b492..cc7d15102 100644 --- a/include/modes/umode_i.h +++ b/include/modes/umode_i.h @@ -22,4 +22,5 @@ class ModeUserInvisible : public ModeHandler public: ModeUserInvisible(InspIRCd* Instance); ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding); + unsigned int GetCount(); }; diff --git a/include/modes/umode_o.h b/include/modes/umode_o.h index 4fe6f6b96..7dfdb4128 100644 --- a/include/modes/umode_o.h +++ b/include/modes/umode_o.h @@ -22,4 +22,5 @@ class ModeUserOperator : public ModeHandler public: ModeUserOperator(InspIRCd* Instance); ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding); + unsigned int GetCount(); }; diff --git a/include/modes/umode_s.h b/include/modes/umode_s.h index 297b49c67..cda223eee 100644 --- a/include/modes/umode_s.h +++ b/include/modes/umode_s.h @@ -22,4 +22,5 @@ class ModeUserServerNotice : public ModeHandler public: ModeUserServerNotice(InspIRCd* Instance); ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding); + unsigned int GetCount(); }; diff --git a/include/modes/umode_w.h b/include/modes/umode_w.h index b1f6e94c7..271e959c4 100644 --- a/include/modes/umode_w.h +++ b/include/modes/umode_w.h @@ -22,4 +22,5 @@ class ModeUserWallops : public ModeHandler public: ModeUserWallops(InspIRCd* Instance); ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding); + unsigned int GetCount(); }; 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; +} + |