#include <vector>
#include "users.h"
#include "channels.h"
+#include "helperfuncs.h"
#include "modules.h"
/* $ModDesc: Provides support for user parking/unparking */
long ParkMaxTime;
long ConcurrentParks;
long ParkMaxMsgs;
+parkedinfo pi;
void handle_park(char **parameters, int pcnt, userrec *user)
{
else
{
awaylog* aw;
- parkedinfo pi;
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);
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);
}
{
Srv = new Server;
pinfo.clear();
+ this->ReadSettings();
Srv->AddCommand("PARK",handle_park,0,0,"m_park.so");
Srv->AddCommand("UNPARK",handle_unpark,0,2,"m_park.so");
Srv->AddCommand("PARKSTATS",handle_parkstats,'o',0,"m_park.so");
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");
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;
}
{
userrec* u = (userrec*)dest;
OnPrePrivmsg(user,u,text);
- return 1;
}
return 0;
}