unrealircd

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

stripcolor.c (3420B)

      1 /*
      2  * Strip Color UnrealIRCd Module (Channel Mode +S)
      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(stripcolor);
     23 
     24 ModuleHeader MOD_HEADER
     25   = {
     26 	"chanmodes/stripcolor",
     27 	"4.2",
     28 	"Channel Mode +S",
     29 	"UnrealIRCd Team",
     30 	"unrealircd-6",
     31     };
     32 
     33 Cmode_t EXTCMODE_STRIPCOLOR;
     34 
     35 #define IsStripColor(channel)    (channel->mode.mode & EXTCMODE_STRIPCOLOR)
     36 
     37 int stripcolor_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype);
     38 const char *stripcolor_prelocalpart(Client *client, Channel *channel, const char *comment);
     39 const char *stripcolor_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 = 'S';
     54 	req.is_ok = extcmode_default_requirechop;
     55 	CmodeAdd(modinfo->handle, req, &EXTCMODE_STRIPCOLOR);
     56 	
     57 	HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_CHANNEL, 0, stripcolor_can_send_to_channel);
     58 	HookAddConstString(modinfo->handle, HOOKTYPE_PRE_LOCAL_PART, 0, stripcolor_prelocalpart);
     59 	HookAddConstString(modinfo->handle, HOOKTYPE_PRE_LOCAL_QUIT_CHAN, 0, stripcolor_prelocalpart);
     60 	HookAddConstString(modinfo->handle, HOOKTYPE_PRE_LOCAL_QUIT, 0, stripcolor_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 int stripcolor_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype)
     77 {
     78 	Hook *h;
     79 	int i;
     80 
     81 	if (MyUser(client) && IsStripColor(channel))
     82 	{
     83 		for (h = Hooks[HOOKTYPE_CAN_BYPASS_CHANNEL_MESSAGE_RESTRICTION]; h; h = h->next)
     84 		{
     85 			i = (*(h->func.intfunc))(client, channel, BYPASS_CHANMSG_COLOR);
     86 			if (i == HOOK_ALLOW)
     87 				return HOOK_CONTINUE; /* bypass this restriction */
     88 			if (i != HOOK_CONTINUE)
     89 				break;
     90 		}
     91 
     92 		*msg = StripColors(*msg);
     93 	}
     94 
     95 	return HOOK_CONTINUE;
     96 }
     97 
     98 const char *stripcolor_prelocalpart(Client *client, Channel *channel, const char *comment)
     99 {
    100 	if (!comment)
    101 		return NULL;
    102 
    103 	if (MyUser(client) && IsStripColor(channel))
    104 		comment = StripColors(comment);
    105 
    106 	return comment;
    107 }
    108 
    109 /** Is any channel where the user is in +S? */
    110 static int IsAnyChannelStripColor(Client *client)
    111 {
    112 	Membership *lp;
    113 
    114 	for (lp = client->user->channel; lp; lp = lp->next)
    115 		if (IsStripColor(lp->channel))
    116 			return 1;
    117 	return 0;
    118 }
    119 
    120 
    121 const char *stripcolor_prelocalquit(Client *client, const char *comment)
    122 {
    123 	if (!comment)
    124 		return NULL;
    125 
    126 	if (MyUser(client) && !BadPtr(comment) && IsAnyChannelStripColor(client))
    127 		comment = StripColors(comment);
    128         
    129 	return comment;
    130 }
    131