]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
kick_channel -> chanrec::KickUser(), server_kick_channel -> chanrec::ServerKickUser()
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 8 Aug 2006 12:20:45 +0000 (12:20 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 8 Aug 2006 12:20:45 +0000 (12:20 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4782 e03df62e-2008-0410-955e-edbf42e46eb7

include/channels.h
src/channels.cpp
src/cmd_kick.cpp
src/modules.cpp
src/modules/m_spanningtree.cpp

index 17e47c88db34fd7bb8cddf484d4fdb2b3c03187e..444adf64fae150bee741c12f77d217457decdbcf 100644 (file)
@@ -245,6 +245,24 @@ class chanrec : public Extensible
         */
        chanrec();
 
+       /* Make src kick user from this channel with the given reason.
+        * @param src The source of the kick
+        * @param user The user being kicked (must be on this channel)
+        * @param reason The reason for the kick
+        * @return The number of users left on the channel. If this is zero
+        * when the method returns, you MUST delete the chanrec immediately!
+        */
+       long KickUser(userrec *src, userrec *user, const char* reason);
+
+       /* Make the server kick user from this channel with the given reason.
+        *  @param user The user being kicked (must be on this channel)
+        *  @param reason The reason for the kick
+        *  @param triggerevents True if you wish this kick to trigger module events
+        *  @return The number of users left on the channel. If this is zero
+        *  when the method returns, you MUST delete the chanrec immediately!
+        */
+       long ServerKickUser(userrec* user, const char* reason, bool triggerevents);
+
        /** Destructor for chanrec
         */
        virtual ~chanrec() { /* stub */ }
@@ -287,7 +305,7 @@ class ucrec : public classbase
 
 chanrec* add_channel(userrec *user, const char* cn, const char* key, bool override);
 chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool local);
-void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason);
-void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool triggerevents);
+//void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason);
+//void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool triggerevents);
 
 #endif
index 3671fdb6dc971d8476803065d09617863f124183..3f1d2ecb67cdd3c02ca170e1306e30ae18cf8b16 100644 (file)
@@ -543,141 +543,131 @@ chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool
        return NULL;
 }
 
-void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool triggerevents)
+long chanrec::ServerKickUser(userrec* user, const char* reason, bool triggerevents)
 {
-       if ((!user) || (!Ptr) || (!reason))
-       {
-               return;
-       }
+       if (!user || !reason)
+               return this->GetUserCounter();
 
        if (IS_LOCAL(user))
        {
-               if (!Ptr->HasUser(user))
+               if (!this->HasUser(user))
                {
                        /* Not on channel */
-                       return;
+                       return this->GetUserCounter();
                }
        }
-       
+
        if (triggerevents)
        {
-               FOREACH_MOD(I_OnUserKick,OnUserKick(NULL,user,Ptr,reason));
+               FOREACH_MOD(I_OnUserKick,OnUserKick(NULL,user,this,reason));
        }
 
        for (unsigned int i =0; i < user->chans.size(); i++)
        {
-               if ((user->chans[i]->channel) && (user->chans[i]->channel == Ptr))
+               if (user->chans[i]->channel == this)
                {
-                       WriteChannelWithServ(Config->ServerName,Ptr,"KICK %s %s :%s",Ptr->name, user->nick, reason);
+                       WriteChannelWithServ(Config->ServerName,this,"KICK %s %s :%s",this->name, user->nick, reason);
                        user->chans[i]->uc_modes = 0;
                        user->chans[i]->channel = NULL;
                        break;
                }
        }
 
-       Ptr->DelUser(user);
-
-       if (!usercount(Ptr))
+       if (!this->DelUser(user))
        {
-               chan_hash::iterator iter = chanlist.find(Ptr->name);
-               log(DEBUG,"del_channel: destroying channel: %s",Ptr->name);
+               chan_hash::iterator iter = chanlist.find(this->name);
                /* kill the record */
                if (iter != chanlist.end())
                {
-                       log(DEBUG,"del_channel: destroyed: %s",Ptr->name);
-                       FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(Ptr));
-                       DELETE(Ptr);
+                       FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this));
                        chanlist.erase(iter);
                }
+               return 0;
        }
+
+       return this->GetUserCounter();
 }
 
-void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason)
+long chanrec::KickUser(userrec *src, userrec *user, const char* reason)
 {
-       if ((!src) || (!user) || (!Ptr) || (!reason))
-       {
-               log(DEFAULT,"*** BUG *** kick_channel was given an invalid parameter");
-               return;
-       }
-
-       log(DEBUG,"kick_channel: removing: %s %s %s",user->nick,Ptr->name,src->nick);
+       if (!src || !user || !reason)
+               return this->GetUserCounter();
 
        if (IS_LOCAL(src))
        {
-               if (!Ptr->HasUser(user))
+               if (!this->HasUser(user))
                {
-                       WriteServ(src->fd,"441 %s %s %s :They are not on that channel",src->nick, user->nick, Ptr->name);
-                       return;
+                       WriteServ(src->fd,"441 %s %s %s :They are not on that channel",src->nick, user->nick, this->name);
+                       return this->GetUserCounter();
                }
                 if ((is_uline(user->server)) && (!is_uline(src->server)))
                {
-                       WriteServ(src->fd,"482 %s %s :Only a u-line may kick a u-line from a channel.",src->nick, Ptr->name);
-                       return;
+                       WriteServ(src->fd,"482 %s %s :Only a u-line may kick a u-line from a channel.",src->nick, this->name);
+                       return this->GetUserCounter();
                }
                int MOD_RESULT = 0;
 
                if (!is_uline(src->server))
                {
                        MOD_RESULT = 0;
-                       FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,Ptr,reason));
+                       FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,this,reason));
                        if (MOD_RESULT == 1)
