unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

bot-tag.c (2700B)

      1 /*
      2  *   IRC - Internet Relay Chat, src/modules/bot-tag.c
      3  *   (C) 2021 Syzop & The UnrealIRCd Team
      4  *
      5  *   See file AUTHORS in IRC package for additional names of
      6  *   the programmers.
      7  *
      8  *   This program is free software; you can redistribute it and/or modify
      9  *   it under the terms of the GNU General Public License as published by
     10  *   the Free Software Foundation; either version 1, or (at your option)
     11  *   any later version.
     12  *
     13  *   This program is distributed in the hope that it will be useful,
     14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  *   GNU General Public License for more details.
     17  *
     18  *   You should have received a copy of the GNU General Public License
     19  *   along with this program; if not, write to the Free Software
     20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     21  */
     22 
     23 /* This implements the message tag that is mentioned in
     24  * https://ircv3.net/specs/extensions/bot-mode
     25  * The B mode and 005 is in the modules/usermodes/bot module.
     26  */
     27 
     28 #include "unrealircd.h"
     29 
     30 ModuleHeader MOD_HEADER
     31   = {
     32 	"bot-tag",
     33 	"5.0",
     34 	"bot message tag",
     35 	"UnrealIRCd Team",
     36 	"unrealircd-6",
     37 	};
     38 
     39 int bottag_mtag_is_ok(Client *client, const char *name, const char *value);
     40 void mtag_add_bottag(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature);
     41 
     42 MOD_INIT()
     43 {
     44 	MessageTagHandlerInfo mtag;
     45 
     46 	MARK_AS_OFFICIAL_MODULE(modinfo);
     47 
     48 	memset(&mtag, 0, sizeof(mtag));
     49 	mtag.name = "bot";
     50 	mtag.is_ok = bottag_mtag_is_ok;
     51 	mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED;
     52 	MessageTagHandlerAdd(modinfo->handle, &mtag);
     53 
     54 	memset(&mtag, 0, sizeof(mtag));
     55 	mtag.name = "draft/bot";
     56 	mtag.is_ok = bottag_mtag_is_ok;
     57 	mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED;
     58 	MessageTagHandlerAdd(modinfo->handle, &mtag);
     59 
     60 	HookAddVoid(modinfo->handle, HOOKTYPE_NEW_MESSAGE, 0, mtag_add_bottag);
     61 
     62 	return MOD_SUCCESS;
     63 }
     64 
     65 MOD_LOAD()
     66 {
     67 	return MOD_SUCCESS;
     68 }
     69 
     70 MOD_UNLOAD()
     71 {
     72 	return MOD_SUCCESS;
     73 }
     74 
     75 /** This function verifies if the client sending the mtag is permitted to do so.
     76  */
     77 int bottag_mtag_is_ok(Client *client, const char *name, const char *value)
     78 {
     79 	if (IsServer(client) && (value == NULL))
     80 		return 1; /* OK */
     81 
     82 	return 0;
     83 }
     84 
     85 void mtag_add_bottag(Client *client, MessageTag *recv_mtags, MessageTag **mtag_list, const char *signature)
     86 {
     87 	MessageTag *m;
     88 
     89 	if (IsUser(client) && has_user_mode(client, 'B'))
     90 	{
     91 		MessageTag *m;
     92 
     93 		m = safe_alloc(sizeof(MessageTag));
     94 		safe_strdup(m->name, "bot");
     95 		m->value = NULL;
     96 		AddListItem(m, *mtag_list);
     97 
     98 		m = safe_alloc(sizeof(MessageTag));
     99 		safe_strdup(m->name, "draft/bot");
    100 		m->value = NULL;
    101 		AddListItem(m, *mtag_list);
    102 	}
    103 }