summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-09 13:21:35 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-09 13:21:35 +0000
commitc330b24501fc56516fef098428889a0a526e706a (patch)
tree83a64774409c8c6808dd4c6a2587ca89229e9e97
parent68da120812b1e593c76ea75d0d591f47b6a4f402 (diff)
Added userrec::modebits - fast way of checking if user has +swi rather than an icky strchr
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3588 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/mode.h6
-rw-r--r--include/users.h7
-rw-r--r--src/helperfuncs.cpp10
-rw-r--r--src/message.cpp2
-rw-r--r--src/mode.cpp32
-rwxr-xr-xsrc/svn-rev.sh2
-rw-r--r--src/users.cpp2
7 files changed, 48 insertions, 13 deletions
diff --git a/include/mode.h b/include/mode.h
index 973e9c22b..54b4aa97e 100644
--- a/include/mode.h
+++ b/include/mode.h
@@ -29,6 +29,12 @@
#include "channels.h"
#include "ctables.h"
+enum UserModeBits {
+ UM_INVISIBLE = 1,
+ UM_SERVERNOTICE = 2,
+ UM_WALLOPS = 3
+};
+
class ModeParser
{
private:
diff --git a/include/users.h b/include/users.h
index 294bc1e1f..e7ad4b9d9 100644
--- a/include/users.h
+++ b/include/users.h
@@ -150,6 +150,13 @@ class userrec : public connection
* an optional + character.
*/
char modes[54];
+
+ /** This contains a bitmask of the RFC modes +swi,
+ * which can be used for fast lookup when iterating all the users.
+ * It is maintained by the mode parser and matches the character
+ * modes stored in 'modes'.
+ */
+ char modebits;
std::vector<ucrec*> chans;
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 27bc22007..effffd6e9 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -975,7 +975,7 @@ void WriteOpers(char* text, ...)
if (IS_LOCAL(a))
{
- if (strchr(a->modes,'s'))
+ if (a->modebits & UM_SERVERNOTICE)
{
// send server notices to all with +s
WriteServ(a->fd,"NOTICE %s :%s",a->nick,textbuffer);
@@ -1118,7 +1118,7 @@ void WriteWallOps(userrec *source, bool local_only, char* text, ...)
{
userrec* t = (userrec*)(*i);
- if ((IS_LOCAL(t)) && (strchr(t->modes,'w')))
+ if ((IS_LOCAL(t)) && (t->modebits & UM_WALLOPS))
{
WriteTo(source,t,"WALLOPS :%s",textbuffer);
}
@@ -1335,7 +1335,7 @@ void userlist(userrec *user,chanrec *c)
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- if ((!has_user) && (strchr(i->second->modes,'i')))
+ if ((!has_user) && (i->second->modebits & UM_INVISIBLE))
{
/*
* user is +i, and source not on the channel, does not show
@@ -1378,7 +1378,7 @@ int usercount_i(chanrec *c)
CUList *ulist= c->GetUsers();
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- if (!strchr(i->second->modes,'i'))
+ if (i->second->modebits & UM_INVISIBLE)
count++;
}
@@ -1467,7 +1467,7 @@ int usercount_invisible(void)
for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
{
- if ((i->second->registered == 7) && (strchr(i->second->modes,'i')))
+ if ((i->second->registered == 7) && (i->second->modebits & UM_INVISIBLE))
c++;
}
diff --git a/src/message.cpp b/src/message.cpp
index 8614acf0e..042901503 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -397,7 +397,7 @@ std::string chlist(userrec *user,userrec* source)
{
return lst;
}
- bool userinvisible = (strchr(user->modes,'i'));
+ bool userinvisible = (user->modebits & UM_INVISIBLE);
for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
{
if ((((ucrec*)(*i))->channel != NULL) && (((ucrec*)(*i))->channel->name))
diff --git a/src/mode.cpp b/src/mode.cpp
index c343ed10b..418ad4eac 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -1239,9 +1239,20 @@ void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
{
charlcat(dmodes,*i,53);
charlcat(outpars,*i,MAXMODES);
- if (*i == 'o')
+ switch (*i)
{
- FOREACH_MOD(I_OnGlobalOper,OnGlobalOper(dest));
+ case 'o':
+ FOREACH_MOD(I_OnGlobalOper,OnGlobalOper(dest));
+ break;
+ case 'i':
+ dest->modebits |= UM_INVISIBLE;
+ break;
+ case 's':
+ dest->modebits |= UM_SERVERNOTICE;
+ break;
+ case 'w':
+ dest->modebits |= UM_WALLOPS;
+ break;
}
}
}
@@ -1254,10 +1265,21 @@ void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
{
charlcat(outpars,*i,MAXMODES);
charremove(dmodes,*i);
- if (*i == 'o')
+ switch (*i)
{
- *dest->oper = 0;
- DeleteOper(dest);
+ case 'o':
+ *dest->oper = 0;
+ DeleteOper(dest);
+ break;
+ case 'i':
+ dest->modebits ^= UM_INVISIBLE;
+ break;
+ case 's':
+ dest->modebits ^= UM_SERVERNOTICE;
+ break;
+ case 'w':
+ dest->modebits ^= UM_WALLOPS;
+ break;
}
}
}
diff --git a/src/svn-rev.sh b/src/svn-rev.sh
index 4236c1544..380078739 100755
--- a/src/svn-rev.sh
+++ b/src/svn-rev.sh
@@ -1 +1 @@
-echo 3581
+echo 3586
diff --git a/src/users.cpp b/src/users.cpp
index 5c1d78fb0..a0929d684 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -107,7 +107,7 @@ userrec::userrec()
server = (char*)FindServerNamePtr(Config->ServerName);
reset_due = TIME;
lines_in = fd = lastping = signon = idle_lastmsg = nping = registered = 0;
- timeout = flood = port = bytes_in = bytes_out = cmds_in = cmds_out = 0;
+ modebits = timeout = flood = port = bytes_in = bytes_out = cmds_in = cmds_out = 0;
haspassed = dns_done = false;
recvq = "";
sendq = "";