mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-10 11:09:04 -04:00
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
This commit is contained in:
parent
68da120812
commit
c330b24501
@ -29,6 +29,12 @@
|
|||||||
#include "channels.h"
|
#include "channels.h"
|
||||||
#include "ctables.h"
|
#include "ctables.h"
|
||||||
|
|
||||||
|
enum UserModeBits {
|
||||||
|
UM_INVISIBLE = 1,
|
||||||
|
UM_SERVERNOTICE = 2,
|
||||||
|
UM_WALLOPS = 3
|
||||||
|
};
|
||||||
|
|
||||||
class ModeParser
|
class ModeParser
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -151,6 +151,13 @@ class userrec : public connection
|
|||||||
*/
|
*/
|
||||||
char modes[54];
|
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;
|
std::vector<ucrec*> chans;
|
||||||
|
|
||||||
/** The server the user is connected to.
|
/** The server the user is connected to.
|
||||||
|
@ -975,7 +975,7 @@ void WriteOpers(char* text, ...)
|
|||||||
|
|
||||||
if (IS_LOCAL(a))
|
if (IS_LOCAL(a))
|
||||||
{
|
{
|
||||||
if (strchr(a->modes,'s'))
|
if (a->modebits & UM_SERVERNOTICE)
|
||||||
{
|
{
|
||||||
// send server notices to all with +s
|
// send server notices to all with +s
|
||||||
WriteServ(a->fd,"NOTICE %s :%s",a->nick,textbuffer);
|
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);
|
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);
|
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++)
|
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
|
* 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();
|
CUList *ulist= c->GetUsers();
|
||||||
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
|
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
|
||||||
{
|
{
|
||||||
if (!strchr(i->second->modes,'i'))
|
if (i->second->modebits & UM_INVISIBLE)
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1467,7 +1467,7 @@ int usercount_invisible(void)
|
|||||||
|
|
||||||
for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
|
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++;
|
c++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ std::string chlist(userrec *user,userrec* source)
|
|||||||
{
|
{
|
||||||
return lst;
|
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++)
|
for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
|
||||||
{
|
{
|
||||||
if ((((ucrec*)(*i))->channel != NULL) && (((ucrec*)(*i))->channel->name))
|
if ((((ucrec*)(*i))->channel != NULL) && (((ucrec*)(*i))->channel->name))
|
||||||
|
26
src/mode.cpp
26
src/mode.cpp
@ -1239,9 +1239,20 @@ void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
|
|||||||
{
|
{
|
||||||
charlcat(dmodes,*i,53);
|
charlcat(dmodes,*i,53);
|
||||||
charlcat(outpars,*i,MAXMODES);
|
charlcat(outpars,*i,MAXMODES);
|
||||||
if (*i == 'o')
|
switch (*i)
|
||||||
{
|
{
|
||||||
|
case 'o':
|
||||||
FOREACH_MOD(I_OnGlobalOper,OnGlobalOper(dest));
|
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);
|
charlcat(outpars,*i,MAXMODES);
|
||||||
charremove(dmodes,*i);
|
charremove(dmodes,*i);
|
||||||
if (*i == 'o')
|
switch (*i)
|
||||||
{
|
{
|
||||||
|
case 'o':
|
||||||
*dest->oper = 0;
|
*dest->oper = 0;
|
||||||
DeleteOper(dest);
|
DeleteOper(dest);
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
dest->modebits ^= UM_INVISIBLE;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
dest->modebits ^= UM_SERVERNOTICE;
|
||||||
|
break;
|
||||||
|
case 'w':
|
||||||
|
dest->modebits ^= UM_WALLOPS;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
echo 3581
|
echo 3586
|
||||||
|
@ -107,7 +107,7 @@ userrec::userrec()
|
|||||||
server = (char*)FindServerNamePtr(Config->ServerName);
|
server = (char*)FindServerNamePtr(Config->ServerName);
|
||||||
reset_due = TIME;
|
reset_due = TIME;
|
||||||
lines_in = fd = lastping = signon = idle_lastmsg = nping = registered = 0;
|
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;
|
haspassed = dns_done = false;
|
||||||
recvq = "";
|
recvq = "";
|
||||||
sendq = "";
|
sendq = "";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user