1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-07 02:23:12 +02:00
Files
unrealircd/src/modules/history.c
T
2020-02-02 12:23:26 +01:00

114 lines
2.9 KiB
C

/* src/modules/history.c - (C) 2020 Bram Matthys (Syzop) & The UnrealIRCd Team
*
* Simple HISTORY command to fetch channel history.
* This is one of the interfaces to the channel history backend.
* The other, most prominent, being history-on-join at the moment.
* In the future there will likely be an IRCv3 standard which
* will allow clients to fetch history automatically, which will
* be implemented under a different command and not really meant
* for end users. However, it will take a while until such a spec is
* finalized, let alone when major clients will finally support it.
*
* See doc/Authors and git history for additional names of the programmers.
*
* This program 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; either version 1, or (at your option)
* any later version.
*
* 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, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "unrealircd.h"
ModuleHeader MOD_HEADER
= {
"history",
"5.0",
"Simple history command for end-users",
"UnrealIRCd Team",
"unrealircd-5",
};
CMD_FUNC(cmd_history);
MOD_INIT()
{
MARK_AS_OFFICIAL_MODULE(modinfo);
CommandAdd(NULL, "HISTORY", cmd_history, MAXPARA, CMD_USER);
return MOD_SUCCESS;
}
MOD_LOAD()
{
return MOD_SUCCESS;
}
MOD_UNLOAD()
{
return MOD_SUCCESS;
}
void history_usage(Client *client)
{
sendnotice(client, " Use: /HISTORY #channel [lines-to-display]");
sendnotice(client, " Ex: /HISTORY #lobby");
sendnotice(client, " Ex: /HISTORY #lobby 50");
sendnotice(client, "The lines-to-display value must be 1-100, the default is 100");
sendnotice(client, "Naturally, the line count and time limits in channel mode +H are obeyed");
}
CMD_FUNC(cmd_history)
{
HistoryFilter filter;
Channel *channel;
int lines;
if ((parc < 3) || BadPtr(parv[2]))
{
history_usage(client);
return;
}
channel = find_channel(parv[1], NULL);
if (!channel)
{
sendnumeric(client, ERR_NOSUCHCHANNEL, parv[1]);
return;
}
if (!IsMember(client, channel))
{
sendnumeric(client, ERR_NOTONCHANNEL, channel->chname);
return;
}
lines = atoi(parv[2]);
if (lines < 1)
{
history_usage(client);
return;
}
if (lines > 100)
lines = 100;
if (!HasCapability(client, "server-time"))
{
sendnotice(client, "Your IRC client does not support the 'server-time' capability");
sendnotice(client, "https://ircv3.net/specs/extensions/server-time-3.2.html");
sendnotice(client, "History request refused.");
return;
}
filter.last_lines = lines;
history_request(client, channel->chname, &filter);
}