Advertisement
Guest User

Untitled

a guest
Nov 19th, 2011
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.39 KB | None | 0 0
  1. /*
  2.  *   StripCodes UnrealIRCd module
  3.  *   (C) 2011 cedric (irc.p2pchat.net)
  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. /*
  21.  * =================================================================
  22.  * Filename:          m_stripcodes.c
  23.  * Description:       Usermode +c to strip out colors & control codes
  24.  * Author:            cedric (irc.p2pchat.net)
  25.  * Credits:           Dominick Meglio (codemastr) for nocolorumode.c, and k4be for m_npircs.c.
  26.                       I based this module on both files
  27.                       Syzop & katsklaw for helping me out on the forums :)
  28.  * Dedicated to:      ibanez & arya_
  29.  * =================================================================
  30.  */
  31.  
  32. #include "config.h"
  33. #include "struct.h"
  34. #include "common.h"
  35. #include "sys.h"
  36. #include "numeric.h"
  37. #include "msg.h"
  38. #include "channel.h"
  39. #include <time.h>
  40. #include <sys/stat.h>
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <string.h>
  44. #ifdef _WIN32
  45. #include <io.h>
  46. #endif
  47. #include <fcntl.h>
  48. #include "h.h"
  49. #include "proto.h"
  50. #ifdef STRIPBADWORDS
  51. #include "badwords.h"
  52. #endif
  53. #ifdef _WIN32
  54. #include "version.h"
  55. #endif
  56.  
  57. #define UFLAG_STRIPCODES    'c'
  58. #define IsColorBlind(x) ((x)->umodes & UMODE_STRIPCODES)
  59. #define     DelUmode(x)     if (x) UmodeDel(x); x = NULL
  60. #define     DelHook(x)      if (x) HookDel(x); x = NULL
  61.  
  62. ModuleHeader MOD_HEADER(stripcodes)
  63.   = {
  64.     "stripcodes",
  65.     "1.0.1",
  66.     "color stripping usermode",
  67.     "3.2-b8-1",
  68.     NULL
  69.     };
  70.  
  71.  
  72. long        UMODE_STRIPCODES = 0L;
  73. Hook        *HookStripCodes = NULL;
  74. Umode       *UmodeStripCodes = NULL;
  75.  
  76. int stripcodes_packet(aClient *, aClient *, char **, int *);
  77.  
  78. DLLFUNC int MOD_INIT(stripcodes)(ModuleInfo *modinfo)
  79. {
  80. /*  #ifndef STATIC_LINKING
  81.         ModuleSetOptions(modinfo->handle, MOD_OPT_PERM);
  82.     #endif
  83. */
  84.     HookStripCodes = HookAddEx(modinfo->handle, HOOKTYPE_PACKET, stripcodes_packet);
  85.     UmodeStripCodes = UmodeAdd(modinfo->handle, UFLAG_STRIPCODES, UMODE_GLOBAL, umode_allow_all, &UMODE_STRIPCODES);
  86.     if (!UmodeStripCodes)
  87.     {
  88.         sendto_realops("m_stripcodes: Couldn't load properly: %s", ModuleGetErrorStr(modinfo->handle));
  89.         MOD_UNLOAD(stripcodes)(0);
  90.         return MOD_FAILED;
  91.     }
  92.  
  93.     return MOD_SUCCESS;
  94. }
  95.  
  96. DLLFUNC int MOD_LOAD(stripcodes)(int module_load)
  97. {
  98.     return MOD_SUCCESS;
  99. }
  100.  
  101. DLLFUNC int MOD_UNLOAD(stripcodes)(int module_unload)
  102. {
  103.     DelUmode(UmodeStripCodes);
  104.     DelHook(HookStripCodes);
  105.  
  106.     return MOD_SUCCESS;
  107. }
  108.  
  109. int stripcodes_packet(aClient *from, aClient *to, char **msg, int *len)
  110. {
  111.     static char buf[512];
  112.  
  113.     if((from != &me && (!IsClient(from) && IsRegistered(from))) || (to != &me && !IsClient(to)))
  114.         return HOOK_CONTINUE;
  115.  
  116.     if (to != &me && IsColorBlind(to)) {
  117.         strcpy(buf, StripControlCodes(*msg));
  118.  
  119.         *len = strlen(buf);
  120.         *msg = buf;
  121.     }
  122.  
  123.     return HOOK_CONTINUE;
  124. }
  125.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement