]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Replace m_halfvoice with m_customprefix
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 20 Feb 2010 16:49:14 +0000 (16:49 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 20 Feb 2010 16:49:14 +0000 (16:49 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12503 e03df62e-2008-0410-955e-edbf42e46eb7

docs/modules.conf.example
include/base.h
src/modules/m_customprefix.cpp [new file with mode: 0644]
src/modules/m_halfvoice.cpp [deleted file]

index 02d80431d82ab73ca28e32dd2ce69b727efdd513..945d54fcd3366841d105e0bc5e27b5e8401914c6 100644 (file)
 #<connflood seconds="30" maxconns="3" timeout="30"
 #   quitmsg="Throttled" bootwait="10">
 
+#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
+# Custom prefixes : allows for channel prefixes to be added. 
+# This replaces m_chanprotect and m_halfop
+#<module name="m_customprefix.so">
+#
+# name       The name of the mode, must be unique from other modes
+# letter     The letter used for this mode. Required.
+# prefix     The prefix used for nicks with this mode. Not required.
+# rank       A numeric rank for this prefix, defining what permissions it gives
+#            VOICE_VALUE is 10000, HALFOP_VALUE is 20000, OP_VALUE is 30000
+# ranktoset  The numeric rank required to set/unset this mode. Defaults to rank.
+# depriv     Can you remove the mode from yourself? Defaults to yes.
+#<customprefix name="founder" letter="q" prefix="~" rank="50000" ranktoset="50000">
+#<customprefix name="admin" letter="a" prefix="&" rank="40000" ranktoset="50000">
+#<customprefix name="halfop" letter="h" prefix="%" rank="20000" ranktoset="30000">
+<customprefix name="halfvoice" letter="V" prefix="-" rank="1" ranktoset="20000">
+
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
 # Custom title module: Adds the /TITLE command which allows for trusted
 #                      users to gain a custom whois line and a optional
 # Halfop module: Provides the +h (halfops) channel status mode.
 #<module name="m_halfop.so">
 
-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
-# Status prefix: Adds the channel status mode +V
-#<module name="m_halfvoice.so">
-
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
 # HELPOP module: Provides the /HELPOP command
 #<module name="m_helpop.so">
index e75b4029fe27903f56b03617a57ed264c1f37c0d..8d8f7b96cf5d6997c9e4a04f563b19c30a0f74f2 100644 (file)
@@ -150,14 +150,13 @@ class reference
  */
 class CoreExport CoreException : public std::exception
 {
- protected:
+ public:
        /** Holds the error message to be displayed
         */
        const std::string err;
        /** Source of the exception
         */
        const std::string source;
- public:
        /** Default constructor, just uses the error mesage 'Core threw an exception'.
         */
        CoreException() : err("Core threw an exception"), source("The core") {}
diff --git a/src/modules/m_customprefix.cpp b/src/modules/m_customprefix.cpp
new file mode 100644 (file)
index 0000000..e31ca52
--- /dev/null
@@ -0,0 +1,133 @@
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  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.
+ *
+ * ---------------------------------------------------
+ */
+
+#include "inspircd.h"
+
+/* $ModDesc: Allows custom prefix modes to be created. */
+
+class CustomPrefixMode : public ModeHandler
+{
+ public:
+       reference<ConfigTag> tag;
+       int rank;
+       bool depriv;
+       CustomPrefixMode(Module* parent, ConfigTag* Tag)
+               : ModeHandler(parent, Tag->getString("name"), 0, PARAM_ALWAYS, MODETYPE_CHANNEL), tag(Tag)
+       {
+               list = true;
+               m_paramtype = TR_NICK;
+               std::string v = tag->getString("prefix");
+               prefix = v.c_str()[0];
+               v = tag->getString("letter");
+               mode = v.c_str()[0];
+               rank = tag->getInt("rank");
+               levelrequired = tag->getInt("ranktoset", rank);
+               depriv = tag->getBool("depriv", true);
+       }
+
+       unsigned int GetPrefixRank()
+       {
+               return rank;
+       }
+
+       ModResult AccessCheck(User* src, Channel*, std::string& value, bool adding)
+       {
+               if (!adding && src->nick == value && depriv)
+                       return MOD_RES_ALLOW;
+               return MOD_RES_PASSTHRU;
+       }
+
+       void RemoveMode(Channel* channel, irc::modestacker* stack)
+       {
+               const UserMembList* cl = channel->GetUsers();
+               std::vector<std::string> mode_junk;
+               mode_junk.push_back(channel->name);
+               irc::modestacker modestack(false);
+               std::deque<std::string> stackresult;
+
+               for (UserMembCIter i = cl->begin(); i != cl->end(); i++)
+               {
+                       if (i->second->hasMode(mode))
+                       {
+                               if (stack)
+                                       stack->Push(this->GetModeChar(), i->first->nick);
+                               else
+                                       modestack.Push(this->GetModeChar(), i->first->nick);
+                       }
+               }
+
+               if (stack)
+                       return;
+
+               while (modestack.GetStackedLine(stackresult))
+               {
+                       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());
+               }
+       }
+
+       void RemoveMode(User* user, irc::modestacker* stack)
+       {
+       }
+
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
+       {
+               return MODEACTION_ALLOW;
+       }
+};
+
+class ModuleCustomPrefix : public Module
+{
+       std::vector<CustomPrefixMode*> modes;
+ public:
+       ModuleCustomPrefix()
+       {
+       }
+
+       void init()
+       {
+               ConfigTagList tags = ServerInstance->Config->ConfTags("customprefix");
+               while (tags.first != tags.second)
+               {
+                       ConfigTag* tag = tags.first->second;
+                       CustomPrefixMode* mh = new CustomPrefixMode(this, tag);
+                       modes.push_back(mh);
+                       if (mh->rank <= 0)
+                               throw ModuleException("Rank must be specified for prefix at " + tag->getTagLocation());
+                       if (!isalpha(mh->GetModeChar()))
+                               throw ModuleException("Mode must be a letter for prefix at " + tag->getTagLocation());
+                       try
+                       {
+                               ServerInstance->Modules->AddService(*mh);
+                       }
+                       catch (ModuleException& e)
+                       {
+                               throw ModuleException(e.err + " (while creating mode from " + tag->getTagLocation() + ")");
+                       }
+               }
+       }
+
+       ~ModuleCustomPrefix()
+       {
+               for (std::vector<CustomPrefixMode*>::iterator i = modes.begin(); i != modes.end(); i++)
+                       delete *i;
+       }
+
+       Version GetVersion()
+       {
+               return Version("Provides custom prefix channel modes", VF_VENDOR);
+       }
+};
+
+MODULE_INIT(ModuleCustomPrefix)
diff --git a/src/modules/m_halfvoice.cpp b/src/modules/m_halfvoice.cpp
deleted file mode 100644 (file)
index c961d7c..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
- *
- *  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.
- *
- * ---------------------------------------------------
- */
-
-#include "inspircd.h"
-
-/* $ModDesc: Provides channel mode +V, adding the - prefix
- *  which does nothing but serves as a status symbol. */
-
-#define HALFVOICE_VALUE 1
-
-class HalfVoiceMode : public ModeHandler
-{
- public:
-       HalfVoiceMode(Module* parent) : ModeHandler(parent, "halfvoice", 'V', PARAM_ALWAYS, MODETYPE_CHANNEL)
-       {
-               list = true;
-               prefix = 0;
-               levelrequired = HALFOP_VALUE;
-               m_paramtype = TR_NICK;
-       }
-
-       void SetPrefix(char pfx) { prefix = pfx; }
-
-       unsigned int GetPrefixRank()
-       {
-               return HALFVOICE_VALUE;
-       }
-
-       void RemoveMode(Channel* channel, irc::modestacker* stack)
-       {
-               const UserMembList* cl = channel->GetUsers();
-               std::vector<std::string> mode_junk;
-               mode_junk.push_back(channel->name);
-               irc::modestacker modestack(false);
-               std::deque<std::string> stackresult;
-
-               for (UserMembCIter i = cl->begin(); i != cl->end(); i++)
-               {
-                       if (i->second->hasMode('V'))
-                       {
-                               if (stack)
-                                       stack->Push(this->GetModeChar(), i->first->nick);
-                               else
-                                       modestack.Push(this->GetModeChar(), i->first->nick);
-                       }
-               }
-
-               if (stack)
-                       return;
-
-               while (modestack.GetStackedLine(stackresult))
-               {
-                       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());
-               }
-       }
-
-       void RemoveMode(User* user, irc::modestacker* stack)
-       {
-       }
-
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
-       {
-               return MODEACTION_ALLOW;
-       }
-};
-
-class ModuleHalfVoice : public Module
-{
-       HalfVoiceMode mh;
-
- public:
-       ModuleHalfVoice() : mh(this)
-       {
-       }
-
-       void init()
-       {
-               ConfigTag* tag = ServerInstance->Config->ConfValue("halfvoice");
-               std::string pfxchar = tag->getString("prefix", "-");
-               mh.SetPrefix(pfxchar[0]);
-               ServerInstance->Modules->AddService(mh);
-       }
-
-       Version GetVersion()
-       {
-               return Version("Provides a channel mode that does nothing but serve as a status symbol", VF_VENDOR);
-       }
-};
-
-MODULE_INIT(ModuleHalfVoice)