unrealircd

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

nocodes.c (2944B)

      1 /*
      2  * "No Codes", a very simple (but often requested) module written by Syzop.
      3  * This module will strip messages with bold/underline/reverse if chanmode
      4  * +S is set, and block them if +c is set.
      5  *
      6  *   This program is free software; you can redistribute it and/or modify
      7  *   it under the terms of the GNU General Public License as published by
      8  *   the Free Software Foundation; either version 1, or (at your option)
      9  *   any later version.
     10  *
     11  *   This program is distributed in the hope that it will be useful,
     12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14  *   GNU General Public License for more details.
     15  *
     16  *   You should have received a copy of the GNU General Public License
     17  *   along with this program; if not, write to the Free Software
     18  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     19  */
     20 
     21 #include "unrealircd.h"
     22 
     23 ModuleHeader MOD_HEADER
     24 = {
     25 	"nocodes",	/* Name of module */
     26 	"1.3", /* Version */
     27 	"Strip/block color/bold/underline/italic/reverse - by Syzop", /* Short description of module */
     28 	"UnrealIRCd Team", /* Author */
     29 	"unrealircd-6",
     30 };
     31 
     32 int nocodes_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype);
     33 
     34 MOD_INIT()
     35 {
     36 	MARK_AS_OFFICIAL_MODULE(modinfo);
     37 
     38 	HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_CHANNEL, 0, nocodes_can_send_to_channel);
     39 	return MOD_SUCCESS;
     40 }
     41 
     42 MOD_LOAD()
     43 {
     44 	return MOD_SUCCESS;
     45 }
     46 
     47 MOD_UNLOAD()
     48 {
     49 	return MOD_SUCCESS;
     50 }
     51 
     52 static int has_controlcodes(const char *p)
     53 {
     54 	for (; *p; p++)
     55 		if ((*p == '\002') || (*p == '\037') || (*p == '\026') || (*p == '\035')) /* bold, underline, reverse, italic */
     56 			return 1;
     57 	return 0;
     58 }
     59 
     60 int nocodes_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype)
     61 {
     62 	static char retbuf[4096];
     63 	Hook *h;
     64 	int i;
     65 
     66 	if (has_channel_mode(channel, 'S'))
     67 	{
     68 		if (!has_controlcodes(*msg))
     69 			return HOOK_CONTINUE;
     70 
     71 		for (h = Hooks[HOOKTYPE_CAN_BYPASS_CHANNEL_MESSAGE_RESTRICTION]; h; h = h->next)
     72 		{
     73 			i = (*(h->func.intfunc))(client, channel, BYPASS_CHANMSG_COLOR);
     74 			if (i == HOOK_ALLOW)
     75 				return HOOK_CONTINUE; /* bypass +S restriction */
     76 			if (i != HOOK_CONTINUE)
     77 				break;
     78 		}
     79 
     80 		strlcpy(retbuf, StripControlCodes(*msg), sizeof(retbuf));
     81 		*msg = retbuf;
     82 		return HOOK_CONTINUE;
     83 	} else
     84 	if (has_channel_mode(channel, 'c'))
     85 	{
     86 		if (!has_controlcodes(*msg))
     87 			return HOOK_CONTINUE;
     88 
     89 		for (h = Hooks[HOOKTYPE_CAN_BYPASS_CHANNEL_MESSAGE_RESTRICTION]; h; h = h->next)
     90 		{
     91 			i = (*(h->func.intfunc))(client, channel, BYPASS_CHANMSG_COLOR);
     92 			if (i == HOOK_ALLOW)
     93 				return HOOK_CONTINUE; /* bypass +c restriction */
     94 			if (i != HOOK_CONTINUE)
     95 				break;
     96 		}
     97 
     98 		*errmsg = "Control codes (color/bold/underline/italic/reverse) are not permitted in this channel";
     99 		return HOOK_DENY;
    100 	}
    101 	return HOOK_CONTINUE;
    102 }