]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_banexception.cpp
Switch <stdint.h> test to use a test file too.
[user/henk/code/inspircd.git] / src / modules / m_banexception.cpp
index 8a73e607072400b4a6680246e03afcc51ca99a02..1811f743de59e5dd7fc64124b1d66ba5ccb9cb32 100644 (file)
@@ -1 +1,136 @@
-/*       +------------------------------------+\r *       | Inspire Internet Relay Chat Daemon |\r *       +------------------------------------+\r *\r *  InspIRCd: (C) 2002-2007 InspIRCd Development Team\r * See: http://www.inspircd.org/wiki/index.php/Credits\r *\r * This program is free but copyrighted software; see\r *            the file COPYING for details.\r *\r * ---------------------------------------------------\r */\r\r#include "inspircd.h"\r#include "users.h"\r#include "channels.h"\r#include "modules.h"\r#include "mode.h"\r#include "u_listmode.h"\r#include "wildcard.h"\r\r/* $ModDesc: Provides support for the +e channel mode */\r/* $ModDep: ../../include/u_listmode.h */\r\r/* Written by Om<om@inspircd.org>, April 2005. */\r/* Rewritten to use the listmode utility by Om, December 2005 */\r/* Adapted from m_exception, which was originally based on m_chanprotect and m_silence */\r\r// The +e channel mode takes a nick!ident@host, glob patterns allowed,\r// and if a user matches an entry on the +e list then they can join the channel, overriding any (+b) bans set on them\r// Now supports CIDR and IP addresses -- Brain\r\r\r/** Handles +e channel mode\r */\rclass BanException : public ListModeBase\r{\r public:\r  BanException(InspIRCd* Instance) : ListModeBase(Instance, 'e', "End of Channel Exception List", "348", "349", true) { }\r};\r\r\rclass ModuleBanException : public Module\r{\r        BanException* be;\r      \r\rpublic:\r      ModuleBanException(InspIRCd* Me)\r       : Module(Me)\r   {\r              be = new BanException(ServerInstance);\r         if (!ServerInstance->AddMode(be, 'e'))\r                 throw ModuleException("Could not add new modes!");\r             ServerInstance->PublishInterface("ChannelBanList", this);\r      }\r      \r       virtual void Implements(char* List)\r    {\r              be->DoImplements(List);\r                List[I_OnRehash] = List[I_OnRequest] = List[I_On005Numeric] = List[I_OnCheckBan] = 1;\r  }\r      \r       virtual void On005Numeric(std::string &output)\r {\r              output.append(" EXCEPTS=e");\r   }\r\r     virtual int OnCheckBan(userrec* user, chanrec* chan)\r   {\r              if (chan != NULL)\r              {\r                      modelist* list;\r                        chan->GetExt(be->GetInfoKey(), list);\r                  \r                       if (list)\r                      {\r                              char mask[MAXBUF];\r                             snprintf(mask, MAXBUF, "%s!%s@%s", user->nick, user->ident, user->GetIPString());\r                              for (modelist::iterator it = list->begin(); it != list->end(); it++)\r                           {\r                                      if (match(user->GetFullRealHost(), it->mask.c_str()) || match(user->GetFullHost(), it->mask.c_str()) || (match(mask, it->mask.c_str(), true)))\r                                 {\r                                              // They match an entry on the list, so let them in.\r                                            return 1;\r                                      }\r                              }\r                              return 0;\r                      }\r                      // or if there wasn't a list, there can't be anyone on it, so we don't need to do anything.\r            }\r              return 0;       \r       }\r\r     virtual void OnCleanup(int target_type, void* item)\r    {\r              be->DoCleanup(target_type, item);\r      }\r\r     virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque)\r {\r              be->DoSyncChannel(chan, proto, opaque);\r        }\r\r     virtual void OnChannelDelete(chanrec* chan)\r    {\r              be->DoChannelDelete(chan);\r     }\r\r     virtual void OnRehash(userrec* user, const std::string &param)\r {\r              be->DoRehash();\r        }\r\r     virtual char* OnRequest(Request* request)\r      {\r              ListModeRequest* LM = (ListModeRequest*)request;\r               if (strcmp("LM_CHECKLIST", request->GetId()) == 0)\r             {\r                      modelist* list;\r                        LM->chan->GetExt(be->GetInfoKey(), list);\r                      if (list)\r                      {\r                              char mask[MAXBUF];\r                             snprintf(mask, MAXBUF, "%s!%s@%s", LM->user->nick, LM->user->ident, LM->user->GetIPString());\r                          for (modelist::iterator it = list->begin(); it != list->end(); it++)\r                           {\r                                      if (match(LM->user->GetFullRealHost(), it->mask.c_str()) || match(LM->user->GetFullHost(), it->mask.c_str()) || (match(mask, it->mask.c_str(), true)))\r                                 {\r                                              // They match an entry\r                                         return (char*)it->mask.c_str();\r                                        }\r                              }\r                              return NULL;\r                   }\r              }\r              return NULL;\r   }\r\r     virtual Version GetVersion()\r   {\r              return Version(1, 1, 0, 3, VF_COMMON | VF_VENDOR, API_VERSION);\r        }\r      \r       virtual ~ModuleBanException()\r  {\r              ServerInstance->Modes->DelMode(be);\r            DELETE(be);\r            ServerInstance->UnpublishInterface("ChannelBanList", this);\r    }\r};\r\rMODULE_INIT(ModuleBanException)\r
\ No newline at end of file
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2006-2008 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "inspircd.h"
+#include "u_listmode.h"
+
+/* $ModDesc: Provides support for the +e channel mode */
+/* $ModDep: ../../include/u_listmode.h */
+
+/* Written by Om<om@inspircd.org>, April 2005. */
+/* Rewritten to use the listmode utility by Om, December 2005 */
+/* Adapted from m_exception, which was originally based on m_chanprotect and m_silence */
+
+// The +e channel mode takes a nick!ident@host, glob patterns allowed,
+// and if a user matches an entry on the +e list then they can join the channel, overriding any (+b) bans set on them
+// Now supports CIDR and IP addresses -- Brain
+
+
+/** Handles +e channel mode
+ */
+class BanException : public ListModeBase
+{
+ public:
+       BanException(Module* Creator) : ListModeBase(Creator, "banexception", 'e', "End of Channel Exception List", 348, 349, true) { }
+};
+
+
+class ModuleBanException : public Module
+{
+       BanException be;
+
+public:
+       ModuleBanException() : be(this)
+       {
+       }
+
+       void init()
+       {
+               ServerInstance->Modules->AddService(be);
+
+               be.DoImplements(this);
+               Implementation list[] = { I_OnRehash, I_On005Numeric, I_OnExtBanCheck, I_OnCheckChannelBan };
+               ServerInstance->Modules->Attach(list, this, sizeof(list)/sizeof(Implementation));
+       }
+
+       void On005Numeric(std::string &output)
+       {
+               output.append(" EXCEPTS=e");
+       }
+
+       ModResult OnExtBanCheck(User *user, Channel *chan, char type)
+       {
+               if (chan != NULL)
+               {
+                       modelist *list = be.extItem.get(chan);
+
+                       if (!list)
+                               return MOD_RES_PASSTHRU;
+
+                       for (modelist::iterator it = list->begin(); it != list->end(); it++)
+                       {
+                               if (it->mask[0] != type || it->mask[1] != ':')
+                                       continue;
+
+                               if (chan->CheckBan(user, it->mask.substr(2)))
+                               {
+                                       // They match an entry on the list, so let them pass this.
+                                       return MOD_RES_ALLOW;
+                               }
+                       }
+               }
+
+               return MOD_RES_PASSTHRU;
+       }
+
+       ModResult OnCheckChannelBan(User* user, Channel* chan)
+       {
+               if (chan)
+               {
+                       modelist *list = be.extItem.get(chan);
+
+                       if (!list)
+                       {
+                               // No list, proceed normally
+                               return MOD_RES_PASSTHRU;
+                       }
+
+                       for (modelist::iterator it = list->begin(); it != list->end(); it++)
+                       {
+                               if (chan->CheckBan(user, it->mask))
+                               {
+                                       // They match an entry on the list, so let them in.
+                                       return MOD_RES_ALLOW;
+                               }
+                       }
+               }
+               return MOD_RES_PASSTHRU;
+       }
+
+       void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
+       {
+               be.DoSyncChannel(chan, proto, opaque);
+       }
+
+       void OnRehash(User* user)
+       {
+               be.DoRehash();
+       }
+
+       Version GetVersion()
+       {
+               return Version("Provides support for the +e channel mode", VF_VENDOR);
+       }
+};
+
+MODULE_INIT(ModuleBanException)