From a1af610ac1916bc3a4f09962ac86a58883514e51 Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 7 Jul 2006 15:27:05 +0000 Subject: Added masking stuff. Basically, so that we can hold user modes and channel modes in the same list, we use bitwise masking. We have a list of handlers, 256 in size 0 through 255, and to work out where a mode handler is dependent on WHAT it is, we use this simple hashing algorithm (no collisions can occur): (modeletter - 65) | mask Where mask is 128 (10000000b) if its a user mode, or 0 (00000000b, duh) if its a channel mode. Smart, and much faster than using a map of pairs. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4128 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/mode.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/mode.h b/include/mode.h index f0efdf1d2..1c30d26e1 100644 --- a/include/mode.h +++ b/include/mode.h @@ -45,6 +45,11 @@ enum ModeAction { MODEACTION_ALLOW = 1 /* Allow the mode */ }; +enum ModeMasks { + MASK_USER = 128, /* A user mode */ + MASK_CHANNEL = 0 /* A channel mode */ +}; + class ModeHandler { char mode; @@ -93,12 +98,14 @@ class ModeParser /** * Mode handlers for each mode, to access a handler subtract * 65 from the ascii value of the mode letter. + * The upper bit of the value indicates if its a usermode + * or a channel mode, so we have 255 of them not 64. */ - ModeHandler* modehandlers[64]; + ModeHandler* modehandlers[256]; /** * Mode watcher classes */ - std::vector modewatchers[64]; + std::vector modewatchers[256]; char* GiveOps(userrec *user,char *dest,chanrec *chan,int status); char* GiveHops(userrec *user,char *dest,chanrec *chan,int status); -- cgit v1.2.3