]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_park.cpp
Gah, im forgetting to SetMode!
[user/henk/code/inspircd.git] / src / modules / m_park.cpp
index 1d71672746fefa4f02b08671c200d2ea6aaa0fa1..a5c62da190fda453c81246a062c6aeec66ceea40 100644 (file)
@@ -42,7 +42,7 @@ class parkedinfo
        time_t parktime;
 };
 
-Server *Srv;
+static Server *Srv;
 typedef std::vector<awaymsg> awaylog;
 typedef std::vector<parkedinfo> parkinfo;
 parkinfo pinfo;
@@ -67,8 +67,9 @@ class cmd_park : public command_t
                 * We then disconnect the real user leaving a controlled ghost in their place :)
                 */
                int othersessions = 0;
+               /* XXX - why can't just use pinfo.size() like we do below, rather than iterating over the whole vector? -- w00t */
                if (pinfo.size())
-                       for (parkinfo::iterator j = pinfo.begin(); j != pinfo.end(); j++)
+                       for (parkinfo::iterator j = pinfo.begin(); j != pinfo.end(); j++)
                                if (j->host == std::string(user->host))
                                        othersessions++;
                if (othersessions >= ConcurrentParks)
@@ -152,22 +153,19 @@ class cmd_unpark : public command_t
                if (key == atoi(parameters[1]))
                {
                        // first part the user from all chans theyre on, so things dont get messy
-                       for (unsigned int i = 0; i < user->chans.size(); i++)
-                       {
-                               if (user->chans[i].channel != NULL)
-                               {
-                                       if (user->chans[i].channel->name)
-                                       {
-                                               Srv->PartUserFromChannel(user,user->chans[i].channel->name,"Unparking");
-                                       }
+                       for (std::vector<ucrec*>::iterator i = user->chans.begin(); i != user->chans.end(); i++)
+                       {
+                               if (((ucrec*)(*i))->channel != NULL)
+                               {
+                                       Srv->PartUserFromChannel(user,((ucrec*)(*i))->channel->name,"Unparking");
                                }
                        }
                        // remove all their old modes
-                       WriteServ(user->fd,"MODE %s -%s",user->nick,user->modes);
+                       WriteServ(user->fd,"MODE %s -%s",user->nick,user->FormatModes());
                        // now, map them to the parked user, while nobody can see :p
                        Srv->PseudoToUser(user,unpark,"Unparked to "+std::string(parameters[0]));
                        // set all their new modes
-                       WriteServ(unpark->fd,"MODE %s +%s",unpark->nick,unpark->modes);
+                       WriteServ(unpark->fd,"MODE %s +%s",unpark->nick,unpark->FormatModes());
                        // spool their away log to them
                        WriteServ(unpark->fd,"NOTICE %s :*** You are now unparked. You have successfully taken back the nickname and privilages of %s.",unpark->nick,unpark->nick);
                        for (awaylog::iterator i = awy->begin(); i != awy->end(); i++)
@@ -178,7 +176,7 @@ class cmd_unpark : public command_t
                                timebuf[strlen(timebuf)-1] = '\0';
                                WriteServ(unpark->fd,"NOTICE %s :From %s at %s: \2%s\2",unpark->nick,i->from.c_str(),timebuf,i->text.c_str());
                        }
-                       delete awy;
+                       DELETE(awy);
                        unpark->Shrink("park_awaylog");
                        unpark->Shrink("park_key");
                        for (parkinfo::iterator j = pinfo.begin(); j != pinfo.end(); j++)
@@ -211,7 +209,7 @@ class ModulePark : public Module
                ParkMaxTime = Conf->ReadInteger("park","maxtime",0,true);
                ConcurrentParks = Conf->ReadInteger("park","maxperip",0,true);
                ParkMaxMsgs = Conf->ReadInteger("park","maxmessages",0,true);
-               delete Conf;
+               DELETE(Conf);
        }
 
        ModulePark(Server* Me)
@@ -237,32 +235,32 @@ class ModulePark : public Module
                List[I_On005Numeric] = List[I_OnRehash] = List[I_OnUserQuit] = List[I_OnUserPreMessage] = List[I_OnUserPreNick] = List[I_OnBackgroundTimer] = List[I_OnWhois] = 1;
        }
 
-       virtual void OnRehash(std::string parameter)
+       virtual void OnRehash(const std::string &parameter)
        {
                this->ReadSettings();
        }
 
