]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Removed has_channel(userrec*,chanrec*), the new preferred way of doing it is channel...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 8 Mar 2006 23:16:18 +0000 (23:16 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 8 Mar 2006 23:16:18 +0000 (23:16 +0000)
Yeah its the other way around to the old way, but somehow, seems less backwards to me (its also faster)

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3560 e03df62e-2008-0410-955e-edbf42e46eb7

17 files changed:
include/channels.h
src/channels.cpp
src/cmd_invite.cpp
src/cmd_kick.cpp
src/cmd_list.cpp
src/cmd_names.cpp
src/cmd_notice.cpp
src/cmd_privmsg.cpp
src/cmd_topic.cpp
src/cmd_who.cpp
src/helperfuncs.cpp
src/message.cpp
src/mode.cpp
src/modules/m_operwho.cpp
src/modules/m_safelist.cpp
src/modules/m_uninvite.cpp
src/svn-rev.sh

index 7481bd67b9915fe6d5e9bf0444732bf4f8aad915..c7a0a8777e941019599ba51d16c44ad437f438a0 100644 (file)
@@ -92,6 +92,10 @@ class userrec;
  */
 typedef std::map<userrec*,userrec*> CUList;
 
+/** A list of custom modes parameters on a channel
+ */
+typedef std::map<char,char*> CustomModeList;
+
 /** Holds all relevent information for a channel.
  * This class represents a channel, and contains its name, modes, time created, topic, topic set time,
  * etc, and an instance of the BanList type.
@@ -107,8 +111,10 @@ class chanrec : public Extensible
         */
        char custom_modes[64];     /* modes handled by modules */
 
-       /** User list (casted to char*'s to stop forward declaration stuff)
-        * (chicken and egg scenario!)
+       /** User lists
+        * There are four user lists, one for 
+        * all the users, one for the ops, one for
+        * the halfops and another for the voices.
         */
        CUList internal_userlist;
        CUList internal_op_userlist;
@@ -117,12 +123,12 @@ class chanrec : public Extensible
 
        /** Parameters for custom modes
         */
-       std::map<char,char*> custom_mode_params;
+       CustomModeList custom_mode_params;
 
        /** Channel topic.
         * If this is an empty string, no channel topic is set.
         */
-       char topic[MAXBUF];
+       char topic[MAXTOPIC];
        /** Creation time.
         */
        time_t created;
@@ -194,42 +200,40 @@ class chanrec : public Extensible
        long GetUserCounter();
 
        /** Add a user pointer to the internal reference list
-        * @param castuser This should be a pointer to a userrec, casted to char*
+        * @param user The user to add
         *
         * The data inserted into the reference list is a table as it is
         * an arbitary pointer compared to other users by its memory address,
         * as this is a very fast 32 or 64 bit integer comparison.
         */
-       void AddUser(userrec* castuser);
-       void AddOppedUser(userrec* castuser);
-       void AddHalfoppedUser(userrec* castuser);
-       void AddVoicedUser(userrec* castuser);
+       void AddUser(userrec* user);
+       void AddOppedUser(userrec* user);
+       void AddHalfoppedUser(userrec* user);
+       void AddVoicedUser(userrec* user);
 
         /** Delete a user pointer to the internal reference list
-        * @param castuser This should be a pointer to a userrec, casted to char*
-        *
-         * The data removed from the reference list is a table as it is
-         * an arbitary pointer compared to other users by its memory address,
-         * as this is a very fast 32 or 64 bit integer comparison.
+        * @param user The user to delete
          */
-       void DelUser(userrec* castuser);
-       void DelOppedUser(userrec* castuser);
-       void DelHalfoppedUser(userrec* castuser);
-       void DelVoicedUser(userrec* castuser);
+       void DelUser(userrec* user);
+       void DelOppedUser(userrec* user);
+       void DelHalfoppedUser(userrec* user);
+       void DelVoicedUser(userrec* user);
 
        /** Obrain the internal reference list
-        * The internal reference list contains a list of userrec*
-        * cast to char*. These are used for rapid comparison to determine
+        * The internal reference list contains a list of userrec*.
+        * These are used for rapid comparison to determine
         * channel membership for PRIVMSG, NOTICE, QUIT, PART etc.
         * The resulting pointer to the vector should be considered
         * readonly and only modified via AddUser and DelUser.
         *
-        * @return This function returns a vector of userrec pointers, each of which has been casted to char* to prevent circular references
+        * @return This function returns pointer to a map of userrec pointers (CUList*).
         */
-       CUList *GetUsers();
-       CUList *GetOppedUsers();
-       CUList *GetHalfoppedUsers();
-       CUList *GetVoicedUsers();
+       CUList* GetUsers();
+       CUList* GetOppedUsers();
+       CUList* GetHalfoppedUsers();
+       CUList* GetVoicedUsers();
+
+       bool HasUser(userrec* user);
 
        /** Creates a channel record and initialises it with default values
         */
index 8aa6e9f54b8ee653e6751819567b30476d33f7df..95e51115686df6b2704a140f0ec4bb113574b2d1 100644 (file)
@@ -128,94 +128,91 @@ long chanrec::GetUserCounter()
        return (this->internal_userlist.size());
 }
 
