]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Extract RFC modes from the core to core_channel and core_user.
authorPeter Powell <petpow@saberuk.com>
Sun, 3 Dec 2017 17:16:28 +0000 (17:16 +0000)
committerPeter Powell <petpow@saberuk.com>
Sun, 10 Dec 2017 12:38:45 +0000 (12:38 +0000)
22 files changed:
docs/Doxyfile
include/builtinmodes.h [deleted file]
include/mode.h
make/calcdep.pl
src/channels.cpp
src/configreader.cpp
src/coremods/core_channel/cmode_k.cpp [new file with mode: 0644]
src/coremods/core_channel/cmode_l.cpp [new file with mode: 0644]
src/coremods/core_channel/core_channel.cpp
src/coremods/core_channel/core_channel.h
src/coremods/core_user/core_user.cpp
src/coremods/core_user/core_user.h
src/coremods/core_user/umode_o.cpp [new file with mode: 0644]
src/coremods/core_user/umode_s.cpp [new file with mode: 0644]
src/inspircd.cpp
src/mode.cpp
src/modes/cmode_k.cpp [deleted file]
src/modes/cmode_l.cpp [deleted file]
src/modes/umode_o.cpp [deleted file]
src/modes/umode_s.cpp [deleted file]
src/modules/m_timedbans.cpp
win/CMakeLists.txt

index aa5a34ba6ae8c473e9d15139bc9581801703d52d..f835ab99634a54ff59c7a5ed9fb4c9d70aceebd3 100644 (file)
@@ -94,7 +94,6 @@ EXCLUDE_SYMLINKS       = YES
 EXCLUDE_PATTERNS       = */.git/* \
                          */doxygen/* \
                          */coremods/* \
-                         */modes/* \
                          */modules/*
 EXCLUDE_SYMBOLS        =
 EXAMPLE_PATH           =
diff --git a/include/builtinmodes.h b/include/builtinmodes.h
deleted file mode 100644 (file)
index 3bd3e25..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
- *
- * 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/>.
- */
-
-#pragma once
-
-#include "mode.h"
-#include "channels.h"
-#include "listmode.h"
-
-/** Channel mode +b
- */
-class ModeChannelBan : public ListModeBase
-{
- public:
-       ModeChannelBan()
-               : ListModeBase(NULL, "ban", 'b', "End of channel ban list", 367, 368, true, "maxbans")
-       {
-       }
-};
-
-/** Channel mode +k
- */
-class ModeChannelKey : public ParamMode<ModeChannelKey, LocalStringExt>
-{
-       static const std::string::size_type maxkeylen = 32;
- public:
-       ModeChannelKey();
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE;
-       void SerializeParam(Channel* chan, const std::string* key, std::string& out)    ;
-       ModeAction OnSet(User* source, Channel* chan, std::string& param) CXX11_OVERRIDE;
-};
-
-/** Channel mode +l
- */
-class ModeChannelLimit : public ParamMode<ModeChannelLimit, LocalIntExt>
-{
- public:
-       ModeChannelLimit();
-       bool ResolveModeConflict(std::string& their_param, const std::string& our_param, Channel* channel) CXX11_OVERRIDE;
-       void SerializeParam(Channel* chan, intptr_t n, std::string& out);
-       ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE;
-};
-
-/** Channel mode +o
- */
-class ModeChannelOp : public PrefixMode
-{
- public:
-       ModeChannelOp()
-               : PrefixMode(NULL, "op", 'o', OP_VALUE, '@')
-       {
-               ranktoset = ranktounset = OP_VALUE;
-       }
-};
-
-/** Channel mode +v
- */
-class ModeChannelVoice : public PrefixMode
-{
- public:
-       ModeChannelVoice()
-               : PrefixMode(NULL, "voice", 'v', VOICE_VALUE, '+')
-       {
-               selfremove = false;
-               ranktoset = ranktounset = HALFOP_VALUE;
-       }
-};
-
-/** User mode +s
- */
-class ModeUserServerNoticeMask : public ModeHandler
-{
-       /** Process a snomask modifier string, e.g. +abc-de
-        * @param user The target user
-        * @param input A sequence of notice mask characters
-        * @return The cleaned mode sequence which can be output,
-        * e.g. in the above example if masks c and e are not
-        * valid, this function will return +ab-d
-        */
-       std::string ProcessNoticeMasks(User* user, const std::string& input);
-
- public:
-       ModeUserServerNoticeMask();
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding) CXX11_OVERRIDE;
-       void OnParameterMissing(User* user, User* dest, Channel* channel) CXX11_OVERRIDE;
-
-       /** Create a displayable mode string of the snomasks set on a given user
-        * @param user The user whose notice masks to format
-        * @return The notice mask character sequence
-        */
-       std::string GetUserParameter(const User* user) const CXX11_OVERRIDE;
-};
-
-/** User mode +o
- */
-class ModeUserOperator : public ModeHandler
-{
- public:
-       ModeUserOperator();
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding) CXX11_OVERRIDE;
-};
index f944da62c7a0f1be90f6a37f7dc130720f9f94fb..ccbfe6f28b6ff93af0682db98e7ad05a4853a14a 100644 (file)
@@ -661,10 +661,6 @@ class CoreExport ModeParser : public fakederef<ModeParser>
        ModeParser();
        ~ModeParser();
 
