unrealircd

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

noctcp.c (2052B)

      1 /*
      2  * Block user-to-user CTCP UnrealIRCd Module (User Mode +T)
      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(noctcp);
     23 
     24 ModuleHeader MOD_HEADER
     25   = {
     26 	"usermodes/noctcp",
     27 	"4.2",
     28 	"User Mode +T",
     29 	"UnrealIRCd Team",
     30 	"unrealircd-6",
     31     };
     32 
     33 long UMODE_NOCTCP = 0L;
     34 
     35 #define IsNoCTCP(client)    (client->umodes & UMODE_NOCTCP)
     36 
     37 int noctcp_can_send_to_user(Client *client, Client *target, const char **text, const char **errmsg, SendType sendtype);
     38 
     39 MOD_TEST()
     40 {
     41 	return MOD_SUCCESS;
     42 }
     43 
     44 MOD_INIT()
     45 {
     46 CmodeInfo req;
     47 
     48 	UmodeAdd(modinfo->handle, 'T', UMODE_GLOBAL, 0, NULL, &UMODE_NOCTCP);
     49 	
     50 	HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_USER, 0, noctcp_can_send_to_user);
     51 	
     52 	MARK_AS_OFFICIAL_MODULE(modinfo);
     53 	return MOD_SUCCESS;
     54 }
     55 
     56 MOD_LOAD()
     57 {
     58 	return MOD_SUCCESS;
     59 }
     60 
     61 MOD_UNLOAD()
     62 {
     63 	return MOD_SUCCESS;
     64 }
     65 
     66 static int IsACTCP(const char *s)
     67 {
     68 	if (!s)
     69 		return 0;
     70 
     71 	if ((*s == '\001') && strncmp(&s[1], "ACTION ", 7) && strncmp(&s[1], "DCC ", 4))
     72 		return 1;
     73 
     74 	return 0;
     75 }
     76 
     77 int noctcp_can_send_to_user(Client *client, Client *target, const char **text, const char **errmsg, SendType sendtype)
     78 {
     79 	if (MyUser(client) && (sendtype == SEND_TYPE_PRIVMSG) &&
     80 	    IsNoCTCP(target) && !IsOper(client) && IsACTCP(*text))
     81 	{
     82 		*errmsg = "User does not accept CTCPs";
     83 		return HOOK_DENY;
     84 	}
     85 	return HOOK_CONTINUE;
     86 }