unrealircd

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

nocolor.c (3692B)

      1 /*
      2  * Block Color UnrealIRCd Module (Channel Mode +c)
      3  * (C) Copyright 2000-.. Bram Matthys (Syzop) and the UnrealIRCd team
      4  *
      5  * This program is free software; you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License as published by
      7  * the Free Software Foundation; either version 1, or (at your option)
      8  * any later version.
      9  *
     10  * This program is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  * GNU General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU General Public License
     16  * along with this program; if not, write to the Free Software
     17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     18  */
     19 
     20 #include "unrealircd.h"
     21 
     22 CMD_FUNC(nocolor);
     23 
     24 ModuleHeader MOD_HEADER
     25   = {
     26 	"chanmodes/nocolor",
     27 	"4.2",
     28 	"Channel Mode +c",
     29 	"UnrealIRCd Team",
     30 	"unrealircd-6",
     31     };
     32 
     33 Cmode_t EXTCMODE_NOCOLOR;
     34 
     35 #define IsNoColor(channel)    (channel->mode.mode & EXTCMODE_NOCOLOR)
     36 
     37 int nocolor_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype);
     38 const char *nocolor_prelocalpart(Client *client, Channel *channel, const char *comment);
     39 const char *nocolor_prelocalquit(Client *client, const char *comment);
     40 
     41 MOD_TEST()
     42 {
     43 	return MOD_SUCCESS;
     44 }
     45 
     46 MOD_INIT()
     47 {
     48 CmodeInfo req;
     49 
     50 	/* Channel mode */
     51 	memset(&req, 0, sizeof(req));
     52 	req.paracount = 0;
     53 	req.letter = 'c';
     54 	req.is_ok = extcmode_default_requirechop;
     55 	CmodeAdd(modinfo->handle, req, &EXTCMODE_NOCOLOR);
     56 	
     57 	HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_CHANNEL, 0, nocolor_can_send_to_channel);
     58 	HookAddConstString(modinfo->handle, HOOKTYPE_PRE_LOCAL_PART, 0, nocolor_prelocalpart);
     59 	HookAddConstString(modinfo->handle, HOOKTYPE_PRE_LOCAL_QUIT_CHAN, 0, nocolor_prelocalpart);
     60 	HookAddConstString(modinfo->handle, HOOKTYPE_PRE_LOCAL_QUIT, 0, nocolor_prelocalquit);
     61 	
     62 	MARK_AS_OFFICIAL_MODULE(modinfo);
     63 	return MOD_SUCCESS;
     64 }
     65 
     66 MOD_LOAD()
     67 {
     68 	return MOD_SUCCESS;
     69 }
     70 
     71 MOD_UNLOAD()
     72 {
     73 	return MOD_SUCCESS;
     74 }
     75 
     76 static int IsUsingColor(const char *s)
     77 {
     78         if (!s)
     79                 return 0;
     80 
     81         for (; *s; s++)
     82                 if (*s == 3 || *s == 27 || *s == 4 || *s == 22) /* mirc color, ansi, rgb, reverse */
     83                         return 1;
     84 
     85         return 0;
     86 }
     87 
     88 int nocolor_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype)
     89 {
     90 	Hook *h;
     91 	int i;
     92 
     93 	if (MyUser(client) && IsNoColor(channel) && IsUsingColor(*msg))
     94 	{
     95 		for (h = Hooks[HOOKTYPE_CAN_BYPASS_CHANNEL_MESSAGE_RESTRICTION]; h; h = h->next)
     96 		{
     97 			i = (*(h->func.intfunc))(client, channel, BYPASS_CHANMSG_COLOR);
     98 			if (i == HOOK_ALLOW)
     99 				return HOOK_CONTINUE; /* bypass this restriction */
    100 			if (i != HOOK_CONTINUE)
    101 				break;
    102 		}
    103 
    104 		*errmsg = "Color is not permitted in this channel";
    105 		return HOOK_DENY;
    106 	}
    107 
    108 	return HOOK_CONTINUE;
    109 }
    110 
    111 const char *nocolor_prelocalpart(Client *client, Channel *channel, const char *comment)
    112 {
    113 	if (!comment)
    114 		return NULL;
    115 
    116 	if (MyUser(client) && IsNoColor(channel) && IsUsingColor(comment))
    117 		return NULL;
    118 
    119 	return comment;
    120 }
    121 
    122 /** Is any channel where the user is in +c? */
    123 static int IsAnyChannelNoColor(Client *client)
    124 {
    125 	Membership *lp;
    126 
    127 	for (lp = client->user->channel; lp; lp = lp->next)
    128 		if (IsNoColor(lp->channel))
    129 			return 1;
    130 	return 0;
    131 }
    132 
    133 const char *nocolor_prelocalquit(Client *client, const char *comment)
    134 {
    135 	if (!comment)
    136 		return NULL;
    137 
    138 	if (MyUser(client) && !BadPtr(comment) && IsUsingColor(comment) && IsAnyChannelNoColor(client))
    139 		return NULL;
    140 
    141 	return comment;
    142 }