From 67aeaba5930fdaa9b991471a578b94528ce94420 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 31 Mar 2012 22:26:45 -0500 Subject: [PATCH] Remove MODE_NOCOLOR from core, replacing it with modules/chm_nocolour.so. --- include/channel.h | 1 - modules/Makefile.in | 1 + modules/chm_nocolour.c | 79 ++++++++++++++++++++++++++++++++++++++++ modules/core/m_message.c | 21 ----------- src/chmode.c | 2 +- 5 files changed, 81 insertions(+), 23 deletions(-) create mode 100644 modules/chm_nocolour.c diff --git a/include/channel.h b/include/channel.h index 9178718b..88bded9c 100644 --- a/include/channel.h +++ b/include/channel.h @@ -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 */ diff --git a/modules/Makefile.in b/modules/Makefile.in index 20f6dc6a..3b1a4754 100644 --- a/modules/Makefile.in +++ b/modules/Makefile.in @@ -55,6 +55,7 @@ CORE_SRCS = \ core/m_squit.c TSRCS = \ + chm_nocolour.c \ m_accept.c \ m_admin.c \ m_away.c \ diff --git a/modules/chm_nocolour.c b/modules/chm_nocolour.c new file mode 100644 index 00000000..3d3e2bb7 --- /dev/null +++ b/modules/chm_nocolour.c @@ -0,0 +1,79 @@ +/* + * charybdis: an advanced ircd. + * chm_nocolour: strip colours (+c mode). + * + * Copyright (c) 2012 William Pitcock + * + * 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$"); diff --git a/modules/core/m_message.c b/modules/core/m_message.c index f99d8959..b2934e9f 100644 --- a/modules/core/m_message.c +++ b/modules/core/m_message.c @@ -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; diff --git a/src/chmode.c b/src/chmode.c index 8177b3ec..ee963289 100644 --- a/src/chmode.c +++ b/src/chmode.c @@ -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 */