-void chanrec::AddUser(userrec* castuser)
+void chanrec::AddUser(userrec* user)
 {
-       internal_userlist[castuser] = castuser;
-       log(DEBUG,"Added casted user to channel's internal list");
+       internal_userlist[user] = user;
 }
 
-void chanrec::DelUser(userrec* castuser)
+void chanrec::DelUser(userrec* user)
 {
-       CUList::iterator a = internal_userlist.find(castuser);
+       CUList::iterator a = internal_userlist.find(user);
        if (a != internal_userlist.end())
        {
-               log(DEBUG,"Removed casted user from channel's internal list");
                internal_userlist.erase(a);
                /* And tidy any others... */
-               DelOppedUser(castuser);
-               DelHalfoppedUser(castuser);
-               DelVoicedUser(castuser);
+               DelOppedUser(user);
+               DelHalfoppedUser(user);
+               DelVoicedUser(user);
                return;
        }
 }
 
-void chanrec::AddOppedUser(userrec* castuser)
+bool chanrec::HasUser(userrec* user)
 {
-       internal_op_userlist[castuser] = castuser;
-       log(DEBUG,"Added casted user to channel's internal list");
+       return (internal_userlist.find(user) != internal_userlist.end());
 }
 
-void chanrec::DelOppedUser(userrec* castuser)
+void chanrec::AddOppedUser(userrec* user)
 {
-       CUList::iterator a = internal_op_userlist.find(castuser);
+       internal_op_userlist[user] = user;
+}
+
+void chanrec::DelOppedUser(userrec* user)
+{
+       CUList::iterator a = internal_op_userlist.find(user);
        if (a != internal_op_userlist.end())
        {
-               log(DEBUG,"Removed casted user from channel's internal list");
                internal_op_userlist.erase(a);
                return;
        }
 }
 
-void chanrec::AddHalfoppedUser(userrec* castuser)
+void chanrec::AddHalfoppedUser(userrec* user)
 {
-       internal_halfop_userlist[castuser] = castuser;
-       log(DEBUG,"Added casted user to channel's internal list");
+       internal_halfop_userlist[user] = user;
 }
 
-void chanrec::DelHalfoppedUser(userrec* castuser)
+void chanrec::DelHalfoppedUser(userrec* user)
 {
-       CUList::iterator a = internal_halfop_userlist.find(castuser);
+       CUList::iterator a = internal_halfop_userlist.find(user);
        if (a != internal_halfop_userlist.end())
        {   
-               log(DEBUG,"Removed casted user from channel's internal list");
                internal_halfop_userlist.erase(a);
                return; 
        }
 }
 
-void chanrec::AddVoicedUser(userrec* castuser)
+void chanrec::AddVoicedUser(userrec* user)
 {
-       internal_voice_userlist[castuser] = castuser;
-       log(DEBUG,"Added casted user to channel's internal list");
+       internal_voice_userlist[user] = user;
 }
 
-void chanrec::DelVoicedUser(userrec* castuser)
+void chanrec::DelVoicedUser(userrec* user)
 {
-       CUList::iterator a = internal_voice_userlist.find(castuser);
+       CUList::iterator a = internal_voice_userlist.find(user);
        if (a != internal_voice_userlist.end())
        {
-               log(DEBUG,"Removed casted user from channel's internal list");
                internal_voice_userlist.erase(a);
                return; 
        }
 }
 
-CUList *chanrec::GetUsers()
+CUListchanrec::GetUsers()
 {
        return &internal_userlist;
 }
 
-CUList *chanrec::GetOppedUsers()
+CUListchanrec::GetOppedUsers()
 {
        return &internal_op_userlist;
 }
 
-CUList *chanrec::GetHalfoppedUsers()
+CUListchanrec::GetHalfoppedUsers()
 {
        return &internal_halfop_userlist;
 }
 
