summaryrefslogtreecommitdiff
path: root/src/coremods/core_channel
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2017-12-03 17:16:28 +0000
committerPeter Powell <petpow@saberuk.com>2017-12-10 12:38:45 +0000
commit98372c3cf2c1455e41c388d822876a4d146ae76d (patch)
treee1f3403a7f16fab366e0304da84d9c10daf1a20e /src/coremods/core_channel
parent150258b1f110aad58c8882b76474a4ceb3b2ab97 (diff)
Extract RFC modes from the core to core_channel and core_user.
Diffstat (limited to 'src/coremods/core_channel')
-rw-r--r--src/coremods/core_channel/cmode_k.cpp74
-rw-r--r--src/coremods/core_channel/cmode_l.cpp49
-rw-r--r--src/coremods/core_channel/core_channel.cpp25
-rw-r--r--src/coremods/core_channel/core_channel.h63
4 files changed, 211 insertions, 0 deletions
diff --git a/src/coremods/core_channel/cmode_k.cpp b/src/coremods/core_channel/cmode_k.cpp
new file mode 100644
index 000000000..9bab05200
--- /dev/null
+++ b/src/coremods/core_channel/cmode_k.cpp
@@ -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
index 000000000..eb16fd182
--- /dev/null
+++ b/src/coremods/core_channel/cmode_l.cpp
@@ -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);
+}
diff --git a/src/coremods/core_channel/core_channel.cpp b/src/coremods/core_channel/core_channel.cpp
index 3af809645..af71e2ced 100644
--- a/src/coremods/core_channel/core_channel.cpp
+++ b/src/coremods/core_channel/core_channel.cpp
@@ -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
diff --git a/src/coremods/core_channel/core_channel.h b/src/coremods/core_channel/core_channel.h
index 46def3e7b..fa600cd17 100644
--- a/src/coremods/core_channel/core_channel.h
+++ b/src/coremods/core_channel/core_channel.h
@@ -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;
+ }
+};