]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_timedbans.cpp
Argh, i give up
[user/henk/code/inspircd.git] / src / modules / m_timedbans.cpp
index 40f740922dd97f438b70aab1c6b3b07d4986b2c2..0e40dc0ea1a9f99edf77451badb8c7a46c7265ce 100644 (file)
@@ -30,19 +30,19 @@ timedbans TimedBanList;
 
 /** Handle /TBAN
  */
-class cmd_tban : public command_t
+class CommandTban : public Command
 {
  public:
cmd_tban (InspIRCd* Instance) : command_t(Instance,"TBAN", 0, 3)
CommandTban (InspIRCd* Instance) : Command(Instance,"TBAN", 0, 3)
        {
                this->source = "m_timedbans.so";
                syntax = "<channel> <duration> <banmask>";
                TRANSLATE4(TR_TEXT, TR_TEXT, TR_TEXT, TR_END);
        }
 
-       CmdResult Handle (const char** parameters, int pcnt, userrec *user)
+       CmdResult Handle (const char** parameters, int pcnt, User *user)
        {
-               chanrec* channel = ServerInstance->FindChan(parameters[0]);
+               Channel* channel = ServerInstance->FindChan(parameters[0]);
                if (channel)
                {
                        int cm = channel->GetStatus(user);
@@ -94,7 +94,8 @@ class cmd_tban : public command_t
                                }
                                return CMD_FAILURE;
                        }
-                       else user->WriteServ("482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, channel->name);
+                       else user->WriteServ("482 %s %s :You must be at least a%soperator to change modes on this channel",user->nick, channel->name,
+                                       ServerInstance->Config->AllowHalfop ? " half-" : " channel ");
                        return CMD_FAILURE;
                }
                user->WriteServ("401 %s %s :No such channel",user->nick, parameters[0]);
@@ -104,15 +105,17 @@ class cmd_tban : public command_t
 
 class ModuleTimedBans : public Module
 {
-       cmd_tban* mycommand;
+       CommandTban* mycommand;
  public:
        ModuleTimedBans(InspIRCd* Me)
                : Module(Me)
        {
                
-               mycommand = new cmd_tban(ServerInstance);
+               mycommand = new CommandTban(ServerInstance);
                ServerInstance->AddCommand(mycommand);
                TimedBanList.clear();
+               Implementation eventlist[] = { I_OnDelBan, I_OnBackgroundTimer };
+               ServerInstance->Modules->Attach(eventlist, this, 2);
        }
        
        virtual ~ModuleTimedBans()
@@ -120,12 +123,8 @@ class ModuleTimedBans : public Module
                TimedBanList.clear();
        }
 
-       void Implements(char* List)
-       {
-               List[I_OnDelBan] = List[I_OnBackgroundTimer] = 1;
-       }
 
-       virtual int OnDelBan(userrec* source, chanrec* chan, const std::string &banmask)
+       virtual int OnDelBan(User* source, Channel* chan, const std::string &banmask)
        {
                irc::string listitem = banmask.c_str();
                irc::string thischan = chan->name;
@@ -152,7 +151,7 @@ class ModuleTimedBans : public Module
                        {
                                if (curtime > i->expire)
                                {
-                                       chanrec* cr = ServerInstance->FindChan(i->channel);
+                                       Channel* cr = ServerInstance->FindChan(i->channel);
                                        again = true;
                                        if (cr)
                                        {
@@ -161,22 +160,15 @@ class ModuleTimedBans : public Module
                                                setban[0] = i->channel.c_str();
                                                setban[1] = "-b";
                                                setban[2] = i->mask.c_str();
-                                               // kludge alert!
-                                               // ::SendMode expects a userrec* to send the numeric replies
-                                               // back to, so we create it a fake user that isnt in the user
-                                               // hash and set its descriptor to FD_MAGIC_NUMBER so the data
-                                               // falls into the abyss :p
-                                               userrec* temp = new userrec(ServerInstance);
-                                               temp->SetFd(FD_MAGIC_NUMBER);
-                                               /* FIX: Send mode remotely*/
+
+                                               /* Send mode remotely*/
                                                std::deque<std::string> n;
                                                n.push_back(setban[0]);
                                                n.push_back("-b");
                                                n.push_back(setban[2]);
-                                               ServerInstance->SendMode(setban,3,temp);
+                                               ServerInstance->SendMode(setban,3, ServerInstance->FakeClient);
                                                Event rmode((char *)&n, NULL, "send_mode");
                                                rmode.Send(ServerInstance);
-                                               DELETE(temp);
                                        }
                                        else
                                        {