From 6b9d3c568d5c13353dab4aad657310a0ed933730 Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 7 Jul 2006 15:24:46 +0000 Subject: [PATCH] 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 --- src/mode.cpp | 27 ++++++++++++++++++++++----- 1 file 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 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'); } -- 2.39.5