]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_nonotice.cpp
Fix mistakenly using Clang instead of GCC on older FreeBSD versions.
[user/henk/code/inspircd.git] / src / modules / m_nonotice.cpp
index fd4c474cb42d7eb35347db6d741baa130952110c..c5b9f3a1c784f6dd894a4ec6b6d5237705826f73 100644 (file)
@@ -1 +1,85 @@
-/*       +------------------------------------+\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\r/* $ModDesc: Provides support for unreal-style channel mode +T */\r\rclass NoNotice : public ModeHandler\r{\r public:\r    NoNotice(InspIRCd* Instance) : ModeHandler(Instance, 'T', 0, 0, false, MODETYPE_CHANNEL, false) { }\r\r   ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)\r {\r              if (adding)\r            {\r                      if (!channel->IsModeSet('T'))\r                  {\r                              channel->SetMode('T',true);\r                            return MODEACTION_ALLOW;\r                       }\r              }\r              else\r           {\r                      if (channel->IsModeSet('T'))\r                   {\r                              channel->SetMode('T',false);\r                           return MODEACTION_ALLOW;\r                       }\r              }\r\r             return MODEACTION_DENY;\r        }\r};\r\rclass ModuleNoNotice : public Module\r{\r   \r       NoNotice* nt;\r public:\r \r       ModuleNoNotice(InspIRCd* Me)\r           : Module(Me)\r   {\r              \r               nt = new NoNotice(ServerInstance);\r             if (!ServerInstance->AddMode(nt, 'T'))\r                 throw ModuleException("Could not add new modes!");\r     }\r\r     void Implements(char* List)\r    {\r              List[I_OnUserPreNotice] = 1;\r   }\r      \r       virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)\r     {\r              if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))\r         {\r                      chanrec* c = (chanrec*)dest;\r                   if (c->IsModeSet('T'))\r                 {\r                              if ((ServerInstance->ULine(user->server)) || (c->GetStatus(user) == STATUS_OP) || (c->GetStatus(user) == STATUS_HOP))\r                          {\r                                      // ops and halfops can still /NOTICE the channel\r                                       return 0;\r                              }\r                              else\r                           {\r                                      user->WriteServ("404 %s %s :Can't send NOTICE to channel (+T set)",user->nick, c->name);\r                                       return 1;\r                              }\r                      }\r              }\r              return 0;\r      }\r\r     virtual ~ModuleNoNotice()\r      {\r              ServerInstance->Modes->DelMode(nt);\r            DELETE(nt);\r    }\r      \r       virtual Version GetVersion()\r   {\r              return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);\r       }\r};\r\rMODULE_INIT(ModuleNoNotice)\r
\ No newline at end of file
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2004, 2008 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
+ *
+ * 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"
+
+/* $ModDesc: Provides channel mode +T to block notices to the channel */
+
+class NoNotice : public SimpleChannelModeHandler
+{
+ public:
+       NoNotice(Module* Creator) : SimpleChannelModeHandler(Creator, "nonotice", 'T') { }
+};
+
+class ModuleNoNotice : public Module
+{
+       NoNotice nt;
+ public:
+
+       ModuleNoNotice()
+               : nt(this)
+       {
+       }
+
+       void init()
+       {
+               ServerInstance->Modules->AddService(nt);
+               Implementation eventlist[] = { I_OnUserPreNotice, I_On005Numeric };
+               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
+       }
+
+       virtual void On005Numeric(std::string &output)
+       {
+               ServerInstance->AddExtBanChar('T');
+       }
+
+       virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
+       {
+               ModResult res;
+               if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
+               {
+                       Channel* c = (Channel*)dest;
+                       if (!c->GetExtBanStatus(user, 'T').check(!c->IsModeSet('T')))
+                       {
+                               res = ServerInstance->OnCheckExemption(user,c,"nonotice");
+                               if (res == MOD_RES_ALLOW)
+                                       return MOD_RES_PASSTHRU;
+                               else
+                               {
+                                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, "%s %s :Can't send NOTICE to channel (+T set)",user->nick.c_str(), c->name.c_str());
+                                       return MOD_RES_DENY;
+                               }
+                       }
+               }
+               return MOD_RES_PASSTHRU;
+       }
+
+       virtual ~ModuleNoNotice()
+       {
+       }
+
+       virtual Version GetVersion()
+       {
+               return Version("Provides channel mode +T to block notices to the channel", VF_VENDOR);
+       }
+};
+
+MODULE_INIT(ModuleNoNotice)