unrealircd

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

servicebot.c (4685B)

      1 /*
      2  * Prevents you from being kicked (User mode +q)
      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 #define IsServiceBot(client)    (client->umodes & UMODE_SERVICEBOT)
     23 
     24 /* Module header */
     25 ModuleHeader MOD_HEADER
     26   = {
     27 	"usermodes/servicebot",
     28 	"4.2",
     29 	"User Mode +S",
     30 	"UnrealIRCd Team",
     31 	"unrealircd-6",
     32     };
     33 
     34 /* Global variables */
     35 long UMODE_SERVICEBOT = 0L;
     36 
     37 /* Forward declarations */
     38 int servicebot_can_kick(Client *client, Client *target, Channel *channel,
     39                     const char *comment, const char *client_member_modes, const char *target_member_modes, const char **reject_reason);
     40 int servicebot_mode_deop(Client *client, Client *target, Channel *channel,
     41                     u_int what, int modechar, const char *client_access, const char *target_access, const char **reject_reason);
     42 int servicebot_pre_kill(Client *client, Client *target, const char *reason);
     43 int servicebot_whois(Client *requester, Client *acptr, NameValuePrioList **list);
     44 int servicebot_see_channel_in_whois(Client *client, Client *target, Channel *channel);
     45                     
     46 MOD_TEST()
     47 {
     48 	return MOD_SUCCESS;
     49 }
     50 
     51 MOD_INIT()
     52 {
     53 	UmodeAdd(modinfo->handle, 'S', UMODE_GLOBAL, 1, umode_allow_none, &UMODE_SERVICEBOT);
     54 	
     55 	HookAdd(modinfo->handle, HOOKTYPE_CAN_KICK, 0, servicebot_can_kick);
     56 	HookAdd(modinfo->handle, HOOKTYPE_MODE_DEOP, 0, servicebot_mode_deop);
     57 	HookAdd(modinfo->handle, HOOKTYPE_PRE_KILL, 0, servicebot_pre_kill);
     58 	HookAdd(modinfo->handle, HOOKTYPE_WHOIS, 0, servicebot_whois);
     59 	HookAdd(modinfo->handle, HOOKTYPE_SEE_CHANNEL_IN_WHOIS, 0, servicebot_see_channel_in_whois);
     60 	
     61 	MARK_AS_OFFICIAL_MODULE(modinfo);
     62 	return MOD_SUCCESS;
     63 }
     64 
     65 MOD_LOAD()
     66 {
     67 	return MOD_SUCCESS;
     68 }
     69 
     70 MOD_UNLOAD()
     71 {
     72 	return MOD_SUCCESS;
     73 }
     74 
     75 int servicebot_can_kick(Client *client, Client *target, Channel *channel, const char *comment,
     76                     const char *client_member_modes, const char *target_member_modes, const char **reject_reason)
     77 {
     78 	static char errmsg[NICKLEN+256];
     79 
     80 	if (MyUser(client) && !IsULine(client) && IsServiceBot(target))
     81 	{
     82 		char errmsg2[NICKLEN+32];
     83 		snprintf(errmsg2, sizeof(errmsg2), "%s is a Service Bot", target->name);
     84 		
     85 		snprintf(errmsg, sizeof(errmsg), ":%s %d %s %s :%s",
     86 		         me.name, ERR_CANNOTDOCOMMAND, client->name, "KICK", errmsg2);
     87 
     88 		*reject_reason = errmsg;
     89 
     90 		return EX_DENY;
     91 	}
     92 
     93 	return EX_ALLOW;
     94 }
     95 
     96 int servicebot_mode_deop(Client *client, Client *target, Channel *channel,
     97                     u_int what, int modechar, const char *client_access, const char *target_access, const char **reject_reason)
     98 {
     99 	static char errmsg[NICKLEN+256];
    100 	
    101 	if (IsServiceBot(target) && MyUser(client) && !ValidatePermissionsForPath("services:servicebot:deop",client,target,channel,NULL) && (what == MODE_DEL))
    102 	{
    103 		snprintf(errmsg, sizeof(errmsg), ":%s %d %s %c :%s is a Service Bot",
    104 			me.name, ERR_CANNOTCHANGECHANMODE, client->name, (char)modechar, target->name);
    105 		
    106 		*reject_reason = errmsg;
    107 		
    108 		return EX_DENY;
    109 	}
    110 	
    111 	return EX_ALLOW;
    112 }
    113 
    114 int servicebot_pre_kill(Client *client, Client *target, const char *reason)
    115 {
    116 	if (IsServiceBot(target) && !(ValidatePermissionsForPath("services:servicebot:kill",client,target,NULL,NULL) || IsULine(client)))
    117 	{
    118 		sendnumeric(client, ERR_KILLDENY, target->name);
    119 		return EX_ALWAYS_DENY;
    120 	}
    121 	return EX_ALLOW;
    122 }
    123 
    124 int servicebot_whois(Client *client, Client *target, NameValuePrioList **list)
    125 {
    126 	int hideoper = (IsHideOper(target) && (client != target) && !IsOper(client)) ? 1 : 0;
    127 
    128 	if (IsServiceBot(target) && !hideoper &&
    129 	    (whois_get_policy(client, target, "services") > WHOIS_CONFIG_DETAILS_NONE))
    130 	{
    131 		add_nvplist_numeric(list, 0, "services", client, RPL_WHOISOPERATOR, target->name, "a Network Service");
    132 	}
    133 
    134 	return 0;
    135 }
    136 
    137 /* This hides the servicebot, even if you are in the same channel, unless oper overriding */
    138 int servicebot_see_channel_in_whois(Client *client, Client *target, Channel *channel)
    139 {
    140 	if (IsServiceBot(target))
    141 		return EX_DENY;
    142 	
    143 	return EX_ALLOW;
    144 }