From 8b0d03971797110112acadf683e08301b094ca92 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 19 Apr 2019 12:39:37 +0100 Subject: Demote core_ison and core_userhost to commands in core_user. These are not important enough for their own module. --- src/coremods/core_ison.cpp | 97 ------------------------------ src/coremods/core_user/cmd_ison.cpp | 59 ++++++++++++++++++ src/coremods/core_user/cmd_userhost.cpp | 61 +++++++++++++++++++ src/coremods/core_user/core_user.cpp | 4 ++ src/coremods/core_user/core_user.h | 46 ++++++++++++++ src/coremods/core_userhost.cpp | 102 -------------------------------- 6 files changed, 170 insertions(+), 199 deletions(-) delete mode 100644 src/coremods/core_ison.cpp create mode 100644 src/coremods/core_user/cmd_ison.cpp create mode 100644 src/coremods/core_user/cmd_userhost.cpp delete mode 100644 src/coremods/core_userhost.cpp (limited to 'src') diff --git a/src/coremods/core_ison.cpp b/src/coremods/core_ison.cpp deleted file mode 100644 index ec097f1c6..000000000 --- a/src/coremods/core_ison.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * Copyright (C) 2009 Daniel De Graaf - * Copyright (C) 2007 Robin Burchell - * - * 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 . - */ - - -#include "inspircd.h" - -/** Handle /ISON. - */ -class CommandIson : public SplitCommand -{ - public: - /** Constructor for ison. - */ - CommandIson(Module* parent) - : SplitCommand(parent, "ISON", 1) - { - syntax = " []+"; - } - /** Handle command. - * @param parameters The parameters to the command - * @param user The user issuing the command - * @return A value from CmdResult to indicate command success or failure. - */ - CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE; -}; - -class IsonReplyBuilder : public Numeric::Builder<' ', true> -{ - public: - IsonReplyBuilder(LocalUser* user) - : Numeric::Builder<' ', true>(user, RPL_ISON) - { - } - - void AddNick(const std::string& nickname) - { - User* const user = ServerInstance->FindNickOnly(nickname); - if ((user) && (user->registered == REG_ALL)) - Add(user->nick); - } -}; - -/** Handle /ISON - */ -CmdResult CommandIson::HandleLocal(LocalUser* user, const Params& parameters) -{ - IsonReplyBuilder reply(user); - - for (std::vector::const_iterator i = parameters.begin(); i != parameters.end()-1; ++i) - { - const std::string& targetstr = *i; - reply.AddNick(targetstr); - } - - // Last parameter can be a space separated list - irc::spacesepstream ss(parameters.back()); - for (std::string token; ss.GetToken(token); ) - reply.AddNick(token); - - reply.Flush(); - return CMD_SUCCESS; -} - -class CoreModIson : public Module -{ - private: - CommandIson cmd; - - public: - CoreModIson() - : cmd(this) - { - } - - Version GetVersion() CXX11_OVERRIDE - { - return Version("Provides the ISON command", VF_CORE | VF_VENDOR); - } -}; - -MODULE_INIT(CoreModIson) diff --git a/src/coremods/core_user/cmd_ison.cpp b/src/coremods/core_user/cmd_ison.cpp new file mode 100644 index 000000000..a316b3c83 --- /dev/null +++ b/src/coremods/core_user/cmd_ison.cpp @@ -0,0 +1,59 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2007 Robin Burchell + * + * 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 . + */ + + +#include "inspircd.h" +#include "core_user.h" + +class IsonReplyBuilder : public Numeric::Builder<' ', true> +{ + public: + IsonReplyBuilder(LocalUser* user) + : Numeric::Builder<' ', true>(user, RPL_ISON) + { + } + + void AddNick(const std::string& nickname) + { + User* const user = ServerInstance->FindNickOnly(nickname); + if ((user) && (user->registered == REG_ALL)) + Add(user->nick); + } +}; + +/** Handle /ISON + */ +CmdResult CommandIson::HandleLocal(LocalUser* user, const Params& parameters) +{ + IsonReplyBuilder reply(user); + + for (std::vector::const_iterator i = parameters.begin(); i != parameters.end()-1; ++i) + { + const std::string& targetstr = *i; + reply.AddNick(targetstr); + } + + // Last parameter can be a space separated list + irc::spacesepstream ss(parameters.back()); + for (std::string token; ss.GetToken(token); ) + reply.AddNick(token); + + reply.Flush(); + return CMD_SUCCESS; +} diff --git a/src/coremods/core_user/cmd_userhost.cpp b/src/coremods/core_user/cmd_userhost.cpp new file mode 100644 index 000000000..f531d2395 --- /dev/null +++ b/src/coremods/core_user/cmd_userhost.cpp @@ -0,0 +1,61 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2007 Robin Burchell + * + * 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 . + */ + + +#include "inspircd.h" +#include "core_user.h" + +CmdResult CommandUserhost::Handle(User* user, const Params& parameters) +{ + const bool has_privs = user->HasPrivPermission("users/auspex"); + + std::string retbuf; + + unsigned int max = parameters.size(); + if (max > 5) + max = 5; + + for (unsigned int i = 0; i < max; i++) + { + User *u = ServerInstance->FindNickOnly(parameters[i]); + + if ((u) && (u->registered == REG_ALL)) + { + retbuf += u->nick; + + if (u->IsOper()) + { + // XXX: +H hidden opers must not be shown as opers + if ((u == user) || (has_privs) || (!u->IsModeSet(hideopermode))) + retbuf += '*'; + } + + retbuf += '='; + retbuf += (u->IsAway() ? '-' : '+'); + retbuf += u->ident; + retbuf += '@'; + retbuf += u->GetHost(u == user || has_privs); + retbuf += ' '; + } + } + + user->WriteNumeric(RPL_USERHOST, retbuf); + + return CMD_SUCCESS; +} diff --git a/src/coremods/core_user/core_user.cpp b/src/coremods/core_user/core_user.cpp index 66622d34d..f2816180b 100644 --- a/src/coremods/core_user/core_user.cpp +++ b/src/coremods/core_user/core_user.cpp @@ -147,6 +147,8 @@ class CoreModUser : public Module CommandPong cmdpong; CommandQuit cmdquit; CommandUser cmduser; + CommandIson cmdison; + CommandUserhost cmduserhost; SimpleUserModeHandler invisiblemode; ModeUserOperator operatormode; ModeUserServerNoticeMask snomaskmode; @@ -161,6 +163,8 @@ class CoreModUser : public Module , cmdpong(this) , cmdquit(this) , cmduser(this) + , cmdison(this) + , cmduserhost(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 ea28176d4..b4f04cd9d 100644 --- a/src/coremods/core_user/core_user.h +++ b/src/coremods/core_user/core_user.h @@ -70,6 +70,28 @@ class CommandAway : public Command RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE; }; +/** Handle /ISON. + */ +class CommandIson : public SplitCommand +{ + public: + /** Constructor for ison. + */ + CommandIson(Module* parent) + : SplitCommand(parent, "ISON", 1) + { + allow_empty_last_param = false; + syntax = " []+"; + } + /** Handle command. + * @param parameters The parameters to the command + * @param user The user issuing the command + * @return A value from CmdResult to indicate command success or failure. + */ + CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE; +}; + + /** Handle /NICK. */ class CommandNick : public SplitCommand @@ -157,6 +179,30 @@ class CommandUser : public SplitCommand static CmdResult CheckRegister(LocalUser* user); }; +/** Handle /USERHOST. + */ +class CommandUserhost : public Command +{ + UserModeReference hideopermode; + + public: + /** Constructor for userhost. + */ + CommandUserhost(Module* parent) + : Command(parent,"USERHOST", 1) + , hideopermode(parent, "hideoper") + { + allow_empty_last_param = false; + syntax = " []+"; + } + /** Handle command. + * @param parameters The parameters to the command + * @param user The user issuing the command + * @return A value from CmdResult to indicate command success or failure. + */ + CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE; +}; + /** User mode +s */ class ModeUserServerNoticeMask : public ModeHandler diff --git a/src/coremods/core_userhost.cpp b/src/coremods/core_userhost.cpp deleted file mode 100644 index e21e7d95b..000000000 --- a/src/coremods/core_userhost.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * Copyright (C) 2009 Daniel De Graaf - * Copyright (C) 2007 Robin Burchell - * - * 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 . - */ - - -#include "inspircd.h" - -/** Handle /USERHOST. - */ -class CommandUserhost : public Command -{ - UserModeReference hideopermode; - - public: - /** Constructor for userhost. - */ - CommandUserhost(Module* parent) - : Command(parent,"USERHOST", 1) - , hideopermode(parent, "hideoper") - { - syntax = " []+"; - } - /** Handle command. - * @param parameters The parameters to the command - * @param user The user issuing the command - * @return A value from CmdResult to indicate command success or failure. - */ - CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE; -}; - -CmdResult CommandUserhost::Handle(User* user, const Params& parameters) -{ - const bool has_privs = user->HasPrivPermission("users/auspex"); - - std::string retbuf; - - unsigned int max = parameters.size(); - if (max > 5) - max = 5; - - for (unsigned int i = 0; i < max; i++) - { - User *u = ServerInstance->FindNickOnly(parameters[i]); - - if ((u) && (u->registered == REG_ALL)) - { - retbuf += u->nick; - - if (u->IsOper()) - { - // XXX: +H hidden opers must not be shown as opers - if ((u == user) || (has_privs) || (!u->IsModeSet(hideopermode))) - retbuf += '*'; - } - - retbuf += '='; - retbuf += (u->IsAway() ? '-' : '+'); - retbuf += u->ident; - retbuf += '@'; - retbuf += u->GetHost(u == user || has_privs); - retbuf += ' '; - } - } - - user->WriteNumeric(RPL_USERHOST, retbuf); - - return CMD_SUCCESS; -} - -class CoreModUserhost : public Module -{ - private: - CommandUserhost cmd; - - public: - CoreModUserhost() - : cmd(this) - { - } - - Version GetVersion() CXX11_OVERRIDE - { - return Version("Provides the USERHOST command", VF_CORE | VF_VENDOR); - } -}; - -MODULE_INIT(CoreModUserhost) -- cgit v1.2.3