]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_park.cpp
Moved a ton of functions into helperfuncs.h to speed up recompiles
[user/henk/code/inspircd.git] / src / modules / m_park.cpp
index f7d54e7309ba5a4990f959b1bfd10f9506359ae5..1cf69b46fea9a2dc9e72b9382ee693b9195483bc 100644 (file)
@@ -19,6 +19,7 @@
 #include <vector>
 #include "users.h"
 #include "channels.h"
+#include "helperfuncs.h"
 #include "modules.h"
 
 /* $ModDesc: Provides support for user parking/unparking */
@@ -46,6 +47,7 @@ parkinfo pinfo;
 long ParkMaxTime;
 long ConcurrentParks;
 long ParkMaxMsgs;
+parkedinfo pi;
 
 void handle_park(char **parameters, int pcnt, userrec *user)
 {
@@ -65,11 +67,10 @@ void handle_park(char **parameters, int pcnt, userrec *user)
        }
        else
        {
-               awaylog* aw = new awaylog;
-               parkedinfo pi;
+               awaylog* aw;
                char msg[MAXBUF];
-               long key = abs(random() * 12345);
-               snprintf(msg,MAXBUF,"You are now parked. To unpark use /UNPARK %s %d",user->nick,key);
+               unsigned long key = abs(random() * 12345);
+               snprintf(msg,MAXBUF,"You are now parked. To unpark use /UNPARK %s %lu",user->nick,key);
                Srv->UserToPseudo(user,std::string(msg));
                aw = new awaylog;
                user->Extend("park_awaylog",(char*)aw);
@@ -84,7 +85,7 @@ void handle_park(char **parameters, int pcnt, userrec *user)
 void handle_parkstats(char **parameters, int pcnt, userrec *user)
 {
        char status[MAXBUF];
-       snprintf(status,MAXBUF,"NOTICE %s :There are a total of %d parked clients on this server, with a maximum of %d parked sessions allowed per user.",user->nick,pinfo.size(),ConcurrentParks);
+       snprintf(status,MAXBUF,"NOTICE %s :There are a total of %lu parked clients on this server, with a maximum of %lu parked sessions allowed per user.",user->nick,(unsigned long)pinfo.size(),(unsigned long)ConcurrentParks);
        Srv->SendServ(user->fd,status);
 }
 
@@ -206,6 +207,21 @@ class ModulePark : public Module
                 output = output + std::string(" PARK");
         }
 
+        virtual void OnUserQuit(userrec* user)
+        {
+                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)
        {
                awaylog* awy = (awaylog*)dest->GetExt("park_awaylog");
@@ -253,9 +269,12 @@ class ModulePark : public Module
                                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");
-                                       pinfo.erase(j);
                                        go_again = true;
                                        break;
                                }
@@ -269,7 +288,6 @@ class ModulePark : public Module
                {
                        userrec* u = (userrec*)dest;
                        OnPrePrivmsg(user,u,text);
-                       return 1;
                }
                return 0;
        }