Remove MODE_NOCOLOR from core, replacing it with modules/chm_nocolour.so.

This commit is contained in:
William Pitcock 2012-03-31 22:26:45 -05:00
parent 6eb033605c
commit 67aeaba593
5 changed files with 81 additions and 23 deletions

View file

@ -169,7 +169,6 @@ typedef int (*ExtbanFunc)(const char *data, struct Client *client_p,
#define MODE_INVITEONLY 0x0010
#define MODE_NOPRIVMSGS 0x0020
#define MODE_REGONLY 0x0040
#define MODE_NOCOLOR 0x0080
#define MODE_EXLIMIT 0x0100 /* exempt from list limits, +b/+e/+I/+q */
#define MODE_PERMANENT 0x0200 /* permanant channel, +P */
#define MODE_OPMODERATE 0x0400 /* send rejected messages to ops */

View file

@ -55,6 +55,7 @@ CORE_SRCS = \
core/m_squit.c
TSRCS = \
chm_nocolour.c \
m_accept.c \
m_admin.c \
m_away.c \

79
modules/chm_nocolour.c Normal file
View file

@ -0,0 +1,79 @@
/*
* charybdis: an advanced ircd.
* chm_nocolour: strip colours (+c mode).
*
* Copyright (c) 2012 William Pitcock <nenolod@dereferenced.org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice is present in all copies.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "stdinc.h"
#include "modules.h"
#include "hook.h"
#include "client.h"
#include "ircd.h"
#include "send.h"
#include "s_conf.h"
#include "s_user.h"
#include "s_serv.h"
#include "numeric.h"
#include "chmode.h"
#include "inline/stringops.h"
static char buf[BUFSIZE];
static unsigned int mode_nocolour;
static void chm_nocolour_process(hook_data_privmsg_channel *);
mapi_hfn_list_av1 chm_nocolour_hfnlist[] = {
{ "privmsg_channel", (hookfn) chm_nocolour_process },
{ NULL, NULL }
};
static void
chm_nocolour_process(hook_data_privmsg_channel *data)
{
/* don't waste CPU if message is already blocked */
if (data->approved)
return;
if (data->chptr->mode.mode & mode_nocolour)
{
rb_strlcpy(buf, data->text, sizeof buf);
strip_colour(buf);
data->text = buf;
}
}
static int
_modinit(void)
{
mode_nocolour = cflag_add('c', chm_simple);
if (mode_nocolour == 0)
return -1;
return 0;
}
static void
_moddeinit(void)
{
cflag_orphan('c');
}
DECLARE_MODULE_AV1(chm_nocolour, _modinit, _moddeinit, NULL, NULL, chm_nocolour_hfnlist, "$Revision$");

View file

@ -489,13 +489,6 @@ msg_channel(enum message_type msgtype,
source_p->localClient->last = rb_current_time();
}
if(chptr->mode.mode & MODE_NOCOLOR)
{
rb_strlcpy(text2, text, BUFSIZE);
strip_colour(text2);
text = text2;
}
hdata.msgtype = msgtype;
hdata.source_p = source_p;
hdata.chptr = chptr;
@ -594,13 +587,6 @@ msg_channel_opmod(enum message_type msgtype,
char text2[BUFSIZE];
hook_data_privmsg_channel hdata;
if(chptr->mode.mode & MODE_NOCOLOR)
{
rb_strlcpy(text2, text, BUFSIZE);
strip_colour(text2);
text = text2;
}
hdata.msgtype = msgtype;
hdata.source_p = source_p;
hdata.chptr = chptr;
@ -683,13 +669,6 @@ msg_channel_flags(enum message_type msgtype, struct Client *client_p,
source_p->localClient->last = rb_current_time();
}
if(chptr->mode.mode & MODE_NOCOLOR)
{
rb_strlcpy(text2, text, BUFSIZE);
strip_colour(text2);
text = text2;
}
hdata.msgtype = msgtype;
hdata.source_p = source_p;
hdata.chptr = chptr;

View file

@ -1517,7 +1517,7 @@ struct ChannelMode chmode_table[256] =
{chm_nosuch, 0 },
{chm_nosuch, 0 }, /* a */
{chm_ban, CHFL_BAN }, /* b */
{chm_simple, MODE_NOCOLOR }, /* c */
{chm_nosuch, 0 }, /* c */
{chm_nosuch, 0 }, /* d */
{chm_ban, CHFL_EXCEPTION }, /* e */
{chm_forward, 0 }, /* f */