-       /** Initialize all built-in modes
-        */
-       static void InitBuiltinModes();
-
        static bool IsModeChar(char chr);
 
        /** Tidy a banmask. This makes a banmask 'acceptable' if fields are left out.
index 3b4ae6b0d7041b3f149489f847504bdcd0330289..f3ed04725b011f57e99d6d82bb48d517e0d945a8 100755 (executable)
@@ -83,7 +83,7 @@ all: inspircd modules
 
 END
        my(@core_deps, @modlist);
-       for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, "threadengines/threadengine_pthread.cpp") {
+       for my $file (<*.cpp>, <socketengines/*.cpp>, "threadengines/threadengine_pthread.cpp") {
                my $out = find_output $file;
                dep_cpp $file, $out, 'gen-o';
                next if $file =~ m#^socketengines/# && $file ne "socketengines/socketengine_$ENV{SOCKETENGINE}.cpp";
@@ -149,7 +149,7 @@ all: inspircd
 
 END
        my(@deps, @srcs);
-       for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, <coremods/*.cpp>, <coremods/core_*/*.cpp>,
+       for my $file (<*.cpp>, <socketengines/*.cpp>, <coremods/*.cpp>, <coremods/core_*/*.cpp>,
                        <modules/*.cpp>, <modules/m_*/*.cpp>, "threadengines/threadengine_pthread.cpp") {
                my $out = find_output $file, 1;
                if ($out =~ m#obj/([^/]+)/[^/]+.o$#) {
index 118a413a86c5e053cd402b02aa236181ca6589b1..3bc58505c83f1edd0d979407637cacd0bbacc090 100644 (file)
@@ -349,6 +349,9 @@ bool Channel::IsBanned(User* user)
                return (result == MOD_RES_DENY);
 
        ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
+       if (!banlm)
+               return false;
+
        const ListModeBase::ModeList* bans = banlm->GetList(this);
        if (bans)
        {
@@ -397,6 +400,9 @@ ModResult Channel::GetExtBanStatus(User *user, char type)
                return rv;
 
        ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
+       if (!banlm)
+               return MOD_RES_PASSTHRU;
+
        const ListModeBase::ModeList* bans = banlm->GetList(this);
        if (bans)
        {
index 18b62fb0943875fabd277bc19c894dd4293ba284..ff9d5bd141dafa02a3d9cf0085b0fc00104fda21 100644 (file)
@@ -809,8 +809,6 @@ void ConfigReaderThread::Finish()
                ServerInstance->Users.RehashCloneCounts();
                ServerInstance->XLines->CheckELines();
                ServerInstance->XLines->ApplyLines();
-               ChanModeReference ban(NULL, "ban");
-               static_cast<ListModeBase*>(*ban)->DoRehash();
                Config->ApplyDisabledCommands();
                User* user = ServerInstance->FindNick(TheUserUID);
 
diff --git a/src/coremods/core_channel/cmode_k.cpp b/src/coremods/core_channel/cmode_k.cpp
new file mode 100644 (file)
index 0000000..9bab052
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
+ *
+ * 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 "core_channel.h"
+
+ModeChannelKey::ModeChannelKey(Module* Creator)
+       : ParamMode<ModeChannelKey, LocalStringExt>(Creator, "key", 'k', PARAM_ALWAYS)
+{
+}
+
+ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
+{
+       const std::string* key = ext.get(channel);
+       bool exists = (key != NULL);
+       if (IS_LOCAL(source))
+       {
+               if (exists == adding)
+                       return MODEACTION_DENY;
+               if (exists && (parameter != *key))
+               {
+                       /* Key is currently set and the correct key wasnt given */
+                       return MODEACTION_DENY;
+               }
+       } else {
+               if (exists && adding && parameter == *key)
+               {
+                       /* no-op, don't show */
+                       return MODEACTION_DENY;
+               }
+       }
+
+       channel->SetMode(this, adding);
+       if (adding)
+       {
+               if (parameter.length() > maxkeylen)
+                       parameter.erase(maxkeylen);
+               ext.set(channel, parameter);
+       }
+       else
+               ext.unset(channel);
+
+       return MODEACTION_ALLOW;
+}
+
+void ModeChannelKey::SerializeParam(Channel* chan, const std::string* key, std::string& out)
+{
+       out += *key;
+}
+
+ModeAction ModeChannelKey::OnSet(User* source, Channel* chan, std::string& param)
+{
+       // Dummy function, never called
+       return MODEACTION_DENY;
+}
diff --git a/src/coremods/core_channel/cmode_l.cpp b/src/coremods/core_channel/cmode_l.cpp
new file mode 100644 (file)
index 0000000..eb16fd1
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
+ *
+ * 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 "core_channel.h"
+
+ModeChannelLimit::ModeChannelLimit(Module* Creator)
+       : ParamMode<ModeChannelLimit, LocalIntExt>(Creator, "limit", 'l')
+{
+}
+
+bool ModeChannelLimit::ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel*)
+{
+       /* When TS is equal, the higher channel limit wins */
+       return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
+}
+
+ModeAction ModeChannelLimit::OnSet(User* user, Channel* chan, std::string& parameter)
+{
+       int limit = ConvToInt(parameter);
+       if (limit < 0)
+               return MODEACTION_DENY;
+
+       ext.set(chan, limit);
+       return MODEACTION_ALLOW;
+}
+
+void ModeChannelLimit::SerializeParam(Channel* chan, intptr_t n, std::string& out)
+{
+       out += ConvToStr(n);
+}
index 3af809645e8fbb4fa8110d4b4aa218ae18a0c27b..af71e2ced19792e098f171cbb998508e9b868513 100644 (file)
@@ -30,6 +30,19 @@ class CoreModChannel : public Module, public CheckExemption::EventListener
        CommandKick cmdkick;
        CommandNames cmdnames;
        CommandTopic cmdtopic;
+
+       ModeChannelBan banmode;
+       SimpleChannelModeHandler inviteonlymode;
+       ModeChannelKey keymode;
+       ModeChannelLimit limitmode;
+       SimpleChannelModeHandler moderatedmode;
+       SimpleChannelModeHandler noextmsgmode;
+       ModeChannelOp opmode;
+       SimpleChannelModeHandler privatemode;
+       SimpleChannelModeHandler secretmode;
+       SimpleChannelModeHandler topiclockmode;
+       ModeChannelVoice voicemode;
+
        insp::flat_map<std::string, char> exemptions;
 
        ModResult IsInvited(User* user, Channel* chan)
@@ -49,6 +62,17 @@ class CoreModChannel : public Module, public CheckExemption::EventListener
                , cmdkick(this)
                , cmdnames(this)
                , cmdtopic(this)
+               , banmode(this)
+               , inviteonlymode(this, "inviteonly", 'i')
+               , keymode(this)
+               , limitmode(this)
+               , moderatedmode(this, "moderated", 'm')
+               , noextmsgmode(this, "noextmsg", 'n')
+               , opmode(this)
+               , privatemode(this, "private", 'p')
+               , secretmode(this, "secret", 's')
+               , topiclockmode(this, "topiclock", 't')
+               , voicemode(this)
        {
        }
 
@@ -80,6 +104,7 @@ class CoreModChannel : public Module, public CheckExemption::EventListener
                        exempts[restriction] = prefix;
                }
                exemptions.swap(exempts);
+               banmode.DoRehash();
        }
 
        void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
index 46def3e7bb502435bad369ab33c0ca1c41248d73..fa600cd17e984667d530f5df5ab1538968250ea0 100644 (file)
@@ -2,6 +2,9 @@
  * InspIRCd -- Internet Relay Chat Daemon
  *
  *   Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
  *
  * 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
@@ -20,6 +23,7 @@
 #pragma once
 
 #include "inspircd.h"
+#include "listmode.h"
 #include "modules/exemption.h"
 
 namespace Topic
@@ -135,3 +139,62 @@ class CommandKick : public Command
        CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE;
        RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) CXX11_OVERRIDE;
 };
