summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-05-12 18:42:06 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-05-12 18:42:06 +0000
commit2cd3b57fe08b6cdae5d99021252898dedd3a0650 (patch)
tree77a8ebf2339d02c324aaa5d066913756c51d35b2
parenta266dadd1351d10b56ec187c7b6f7af75350ed68 (diff)
Structure optimizations, changed a lot of bools into binary bitmasks
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1368 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/channels.h41
-rw-r--r--include/connection.h24
-rw-r--r--include/users.h14
-rw-r--r--src/channels.cpp4
-rw-r--r--src/commands.cpp22
-rw-r--r--src/inspircd.cpp27
-rw-r--r--src/message.cpp2
-rw-r--r--src/mode.cpp128
-rw-r--r--src/modules/m_knock.cpp2
-rw-r--r--src/modules/m_override.cpp2
-rw-r--r--src/users.cpp1
11 files changed, 128 insertions, 139 deletions
diff --git a/include/channels.h b/include/channels.h
index 6080cda98..ac1ee0385 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -23,6 +23,13 @@
#ifndef __CHANNELS_H__
#define __CHANNELS_H__
+#define CM_TOPICLOCK 1
+#define CM_NOEXTERNAL 2
+#define CM_INVITEONLY 4
+#define CM_MODERATED 8
+#define CM_SECRET 16
+#define CM_PRIVATE 32
+
/** Holds an entry for a ban list, exemption list, or invite list.
* This class contains a single element in a channel list, such as a banlist.
*/
@@ -102,10 +109,6 @@ class chanrec : public Extensible
*/
char custom_modes[MAXMODES]; /* modes handled by modules */
- /** Count of users on the channel used for fast user counting
- */
- long users;
-
/** User list (casted to char*'s to stop forward declaration stuff)
* (chicken and egg scenario!)
*/
@@ -130,38 +133,16 @@ class chanrec : public Extensible
/** Contains the channel user limit.
* If this value is zero, there is no limit in place.
*/
- long limit;
+ short int limit;
/** Contains the channel key.
* If this value is an empty string, there is no channel key in place.
*/
char key[32];
- /** Nonzero if the mode +t is set.
- */
- short int topiclock;
-
- /** Nonzero if the mode +n is set.
- */
- short int noexternal;
-
- /** Nonzero if the mode +i is set.
- */
- short int inviteonly;
-
- /** Nonzero if the mode +m is set.
- */
- short int moderated;
-
- /** Nonzero if the mode +s is set.
- * This value cannot be set at the same time as chanrec::c_private
- */
- short int secret;
-
- /** Nonzero if the mode +p is set.
- * This value cannot be set at the same time as chanrec::secret
+ /** Contains a bitmask of the CM_* builtin (RFC) binary mode symbols
*/
- short int c_private;
+ char binarymodes;
/** The list of all bans set on the channel.
*/
@@ -260,7 +241,7 @@ class ucrec : public classbase
/** Contains a bitmask of the UCMODE_OP ... UCMODE_FOUNDER values.
* If this value is zero, the user has no privilages upon the channel.
*/
- long uc_modes;
+ char uc_modes;
/** Points to the channel record where the given modes apply.
* If the record is not in use, this value will be NULL.
diff --git a/include/connection.h b/include/connection.h
index 300a83d4a..b9be696fe 100644
--- a/include/connection.h
+++ b/include/connection.h
@@ -216,15 +216,11 @@ class connection : public Extensible
/** Hostname of connection. Not used if this is a serverrec
*/
- char host[256];
+ char host[160];
- /** IP of connection. Reserved for future use.
+ /** IP of connection.
*/
- char ip[32];
-
- /** Inbuf of connection. Only used for userrec
- */
- char inbuf[MAXBUF];
+ char ip[16];
/** Stats counter for bytes inbound
*/
@@ -254,11 +250,7 @@ class connection : public Extensible
/** Used by userrec to indicate the registration status of the connection
*/
- int registered;
-
- /** Reserved for future use
- */
- short int state;
+ short int registered;
/** Time the connection was last pinged
*/
@@ -276,13 +268,9 @@ class connection : public Extensible
*/
time_t nping;
- /** Unused, will be removed in a future alpha/beta
- */
- char internal_addr[MAXBUF];
+ //char internal_addr[MAXBUF];
- /** Unused, will be removed in a future alpha/beta
- */
- int internal_port;
+ //int internal_port;
/** With a serverrec, this is a list of all established server connections.
* With a userrec this is unused.
diff --git a/include/users.h b/include/users.h
index fa7ea0cfb..2241a6e28 100644
--- a/include/users.h
+++ b/include/users.h
@@ -47,7 +47,7 @@ class ConnectClass : public classbase
public:
/** Type of line, either CC_ALLOW or CC_DENY
*/
- int type;
+ char type;
/** Max time to register the connection in seconds
*/
int registration_timeout;
@@ -66,7 +66,7 @@ class ConnectClass : public classbase
/** Threshold value for flood disconnect
*/
- long threshold;
+ int threshold;
/** Maximum size of sendq for users in this class (bytes)
*/
@@ -122,12 +122,12 @@ class userrec : public connection
/** The users ident reply.
*/
- char ident[64];
+ char ident[16];
/** The host displayed to non-opers (used for cloaking etc).
* This usually matches the value of userrec::host.
*/
- char dhost[256];
+ char dhost[160];
/** The users full name.
*/
@@ -165,7 +165,7 @@ class userrec : public connection
* If they do not send their details in this time limit they
* will be disconnected
*/
- unsigned long timeout;
+ unsigned int timeout;
/** The oper type they logged in as, if they are an oper.
* This is used to check permissions in operclasses, so that
@@ -180,7 +180,7 @@ class userrec : public connection
/** Number of seconds between PINGs for this user (set from &lt;connect:allow&gt; tag
*/
- unsigned long pingmax;
+ unsigned int pingmax;
/** Password specified by the user when they registered.
* This is stored even if the <connect> block doesnt need a password, so that
@@ -201,7 +201,7 @@ class userrec : public connection
/** Flood counters
*/
- long lines_in;
+ int lines_in;
time_t reset_due;
long threshold;
diff --git a/src/channels.cpp b/src/channels.cpp
index 4e46c3b30..5ba38a9e6 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -117,8 +117,8 @@ chanrec::chanrec()
strcpy(topic,"");
strcpy(setby,"");
strcpy(key,"");
- created = topicset = limit = users = 0;
- topiclock = noexternal = inviteonly = moderated = secret = c_private = false;
+ created = topicset = limit = 0;
+ binarymodes = 0;
internal_userlist.clear();
}
diff --git a/src/commands.cpp b/src/commands.cpp
index f98ad5eb2..d04a79f4d 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -473,7 +473,7 @@ void handle_invite(char **parameters, int pcnt, userrec *user)
}
else
{
- if (c->inviteonly)
+ if (c->binarymodes & CM_INVITEONLY)
{
WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
}
@@ -482,7 +482,7 @@ void handle_invite(char **parameters, int pcnt, userrec *user)
return;
}
- if (c->inviteonly)
+ if (c->binarymodes & CM_INVITEONLY)
{
if (cstatus(user,c) < STATUS_HOP)
{
@@ -528,7 +528,7 @@ void handle_topic(char **parameters, int pcnt, userrec *user)
Ptr = FindChan(parameters[0]);
if (Ptr)
{
- if (((Ptr) && (!has_channel(user,Ptr))) && (Ptr->secret))
+ if (((Ptr) && (!has_channel(user,Ptr))) && (Ptr->binarymodes & CM_SECRET))
{
WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, Ptr->name);
return;
@@ -562,7 +562,7 @@ void handle_topic(char **parameters, int pcnt, userrec *user)
WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, Ptr->name);
return;
}
- if ((Ptr->topiclock) && (cstatus(user,Ptr)<STATUS_HOP))
+ if ((Ptr->binarymodes & CM_TOPICLOCK) && (cstatus(user,Ptr)<STATUS_HOP))
{
WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel", user->nick, Ptr->name);
return;
@@ -616,7 +616,7 @@ void handle_names(char **parameters, int pcnt, userrec *user)
c = FindChan(parameters[0]);
if (c)
{
- if (((c) && (!has_channel(user,c))) && (c->secret))
+ if (((c) && (!has_channel(user,c))) && (c->binarymodes & CM_SECRET))
{
WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, c->name);
return;
@@ -644,12 +644,12 @@ void handle_privmsg(char **parameters, int pcnt, userrec *user)
chan = FindChan(parameters[0]);
if (chan)
{
- if ((chan->noexternal) && (!has_channel(user,chan)))
+ if ((chan->binarymodes & CM_NOEXTERNAL) && (!has_channel(user,chan)))
{
WriteServ(user->fd,"404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
return;
}
- if ((chan->moderated) && (cstatus(user,chan)<STATUS_VOICE))
+ if ((chan->binarymodes & CM_MODERATED) && (cstatus(user,chan)<STATUS_VOICE))
{
WriteServ(user->fd,"404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
return;
@@ -738,12 +738,12 @@ void handle_notice(char **parameters, int pcnt, userrec *user)
chan = FindChan(parameters[0]);
if (chan)
{
- if ((chan->noexternal) && (!has_channel(user,chan)))
+ if ((chan->binarymodes & CM_NOEXTERNAL) && (!has_channel(user,chan)))
{
WriteServ(user->fd,"404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
return;
}
- if ((chan->moderated) && (cstatus(user,chan)<STATUS_VOICE))
+ if ((chan->binarymodes & CM_MODERATED) && (cstatus(user,chan)<STATUS_VOICE))
{
WriteServ(user->fd,"404 %s %s :Cannot send to channel (+m)", user->nick, chan->name);
return;
@@ -1121,7 +1121,7 @@ void handle_list(char **parameters, int pcnt, userrec *user)
for (chan_hash::const_iterator i = chanlist.begin(); i != chanlist.end(); i++)
{
// if the channel is not private/secret, OR the user is on the channel anyway
- if (((!i->second->c_private) && (!i->second->secret)) || (has_channel(user,i->second)))
+ if (((!(i->second->binarymodes & CM_PRIVATE)) && (!(i->second->binarymodes & CM_SECRET))) || (has_channel(user,i->second)))
{
WriteServ(user->fd,"322 %s %s %d :[+%s] %s",user->nick,i->second->name,usercount_i(i->second),chanmodes(i->second),i->second->topic);
}
@@ -2421,7 +2421,7 @@ void handle_N(char token,char* params,serverrec* source,serverrec* reply, char*
strlcpy(clientlist[nick]->server, server,256);
strlcpy(clientlist[nick]->ident, ident,10); // +1 char to compensate for tilde
strlcpy(clientlist[nick]->fullname, gecos,128);
- strlcpy(clientlist[nick]->ip,ipaddr,32);
+ strlcpy(clientlist[nick]->ip,ipaddr,16);
clientlist[nick]->signon = TS;
clientlist[nick]->nping = 0; // this is ignored for a remote user anyway.
clientlist[nick]->lastping = 1;
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index f11386a26..635effbeb 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -1437,11 +1437,11 @@ char* chanmodes(chanrec *chan)
strcpy(scratch,"");
strcpy(sparam,"");
- if (chan->noexternal)
+ if (chan->binarymodes & CM_NOEXTERNAL)
{
strlcat(scratch,"n",MAXMODES);
}
- if (chan->topiclock)
+ if (chan->binarymodes & CM_TOPICLOCK)
{
strlcat(scratch,"t",MAXMODES);
}
@@ -1453,19 +1453,19 @@ char* chanmodes(chanrec *chan)
{
strlcat(scratch,"l",MAXMODES);
}
- if (chan->inviteonly)
+ if (chan->binarymodes & CM_INVITEONLY)
{
strlcat(scratch,"i",MAXMODES);
}
- if (chan->moderated)
+ if (chan->binarymodes & CM_MODERATED)
{
strlcat(scratch,"m",MAXMODES);
}
- if (chan->secret)
+ if (chan->binarymodes & CM_SECRET)
{
strlcat(scratch,"s",MAXMODES);
}
- if (chan->c_private)
+ if (chan->binarymodes & CM_PRIVATE)
{
strlcat(scratch,"p",MAXMODES);
}
@@ -1639,8 +1639,7 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
chanlist[cname] = new chanrec();
strlcpy(chanlist[cname]->name, cname,CHANMAX);
- chanlist[cname]->topiclock = 1;
- chanlist[cname]->noexternal = 1;
+ chanlist[cname]->binarymodes = CM_TOPICLOCK | CM_NOEXTERNAL;
chanlist[cname]->created = TIME;
strcpy(chanlist[cname]->topic, "");
strncpy(chanlist[cname]->setby, user->nick,NICKMAX);
@@ -1705,7 +1704,7 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
FOREACH_RESULT(OnCheckInvite(user, Ptr));
if (MOD_RESULT == 0)
{
- if (Ptr->inviteonly)
+ if (Ptr->binarymodes & CM_INVITEONLY)
{
log(DEBUG,"add_channel: channel is +i");
if (user->IsInvited(Ptr->name))
@@ -2450,9 +2449,9 @@ void AddWhoWas(userrec* u)
user_hash::iterator iter = whowas.find(u->nick);
userrec *a = new userrec();
strlcpy(a->nick,u->nick,NICKMAX);
- strlcpy(a->ident,u->ident,64);
- strlcpy(a->dhost,u->dhost,256);
- strlcpy(a->host,u->host,256);
+ strlcpy(a->ident,u->ident,15);
+ strlcpy(a->dhost,u->dhost,160);
+ strlcpy(a->host,u->host,160);
strlcpy(a->fullname,u->fullname,128);
strlcpy(a->server,u->server,256);
a->signon = u->signon;
@@ -2541,12 +2540,12 @@ void AddClient(int socket, char* host, int port, bool iscached, char* ip)
strncpy(clientlist[tempnick]->host, host,160);
strncpy(clientlist[tempnick]->dhost, host,160);
strncpy(clientlist[tempnick]->server, ServerName,256);
- strncpy(clientlist[tempnick]->ident, "unknown",12);
+ strncpy(clientlist[tempnick]->ident, "unknown",15);
clientlist[tempnick]->registered = 0;
clientlist[tempnick]->signon = TIME+dns_timeout;
clientlist[tempnick]->lastping = 1;
clientlist[tempnick]->port = port;
- strncpy(clientlist[tempnick]->ip,ip,32);
+ strncpy(clientlist[tempnick]->ip,ip,16);
// set the registration timeout for this user
unsigned long class_regtimeout = 90;
diff --git a/src/message.cpp b/src/message.cpp
index 59e961d9a..2f372b5d8 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -483,7 +483,7 @@ char* chlist(userrec *user,userrec* source)
if (!strstr(lst,cmp))
{
// if the channel is NOT private/secret, OR the source user is on the channel
- if (((!user->chans[i].channel->c_private) && (!user->chans[i].channel->secret)) || (has_channel(source,user->chans[i].channel)))
+ if (((!(user->chans[i].channel->binarymodes & CM_PRIVATE)) && (!(user->chans[i].channel->binarymodes & CM_SECRET))) || (has_channel(source,user->chans[i].channel)))
{
strlcat(lst,cmode(user,user->chans[i].channel),MAXBUF);
strlcat(lst,user->chans[i].channel->name,MAXBUF);
diff --git a/src/mode.cpp b/src/mode.cpp
index 69284ab5c..67f3785d8 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -882,7 +882,7 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
// reported by mech: large values cause underflow
if (chan->limit < 0)
- chan->limit = 0x7FFFFF;
+ chan->limit = 0x7FFF;
}
if (chan->limit)
@@ -899,11 +899,16 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
FOREACH_RESULT(OnRawMode(user, chan, 'i', "", mdir, 0));
if (!MOD_RESULT)
{
- if (chan->inviteonly != mdir)
+ if (mdir)
{
- strlcat(outlist,"i",MAXBUF);
+ if (!(chan->binarymodes & CM_INVITEONLY)) strlcat(outlist,"i",MAXBUF);
+ chan->binarymodes |= CM_INVITEONLY;
+ }
+ else
+ {
+ if (chan->binarymodes & CM_INVITEONLY) strlcat(outlist,"i",MAXBUF);
+ chan->binarymodes &= ~CM_INVITEONLY;
}
- chan->inviteonly = mdir;
}
break;
@@ -912,11 +917,16 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
FOREACH_RESULT(OnRawMode(user, chan, 't', "", mdir, 0));
if (!MOD_RESULT)
{
- if (chan->topiclock != mdir)
- {
- strlcat(outlist,"t",MAXBUF);
- }
- chan->topiclock = mdir;
+ if (mdir)
+ {
+ if (!(chan->binarymodes & CM_TOPICLOCK)) strlcat(outlist,"t",MAXBUF);
+ chan->binarymodes |= CM_TOPICLOCK;
+ }
+ else
+ {
+ if (chan->binarymodes & CM_NOEXTERNAL) strlcat(outlist,"t",MAXBUF);
+ chan->binarymodes &= ~CM_TOPICLOCK;
+ }
}
break;
@@ -925,11 +935,16 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
FOREACH_RESULT(OnRawMode(user, chan, 'n', "", mdir, 0));
if (!MOD_RESULT)
{
- if (chan->noexternal != mdir)
- {
- strlcat(outlist,"n",MAXBUF);
- }
- chan->noexternal = mdir;
+ if (mdir)
+ {
+ if (!(chan->binarymodes & CM_NOEXTERNAL)) strlcat(outlist,"n",MAXBUF);
+ chan->binarymodes |= CM_NOEXTERNAL;
+ }
+ else
+ {
+ if (chan->binarymodes & CM_NOEXTERNAL) strlcat(outlist,"n",MAXBUF);
+ chan->binarymodes &= ~CM_NOEXTERNAL;
+ }
}
break;
@@ -938,11 +953,16 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
FOREACH_RESULT(OnRawMode(user, chan, 'm', "", mdir, 0));
if (!MOD_RESULT)
{
- if (chan->moderated != mdir)
- {
- strlcat(outlist,"m",MAXBUF);
- }
- chan->moderated = mdir;
+ if (mdir)
+ {
+ if (!(chan->binarymodes & CM_MODERATED)) strlcat(outlist,"m",MAXBUF);
+ chan->binarymodes |= CM_MODERATED;
+ }
+ else
+ {
+ if (chan->binarymodes & CM_MODERATED) strlcat(outlist,"m",MAXBUF);
+ chan->binarymodes &= ~CM_MODERATED;
+ }
}
break;
@@ -951,23 +971,24 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
FOREACH_RESULT(OnRawMode(user, chan, 's', "", mdir, 0));
if (!MOD_RESULT)
{
- if (chan->secret != mdir)
- {
- strcat(outlist,"s");
- if (chan->c_private)
- {
- chan->c_private = 0;
- if (mdir)
- {
- strlcat(outlist,"-p+",MAXBUF);
- }
- else
- {
- strlcat(outlist,"+p-",MAXBUF);
- }
- }
- }
- chan->secret = mdir;
+ if (mdir)
+ {
+ if (!(chan->binarymodes & CM_SECRET)) strlcat(outlist,"s",MAXBUF);
+ chan->binarymodes |= CM_SECRET;
+ if (chan->binarymodes & CM_PRIVATE)
+ {
+ chan->binarymodes &= ~CM_PRIVATE;
+ if (mdir)
+ {
+ strlcat(outlist,"-p+",MAXBUF);
+ }
+ }
+ }
+ else
+ {
+ if (chan->binarymodes & CM_SECRET) strlcat(outlist,"s",MAXBUF);
+ chan->binarymodes &= ~CM_SECRET;
+ }
}
break;
@@ -976,23 +997,24 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
FOREACH_RESULT(OnRawMode(user, chan, 'p', "", mdir, 0));
if (!MOD_RESULT)
{
- if (chan->c_private != mdir)
- {
- strlcat(outlist,"p",MAXBUF);
- if (chan->secret)
- {
- chan->secret = 0;
- if (mdir)
- {
- strlcat(outlist,"-s+",MAXBUF);
- }
- else
- {
- strlcat(outlist,"+s-",MAXBUF);
- }
- }
- }
- chan->c_private = mdir;
+ if (mdir)
+ {
+ if (!(chan->binarymodes & CM_PRIVATE)) strlcat(outlist,"p",MAXBUF);
+ chan->binarymodes |= CM_PRIVATE;
+ if (chan->binarymodes & CM_SECRET)
+ {
+ chan->binarymodes &= ~CM_SECRET;
+ if (mdir)
+ {
+ strlcat(outlist,"-s+",MAXBUF);
+ }
+ }
+ }
+ else
+ {
+ if (chan->binarymodes & CM_PRIVATE) strlcat(outlist,"p",MAXBUF);
+ chan->binarymodes &= ~CM_PRIVATE;
+ }
}
break;
diff --git a/src/modules/m_knock.cpp b/src/modules/m_knock.cpp
index 649c210b8..e1654c181 100644
--- a/src/modules/m_knock.cpp
+++ b/src/modules/m_knock.cpp
@@ -40,7 +40,7 @@ void handle_knock(char **parameters, int pcnt, userrec *user)
WriteServ(user->fd,"480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
return;
}
- if (c->inviteonly)
+ if (c->binarymodes & CM_INVITEONLY)
{
WriteChannelWithServ((char*)Srv->GetServerName().c_str(),c,"NOTICE %s :User %s is KNOCKing on %s (%s)",c->name,user->nick,c->name,line.c_str());
WriteServ(user->fd,"NOTICE %s :KNOCKing on %s",user->nick,c->name);
diff --git a/src/modules/m_override.cpp b/src/modules/m_override.cpp
index 063e94b12..916acb36e 100644
--- a/src/modules/m_override.cpp
+++ b/src/modules/m_override.cpp
@@ -165,7 +165,7 @@ class ModuleOverride : public Module
{
if (chan)
{
- if ((chan->inviteonly) && (CanOverride(user,"INVITE")))
+ if ((chan->binarymodes & CM_INVITEONLY) && (CanOverride(user,"INVITE")))
{
if (NoisyOverride)
{
diff --git a/src/users.cpp b/src/users.cpp
index 0060b45ee..7a8878106 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -36,7 +36,6 @@ userrec::userrec()
strcpy(dhost,"");
strcpy(fullname,"");
strcpy(modes,"");
- strcpy(inbuf,"");
strcpy(server,"");
strcpy(awaymsg,"");
strcpy(oper,"");