-                               return;
+                               return this->GetUserCounter();
                }
                /* Set to -1 by OnUserPreKick if explicit allow was set */
                if (MOD_RESULT != -1)
                {
-                       FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,Ptr,AC_KICK));
+                       FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,this,AC_KICK));
                        if ((MOD_RESULT == ACR_DENY) && (!is_uline(src->server)))
-                               return;
+                               return this->GetUserCounter();
        
                        if ((MOD_RESULT == ACR_DEFAULT) || (!is_uline(src->server)))
                        {
-                               if ((cstatus(src,Ptr) < STATUS_HOP) || (cstatus(src,Ptr) < cstatus(user,Ptr)))
+                               int them = cstatus(src, this);
+                               int us = cstatus(user, this);
+                               if ((them < STATUS_HOP) || (them < us))
                                {
-                                       if (cstatus(src,Ptr) == STATUS_HOP)
+                                       if (them == STATUS_HOP)
                                        {
-                                               WriteServ(src->fd,"482 %s %s :You must be a channel operator",src->nick, Ptr->name);
+                                               WriteServ(src->fd,"482 %s %s :You must be a channel operator",src->nick, this->name);
                                        }
                                        else
                                        {
-                                               WriteServ(src->fd,"482 %s %s :You must be at least a half-operator",src->nick, Ptr->name);
+                                               WriteServ(src->fd,"482 %s %s :You must be at least a half-operator",src->nick, this->name);
                                        }
-               
-                                       return;
+                                       return this->GetUserCounter();
                                }
                        }
                }
        }
 
-       FOREACH_MOD(I_OnUserKick,OnUserKick(src,user,Ptr,reason));
+       FOREACH_MOD(I_OnUserKick,OnUserKick(src,user,this,reason));
                        
        for (UserChanList::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
        {
                /* zap it from the channel list of the user */
-               if ((*i)->channel && ((*i)->channel == Ptr))
+               if ((*i)->channel == this)
                {
-                       WriteChannel(Ptr,src,"KICK %s %s :%s",Ptr->name, user->nick, reason);
+                       WriteChannel(this,src,"KICK %s %s :%s",this->name, user->nick, reason);
                        (*i)->uc_modes = 0;
                        (*i)->channel = NULL;
-                       log(DEBUG,"del_channel: unlinked: %s %s",user->nick,Ptr->name);
                        break;
                }
        }
 
-       if (!Ptr->DelUser(user))
+       if (!this->DelUser(user))
        /* if there are no users left on the channel */
        {
-               chan_hash::iterator iter = chanlist.find(Ptr->name);
-
-               log(DEBUG,"del_channel: destroying channel: %s",Ptr->name);
+               chan_hash::iterator iter = chanlist.find(this->name);
 
                /* kill the record */
                if (iter != chanlist.end())
                {
-                       log(DEBUG,"del_channel: destroyed: %s",Ptr->name);
-                       FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(Ptr));
-                       DELETE(Ptr);
+                       FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this));
                        chanlist.erase(iter);
                }
+               return 0;
        }
+
+       return this->GetUserCounter();
 }
index 4743f47df91c53991a6759767d160a07c3e57ed5..1da6d356f496a9d01b93c3375ecfdd2e15c70362 100644 (file)
@@ -24,7 +24,7 @@ void cmd_kick::Handle (const char** parameters, int pcnt, userrec *user)
 {
        char reason[MAXKICK];
        chanrec* c = FindChan(parameters[0]);
-       userrec* u   = Find(parameters[1]);
+       userrec* u = Find(parameters[1]);
 
        if (!u || !c)
        {
@@ -47,5 +47,7 @@ void cmd_kick::Handle (const char** parameters, int pcnt, userrec *user)
                strlcpy(reason, user->nick, MAXKICK - 1);
        }
 
-       kick_channel(user, u, c, reason);
+       if (!c->KickUser(user, u, reason))
+               /* Nobody left here, delete the chanrec */
+               delete c;
 }
index 9bb8e9a057bc0756b136040cbb0d85af9b83b75c..bda6f765b232e2286f3df326391ac7c9453a108a 100644 (file)
@@ -428,11 +428,11 @@ void Server::KickUser(userrec* source, userrec* target, chanrec* chan, const std
 {
        if (source)
        {
-               kick_channel(source,target,chan,(char*)reason.c_str());
+               chan->KickUser(source, target, reason.c_str());
        }
        else
        {
-               server_kick_channel(target,chan,(char*)reason.c_str(),true);
+               chan->ServerKickUser(target, reason.c_str(), true);
        }
 }
 
index 91a917b8eee87e2f5bffffc686306656d4b59652..51c68aeffa3d3995c37fa24658fd371e598a544c 100644 (file)
@@ -2896,7 +2896,7 @@ class TreeSocket : public InspSocket
                                                chanrec* chan = Srv->FindChannel(params[0]);
                                                if (user && chan)
                                                {
-                                                       server_kick_channel(user,chan,(char*)params[2].c_str(),false);
+                                                       chan->ServerKickUser(user, params[2].c_str(), false);
                                                }
                                        }
                                        if (this->InboundServerName != "")