]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_banredirect.cpp
Add IP address conversion utility functions, irc::sockets::aptosa and irc::sockets...
[user/henk/code/inspircd.git] / src / modules / m_banredirect.cpp
index ffb263ff7743c14218ddb44e646964686370643e..2269f24216ddb5de6a6d6467a9e8b3c0049b08c1 100644 (file)
@@ -2,8 +2,8 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
@@ -15,8 +15,9 @@
 #include "u_listmode.h"
 
 /* $ModDesc: Allows an extended ban (+b) syntax redirecting banned users to another channel */
+/* $ModDep: ../../include/u_listmode.h */
 
-/* Originally written by Om, January 2008
+/* Originally written by Om, January 2009
  */
 
 class BanRedirectEntry : public classbase
@@ -36,11 +37,9 @@ typedef std::deque<std::string> StringDeque;
 
 class BanRedirect : public ModeWatcher
 {
- private:
-       InspIRCd* Srv;
  public:
        BanRedirect(InspIRCd* Instance)
-       : ModeWatcher(Instance, 'b', MODETYPE_CHANNEL), Srv(Instance)
+       : ModeWatcher(Instance, 'b', MODETYPE_CHANNEL)
        {
        }
 
@@ -62,6 +61,9 @@ class BanRedirect : public ModeWatcher
                        std::string::iterator start_pos = param.begin();
                        long maxbans = channel->GetMaxBans();
 
+                       if (param.length() >= 2 && param[1] == ':')
+                               return true;
+
                        if(adding && (channel->bans.size() > static_cast<unsigned>(maxbans)))
                        {
                                source->WriteNumeric(478, "%s %s :Channel ban list for %s is full (maximum entries for this channel is %ld)", source->nick.c_str(), channel->name.c_str(), channel->name.c_str(), maxbans);
@@ -114,7 +116,7 @@ class BanRedirect : public ModeWatcher
 
                        if(mask[CHAN].length())
                        {
-                               if(!IS_LOCAL(source) || Srv->IsChannel(mask[CHAN].c_str(), ServerInstance->Config->Limits.ChanMax))
+                               if(!IS_LOCAL(source) || ServerInstance->IsChannel(mask[CHAN].c_str(), ServerInstance->Config->Limits.ChanMax))
                                {
                                        if (assign(channel->name) == mask[CHAN])
                                        {
@@ -238,12 +240,9 @@ class ModuleBanRedirect : public Module
 
                                while(modestack.GetStackedLine(stackresult))
                                {
-                                       for(StringDeque::size_type i = 0; i < stackresult.size(); i++)
-                                       {
-                                               mode_junk.push_back(stackresult[i]);
-                                       }
-
+                                       mode_junk.insert(mode_junk.end(), stackresult.begin(), stackresult.end());
                                        ServerInstance->SendMode(mode_junk, ServerInstance->FakeClient);
+                                       mode_junk.erase(mode_junk.begin() + 1, mode_junk.end());
                                }
 
                                delete redirects;
@@ -291,7 +290,7 @@ class ModuleBanRedirect : public Module
 
                                for(BanRedirectList::iterator redir = redirects->begin(); redir != redirects->end(); redir++)
                                {
-                                       if(ServerInstance->MatchText(user->GetFullRealHost(), redir->banmask) || ServerInstance->MatchText(user->GetFullHost(), redir->banmask) || ServerInstance->MatchText(ipmask, redir->banmask))
+                                       if(InspIRCd::Match(user->GetFullRealHost(), redir->banmask) || InspIRCd::Match(user->GetFullHost(), redir->banmask) || InspIRCd::MatchCIDR(ipmask, redir->banmask))
                                        {
                                                /* tell them they're banned and are being transferred */
                                                Channel* destchan = ServerInstance->FindChan(redir->targetchan);
@@ -308,7 +307,7 @@ class ModuleBanRedirect : public Module
                                                else
                                                {
                                                        user->WriteNumeric(474, "%s %s :Cannot join channel (You are banned)", user->nick.c_str(), chan->name.c_str());
-                                                       user->WriteNumeric(470, "%s :You are being automatically redirected to %s", user->nick.c_str(), redir->targetchan.c_str());
+                                                       user->WriteNumeric(470, "%s %s %s :You are banned from this channel, so you are automatically transfered to the redirected channel.", user->nick.c_str(), chan->name.c_str(), redir->targetchan.c_str());
                                                        nofollow = true;
                                                        Channel::JoinUser(ServerInstance, user, redir->targetchan.c_str(), false, "", false, ServerInstance->Time());
                                                        nofollow = false;
@@ -329,13 +328,13 @@ class ModuleBanRedirect : public Module
 
        virtual Version GetVersion()
        {
-               return Version(1, 0, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
+               return Version("$Id$", VF_COMMON|VF_VENDOR, API_VERSION);
        }
 
        void Prioritize()
        {
                Module* banex = ServerInstance->Modules->Find("m_banexception.so");
-               ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIO_BEFORE, &banex);
+               ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_BEFORE, &banex);
        }
 };