+
+/** Channel mode +b
+ */
+class ModeChannelBan : public ListModeBase
+{
+ public:
+       ModeChannelBan(Module* Creator)
+               : ListModeBase(Creator, "ban", 'b', "End of channel ban list", 367, 368, true, "maxbans")
+       {
+       }
+};
+
+/** Channel mode +k
+ */
+class ModeChannelKey : public ParamMode<ModeChannelKey, LocalStringExt>
+{
+       static const std::string::size_type maxkeylen = 32;
+ public:
+       ModeChannelKey(Module* Creator);
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE;
+       void SerializeParam(Channel* chan, const std::string* key, std::string& out)    ;
+       ModeAction OnSet(User* source, Channel* chan, std::string& param) CXX11_OVERRIDE;
+};
+
+/** Channel mode +l
+ */
+class ModeChannelLimit : public ParamMode<ModeChannelLimit, LocalIntExt>
+{
+ public:
+       ModeChannelLimit(Module* Creator);
+       bool ResolveModeConflict(std::string& their_param, const std::string& our_param, Channel* channel) CXX11_OVERRIDE;
+       void SerializeParam(Channel* chan, intptr_t n, std::string& out);
+       ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE;
+};
+
+/** Channel mode +o
+ */
+class ModeChannelOp : public PrefixMode
+{
+ public:
+       ModeChannelOp(Module* Creator)
+               : PrefixMode(Creator, "op", 'o', OP_VALUE, '@')
+       {
+               ranktoset = ranktounset = OP_VALUE;
+       }
+};
+
+/** Channel mode +v
+ */
+class ModeChannelVoice : public PrefixMode
+{
+ public:
+       ModeChannelVoice(Module* Creator)
+               : PrefixMode(Creator, "voice", 'v', VOICE_VALUE, '+')
+       {
+               selfremove = false;
+               ranktoset = ranktounset = HALFOP_VALUE;
+       }
+};
index 5068bd4aaff70ad04bd1eb75721aa4082c169ae9..8504de8e0e969e8426c0c6699e6b3bc49bf60f21 100644 (file)
@@ -147,11 +147,24 @@ class CoreModUser : public Module
        CommandPong cmdpong;
        CommandQuit cmdquit;
        CommandUser cmduser;
