]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_park.cpp
Made SANICK not collide the user (theres no need to in the new 1.1 now we have return...
[user/henk/code/inspircd.git] / src / modules / m_park.cpp
index c571022873952736ed5dc839bf95a13b82afac5f..de8eeb25e57e1d58484c6ce5d4ebc18b1a35548a 100644 (file)
@@ -21,8 +21,11 @@ using namespace std;
 #include <vector>
 #include "users.h"
 #include "channels.h"
-#include "helperfuncs.h"
+
 #include "modules.h"
+#include "inspircd.h"
+
+
 
 /* $ModDesc: Provides support for user parking/unparking */
 
@@ -46,7 +49,7 @@ class parkedinfo : public parking
        time_t parktime;
 };
 
-static Server *Srv;
+
 typedef std::vector<awaymsg> awaylog;
 typedef std::vector<parkedinfo> parkinfo;
 parkinfo pinfo;
@@ -58,12 +61,12 @@ parkedinfo pi;
 class cmd_park : public command_t
 {
  public:
-       cmd_park () : command_t("PARK", 0, 0)
+       cmd_park (InspIRCd* Instance) : command_t(Instance,"PARK", 0, 0)
        {
                this->source = "m_park.so";
        }
 
-       void Handle (char **parameters, int pcnt, userrec *user)
+       CmdResult Handle (const char** parameters, int pcnt, userrec *user)
        {
                /** Parking. easy stuff.
                 *
@@ -78,7 +81,8 @@ class cmd_park : public command_t
                                        othersessions++;
                if (othersessions >= ConcurrentParks)
                {
-                       Srv->SendServ(user->fd,"927 "+std::string(user->nick)+" :You are already parked up to the maximum number of allowed times.");
+                       user->WriteServ("927 "+std::string(user->nick)+" :You are already parked up to the maximum number of allowed times.");
+                       return CMD_FAILURE;
                }
                else
                {
@@ -87,7 +91,7 @@ class cmd_park : public command_t
                        unsigned long* key = new 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));
+                       ServerInstance->UserToPseudo(user,std::string(msg));
                        aw = new awaylog;
                        user->Extend("park_awaylog", aw);
                        user->Extend("park_key", key);
@@ -95,6 +99,7 @@ class cmd_park : public command_t
                        pi.host = user->host;
                        pi.parktime = time(NULL);
                        pinfo.push_back(pi);
+                       return CMD_SUCCESS;
                }
        }
 
@@ -103,28 +108,30 @@ class cmd_park : public command_t
 class cmd_parkstats : public command_t
 {
  public:
-       cmd_parkstats () : command_t("PARKSTATS", 'o', 0)
+       cmd_parkstats (InspIRCd* Instance) : command_t(Instance,"PARKSTATS", 'o', 0)
        {
                this->source = "m_park.so";
        }
 
-       void Handle (char **parameters, int pcnt, userrec *user)
+       CmdResult Handle (const char** parameters, int pcnt, userrec *user)
        {
                char status[MAXBUF];
                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);
+               user->WriteServ(std::string(status));
+               return CMD_SUCCESS;
        }
 };
 
 class cmd_unpark : public command_t
 {
  public:
-       cmd_unpark () : command_t("UNPARK", 0, 2)
+       cmd_unpark (InspIRCd* Instance) : command_t(Instance,"UNPARK", 0, 2)
        {
                this->source = "m_park.so";
+               syntax = "<nick> <key>";
        }
 
-       void Handle (char **parameters, int pcnt, userrec *user)
+       CmdResult Handle (const char** parameters, int pcnt, userrec *user)
        {
                /** Unparking. complicated stuff.
                 *
@@ -142,11 +149,11 @@ class cmd_unpark : public command_t
                 *
                 * And there you have it, easy huh (NOT)...
                 */
-               userrec* unpark = Srv->FindNick(std::string(parameters[0]));
+               userrec* unpark = ServerInstance->FindNick(parameters[0]);
                if (!unpark)
                {
-                       WriteServ(user->fd,"942 %s %s :Invalid user specified.",user->nick, parameters[0]);
-                       return;
+                       user->WriteServ("942 %s %s :Invalid user specified.",user->nick, parameters[0]);
+                       return CMD_FAILURE;
                }
                awaylog* awy;
                unpark->GetExt("park_awaylog", awy);
@@ -154,34 +161,36 @@ class cmd_unpark : public command_t
                unpark->GetExt("park_key", key);
                if (!awy)
                {
-                       WriteServ(user->fd,"943 %s %s :This user is not parked.",user->nick, unpark->nick);
-                       return;
+                       user->WriteServ("943 %s %s :This user is not parked.",user->nick, unpark->nick);
+                       return CMD_FAILURE;
                }
                if (*key == atoi(parameters[1]))
                {
                        // 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
-                       WriteServ(user->fd,"MODE %s -%s",user->nick,user->FormatModes());
+                       user->WriteServ("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]));
+                       ServerInstance->PseudoToUser(user,unpark,"Unparked to "+std::string(parameters[0]));
                        // set all their new modes
-                       WriteServ(unpark->fd,"MODE %s +%s",unpark->nick,unpark->FormatModes());
+                       unpark->WriteServ("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);
+                       unpark->WriteServ("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++)
                        {
                                char timebuf[MAXBUF];
                                tm *timeinfo = localtime(&i->tm);
                                strlcpy(timebuf,asctime(timeinfo),MAXBUF);
                                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());
+                               unpark->WriteServ("NOTICE %s :From %s at %s: \2%s\2",unpark->nick,i->from.c_str(),timebuf,i->text.c_str());
                        }
                        DELETE(awy);
                        DELETE(key);
@@ -198,8 +207,11 @@ class cmd_unpark : public command_t
                }
                else
                {
-                       Srv->SendServ(user->fd,"928 "+std::string(user->nick)+" :Incorrect park key.");
+                       user->WriteServ("928 "+std::string(user->nick)+" :Incorrect park key.");
+                       return CMD_FAILURE;
                }
+
+               return CMD_SUCCESS;
        }
 };
 
@@ -213,25 +225,25 @@ class ModulePark : public Module
  public:
        virtual void ReadSettings()
        {
-               Conf = new ConfigReader;
+               Conf = new ConfigReader(ServerInstance);
                ParkMaxTime = Conf->ReadInteger("park","maxtime",0,true);
                ConcurrentParks = Conf->ReadInteger("park","maxperip",0,true);
                ParkMaxMsgs = Conf->ReadInteger("park","maxmessages",0,true);
                DELETE(Conf);
        }
 
-       ModulePark(Server* Me)
+       ModulePark(InspIRCd* Me)
                : Module::Module(Me)
        {
-               Srv = Me;
+               
                pinfo.clear();
                this->ReadSettings();
-               cmd1 = new cmd_park();
-               cmd2 = new cmd_unpark();
-               cmd3 = new cmd_parkstats();
-               Srv->AddCommand(cmd1);
-               Srv->AddCommand(cmd2);
-               Srv->AddCommand(cmd3);
+               cmd1 = new cmd_park(ServerInstance);
+               cmd2 = new cmd_unpark(ServerInstance);
+               cmd3 = new cmd_parkstats(ServerInstance);
+               ServerInstance->AddCommand(cmd1);
+               ServerInstance->AddCommand(cmd2);
+               ServerInstance->AddCommand(cmd3);
        }
 
        virtual ~ModulePark()
@@ -281,9 +293,9 @@ class ModulePark : public Module
                                am.from = user->GetFullHost();
                                am.tm = time(NULL);
                                awy->push_back(am);
-                               Srv->SendServ(user->fd,"930 "+std::string(user->nick)+" :User "+std::string(dest->nick)+" is parked. Your message has been stored.");
+                               user->WriteServ("930 "+std::string(user->nick)+" :User "+std::string(dest->nick)+" is parked. Your message has been stored.");
                        }
-                       else Srv->SendServ(user->fd,"929 "+std::string(user->nick)+" :User "+std::string(dest->nick)+" is parked, but their message queue is full. Message not saved.");
+                       else user->WriteServ("929 "+std::string(user->nick)+" :User "+std::string(dest->nick)+" is parked, but their message queue is full. Message not saved.");
                }
        }
 
@@ -316,13 +328,13 @@ class ModulePark : public Module
                        {
                                if (time(NULL) >= (j->parktime+ParkMaxTime))
                                {
-                                       userrec* thisnick = Srv->FindNick(j->nick);
+                                       userrec* thisnick = ServerInstance->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");
+                                               userrec::QuitUser(ServerInstance,thisnick,"PARK timeout");
                                        go_again = true;
                                        break;
                                }
@@ -345,7 +357,7 @@ class ModulePark : public Module
        {
                char* dummy;
                if (dst->GetExt("park_awaylog", dummy))
-                       Srv->SendTo(NULL,src,"335 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is a parked client");
+                       src->WriteServ("335 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is a parked client");
        }
        
        virtual Version GetVersion()
@@ -368,7 +380,7 @@ class ModuleParkFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule(Server* Me)
+       virtual Module * CreateModule(InspIRCd* Me)
        {
                return new ModulePark(Me);
        }