]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_banexception.cpp
More stuff so that freebsd users can still use the ports version of openssl if they...
[user/henk/code/inspircd.git] / src / modules / m_banexception.cpp
index 8a73e607072400b4a6680246e03afcc51ca99a02..7c33e489e80881df653038967ba4f6d61fa57568 100644 (file)
@@ -1 +1,147 @@
-/*       +------------------------------------+\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
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
+ * This program is free but copyrighted software; see
+ *            the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
+#include "inspircd.h"
+#include "u_listmode.h"
+#include "wildcard.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(InspIRCd* Instance) : ListModeBase(Instance, 'e', "End of Channel Exception List", "348", "349", true) { }
+};
+
+
+class ModuleBanException : public Module
+{
+       BanException* be;
+       
+
+public:
+       ModuleBanException(InspIRCd* Me) : Module(Me)
+       {
+               be = new BanException(ServerInstance);
+               if (!ServerInstance->Modes->AddMode(be))
+                       throw ModuleException("Could not add new modes!");
+               ServerInstance->Modules->PublishInterface("ChannelBanList", this);
+
+               be->DoImplements(this);
+               Implementation list[] = { I_OnRehash, I_OnRequest, I_On005Numeric, I_OnCheckBan };
+               Me->Modules->Attach(list, this, 4);
+
+       }
+       
+       virtual void On005Numeric(std::string &output)
+       {
+               output.append(" EXCEPTS=e");
+       }
+
+       virtual int OnCheckBan(User* user, Channel* chan)
+       {
+               if (chan != NULL)
+               {
+                       modelist* list;
+                       chan->GetExt(be->GetInfoKey(), list);
+                       
+                       if (list)
+                       {
+                               char mask[MAXBUF];
+                               snprintf(mask, MAXBUF, "%s!%s@%s", user->nick, user->ident, user->GetIPString());
+                               for (modelist::iterator it = list->begin(); it != list->end(); it++)
+                               {
+                                       if (match(user->GetFullRealHost(), it->mask.c_str()) || match(user->GetFullHost(), it->mask.c_str()) || (match(mask, it->mask.c_str(), true)))
+                                       {
+                                               // They match an entry on the list, so let them in.
+                                               return 1;
+                                       }
+                               }
+                               return 0;
+                       }
+                       // or if there wasn't a list, there can't be anyone on it, so we don't need to do anything.
+               }
+               return 0;       
+       }
+
+       virtual void OnCleanup(int target_type, void* item)
+       {
+               be->DoCleanup(target_type, item);
+       }
+
+       virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
+       {
+               be->DoSyncChannel(chan, proto, opaque);
+       }
+
+       virtual void OnChannelDelete(Channel* chan)
+       {
+               be->DoChannelDelete(chan);
+       }
+
+       virtual void OnRehash(User* user, const std::string &param)
+       {
+               be->DoRehash();
+       }
+
+       virtual const char* OnRequest(Request* request)
+       {
+               ListModeRequest* LM = (ListModeRequest*)request;
+               if (strcmp("LM_CHECKLIST", request->GetId()) == 0)
+               {
+                       modelist* list;
+                       LM->chan->GetExt(be->GetInfoKey(), list);
+                       if (list)
+                       {
+                               char mask[MAXBUF];
+                               snprintf(mask, MAXBUF, "%s!%s@%s", LM->user->nick, LM->user->ident, LM->user->GetIPString());
+                               for (modelist::iterator it = list->begin(); it != list->end(); it++)
+                               {
+                                       if (match(LM->user->GetFullRealHost(), it->mask.c_str()) || match(LM->user->GetFullHost(), it->mask.c_str()) || (match(mask, it->mask.c_str(), true)))
+                                       {
+                                               // They match an entry
+                                               return (char*)it->mask.c_str();
+                                       }
+                               }
+                               return NULL;
+                       }
+               }
+               return NULL;
+       }
+
+       virtual Version GetVersion()
+       {
+               return Version(1, 2, 0, 3, VF_COMMON | VF_VENDOR, API_VERSION);
+       }
+       
+       virtual ~ModuleBanException()
+       {
+               ServerInstance->Modes->DelMode(be);
+               delete be;
+               ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
+       }
+};
+
+MODULE_INIT(ModuleBanException)