+       SimpleUserModeHandler invisiblemode;
+       ModeUserOperator operatormode;
+       ModeUserServerNoticeMask snomaskmode;
 
  public:
        CoreModUser()
-               : cmdaway(this), cmdmode(this), cmdnick(this), cmdpart(this), cmdpass(this), cmdping(this)
-               , cmdpong(this), cmdquit(this), cmduser(this)
+               : cmdaway(this)
+               , cmdmode(this)
+               , cmdnick(this)
+               , cmdpart(this)
+               , cmdpass(this)
+               , cmdping(this)
+               , cmdpong(this)
+               , cmdquit(this)
+               , cmduser(this)
+               , invisiblemode(this, "invisible", 'i')
+               , operatormode(this)
+               , snomaskmode(this)
        {
        }
 
index 2a1ba7bfdf635167c01d4ec8fdaa811c2ebdbeb9..befb07ef5862919d37c020c8b45ae4a45edc866f 100644 (file)
@@ -2,6 +2,9 @@
  * InspIRCd -- Internet Relay Chat Daemon
  *
  *   Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
  *
  * 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
@@ -20,6 +23,7 @@
 #pragma once
 
 #include "inspircd.h"
+#include "listmode.h"
 
 class MessageWrapper
 {
@@ -182,3 +186,37 @@ class CommandUser : public SplitCommand
         */
        static CmdResult CheckRegister(LocalUser* user);
 };