-CUList *chanrec::GetVoicedUsers()
+CUListchanrec::GetVoicedUsers()
 {
        return &internal_voice_userlist;
 }
@@ -273,7 +270,7 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
        else
        {
                /* Already on the channel */
-               if (has_channel(user,Ptr))
+               if (Ptr->HasUser(user))
                        return NULL;
 
                /*
@@ -536,7 +533,7 @@ void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool trigger
 
        if (IS_LOCAL(user))
        {
-               if (!has_channel(user,Ptr))
+               if (!Ptr->HasUser(user))
                {
                        /* Not on channel */
                        return;
@@ -589,7 +586,7 @@ void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason)
 
        if (IS_LOCAL(src))
        {
-               if (!has_channel(user,Ptr))
+               if (!Ptr->HasUser(user))
                {
                        WriteServ(src->fd,"441 %s %s %s :They are not on that channel",src->nick, user->nick, Ptr->name);
                        return;
index 6f6cbaa7d70271efb02b6af133a773414e8e4031..07559a08236c9f22957308775abbeb994da975e3 100644 (file)
@@ -70,12 +70,12 @@ void cmd_invite::Handle (char **parameters, int pcnt, userrec *user)
                                return;
                        }
                }
-               if (has_channel(u,c))
+               if (c->HasUser(u))
                {
                        WriteServ(user->fd,"443 %s %s %s :Is already on channel %s",user->nick,u->nick,c->name,c->name);
                        return;
                }
-               if ((IS_LOCAL(user)) && (!has_channel(user,c)))
+               if ((IS_LOCAL(user)) && (!c->HasUser(user)))
                {
                        WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, c->name);
                        return;
index 5c272112c75ff461fc8bc948afe720c6122c001e..8732dd7cfa05266247325dd2d274ce4f63f77909 100644 (file)
@@ -51,7 +51,7 @@ void cmd_kick::Handle (char **parameters, int pcnt, userrec *user)
                WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, u ? parameters[0] : parameters[1]);
                return;
        }
-       if ((IS_LOCAL(user)) && (!has_channel(user,Ptr)) && (!is_uline(user->server)))
+       if ((IS_LOCAL(user)) && (!Ptr->HasUser(user)) && (!is_uline(user->server)))
        {
                WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, parameters[0]);
                return;
index 262738fb341fbc0cfdf15e8cf496e516543503b8..7b17cfa7753fb4dbe8a9a047676cdf5d714712eb 100644 (file)
@@ -46,9 +46,9 @@ void cmd_list::Handle (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->binarymodes & CM_PRIVATE)) && (!(i->second->binarymodes & CM_SECRET))) || (has_channel(user,i->second)))
+               if (((!(i->second->binarymodes & CM_PRIVATE)) && (!(i->second->binarymodes & CM_SECRET))) || (i->second->HasUser(user)))
                {
-                       WriteServ(user->fd,"322 %s %s %d :[+%s] %s",user->nick,i->second->name,usercount_i(i->second),chanmodes(i->second,has_channel(user,i->second)),i->second->topic);
+                       WriteServ(user->fd,"322 %s %s %d :[+%s] %s",user->nick,i->second->name,usercount_i(i->second),chanmodes(i->second,i->second->HasUser(user)),i->second->topic);
                }
        }
        WriteServ(user->fd,"323 %s :End of channel list.",user->nick);
