X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_park.cpp;h=1cf69b46fea9a2dc9e72b9382ee693b9195483bc;hb=eb4229deed0281ae566ef7e55a144e5d3183a4b2;hp=f7d54e7309ba5a4990f959b1bfd10f9506359ae5;hpb=108dca35eafaa3ea4aad9ec21cbb723d7b3de587;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_park.cpp b/src/modules/m_park.cpp index f7d54e730..1cf69b46f 100644 --- a/src/modules/m_park.cpp +++ b/src/modules/m_park.cpp @@ -19,6 +19,7 @@ #include #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; }