Add support for the <count> param of WHOWAS (#1968)

Not very useful IMO, but every server but InspIRCd seems to implement it,
and it's part of the RFCs:

* https://datatracker.ietf.org/doc/html/rfc1459#section-4.5.3
* https://datatracker.ietf.org/doc/html/rfc2812#section-3.6.3
This commit is contained in:
Val Lorentz 2022-03-19 19:13:10 +01:00 committed by GitHub
parent bc64702bb2
commit 740e193f59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -419,9 +419,11 @@ server.
You should not use it during an established connection.
">
<helpop key="whowas" title="/WHOWAS <nick>" value="
<helpop key="whowas" title="/WHOWAS <nick> [<count>]" value="
Returns a list of times the user was seen recently on IRC along with
the time they were last seen and their server.
If <count> is given, only return the <count> most recent entries.
">
<helpop key="links" title="/LINKS" value="

View File

@ -187,7 +187,7 @@ class CommandWhowas : public Command
CommandWhowas::CommandWhowas( Module* parent)
: Command(parent, "WHOWAS", 1)
{
syntax = "<nick>";
syntax = "<nick> [<count>]";
Penalty = 2;
}
@ -208,7 +208,15 @@ CmdResult CommandWhowas::Handle(User* user, const Params& parameters)
else
{
const WhoWas::Nick::List& list = nick->entries;
for (WhoWas::Nick::List::const_reverse_iterator i = list.rbegin(); i != list.rend(); ++i)
WhoWas::Nick::List::const_reverse_iterator last = list.rend();
if (parameters.size() > 1)
{
size_t count = ConvToNum<size_t>(parameters[1]);
if (count > 0 && (size_t) std::distance(list.rbegin(), last) > count)
last = list.rbegin() + count;
}
for (WhoWas::Nick::List::const_reverse_iterator i = list.rbegin(); i != last; ++i)
{
WhoWas::Entry* u = *i;