]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Change to chanrec::PartUser. As with KickUser and ServerKickUser, returns the number...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 8 Aug 2006 12:52:24 +0000 (12:52 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 8 Aug 2006 12:52:24 +0000 (12:52 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4786 e03df62e-2008-0410-955e-edbf42e46eb7

include/channels.h
include/modules.h
src/channels.cpp
src/cmd_part.cpp
src/modules.cpp
src/modules/m_park.cpp
src/modules/m_remove.cpp
src/modules/m_sapart.cpp

index 444adf64fae150bee741c12f77d217457decdbcf..9062971048f5e5755f893759eee3e30880f9ca0a 100644 (file)
@@ -263,6 +263,15 @@ class chanrec : public Extensible
         */
        long ServerKickUser(userrec* user, const char* reason, bool triggerevents);
 
+       /* Part a user from this channel with the given reason.
+        * If the reason field is NULL, no reason will be sent.
+        * @param user The user who is parting (must be on this channel)
+        * @param reason The (optional) part reason
+        * @return The number of users left on the channel. If this is zero
+        * when the method returns, you MUST delete the chanrec immediately!
+        */
+       long PartUser(userrec *user, const char* reason = NULL);
+
        /** Destructor for chanrec
         */
        virtual ~chanrec() { /* stub */ }
@@ -304,7 +313,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);
+//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);
 
index 25fb52077938fa6c0f5714464901e285bc32d008..39265fceeeaba227440001986301a93da3b77d20 100644 (file)
@@ -1520,13 +1520,6 @@ class Server : public Extensible
         */
        virtual chanrec* JoinUserToChannel(userrec* user, const std::string &cname, const std::string &key);
        
-       /** Forces a user to part a channel.
-        * This is similar to svspart and can be used to implement redirection, etc.
-        * Although the return value of this function is a pointer to a channel record, the returned data is
-        * undefined and should not be read or written to. This behaviour may be changed in a future version.
-        */
-       virtual chanrec* PartUserFromChannel(userrec* user, const std::string &cname, const std::string &reason);
-       
        /** Forces a user nickchange.
         * This command works similarly to SVSNICK, and can be used to implement Q-lines etc.
         * If you specify an invalid nickname, the nick change will be dropped and the target user will receive
index 3f1d2ecb67cdd3c02ca170e1306e30ae18cf8b16..6d8cb756f48c8ec11eef0a6c9e93892c9a717383 100644 (file)
@@ -479,68 +479,50 @@ chanrec* ForceChan(chanrec* Ptr,ucrec *a,userrec* user, int created)
        return Ptr;
 }
 
-/*
- *remove a channel from a users record, and remove the record from memory
+/* chanrec::PartUser
+ * remove a channel from a users record, and remove the record from the hash
  * if the channel has become empty
  */
-
-chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool local)
+long chanrec::PartUser(userrec *user, const char* reason)
 {
-       if ((!user) || (!cname))
-       {
-               log(DEFAULT,"*** BUG *** del_channel was given an invalid parameter");
-               return NULL;
-       }
-
-       chanrec* Ptr = FindChan(cname);
-
-       if (!Ptr)
-               return NULL;
-
-       log(DEBUG,"del_channel: removing: %s %s",user->nick,Ptr->name);
+       if (!user)
+               return this->GetUserCounter();
 
        for (unsigned int i =0; i < user->chans.size(); i++)
        {
                /* zap it from the channel list of the user */
-               if (user->chans[i]->channel == Ptr)
+               if (user->chans[i]->channel == this)
                {
                        if (reason)
                        {
-                               FOREACH_MOD(I_OnUserPart,OnUserPart(user,Ptr,reason));
-                               WriteChannel(Ptr,user,"PART %s :%s",Ptr->name, reason);
+                               FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason));
+                               WriteChannel(this, user, "PART %s :%s", this->name, reason);
                        }
                        else
                        {
-                               FOREACH_MOD(I_OnUserPart,OnUserPart(user,Ptr,""));
-                               WriteChannel(Ptr,user,"PART :%s",Ptr->name);
+                               FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, ""));
+                               WriteChannel(this, user, "PART :%s", this->name);
                        }
                        user->chans[i]->uc_modes = 0;
                        user->chans[i]->channel = NULL;
-                       log(DEBUG,"del_channel: unlinked: %s %s",user->nick,Ptr->name);
                        break;
                }
        }
 
-       Ptr->DelUser(user);
-
-       /* if there are no users left on the channel */
-       if (!usercount(Ptr))
+       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);
+                       log(DEBUG,"del_channel: destroyed: %s", this->name);
+                       FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this));
                        chanlist.erase(iter);
                }
+               return 0;
        }
 
