|
| 1 | +/* |
| 2 | + * Copyright (C) 2021 David Schultz <[email protected]> |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation; either version 2 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program; if not, write to the Free Software |
| 16 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 17 | + * USA |
| 18 | + */ |
| 19 | + |
| 20 | +#include "stdinc.h" |
| 21 | +#include "capability.h" |
| 22 | +#include "client.h" |
| 23 | +#include "hook.h" |
| 24 | +#include "ircd.h" |
| 25 | +#include "send.h" |
| 26 | +#include "logger.h" |
| 27 | +#include "modules.h" |
| 28 | +#include "msgbuf.h" |
| 29 | +#include "numeric.h" |
| 30 | +#include "supported.h" |
| 31 | +#include "s_conf.h" |
| 32 | +#include "s_serv.h" |
| 33 | +#include "s_user.h" |
| 34 | +#include "s_newconf.h" |
| 35 | + |
| 36 | +static char botmode_desc[] = "Provides support for the IRCv3 draft/bot spec"; |
| 37 | + |
| 38 | +static void h_bm_outbound_msgbuf(void *); |
| 39 | +static void h_bm_whois(void *); |
| 40 | + |
| 41 | +static unsigned CLICAP_BOT; |
| 42 | + |
| 43 | +mapi_cap_list_av2 botmode_caps[] = { |
| 44 | + { MAPI_CAP_CLIENT, "draft/bot", NULL, &CLICAP_BOT }, |
| 45 | + { 0, NULL, NULL, NULL}, |
| 46 | +}; |
| 47 | + |
| 48 | +mapi_hfn_list_av1 botmode_hfnlist[] = { |
| 49 | + { "outbound_msgbuf", h_bm_outbound_msgbuf, HOOK_NORMAL }, |
| 50 | + { "doing_whois_global", h_bm_whois, HOOK_MONITOR }, |
| 51 | + { "doing_whois", h_bm_whois, HOOK_MONITOR }, |
| 52 | + { NULL, NULL, 0 } |
| 53 | +}; |
| 54 | + |
| 55 | +static void |
| 56 | +h_bm_outbound_msgbuf(void *data_) |
| 57 | +{ |
| 58 | + hook_data *data = data_; |
| 59 | + struct MsgBuf *msgbuf = data->arg1; |
| 60 | + |
| 61 | + if (data->client->umodes & user_modes['B']) |
| 62 | + { |
| 63 | + msgbuf_append_tag(msgbuf, "draft/bot", NULL, CLICAP_BOT); |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +static void |
| 68 | +h_bm_whois(void *data_) |
| 69 | +{ |
| 70 | + hook_data_client *data = data_; |
| 71 | + if (data->target->umodes & user_modes['B']) |
| 72 | + { |
| 73 | + sendto_one_numeric(data->client, RPL_WHOISBOT, |
| 74 | + form_str(RPL_WHOISBOT), data->target->name, ServerInfo.network_name); |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +static int |
| 79 | +_modinit(void) |
| 80 | +{ |
| 81 | + user_modes['B'] = find_umode_slot(); |
| 82 | + construct_umodebuf(); |
| 83 | + if (!user_modes['B']) |
| 84 | + { |
| 85 | + ierror("m_botmode: unable to allocate usermode slot for +B, unloading extension"); |
| 86 | + return -1; |
| 87 | + } |
| 88 | + add_isupport("BOT", isupport_umode, "B"); |
| 89 | + return 0; |
| 90 | +} |
| 91 | + |
| 92 | +static void |
| 93 | +_moddeinit(void) |
| 94 | +{ |
| 95 | + user_modes['B'] = 0; |
| 96 | + construct_umodebuf(); |
| 97 | + delete_isupport("BOT"); |
| 98 | +} |
| 99 | + |
| 100 | +DECLARE_MODULE_AV2(botmode, _modinit, _moddeinit, NULL, NULL, botmode_hfnlist, botmode_caps, NULL, botmode_desc); |
0 commit comments