]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modes/cmode_b.cpp
...because every now and again, i have to do a massive commit.
[user/henk/code/inspircd.git] / src / modes / cmode_b.cpp
index 8c1c2cd63e7c4b9e0e41205ba946398c26eb8256..5fcebfde961ff2c43043c40a78c1e1322bea7018 100644 (file)
@@ -1,32 +1,38 @@
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
+ *
+ * This program is free but copyrighted software; see
+ *            the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
+#include "inspircd.h"
 #include <string>
 #include <vector>
 #include "inspircd_config.h"
 #include "configreader.h"
 #include "hash_map.h"
-#include "inspircd.h"
 #include "mode.h"
 #include "channels.h"
 #include "users.h"
-#include "helperfuncs.h"
 #include "modules.h"
 #include "inspstring.h"
 #include "hashcomp.h"
 #include "modes/cmode_b.h"
 
-extern InspIRCd* ServerInstance;
-extern InspIRCd* ServerInstance;
-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() : ModeHandler(NULL, "ban", 'b', PARAM_ALWAYS, MODETYPE_CHANNEL)
 {
+       list = true;
 }
 
-ModeAction ModeChannelBan::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
+ModeAction ModeChannelBan::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
 {
-       int status = channel->GetStatus(source);
+       int status = channel->GetPrefixValue(source);
        /* Call the correct method depending on wether we're adding or removing the mode */
        if (adding)
        {
@@ -44,22 +50,54 @@ ModeAction ModeChannelBan::OnModeChange(userrec* source, userrec* dest, chanrec*
        return MODEACTION_ALLOW;
 }
 
-void ModeChannelBan::DisplayList(userrec* user, chanrec* channel)
+void ModeChannelBan::RemoveMode(Channel* channel, irc::modestacker* stack)
 {
-       /* Display the channel banlist */
+       BanList copy;
+
        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);
+               copy.push_back(*i);
+       }
+
+       for (BanList::iterator i = copy.begin(); i != copy.end(); i++)
+       {
+               if (stack)
+               {
+                       stack->Push(this->GetModeChar(), i->data);
+               }
+               else
+               {
+                       std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-b"); parameters.push_back(i->data);
+                       ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
+               }
+       }
+}
+
+void ModeChannelBan::RemoveMode(User*, irc::modestacker* stack)
+{
+}
+
+void ModeChannelBan::DisplayList(User* user, Channel* channel)
+{
+       /* Display the channel banlist */
+       for (BanList::reverse_iterator i = channel->bans.rbegin(); i != channel->bans.rend(); ++i)
+       {
+               user->WriteServ("367 %s %s %s %s %lu",user->nick.c_str(), channel->name.c_str(), i->data.c_str(), i->set_by.c_str(), (unsigned long)i->set_time);
        }
-       user->WriteServ("368 %s %s :End of channel ban list",user->nick, channel->name);
+       user->WriteServ("368 %s %s :End of channel ban list",user->nick.c_str(), channel->name.c_str());
        return;
 }
 
-std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *chan,int status)
+void ModeChannelBan::DisplayEmptyList(User* user, Channel* channel)
+{
+       user->WriteServ("368 %s %s :End of channel ban list",user->nick.c_str(), channel->name.c_str());
+}
+
+std::string& ModeChannelBan::AddBan(User *user, std::string &dest, Channel *chan, int)
 {
        if ((!user) || (!chan))
        {
-               log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
+               ServerInstance->Logs->Log("MODE",DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
                dest = "";
                return dest;
        }
@@ -71,16 +109,16 @@ std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *cha
                return dest;
 
        long maxbans = chan->GetMaxBans();
-       if ((unsigned)chan->bans.size() > (unsigned)maxbans)
+       if (!IS_LOCAL(user) && ((unsigned)chan->bans.size() > (unsigned)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);
+               user->WriteServ("478 %s %s :Channel ban list for %s is full (maximum entries for this channel is %ld)",user->nick.c_str(), chan->name.c_str(), chan->name.c_str(), maxbans);
                dest = "";
                return dest;
        }
 
-       int MOD_RESULT = 0;
-       FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));
-       if (MOD_RESULT)
+       ModResult MOD_RESULT;
+       FIRST_MOD_RESULT(OnAddBan, MOD_RESULT, (user,chan,dest));
+       if (MOD_RESULT == MOD_RES_DENY)
        {
                dest = "";
                return dest;
@@ -88,7 +126,7 @@ std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *cha
 
        for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
        {
-               if (!strcasecmp(i->data,dest.c_str()))
+               if (i->data == dest)
                {
                        /* dont allow a user to set the same ban twice */
                        dest = "";
@@ -96,37 +134,18 @@ std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *cha
                }
        }
 
-       b.set_time = TIME;
-       strlcpy(b.data,dest.c_str(),MAXBUF);
-       if (*user->nick)
-       {
-               strlcpy(b.set_by,user->nick,NICKMAX-1);
-       }
-       else
-       {
-               strlcpy(b.set_by,ServerInstance->Config->ServerName,NICKMAX-1);
-       }
+       b.set_time = ServerInstance->Time();
+       b.data.assign(dest, 0, MAXBUF);
+       b.set_by.assign(user->nick, 0, 64);
        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)
+std::string& ModeChannelBan::DelBan(User *user, std::string& dest, Channel *chan, int)
 {
        if ((!user) || (!chan))
        {
-               log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
+               ServerInstance->Logs->Log("MODE",DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
                dest = "";
                return dest;
        }
@@ -136,11 +155,11 @@ std::string& ModeChannelBan::DelBan(userrec *user,std::string& dest,chanrec *cha
 
        for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
        {
-               if (!strcasecmp(i->data,dest.c_str()))
+               if (!strcasecmp(i->data.c_str(), dest.c_str()))
                {
-                       int MOD_RESULT = 0;
-                       FOREACH_RESULT(I_OnDelBan,OnDelBan(user,chan,dest));
-                       if (MOD_RESULT)
+                       ModResult MOD_RESULT;
+                       FIRST_MOD_RESULT(OnDelBan, MOD_RESULT, (user, chan, dest));
+                       if (MOD_RESULT == MOD_RES_DENY)
                        {
                                dest = "";
                                return dest;