-        virtual void On005Numeric(std::string &output)
-        {
-                output = output + std::string(" PARK");
-        }
+       virtual void On005Numeric(std::string &output)
+       {
+               output = output + std::string(" PARK");
+       }
 
-        virtual void OnUserQuit(userrec* user, std::string reason)
-        {
-                std::string nick = user->nick;
-                // track quits in our parked user list
-                for (parkinfo::iterator j = pinfo.begin(); j != pinfo.end(); j++)
-                {
-                        if (j->nick == nick)
-                        {
-                                pinfo.erase(j);
-                                break;
-                        }
-                }
-        }
+       virtual void OnUserQuit(userrec* user, const std::string &reason)
+       {
+               std::string nick = user->nick;
+               // track quits in our parked user list
+               for (parkinfo::iterator j = pinfo.begin(); j != pinfo.end(); j++)
+               {
+                       if (j->nick == nick)
+                       {
+                               pinfo.erase(j);
+                               break;
+                       }
+               }
+       }
 
 
-       virtual void OnPrePrivmsg(userrec* user, userrec* dest, std::string text)
+       virtual void OnPrePrivmsg(userrec* user, userrec* dest, const std::string &text)
        {
                awaylog* awy = (awaylog*)dest->GetExt("park_awaylog");
                if (awy)
@@ -280,49 +278,51 @@ class ModulePark : public Module
                }
        }
 
-       virtual int OnUserPreNick(userrec* user, std::string newnick)
+       virtual int OnUserPreNick(userrec* user, const std::string &newnick)
        {
                // track nickchanges in our parked user list
                // (this isnt too efficient, i'll tidy it up some time)
-                for (parkinfo::iterator j = pinfo.begin(); j != pinfo.end(); j++)
-                {
-                        if (j->nick == std::string(user->nick))
-                        {
-                                j->nick = newnick;
-                                break;
-                        }
-                }
+               /* XXX - perhaps extend the user record, or, that wouldn't work - perhaps use a map? -- w00t */
+               for (parkinfo::iterator j = pinfo.begin(); j != pinfo.end(); j++)
+               {
+                       if (j->nick == std::string(user->nick))
+                       {
+                               j->nick = newnick;
+                               break;
+                       }
+               }
                return 0;
        }
 
        virtual void OnBackgroundTimer(time_t curtime)
        {
-               // look for parked clients which have timed out (this needs tidying)
-               if (pinfo.empty())
-                       return;
-               bool go_again = true;
-               while (go_again)
-               {
-                       go_again = false;
-                       for (parkinfo::iterator j = pinfo.begin(); j != pinfo.end(); j++)
-                       {
-                               if (time(NULL) >= (j->parktime+ParkMaxTime))
-                               {
-                                       userrec* thisnick = Srv->FindNick(j->nick);
+               // look for parked clients which have timed out (this needs tidying)
+               if (pinfo.empty())
+                       return;
+               bool go_again = true;
+               while (go_again)
+               {
+                       go_again = false;
+                       for (parkinfo::iterator j = pinfo.begin(); j != pinfo.end(); j++)
+                       {
+                               if (time(NULL) >= (j->parktime+ParkMaxTime))
+                               {
+                                       userrec* thisnick = Srv->FindNick(j->nick);
                                        // THIS MUST COME BEFORE THE QuitUser - QuitUser can
                                        // create a recursive call to OnUserQuit in this module
                                        // and then corrupt the pointer!
                                        pinfo.erase(j);
-                                       if (thisnick)
-                                               Srv->QuitUser(thisnick,"PARK timeout");
-                                       go_again = true;
-                                       break;
-                               }
-                       }
-               }
+                                       if (thisnick)
+                                               Srv->QuitUser(thisnick,"PARK timeout");
+                                       go_again = true;
+                                       break;
+                               }
+                       }
+               }
        }
 
-       virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
+       /* XXX - why is OnPrePrivmsg seperated here, I assume there is reason for the extra function call? --w00t */
+       virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
        {
                if (target_type == TYPE_USER)
                {
@@ -332,11 +332,11 @@ class ModulePark : public Module
                return 0;
        }
 
-        virtual void OnWhois(userrec* src, userrec* dst)
-        {
+       virtual void OnWhois(userrec* src, userrec* dst)
+       {
                if (dst->GetExt("park_awaylog"))
-                       Srv->SendTo(NULL,src,"335 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is a parked client");
-        }
+                       Srv->SendTo(NULL,src,"335 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is a parked client");
+       }
        
        virtual Version GetVersion()
        {