unrealircd- supernets unrealircd source & configuration |
git clone git://git.acid.vegas/unrealircd.git |
Log | Files | Refs | Archive | README | LICENSE |
history.c (3506B)
1 /* src/modules/history.c - (C) 2020 Bram Matthys (Syzop) & The UnrealIRCd Team 2 * 3 * Simple HISTORY command to fetch channel history. 4 * This is one of the interfaces to the channel history backend. 5 * The other, most prominent, being history-on-join at the moment. 6 * In the future there will likely be an IRCv3 standard which 7 * will allow clients to fetch history automatically, which will 8 * be implemented under a different command and not really meant 9 * for end users. However, it will take a while until such a spec is 10 * finalized, let alone when major clients will finally support it. 11 * 12 * See doc/Authors and git history for additional names of the programmers. 13 * 14 * This program is free software; you can redistribute it and/or modify 15 * it under the terms of the GNU General Public License as published by 16 * the Free Software Foundation; either version 1, or (at your option) 17 * any later version. 18 * 19 * This program is distributed in the hope that it will be useful, 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * GNU General Public License for more details. 23 * 24 * You should have received a copy of the GNU General Public License 25 * along with this program; if not, write to the Free Software 26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 27 */ 28 29 #include "unrealircd.h" 30 31 ModuleHeader MOD_HEADER 32 = { 33 "history", 34 "5.0", 35 "Simple history command for end-users", 36 "UnrealIRCd Team", 37 "unrealircd-6", 38 }; 39 40 #define HISTORY_LINES_DEFAULT 100 41 #define HISTORY_LINES_MAX 100 42 43 CMD_FUNC(cmd_history); 44 45 MOD_INIT() 46 { 47 MARK_AS_OFFICIAL_MODULE(modinfo); 48 CommandAdd(modinfo->handle, "HISTORY", cmd_history, MAXPARA, CMD_USER); 49 return MOD_SUCCESS; 50 } 51 52 MOD_LOAD() 53 { 54 return MOD_SUCCESS; 55 } 56 57 MOD_UNLOAD() 58 { 59 return MOD_SUCCESS; 60 } 61 62 void history_usage(Client *client) 63 { 64 sendnotice(client, " Use: /HISTORY #channel [lines-to-display]"); 65 sendnotice(client, " Ex: /HISTORY #lobby"); 66 sendnotice(client, " Ex: /HISTORY #lobby 50"); 67 sendnotice(client, "The lines-to-display value must be 1-%d, the default is %d", 68 HISTORY_LINES_MAX, HISTORY_LINES_DEFAULT); 69 sendnotice(client, "Naturally, the line count and time limits in channel mode +H are obeyed"); 70 } 71 72 CMD_FUNC(cmd_history) 73 { 74 HistoryFilter filter; 75 HistoryResult *r; 76 Channel *channel; 77 int lines = HISTORY_LINES_DEFAULT; 78 79 if (!MyUser(client)) 80 return; 81 82 if ((parc < 2) || BadPtr(parv[1])) 83 { 84 history_usage(client); 85 return; 86 } 87 88 channel = find_channel(parv[1]); 89 if (!channel) 90 { 91 sendnumeric(client, ERR_NOSUCHCHANNEL, parv[1]); 92 return; 93 } 94 95 if (!IsMember(client, channel)) 96 { 97 sendnumeric(client, ERR_NOTONCHANNEL, channel->name); 98 return; 99 } 100 101 if (!has_channel_mode(channel, 'H')) 102 { 103 sendnotice(client, "Channel %s does not have channel mode +H set", channel->name); 104 return; 105 } 106 107 if (parv[2]) 108 { 109 lines = atoi(parv[2]); 110 if (lines < 1) 111 { 112 history_usage(client); 113 return; 114 } 115 if (lines > HISTORY_LINES_MAX) 116 lines = HISTORY_LINES_MAX; 117 } 118 119 if (!HasCapability(client, "server-time")) 120 { 121 sendnotice(client, "Your IRC client does not support the 'server-time' capability"); 122 sendnotice(client, "https://ircv3.net/specs/extensions/server-time"); 123 sendnotice(client, "History request refused."); 124 return; 125 } 126 127 memset(&filter, 0, sizeof(filter)); 128 filter.cmd = HFC_SIMPLE; 129 filter.last_lines = lines; 130 131 if ((r = history_request(channel->name, &filter))) 132 { 133 history_send_result(client, r); 134 free_history_result(r); 135 } 136 }