inspircd

A modular C++ IRC daemon (ircd). https://www.inspircd.org/
Log | Files | Refs | README

commit 8b0d03971797110112acadf683e08301b094ca92
parent 0f2341e76eb54fb38b97305609db9f025331d002
Author: Peter Powell <petpow@saberuk.com>
Date:   Fri, 19 Apr 2019 12:39:37 +0100

Demote core_ison and core_userhost to commands in core_user.

These are not important enough for their own module.

Diffstat:
Dsrc/coremods/core_ison.cpp | 97-------------------------------------------------------------------------------
Asrc/coremods/core_user/cmd_ison.cpp | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/coremods/core_user/cmd_userhost.cpp | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/coremods/core_user/core_user.cpp | 4++++
Msrc/coremods/core_user/core_user.h | 46++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/coremods/core_userhost.cpp | 102-------------------------------------------------------------------------------
6 files changed, 170 insertions(+), 199 deletions(-)

diff --git a/src/coremods/core_ison.cpp b/src/coremods/core_ison.cpp @@ -1,97 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org> - * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net> - * - * 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" - -/** Handle /ISON. - */ -class CommandIson : public SplitCommand -{ - public: - /** Constructor for ison. - */ - CommandIson(Module* parent) - : SplitCommand(parent, "ISON", 1) - { - syntax = "<nick> [<nick>]+"; - } - /** 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<std::string>::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 @@ -0,0 +1,59 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org> + * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net> + * + * 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" + +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<std::string>::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 @@ -0,0 +1,61 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org> + * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net> + * + * 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" + +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 @@ -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 @@ -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 = "<nick> [<nick>]+"; + } + /** 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 = "<nick> [<nick>]+"; + } + /** 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 @@ -1,102 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org> - * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net> - * - * 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" - -/** Handle /USERHOST. - */ -class CommandUserhost : public Command -{ - UserModeReference hideopermode; - - public: - /** Constructor for userhost. - */ - CommandUserhost(Module* parent) - : Command(parent,"USERHOST", 1) - , hideopermode(parent, "hideoper") - { - syntax = "<nick> [<nick>]+"; - } - /** 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)