]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modes/cmode_b.cpp
Document TimerManager class
[user/henk/code/inspircd.git] / src / modes / cmode_b.cpp
index 57e13159d9138172b847e82490a5f4dcbd061953..82e57ea7bb1e3bddd406482b9b4dfa6dc560a1fe 100644 (file)
@@ -8,74 +8,65 @@
 #include "channels.h"
 #include "users.h"
 #include "helperfuncs.h"
-#include "message.h"
 #include "modules.h"
 #include "inspstring.h"
 #include "hashcomp.h"
 #include "modes/cmode_b.h"
 
-extern InspIRCd* ServerInstance;
-extern ServerConfig* Config;
-extern std::vector<Module*> modules;
-extern std::vector<ircd_module*> factory;
-extern int MODCOUNT;
-extern time_t TIME;
-
-ModeChannelBan::ModeChannelBan() : ModeHandler('b', 1, 1, true, MODETYPE_CHANNEL, false)
+ModeChannelBan::ModeChannelBan(InspIRCd* Instance) : ModeHandler(Instance, 'b', 1, 1, true, MODETYPE_CHANNEL, false)
 {
 }
 
 ModeAction ModeChannelBan::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
 {
-       int status = cstatus(source, channel);
-       adding ? parameter = this->AddBan(source, parameter, channel, status) : parameter = this->DelBan(source, parameter, channel, status);
+       int status = channel->GetStatus(source);
+       /* Call the correct method depending on wether we're adding or removing the mode */
+       if (adding)
+       {
+               parameter = this->AddBan(source, parameter, channel, status);
+       }
+       else
+       {
+               parameter = this->DelBan(source, parameter, channel, status);
+       }
+       /* If the method above 'ate' the parameter by reducing it to an empty string, then
+        * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
+        * the return value and is always MODEACTION_DENY if the mode is supposed to have
+        * a parameter.
+        */
        return MODEACTION_ALLOW;
 }
 
-std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *chan,int status)
+void ModeChannelBan::DisplayList(userrec* user, chanrec* channel)
 {
-       BanItem b;
-       int toomanyexclamation = 0;
-       int toomanyat = 0;
+       /* Display the channel banlist */
+       for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
+       {
+               user->WriteServ("367 %s %s %s %s %d",user->nick, channel->name, i->data, i->set_by, i->set_time);
+       }
+       user->WriteServ("368 %s %s :End of channel ban list",user->nick, channel->name);
+       return;
+}
 
+std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *chan,int status)
+{
        if ((!user) || (!chan))
        {
-               log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
+               ServerInstance->Log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
                dest = "";
                return dest;
        }
 
-       for (std::string::iterator i = dest.begin(); i != dest.end(); i++)
-       {
-               if ((*i < 32) || (*i > 126))
-               {
-                       dest = "";
-                       return dest;
-               }
-               else if (*i == '!')
-               {
-                       toomanyexclamation++;
-               }
-               else if (*i == '@')
-               {
-                       toomanyat++;
-               }
-       }
-
-       if (toomanyexclamation != 1 || toomanyat != 1)
-       {
-               /*
-                * this stops sillyness like n!u!u!u@h, though note that most
-                * ircds don't actually verify banmask validity. --w00t
-                */
-               dest = "";
+       /* Attempt to tidy the mask */
+       ModeParser::CleanMask(dest);
+       /* If the mask was invalid, we exit */
+       if (dest == "")
                return dest;
-       }
 
-       long maxbans = GetMaxBans(chan->name);
+       long maxbans = chan->GetMaxBans();
        if ((unsigned)chan->bans.size() > (unsigned)maxbans)
        {
-               WriteServ(user->fd,"478 %s %s :Channel ban list for %s is full (maximum entries for this channel is %d)",user->nick, chan->name,chan->name,maxbans);
+               user->WriteServ("478 %s %s :Channel ban list for %s is full (maximum entries for this channel is %d)",user->nick, chan->name,chan->name,maxbans);
                dest = "";
                return dest;
        }
@@ -98,7 +89,7 @@ std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *cha
                }
        }
 
-       b.set_time = TIME;
+       b.set_time = ServerInstance->Time();
        strlcpy(b.data,dest.c_str(),MAXBUF);
        if (*user->nick)
        {
@@ -106,21 +97,36 @@ std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *cha
        }
        else
        {
-               strlcpy(b.set_by,Config->ServerName,NICKMAX-1);
+               strlcpy(b.set_by,ServerInstance->Config->ServerName,NICKMAX-1);
        }
        chan->bans.push_back(b);
        return dest;
 }
 
+ModePair ModeChannelBan::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
+{
+       for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
+       {
+               if (!strcasecmp(i->data,parameter.c_str()))
+               {
+                       return std::make_pair(true, i->data);
+               }
+       }
+        return std::make_pair(false, parameter);
+}
+
 std::string& ModeChannelBan::DelBan(userrec *user,std::string& dest,chanrec *chan,int status)
 {
        if ((!user) || (!chan))
        {
-               log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
+               ServerInstance->Log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
                dest = "";
                return dest;
        }
 
+       /* 'Clean' the mask, e.g. nick -> nick!*@* */
+       ModeParser::CleanMask(dest);
+
        for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
        {
                if (!strcasecmp(i->data,dest.c_str()))