-       return NULL;
+       return this->GetUserCounter();
 }
 
 long chanrec::ServerKickUser(userrec* user, const char* reason, bool triggerevents)
index 39a9621404e867b6ff915e024b8498fd6f3e2ca2..1b9680d5d44950395f55e10e42b510a8c5b521f0 100644 (file)
@@ -26,13 +26,17 @@ void cmd_part::Handle (const char** parameters, int pcnt, userrec *user)
 {
        if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
                return;
+
+       chanrec* c = FindChan(parameters[0]);
        
-       if (pcnt > 1)
+       if (c)
        {
-               del_channel(user,parameters[0],parameters[1],false);
+               if (!c->PartUser(user, pcnt > 1 ? parameters[0] : NULL))
+                       /* Arse, who stole our channel! :/ */
+                       delete c;
        }
        else
        {
-               del_channel(user,parameters[0],NULL,false);
+               WriteServ(user->fd, "401 %s %s :No such channel", user->nick, parameters[0]);
        }
 }
index f09c85d087738fd5b81c5a8714dafe02364fafc4..a171e427f886d42aa40aa8a2262b9ff94c1229fd 100644 (file)
@@ -405,11 +405,6 @@ chanrec* Server::JoinUserToChannel(userrec* user, const std::string &cname, cons
        return add_channel(user,cname.c_str(),key.c_str(),false);
 }
 
-chanrec* Server::PartUserFromChannel(userrec* user, const std::string &cname, const std::string &reason)
-{
-       return del_channel(user,cname.c_str(),reason.c_str(),false);
-}
-
 chanuserlist Server::GetUsers(chanrec* chan)
 {
        chanuserlist userl;
index 9fbae35290a4c4effc2be60152902d7387e76151..31da8f03360eb7dcb82853482d9df7cae329af50 100644 (file)
@@ -163,9 +163,11 @@ class cmd_unpark : public command_t
                        // first part the user from all chans theyre on, so things dont get messy
                        for (std::vector<ucrec*>::iterator i = user->chans.begin(); i != user->chans.end(); i++)
                        {
-                               if (((ucrec*)(*i))->channel != NULL)
+                               chanrec* chan = (*i)->channel;
+                               if (chan != NULL)
                                {
-                                       Srv->PartUserFromChannel(user,((ucrec*)(*i))->channel->name,"Unparking");
+                                       if (!chan->PartUser(user, "Unparking"))
+                                               delete chan;
                                }
                        }
                        // remove all their old modes
index ab0f2dbaa75d4018dd5c185d7e39b9ef646bb848..bab5ea11b77e1777b56a5dd7b61abb6565434c7e 100644 (file)
@@ -181,10 +181,12 @@ class RemoveBase
 
                                /* Build up the part reason string. */
                                reason << "Removed by " << user->nick << reasonparam;
-                                               
-                               Srv->PartUserFromChannel(target, channel->name, reason.str());
+
                                WriteChannelWithServ(Srv->GetServerName().c_str(), channel, "NOTICE %s :%s removed %s from the channel", channel->name, user->nick, target->nick);
                                WriteServ(target->fd, "NOTICE %s :*** %s removed you from %s with the message: %s", target->nick, user->nick, channel->name, reasonparam.c_str());
+
+                               if (!channel->PartUser(target, reason.str().c_str()))
+                                       delete channel;
                        }
                        else
                        {
index f7620ec006cd1e3cf4698d2ac89be7d4097ac4be..df44e467196cd8d0e2a8872972b8302facfd96a4 100644 (file)
@@ -38,22 +38,18 @@ class cmd_sapart : public command_t
         
        void Handle (const char** parameters, int pcnt, userrec *user)
        {
-               userrec* dest = Srv->FindNick(std::string(parameters[0]));
-               if (dest)
+               userrec* dest = Srv->FindNick(parameters[0]);
+               chanrec* channel = Srv->FindChannel(parameters[1]);
+               if (dest && channel)
                {
                        if (Srv->IsUlined(dest->server))
                        {
                                WriteServ(user->fd,"990 %s :Cannot use an SA command on a u-lined client",user->nick);
                                return;
                        }
-                       if (!IsValidChannelName(parameters[1]))
-                       {
-                               Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name");
-                               return;
-                       }
-
-                       Srv->SendOpers(std::string(user->nick)+" used SAPART to make "+std::string(dest->nick)+" part "+parameters[1]);
-                       Srv->PartUserFromChannel(dest,std::string(parameters[1]),std::string(dest->nick));
+                       Srv->SendOpers(std::string(user->nick)+" used SAPART to make "+dest->nick+" part "+parameters[1]);
+                       if (!channel->PartUser(dest, dest->nick))
+                               delete channel;
                }
        }
 };