+
+/** User mode +s
+ */
+class ModeUserServerNoticeMask : public ModeHandler
+{
+       /** Process a snomask modifier string, e.g. +abc-de
+        * @param user The target user
+        * @param input A sequence of notice mask characters
+        * @return The cleaned mode sequence which can be output,
+        * e.g. in the above example if masks c and e are not
+        * valid, this function will return +ab-d
+        */
+       std::string ProcessNoticeMasks(User* user, const std::string& input);
+
+ public:
+       ModeUserServerNoticeMask(Module* Creator);
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding) CXX11_OVERRIDE;
+       void OnParameterMissing(User* user, User* dest, Channel* channel) CXX11_OVERRIDE;
+
+       /** Create a displayable mode string of the snomasks set on a given user
+        * @param user The user whose notice masks to format
+        * @return The notice mask character sequence
+        */
+       std::string GetUserParameter(const User* user) const CXX11_OVERRIDE;
+};
+
+/** User mode +o
+ */
+class ModeUserOperator : public ModeHandler
+{
+ public:
+       ModeUserOperator(Module* Creator);
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding) CXX11_OVERRIDE;
+};
diff --git a/src/coremods/core_user/umode_o.cpp b/src/coremods/core_user/umode_o.cpp
new file mode 100644 (file)
index 0000000..20668fd
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
+ *
+ * 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 "core_user.h"
+
+ModeUserOperator::ModeUserOperator(Module* Creator)
+       : ModeHandler(Creator, "oper", 'o', PARAM_NONE, MODETYPE_USER)
+{
+       oper = true;
+}
+
+ModeAction ModeUserOperator::OnModeChange(User* source, User* dest, Channel*, std::string&, bool adding)
+{
+       /* Only opers can execute this class at all */
+       if (!source->server->IsULine() && !source->IsOper())
+               return MODEACTION_DENY;
+
+       /* Not even opers can GIVE the +o mode, only take it away */
+       if (adding)
+               return MODEACTION_DENY;
+
+       /* Set the bitfields.
+        * Note that oper status is only given in User::Oper()
+        * NOT here. It is impossible to directly set +o without
+        * verifying as an oper and getting an opertype assigned
+        * to your User!
+        */
+       char snomask = IS_LOCAL(dest) ? 'o' : 'O';
+       ServerInstance->SNO->WriteToSnoMask(snomask, "User %s de-opered (by %s)", dest->nick.c_str(), source->nick.c_str());
+       dest->UnOper();
+
+       return MODEACTION_ALLOW;
+}
diff --git a/src/coremods/core_user/umode_s.cpp b/src/coremods/core_user/umode_s.cpp
new file mode 100644 (file)
index 0000000..0122ebe
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
+ *
+ * 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 "core_user.h"
+
+ModeUserServerNoticeMask::ModeUserServerNoticeMask(Module* Creator)
+       : ModeHandler(Creator, "snomask", 's', PARAM_SETONLY, MODETYPE_USER)
+{
+       oper = true;
+}
+
+ModeAction ModeUserServerNoticeMask::OnModeChange(User* source, User* dest, Channel*, std::string &parameter, bool adding)
+{
+       if (adding)
+       {
+               dest->SetMode(this, true);
+               // Process the parameter (remove chars we don't understand, remove redundant chars, etc.)
+               parameter = ProcessNoticeMasks(dest, parameter);
+               return MODEACTION_ALLOW;
+       }
+       else
+       {
+               if (dest->IsModeSet(this))
+               {
+                       dest->SetMode(this, false);
+                       dest->snomasks.reset();
+                       return MODEACTION_ALLOW;
+               }
+       }
+
+       // Mode not set and trying to unset, deny
+       return MODEACTION_DENY;
+}
+
+std::string ModeUserServerNoticeMask::GetUserParameter(const User* user) const
+{
+       std::string ret;
+       if (!user->IsModeSet(this))
+               return ret;
+
+       ret.push_back('+');
+       for (unsigned char n = 0; n < 64; n++)
+       {
+               if (user->snomasks[n])
+                       ret.push_back(n + 'A');
+       }
+       return ret;
+}
+
+void ModeUserServerNoticeMask::OnParameterMissing(User* user, User* dest, Channel* channel)
+{
+       user->WriteNotice("*** The user mode +s requires a parameter (server notice mask). Please provide a parameter, e.g. '+s +*'.");
+}
+
+std::string ModeUserServerNoticeMask::ProcessNoticeMasks(User* user, const std::string& input)
+{
+       bool adding = true;
+       std::bitset<64> curr = user->snomasks;
+
+       for (std::string::const_iterator i = input.begin(); i != input.end(); ++i)
+       {
+               switch (*i)
+               {
+                       case '+':
+                               adding = true;
+                       break;
+                       case '-':
+                               adding = false;
+                       break;
+                       case '*':
+                               for (size_t j = 0; j < 64; j++)
+                               {
+                                       if (ServerInstance->SNO->IsSnomaskUsable(j+'A'))
+                                               curr[j] = adding;
+                               }
+                       break;
+                       default:
+                               // For local users check whether the given snomask is valid and enabled - IsSnomaskUsable() tests both.
+                               // For remote users accept what we were told, unless the snomask char is not a letter.
+                               if (IS_LOCAL(user))
+                               {
+                                       if (!ServerInstance->SNO->IsSnomaskUsable(*i))
+                                       {
+                                               user->WriteNumeric(ERR_UNKNOWNSNOMASK, *i, "is unknown snomask char to me");
+                                               continue;
+                                       }
+                               }
+                               else if (!(((*i >= 'a') && (*i <= 'z')) || ((*i >= 'A') && (*i <= 'Z'))))
+                                       continue;
+
+                               size_t index = ((*i) - 'A');
+                               curr[index] = adding;
+                       break;
+               }
+       }
+
+       std::string plus = "+";
+       std::string minus = "-";
+
+       // Apply changes and construct two strings consisting of the newly added and the removed snomask chars
+       for (size_t i = 0; i < 64; i++)
+       {
+               bool isset = curr[i];
+               if (user->snomasks[i] != isset)
+               {
+                       user->snomasks[i] = isset;
+                       std::string& appendhere = (isset ? plus : minus);
+                       appendhere.push_back(i+'A');
+               }
+       }
+
+       // Create the final string that will be shown to the user and sent to servers
+       // Form: "+ABc-de"
+       std::string output;
+       if (plus.length() > 1)
+               output = plus;
+
+       if (minus.length() > 1)
+               output += minus;
+
+       // Unset the snomask usermode itself if every snomask was unset
+       if (user->snomasks.none())
+               user->SetMode(this, false);
+
+       return output;
+}
index 0068a6fee1fed0467186ac345e9696aefbef277e..8c5137d3b426d187bfeaa3a285f443836d816912 100644 (file)
@@ -398,7 +398,6 @@ InspIRCd::InspIRCd(int argc, char** argv) :
        this->Config->Read();
        this->Config->Apply(NULL, "");
        Logs->OpenFileLogs();