index bc1eb69c7c59173ebbe5b514cf7d8104b8ae810b..43797cbeb76829d63a0bb5bb6f0e8dfc7e1990c2 100644 (file)
@@ -76,7 +76,7 @@ void cmd_names::Handle (char **parameters, int pcnt, userrec *user)
        c = FindChan(parameters[0]);
        if (c)
        {
-                if (((c) && (!has_channel(user,c))) && (c->binarymodes & CM_SECRET))
+                if ((c->binarymodes & CM_SECRET) && (!c->HasUser(user)))
                 {
                       WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, c->name);
                       return;
index 6dcab95534dc79dd7fd91d789d14429c883e2d60..58800ccc08352fed11fe65931f1507cf4fb1a4cb 100644 (file)
@@ -94,7 +94,7 @@ void cmd_notice::Handle (char **parameters, int pcnt, userrec *user)
                {
                        if (IS_LOCAL(user))
                        {
-                               if ((chan->binarymodes & CM_NOEXTERNAL) && (!has_channel(user,chan)))
+                               if ((chan->binarymodes & CM_NOEXTERNAL) && (!chan->HasUser(user)))
                                {
                                        WriteServ(user->fd,"404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
                                        return;
index 41999a4ec5b16ef9fc5e0e3bab68768f0e48a18d..2770be33056680311748f6b5b12771df7e391f6d 100644 (file)
@@ -94,7 +94,7 @@ void cmd_privmsg::Handle (char **parameters, int pcnt, userrec *user)
                {
                        if (IS_LOCAL(user))
                        {
-                               if ((chan->binarymodes & CM_NOEXTERNAL) && (!has_channel(user,chan)))
+                               if ((chan->binarymodes & CM_NOEXTERNAL) && (!chan->HasUser(user)))
                                {
                                        WriteServ(user->fd,"404 %s %s :Cannot send to channel (no external messages)", user->nick, chan->name);
                                        return;
index e1e77bf58411b8c97c48a75c06b9b6762470a6d5..9de8637b4ba036221cb0553fb9567484b63a7e2a 100644 (file)
@@ -70,7 +70,7 @@ void cmd_topic::Handle (char **parameters, int pcnt, userrec *user)
                Ptr = FindChan(parameters[0]);
                if (Ptr)
                {
-                       if (((Ptr) && (!has_channel(user,Ptr))) && (Ptr->binarymodes & CM_SECRET))
+                       if ((Ptr->binarymodes & CM_SECRET) && (!Ptr->HasUser(user)))
                        {
                                WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, Ptr->name);
                                return;
index d82b7906f46a6ed19323a8aa1cd55c1d4ef9ec46..c25fa611d13cadee5cd5a27537efeeb835772513 100644 (file)
@@ -115,7 +115,7 @@ void cmd_who::Handle (char **parameters, int pcnt, userrec *user)
                                int n_list = 0;
                                for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
                                {
-                                       if ((has_channel(i->second,Ptr)) && (isnick(i->second->nick)))
+                                       if ((Ptr->HasUser(i->second)) && (isnick(i->second->nick)))
                                        {
                                                // Fix Bug #29 - Part 2..
                                                *tmp = 0;
index c313b5456f748a87b19a44e2ddb0328dd1668ffc..2a929f3b2a4bb8451b5d76f18784e94d5c5aa3eb 100644 (file)
@@ -1348,9 +1348,14 @@ void userlist(userrec *user,chanrec *c)
 
        CUList *ulist= c->GetUsers();
 
+       /* Improvement by Brain - this doesnt change in value, so why was it inside
+        * the loop?
+        */
+       bool has_user = c->HasUser(user,c);
+
        for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
        {
-               if ((!has_channel(user,c)) && (strchr(i->second->modes,'i')))
+               if ((!n) && (strchr(i->second->modes,'i')))
                {
                        /*
                         * user is +i, and source not on the channel, does not show
index 9cfecb8500d8c4dd405a2919407bad1c6ceb6d55..e943aa784a51c91e681043be450295adcfdbd9e4 100644 (file)
@@ -371,29 +371,6 @@ int cstatus(userrec *user, chanrec *chan)
        return STATUS_NORMAL;
 }
 
-/* returns 1 if user u has channel c in their record, 0 if not */
-
-int has_channel(userrec *u, chanrec *c)
-{
-       if ((!u) || (!c))
-       {
-               log(DEFAULT,"*** BUG *** has_channel was given an invalid parameter");
-               return 0;
-       }
-       for (unsigned int i =0; i < u->chans.size(); i++)
-       {
-               if (u->chans[i].channel)
-               {
-                       if (u->chans[i].channel == c)
-                       {
-                               return 1;
-                       }
-               }
-       }
-       return 0;
-}
-
-
 void TidyBan(char *ban)
 {
        if (!ban) {
@@ -443,7 +420,7 @@ std::string chlist(userrec *user,userrec* source)
                                {
                                        // if the channel is NOT private/secret, OR the source user is on the channel, AND the user is not invisible.
                                        // if the user is the same as the source, shortcircuit the comparison.
-                                       if ((source == user) || ((((!(user->chans[i].channel->binarymodes & CM_PRIVATE)) && (!(user->chans[i].channel->binarymodes & CM_SECRET)) && (!userinvisible)) || (has_channel(source,user->chans[i].channel)))))
+                                       if ((source == user) || ((((!(user->chans[i].channel->binarymodes & CM_PRIVATE)) && (!(user->chans[i].channel->binarymodes & CM_SECRET)) && (!userinvisible)) || (user->chans[i].channel->HasUser(source)))))
                                        {
                                                lst = lst + std::string(cmode(user,user->chans[i].channel)) + std::string(user->chans[i].channel->name) + " ";
                                        }
index 0acdd2bc09e517f634bb0b808bdaf8209703c3b2..5b5523dfe4829d5ae1a402f3b8d5af293c8899ea 100644 (file)
@@ -1310,7 +1310,7 @@ void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
                        if (pcnt == 1)
                        {
                                /* just /modes #channel */
-                               WriteServ(user->fd,"324 %s %s +%s",user->nick, Ptr->name, chanmodes(Ptr,has_channel(user,Ptr)));
+                               WriteServ(user->fd,"324 %s %s +%s",user->nick, Ptr->name, chanmodes(Ptr,Ptr->HasUser(user)));
                                WriteServ(user->fd,"329 %s %s %d", user->nick, Ptr->name, Ptr->created);
                                return;
                        }
@@ -1342,7 +1342,7 @@ void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
                                }
                        }
 
-                       if (((Ptr) && (!has_channel(user,Ptr))) && (!is_uline(user->server)) && (IS_LOCAL(user)))
+                       if ((IS_LOCAL(user)) && (!is_uline(user->server)) && (!Ptr->HasUser(user)))
                        {
                                WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, Ptr->name);
                                return;
@@ -1357,7 +1357,7 @@ void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
                                        return;
                                if (MOD_RESULT == ACR_DEFAULT)
                                {
-                                       if ((cstatus(user,Ptr) < STATUS_HOP) && (IS_LOCAL(user)))
+                                       if ((IS_LOCAL(user)) && (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;
index e4dbf323547acbda943bec313003dd8599ee2fd1..8926b2a9c8f406de924742304828e514d6337433 100644 (file)
@@ -128,7 +128,7 @@ class ModuleOperWho : public Module
                                {
                                        for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
                                        {
-                                               if ((has_channel(i->second,Ptr)) && (isnick(i->second->nick)))
+                                               if ((Ptr->HasUser(i->second)) && (isnick(i->second->nick)))
                                                {
                                                        // Fix Bug #29 - Part 2..
                                                        *tmp = 0;
index debacaaebe12ae889e96f0632148e512d84bb935..6e1789097d7635d0b2dbf43269fc37e3643a9958 100644 (file)
@@ -97,10 +97,11 @@ class ListTimer : public InspTimer
                                                WriteServ(u->fd,"321 %s Channel :Users Name",u->nick);
                                         chan = Srv->GetChannelIndex(ld->list_position);
                                         /* spool details */
-                                        if ((chan) && (((!(chan->binarymodes & CM_PRIVATE)) && (!(chan->binarymodes & CM_SECRET))) || (has_channel(u,chan))))
+                                       bool has_user = chan->HasUser(u);
+                                        if ((chan) && (((!(chan->binarymodes & CM_PRIVATE)) && (!(chan->binarymodes & CM_SECRET))) || (has_user)))
                                         {
                                                 /* Increment total plus linefeed */
-                                                int counter = snprintf(buffer,MAXBUF,"322 %s %s %d :[+%s] %s",u->nick,chan->name,usercount_i(chan),chanmodes(chan,has_channel(u,chan)),chan->topic);
+                                                int counter = snprintf(buffer,MAXBUF,"322 %s %s %d :[+%s] %s",u->nick,chan->name,usercount_i(chan),chanmodes(chan,has_user),chan->topic);
                                                 amount_sent += counter + 4 + Srv->GetServerName().length();
                                                 log(DEBUG,"m_safelist.so: Sent %ld of safe %ld / 4",amount_sent,u->sendqmax);
                                                 WriteServ_NoFormat(u->fd,buffer);
index e9c2078cb9f1199b0b98d8babe78a0f787e84e4a..dbd3af52f7e27624160d230ab99c0b618c3e9c3f 100644 (file)
@@ -70,7 +70,7 @@ class cmd_uninvite : public command_t
                         WriteServ(user->fd,"491 %s %s %s :Is not invited to channel %s",user->nick,u->nick,c->name,c->name);
                         return;
                 }
-                if (!has_channel(user,c))
+                if (!c->HasUser(user))
                 {
                         WriteServ(user->fd,"492 %s %s :You're not on that channel!",user->nick, c->name);
                         return;
index 157c5c4568685e5705d92870d1dc45b5600dddf3..1a7209991114d8e27bfc2267fdbff4f85f062ccb 100755 (executable)
@@ -1 +1 @@
-echo 3557
+echo 3559