/* * StripCodes UnrealIRCd module * (C) 2011 cedric (irc.p2pchat.net) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 1, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * ================================================================= * Filename: m_stripcodes.c * Description: Usermode +c to strip out colors & control codes * Author: cedric (irc.p2pchat.net) * Credits: Dominick Meglio (codemastr) for nocolorumode.c, and k4be for m_npircs.c. I based this module on both files Syzop & katsklaw for helping me out on the forums :) * Dedicated to: ibanez & arya_ * ================================================================= */ #include "config.h" #include "struct.h" #include "common.h" #include "sys.h" #include "numeric.h" #include "msg.h" #include "channel.h" #include #include #include #include #include #ifdef _WIN32 #include #endif #include #include "h.h" #include "proto.h" #ifdef STRIPBADWORDS #include "badwords.h" #endif #ifdef _WIN32 #include "version.h" #endif #define UFLAG_STRIPCODES 'c' #define IsColorBlind(x) ((x)->umodes & UMODE_STRIPCODES) #define DelUmode(x) if (x) UmodeDel(x); x = NULL #define DelHook(x) if (x) HookDel(x); x = NULL ModuleHeader MOD_HEADER(stripcodes) = { "stripcodes", "1.0.1", "color stripping usermode", "3.2-b8-1", NULL }; long UMODE_STRIPCODES = 0L; Hook *HookStripCodes = NULL; Umode *UmodeStripCodes = NULL; int stripcodes_packet(aClient *, aClient *, char **, int *); DLLFUNC int MOD_INIT(stripcodes)(ModuleInfo *modinfo) { /* #ifndef STATIC_LINKING ModuleSetOptions(modinfo->handle, MOD_OPT_PERM); #endif */ HookStripCodes = HookAddEx(modinfo->handle, HOOKTYPE_PACKET, stripcodes_packet); UmodeStripCodes = UmodeAdd(modinfo->handle, UFLAG_STRIPCODES, UMODE_GLOBAL, umode_allow_all, &UMODE_STRIPCODES); if (!UmodeStripCodes) { sendto_realops("m_stripcodes: Couldn't load properly: %s", ModuleGetErrorStr(modinfo->handle)); MOD_UNLOAD(stripcodes)(0); return MOD_FAILED; } return MOD_SUCCESS; } DLLFUNC int MOD_LOAD(stripcodes)(int module_load) { return MOD_SUCCESS; } DLLFUNC int MOD_UNLOAD(stripcodes)(int module_unload) { DelUmode(UmodeStripCodes); DelHook(HookStripCodes); return MOD_SUCCESS; } int stripcodes_packet(aClient *from, aClient *to, char **msg, int *len) { static char buf[512]; if((from != &me && (!IsClient(from) && IsRegistered(from))) || (to != &me && !IsClient(to))) return HOOK_CONTINUE; if (to != &me && IsColorBlind(to)) { strcpy(buf, StripControlCodes(*msg)); *len = strlen(buf); *msg = buf; } return HOOK_CONTINUE; }