-       ModeParser::InitBuiltinModes();
 
        // If we don't have a SID, generate one based on the server name and the server description
        if (Config->sid.empty())
index 98b0f98540449f4543628c7620da7b5d54310014..e2129b55a46ce03a9466d169b2bed3886c5d082b 100644 (file)
@@ -24,7 +24,6 @@
 
 
 #include "inspircd.h"
-#include "builtinmodes.h"
 
 ModeHandler::ModeHandler(Module* Creator, const std::string& Name, char modeletter, ParamSpec Params, ModeType type, Class mclass)
        : ServiceProvider(Creator, Name, SERVICE_MODE)
@@ -894,53 +893,6 @@ void PrefixMode::RemoveMode(Channel* chan, Modes::ChangeList& changelist)
        }
 }
 
-struct builtin_modes
-{
-       SimpleChannelModeHandler s;
-       SimpleChannelModeHandler p;
-       SimpleChannelModeHandler m;
-       SimpleChannelModeHandler t;
-
-       SimpleChannelModeHandler n;
-       SimpleChannelModeHandler i;
-       ModeChannelKey k;
-       ModeChannelLimit l;
-
-       ModeChannelBan b;
-       ModeChannelOp o;
-       ModeChannelVoice v;
-
-       SimpleUserModeHandler ui;
-       ModeUserOperator uo;
-       ModeUserServerNoticeMask us;
-
-       builtin_modes()
-               : s(NULL, "secret", 's')
-               , p(NULL, "private", 'p')
-               , m(NULL, "moderated", 'm')
-               , t(NULL, "topiclock", 't')
-               , n(NULL, "noextmsg", 'n')
-               , i(NULL, "inviteonly", 'i')
-               , ui(NULL, "invisible", 'i')
-       {
-       }
-
-       void init()
-       {
-               ServiceProvider* modes[] = { &s, &p, &m, &t, &n, &i, &k, &l, &b, &o, &v,
-                                                                        &ui, &uo, &us };
-               ServerInstance->Modules->AddServices(modes, sizeof(modes)/sizeof(ServiceProvider*));
-       }
-};
-
-static builtin_modes static_modes;
-
-void ModeParser::InitBuiltinModes()
-{
-       static_modes.init();
-       static_modes.b.DoRehash();
-}
-
 bool ModeParser::IsModeChar(char chr)
 {
        return ((chr >= 'A' && chr <= 'Z') || (chr >= 'a' && chr <= 'z'));
diff --git a/src/modes/cmode_k.cpp b/src/modes/cmode_k.cpp
deleted file mode 100644 (file)
index 980b321..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
- *
- * 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 "builtinmodes.h"
-
-ModeChannelKey::ModeChannelKey()
-       : ParamMode<ModeChannelKey, LocalStringExt>(NULL, "key", 'k', PARAM_ALWAYS)
-{
-}
-
-ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
-{
-       const std::string* key = ext.get(channel);
-       bool exists = (key != NULL);
-       if (IS_LOCAL(source))
-       {
-               if (exists == adding)
-                       return MODEACTION_DENY;
-               if (exists && (parameter != *key))
-               {
-                       /* Key is currently set and the correct key wasnt given */
-                       return MODEACTION_DENY;
-               }
-       } else {
-               if (exists && adding && parameter == *key)
-               {
-                       /* no-op, don't show */
-                       return MODEACTION_DENY;
-               }
-       }
-
-       channel->SetMode(this, adding);
-       if (adding)
-       {
-               if (parameter.length() > maxkeylen)
-                       parameter.erase(maxkeylen);
-               ext.set(channel, parameter);
-       }
-       else
-               ext.unset(channel);
-
-       return MODEACTION_ALLOW;
-}
-
-void ModeChannelKey::SerializeParam(Channel* chan, const std::string* key, std::string& out)
-{
-       out += *key;
-}
-
-ModeAction ModeChannelKey::OnSet(User* source, Channel* chan, std::string& param)
-{
-       // Dummy function, never called
-       return MODEACTION_DENY;
-}
diff --git a/src/modes/cmode_l.cpp b/src/modes/cmode_l.cpp
deleted file mode 100644 (file)
index d61b259..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
- *
- * 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 "builtinmodes.h"
-
-ModeChannelLimit::ModeChannelLimit()
-       : ParamMode<ModeChannelLimit, LocalIntExt>(NULL, "limit", 'l')
-{
-}
-
-bool ModeChannelLimit::ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel*)
-{
-       /* When TS is equal, the higher channel limit wins */
-       return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
-}
-
-ModeAction ModeChannelLimit::OnSet(User* user, Channel* chan, std::string& parameter)
-{
-       int limit = ConvToInt(parameter);
-       if (limit < 0)
-               return MODEACTION_DENY;
-
-       ext.set(chan, limit);
-       return MODEACTION_ALLOW;
-}
-
-void ModeChannelLimit::SerializeParam(Channel* chan, intptr_t n, std::string& out)
-{
-       out += ConvToStr(n);
-}
diff --git a/src/modes/umode_o.cpp b/src/modes/umode_o.cpp
deleted file mode 100644 (file)
index 9d50e57..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
- *
- * 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 "builtinmodes.h"
-
-ModeUserOperator::ModeUserOperator() : ModeHandler(NULL, "oper", 'o', PARAM_NONE, MODETYPE_USER)
-{
-       oper = true;
-}
-
-ModeAction ModeUserOperator::OnModeChange(User* source, User* dest, Channel*, std::string&, bool adding)
-{
-       /* Only opers can execute this class at all */
-       if (!source->server->IsULine() && !source->IsOper())
-               return MODEACTION_DENY;
-
-       /* Not even opers can GIVE the +o mode, only take it away */
-       if (adding)
-               return MODEACTION_DENY;
-
-       /* Set the bitfields.
-        * Note that oper status is only given in User::Oper()
-        * NOT here. It is impossible to directly set +o without
-        * verifying as an oper and getting an opertype assigned
-        * to your User!
-        */
-       char snomask = IS_LOCAL(dest) ? 'o' : 'O';
-       ServerInstance->SNO->WriteToSnoMask(snomask, "User %s de-opered (by %s)", dest->nick.c_str(), source->nick.c_str());
-       dest->UnOper();
-
-       return MODEACTION_ALLOW;
-}
diff --git a/src/modes/umode_s.cpp b/src/modes/umode_s.cpp
deleted file mode 100644 (file)
index ffad216..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
- *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
- *
- * 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 "builtinmodes.h"
-
-ModeUserServerNoticeMask::ModeUserServerNoticeMask() : ModeHandler(NULL, "snomask", 's', PARAM_SETONLY, MODETYPE_USER)
-{
-       oper = true;
-}
-
-ModeAction ModeUserServerNoticeMask::OnModeChange(User* source, User* dest, Channel*, std::string &parameter, bool adding)
-{
-       if (adding)
-       {
-               dest->SetMode(this, true);
-               // Process the parameter (remove chars we don't understand, remove redundant chars, etc.)
-               parameter = ProcessNoticeMasks(dest, parameter);
-               return MODEACTION_ALLOW;
-       }
-       else
-       {
-               if (dest->IsModeSet(this))
-               {
-                       dest->SetMode(this, false);
-                       dest->snomasks.reset();
-                       return MODEACTION_ALLOW;
-               }
-       }
-
-       // Mode not set and trying to unset, deny
-       return MODEACTION_DENY;
-}
-
-std::string ModeUserServerNoticeMask::GetUserParameter(const User* user) const
-{
-       std::string ret;
-       if (!user->IsModeSet(this))
-               return ret;
-
-       ret.push_back('+');
-       for (unsigned char n = 0; n < 64; n++)
-       {
-               if (user->snomasks[n])
-                       ret.push_back(n + 'A');
-       }
-       return ret;
-}
-
-void ModeUserServerNoticeMask::OnParameterMissing(User* user, User* dest, Channel* channel)
-{
-       user->WriteNotice("*** The user mode +s requires a parameter (server notice mask). Please provide a parameter, e.g. '+s +*'.");
-}
-
-std::string ModeUserServerNoticeMask::ProcessNoticeMasks(User* user, const std::string& input)
-{
-       bool adding = true;
-       std::bitset<64> curr = user->snomasks;
-
-       for (std::string::const_iterator i = input.begin(); i != input.end(); ++i)
-       {
-               switch (*i)
-               {
-                       case '+':
-                               adding = true;
-                       break;
-                       case '-':
-                               adding = false;
-                       break;
-                       case '*':
-                               for (size_t j = 0; j < 64; j++)
-                               {
-                                       if (ServerInstance->SNO->IsSnomaskUsable(j+'A'))
-                                               curr[j] = adding;
-                               }
-                       break;
-                       default:
-                               // For local users check whether the given snomask is valid and enabled - IsSnomaskUsable() tests both.
-                               // For remote users accept what we were told, unless the snomask char is not a letter.
-                               if (IS_LOCAL(user))
-                               {
-                                       if (!ServerInstance->SNO->IsSnomaskUsable(*i))
-                                       {
-                                               user->WriteNumeric(ERR_UNKNOWNSNOMASK, *i, "is unknown snomask char to me");
-                                               continue;
-                                       }
-                               }
-                               else if (!(((*i >= 'a') && (*i <= 'z')) || ((*i >= 'A') && (*i <= 'Z'))))
-                                       continue;
-
-                               size_t index = ((*i) - 'A');
-                               curr[index] = adding;
-                       break;
-               }
-       }
-
-       std::string plus = "+";
-       std::string minus = "-";
-
-       // Apply changes and construct two strings consisting of the newly added and the removed snomask chars
-       for (size_t i = 0; i < 64; i++)
-       {
-               bool isset = curr[i];
-               if (user->snomasks[i] != isset)
-               {
-                       user->snomasks[i] = isset;
-                       std::string& appendhere = (isset ? plus : minus);
-                       appendhere.push_back(i+'A');
-               }
-       }
-
-       // Create the final string that will be shown to the user and sent to servers
-       // Form: "+ABc-de"
-       std::string output;
-       if (plus.length() > 1)
-               output = plus;
-
-       if (minus.length() > 1)
-               output += minus;
-
-       // Unset the snomask usermode itself if every snomask was unset
-       if (user->snomasks.none())
-               user->SetMode(this, false);
-
-       return output;
-}
index 9b74b6f23f7e9c6d9618954d17ce0280199daed3..14ef11107c791fc14260d6f63d3d88d9fc3ed584 100644 (file)
@@ -45,6 +45,8 @@ class CommandTban : public Command
        bool IsBanSet(Channel* chan, const std::string& mask)
        {
                ListModeBase* banlm = static_cast<ListModeBase*>(*banmode);
+               if (!banlm)
+                       return false;
                const ListModeBase::ModeList* bans = banlm->GetList(chan);
                if (bans)
                {
index e53f6c6d3c45ebf0ab999113352fe77027e87e25..e8ff42d1ee54b1740163b613da4da065caf50167 100644 (file)
@@ -43,7 +43,6 @@ endif(MSVC)
 file(GLOB INSPIRCD_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
 "${INSPIRCD_BASE}/win/inspircd_win32wrapper.cpp"
 "${INSPIRCD_BASE}/win/win32service.cpp" "${INSPIRCD_BASE}/src/*.cpp"
-"${INSPIRCD_BASE}/src/modes/*.cpp"
 "${INSPIRCD_BASE}/src/socketengines/socketengine_select.cpp"
 "${INSPIRCD_BASE}/src/threadengines/threadengine_win32.cpp")
 list(SORT INSPIRCD_SOURCES)