diff options
author | Peter Powell <petpow@saberuk.com> | 2017-12-03 17:16:28 +0000 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2017-12-10 12:38:45 +0000 |
commit | 98372c3cf2c1455e41c388d822876a4d146ae76d (patch) | |
tree | e1f3403a7f16fab366e0304da84d9c10daf1a20e | |
parent | 150258b1f110aad58c8882b76474a4ceb3b2ab97 (diff) |
Extract RFC modes from the core to core_channel and core_user.
-rw-r--r-- | docs/Doxyfile | 1 | ||||
-rw-r--r-- | include/builtinmodes.h | 118 | ||||
-rw-r--r-- | include/mode.h | 4 | ||||
-rwxr-xr-x | make/calcdep.pl | 4 | ||||
-rw-r--r-- | src/channels.cpp | 6 | ||||
-rw-r--r-- | src/configreader.cpp | 2 | ||||
-rw-r--r-- | src/coremods/core_channel/cmode_k.cpp (renamed from src/modes/cmode_k.cpp) | 6 | ||||
-rw-r--r-- | src/coremods/core_channel/cmode_l.cpp (renamed from src/modes/cmode_l.cpp) | 6 | ||||
-rw-r--r-- | src/coremods/core_channel/core_channel.cpp | 25 | ||||
-rw-r--r-- | src/coremods/core_channel/core_channel.h | 63 | ||||
-rw-r--r-- | src/coremods/core_user/core_user.cpp | 17 | ||||
-rw-r--r-- | src/coremods/core_user/core_user.h | 38 | ||||
-rw-r--r-- | src/coremods/core_user/umode_o.cpp (renamed from src/modes/umode_o.cpp) | 5 | ||||
-rw-r--r-- | src/coremods/core_user/umode_s.cpp (renamed from src/modes/umode_s.cpp) | 5 | ||||
-rw-r--r-- | src/inspircd.cpp | 1 | ||||
-rw-r--r-- | src/mode.cpp | 48 | ||||
-rw-r--r-- | src/modules/m_timedbans.cpp | 2 | ||||
-rw-r--r-- | win/CMakeLists.txt | 1 |
18 files changed, 163 insertions, 189 deletions
diff --git a/docs/Doxyfile b/docs/Doxyfile index aa5a34ba6..f835ab996 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -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 index 3bd3e2566..000000000 --- a/include/builtinmodes.h +++ /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 ¶meter, 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 ¶meter, bool adding) CXX11_OVERRIDE; -}; diff --git a/include/mode.h b/include/mode.h index f944da62c..ccbfe6f28 100644 --- a/include/mode.h +++ b/include/mode.h @@ -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. diff --git a/make/calcdep.pl b/make/calcdep.pl index 3b4ae6b0d..f3ed04725 100755 --- a/make/calcdep.pl +++ b/make/calcdep.pl @@ -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$#) { diff --git a/src/channels.cpp b/src/channels.cpp index 118a413a8..3bc58505c 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -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) { diff --git a/src/configreader.cpp b/src/configreader.cpp index 18b62fb09..ff9d5bd14 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -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/modes/cmode_k.cpp b/src/coremods/core_channel/cmode_k.cpp index 980b3215a..9bab05200 100644 --- a/src/modes/cmode_k.cpp +++ b/src/coremods/core_channel/cmode_k.cpp @@ -21,10 +21,10 @@ #include "inspircd.h" -#include "builtinmodes.h" +#include "core_channel.h" -ModeChannelKey::ModeChannelKey() - : ParamMode<ModeChannelKey, LocalStringExt>(NULL, "key", 'k', PARAM_ALWAYS) +ModeChannelKey::ModeChannelKey(Module* Creator) + : ParamMode<ModeChannelKey, LocalStringExt>(Creator, "key", 'k', PARAM_ALWAYS) { } diff --git a/src/modes/cmode_l.cpp b/src/coremods/core_channel/cmode_l.cpp index d61b2597b..eb16fd182 100644 --- a/src/modes/cmode_l.cpp +++ b/src/coremods/core_channel/cmode_l.cpp @@ -20,10 +20,10 @@ #include "inspircd.h" -#include "builtinmodes.h" +#include "core_channel.h" -ModeChannelLimit::ModeChannelLimit() - : ParamMode<ModeChannelLimit, LocalIntExt>(NULL, "limit", 'l') +ModeChannelLimit::ModeChannelLimit(Module* Creator) + : ParamMode<ModeChannelLimit, LocalIntExt>(Creator, "limit", 'l') { } 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; + } +}; diff --git a/src/coremods/core_user/core_user.cpp b/src/coremods/core_user/core_user.cpp index 5068bd4aa..8504de8e0 100644 --- a/src/coremods/core_user/core_user.cpp +++ b/src/coremods/core_user/core_user.cpp @@ -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) { } diff --git a/src/coremods/core_user/core_user.h b/src/coremods/core_user/core_user.h index 2a1ba7bfd..befb07ef5 100644 --- a/src/coremods/core_user/core_user.h +++ b/src/coremods/core_user/core_user.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" 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 ¶meter, 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 ¶meter, bool adding) CXX11_OVERRIDE; +}; diff --git a/src/modes/umode_o.cpp b/src/coremods/core_user/umode_o.cpp index 9d50e571b..20668fdaa 100644 --- a/src/modes/umode_o.cpp +++ b/src/coremods/core_user/umode_o.cpp @@ -19,9 +19,10 @@ #include "inspircd.h" -#include "builtinmodes.h" +#include "core_user.h" -ModeUserOperator::ModeUserOperator() : ModeHandler(NULL, "oper", 'o', PARAM_NONE, MODETYPE_USER) +ModeUserOperator::ModeUserOperator(Module* Creator) + : ModeHandler(Creator, "oper", 'o', PARAM_NONE, MODETYPE_USER) { oper = true; } diff --git a/src/modes/umode_s.cpp b/src/coremods/core_user/umode_s.cpp index ffad21662..0122ebe3e 100644 --- a/src/modes/umode_s.cpp +++ b/src/coremods/core_user/umode_s.cpp @@ -20,9 +20,10 @@ #include "inspircd.h" -#include "builtinmodes.h" +#include "core_user.h" -ModeUserServerNoticeMask::ModeUserServerNoticeMask() : ModeHandler(NULL, "snomask", 's', PARAM_SETONLY, MODETYPE_USER) +ModeUserServerNoticeMask::ModeUserServerNoticeMask(Module* Creator) + : ModeHandler(Creator, "snomask", 's', PARAM_SETONLY, MODETYPE_USER) { oper = true; } diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 0068a6fee..8c5137d3b 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -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()) diff --git a/src/mode.cpp b/src/mode.cpp index 98b0f9854..e2129b55a 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -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/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp index 9b74b6f23..14ef11107 100644 --- a/src/modules/m_timedbans.cpp +++ b/src/modules/m_timedbans.cpp @@ -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) { diff --git a/win/CMakeLists.txt b/win/CMakeLists.txt index e53f6c6d3..e8ff42d1e 100644 --- a/win/CMakeLists.txt +++ b/win/CMakeLists.txt @@ -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) |