X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcoremods%2Fcore_channel%2Fcmd_names.cpp;h=bf13fac65a82a7fdaa32464fd014da4230259e57;hb=df17d47b6a17ee6214f7f501e3b9d73cb8acd36e;hp=3af99ed2b9ea9e86ff916caa9326f4da9083a248;hpb=8320bcc9df1ea89a47257c9f9c70aa6d476beaa8;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/coremods/core_channel/cmd_names.cpp b/src/coremods/core_channel/cmd_names.cpp index 3af99ed2b..bf13fac65 100644 --- a/src/coremods/core_channel/cmd_names.cpp +++ b/src/coremods/core_channel/cmd_names.cpp @@ -1,8 +1,16 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2018-2019 Sadie Powell + * Copyright (C) 2018 Dylan Frank + * Copyright (C) 2017 B00mX0r + * Copyright (C) 2013-2016 Attila Molnar + * Copyright (C) 2012, 2019 Robby + * Copyright (C) 2009 Uli Schlachter * Copyright (C) 2009 Daniel De Graaf * Copyright (C) 2007 Robin Burchell + * Copyright (C) 2007 Dennis Friis + * Copyright (C) 2006, 2008, 2010 Craig Edwards * * 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,25 +28,27 @@ #include "inspircd.h" #include "core_channel.h" +#include "modules/names.h" CommandNames::CommandNames(Module* parent) - : Command(parent, "NAMES", 0, 0) + : SplitCommand(parent, "NAMES", 0, 0) , secretmode(parent, "secret") , privatemode(parent, "private") , invisiblemode(parent, "invisible") + , namesevprov(parent, "event/names") { - syntax = "{{,}}"; + syntax = "[[,]+]"; } /** Handle /NAMES */ -CmdResult CommandNames::Handle (const std::vector& parameters, User *user) +CmdResult CommandNames::HandleLocal(LocalUser* user, const Params& parameters) { Channel* c; - if (!parameters.size()) + if (parameters.empty()) { - user->WriteNumeric(RPL_ENDOFNAMES, "* :End of /NAMES list."); + user->WriteNumeric(RPL_ENDOFNAMES, '*', "End of /NAMES list."); return CMD_SUCCESS; } @@ -62,25 +72,24 @@ CmdResult CommandNames::Handle (const std::vector& parameters, User } } - user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", parameters[0].c_str()); + user->WriteNumeric(Numerics::NoSuchChannel(parameters[0])); return CMD_FAILURE; } -void CommandNames::SendNames(User* user, Channel* chan, bool show_invisible) +void CommandNames::SendNames(LocalUser* user, Channel* chan, bool show_invisible) { - std::string list; + Numeric::Builder<' '> reply(user, RPL_NAMREPLY, false, chan->name.size() + 3); + Numeric::Numeric& numeric = reply.GetNumeric(); if (chan->IsModeSet(secretmode)) - list.push_back('@'); + numeric.push(std::string(1, '@')); else if (chan->IsModeSet(privatemode)) - list.push_back('*'); + numeric.push(std::string(1, '*')); else - list.push_back('='); + numeric.push(std::string(1, '=')); - list.push_back(' '); - list.append(chan->name).append(" :"); - std::string::size_type pos = list.size(); + numeric.push(chan->name); + numeric.push(std::string()); - const size_t maxlen = ServerInstance->Config->Limits.MaxLine - 10 - ServerInstance->Config->ServerName.size() - user->nick.size(); std::string prefixlist; std::string nick; const Channel::MemberMap& members = chan->GetUsers(); @@ -101,27 +110,11 @@ void CommandNames::SendNames(User* user, Channel* chan, bool show_invisible) nick = i->first->nick; ModResult res; - FIRST_MOD_RESULT(OnNamesListItem, res, (user, memb, prefixlist, nick)); - - // See if a module wants us to exclude this user from NAMES - if (res == MOD_RES_DENY) - continue; - - if (list.size() + prefixlist.length() + nick.length() + 1 > maxlen) - { - // List overflowed into multiple numerics - user->WriteNumeric(RPL_NAMREPLY, list); - - // Erase all nicks, keep the constant part - list.erase(pos); - } - - list.append(prefixlist).append(nick).push_back(' '); + FIRST_MOD_RESULT_CUSTOM(namesevprov, Names::EventListener, OnNamesListItem, res, (user, memb, prefixlist, nick)); + if (res != MOD_RES_DENY) + reply.Add(prefixlist, nick); } - // Only send the user list numeric if there is at least one user in it - if (list.size() != pos) - user->WriteNumeric(RPL_NAMREPLY, list); - - user->WriteNumeric(RPL_ENDOFNAMES, "%s :End of /NAMES list.", chan->name.c_str()); + reply.Flush(); + user->WriteNumeric(RPL_ENDOFNAMES, chan->name, "End of /NAMES list."); }