diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-07-07 15:24:46 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-07-07 15:24:46 +0000 |
commit | 6b9d3c568d5c13353dab4aad657310a0ed933730 (patch) | |
tree | cce07e7ff544fb50f0017dea4873fea3cc075582 | |
parent | ace37813034e91b0972ba84962814571644f2eee (diff) |
Added hashing stuff to hold both user and channel modes in the watcher/handler list
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4127 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | src/mode.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/mode.cpp b/src/mode.cpp index 1055dd492..059a9027b 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -47,6 +47,7 @@ using namespace std; #include "mode.h" #include "modes/cmode_s.h" +#include "modes/cmode_p.h" extern int MODCOUNT; extern std::vector<Module*> modules; @@ -481,6 +482,7 @@ void ModeParser::Process(char **parameters, int pcnt, userrec *user, bool server { std::string target = parameters[0]; ModeType type = MODETYPE_USER; + unsigned char mask = 0; chanrec* targetchannel = FindChan(parameters[0]); userrec* targetuser = Find(parameters[0]); @@ -492,11 +494,13 @@ void ModeParser::Process(char **parameters, int pcnt, userrec *user, bool server { log(DEBUG,"Target type is CHANNEL"); type = MODETYPE_CHANNEL; + mask = MASK_CHANNEL; } else if (targetuser) { log(DEBUG,"Target type is USER"); type = MODETYPE_USER; + mask = MASK_USER; } else { @@ -543,8 +547,16 @@ void ModeParser::Process(char **parameters, int pcnt, userrec *user, bool server break; default: - /* 65 is the ascii value of 'A' */ - handler_id = *modeletter - 65; + /** + * Watch carefully for the sleight of hand trick. + * 65 is the ascii value of 'A'. We take this from + * the char we're looking at to get a number between + * 1 and 127. We then logic-or it to get the hashed + * position, dependent on wether its a channel or + * a user mode. This is a little stranger, but a lot + * faster, than using a map of pairs. + */ + handler_id = (*modeletter - 65) | mask; if (modehandlers[handler_id]) { @@ -654,10 +666,15 @@ void cmd_mode::Handle (char **parameters, int pcnt, userrec *user) return; } +ModeParser::AddMode(ModeHandler* mh, unsigned const char* modeletter) +{ + mh->GetType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL; + modehandlers[(modeletter-65) | mask] = mh; +} ModeParser::ModeParser() { - /* Dummy framework, XXX tidyme */ - ModeChannelSecret* cmode_s = new ModeChannelSecret(); - modehandlers[(unsigned char)'s'-65] = cmode_s; + /* Initialise the RFC mode letters */ + this->AddMode(new ModeChannelSecret, 's'); + this->AddMode(new ModeChannelPrivate, 'p'); } |