unrealircd- supernets unrealircd source & configuration |
git clone git://git.acid.vegas/unrealircd.git |
Log | Files | Refs | Archive |
inchannel.c (3710B)
1 /* 2 * Extended ban: "in channel?" (+b ~c:#chan) 3 * (C) Copyright 2003-.. 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 #include "unrealircd.h" 20 21 ModuleHeader MOD_HEADER 22 = { 23 "extbans/inchannel", 24 "4.2", 25 "ExtBan ~c - banned when in specified channel", 26 "UnrealIRCd Team", 27 "unrealircd-6", 28 }; 29 30 /* Forward declarations */ 31 int extban_inchannel_is_ok(BanContext *b); 32 const char *extban_inchannel_conv_param(BanContext *b, Extban *extban); 33 int extban_inchannel_is_banned(BanContext *b); 34 35 Extban *register_channel_extban(ModuleInfo *modinfo) 36 { 37 ExtbanInfo req; 38 39 memset(&req, 0, sizeof(req)); 40 req.letter = 'c'; 41 req.name = "channel"; 42 req.is_ok = extban_inchannel_is_ok; 43 req.conv_param = extban_inchannel_conv_param; 44 req.is_banned = extban_inchannel_is_banned; 45 req.is_banned_events = BANCHK_ALL|BANCHK_TKL; 46 req.options = EXTBOPT_INVEX|EXTBOPT_TKL; 47 return ExtbanAdd(modinfo->handle, req); 48 } 49 50 MOD_TEST() 51 { 52 MARK_AS_OFFICIAL_MODULE(modinfo); 53 if (!register_channel_extban(modinfo)) 54 { 55 config_error("could not register extended ban type"); 56 return MOD_FAILED; 57 } 58 59 return MOD_SUCCESS; 60 } 61 62 MOD_INIT() 63 { 64 MARK_AS_OFFICIAL_MODULE(modinfo); 65 if (!register_channel_extban(modinfo)) 66 { 67 config_error("could not register extended ban type"); 68 return MOD_FAILED; 69 } 70 71 return MOD_SUCCESS; 72 } 73 74 MOD_LOAD() 75 { 76 return MOD_SUCCESS; 77 } 78 79 MOD_UNLOAD() 80 { 81 return MOD_SUCCESS; 82 } 83 84 const char *extban_inchannel_conv_param(BanContext *b, Extban *extban) 85 { 86 static char retbuf[CHANNELLEN+6]; 87 char *chan, *p, symbol='\0'; 88 89 strlcpy(retbuf, b->banstr, sizeof(retbuf)); 90 chan = retbuf; 91 92 if ((*chan == '+') || (*chan == '%') || (*chan == '%') || 93 (*chan == '@') || (*chan == '&') || (*chan == '~')) 94 chan++; 95 96 if ((*chan != '#') && (*chan != '*') && (*chan != '?')) 97 return NULL; 98 99 if (!valid_channelname(chan)) 100 return NULL; 101 102 p = strchr(chan, ':'); /* ~r:#chan:*.blah.net is not allowed (for now) */ 103 if (p) 104 *p = '\0'; 105 106 /* on a sidenote '#' is allowed because it's a valid channel (atm) */ 107 return retbuf; 108 } 109 110 /* The only purpose of this function is a temporary workaround to prevent a desync.. pfff */ 111 int extban_inchannel_is_ok(BanContext *b) 112 { 113 const char *p = b->banstr; 114 115 if ((b->is_ok_check == EXBCHK_PARAM) && MyUser(b->client) && (b->what == MODE_ADD) && (strlen(b->banstr) > 3)) 116 { 117 if ((*p == '+') || (*p == '%') || (*p == '%') || 118 (*p == '@') || (*p == '&') || (*p == '~')) 119 p++; 120 121 if (*p != '#') 122 { 123 sendnotice(b->client, "Please use a # in the channelname (eg: ~c:#*blah*)"); 124 return 0; 125 } 126 } 127 return 1; 128 } 129 130 int extban_inchannel_is_banned(BanContext *b) 131 { 132 Membership *lp; 133 const char *p = b->banstr; 134 char symbol = '\0'; 135 136 if (!b->client->user) 137 return 0; 138 139 if (*p != '#') 140 { 141 symbol = *p; 142 p++; 143 } 144 145 for (lp = b->client->user->channel; lp; lp = lp->next) 146 { 147 if (match_esc(p, lp->channel->name)) 148 { 149 /* Channel matched, check symbol if needed (+/%/@/etc) */ 150 if (symbol) 151 { 152 if (inchannel_compareflags(symbol, lp->member_modes)) 153 return 1; 154 } else 155 return 1; 156 } 157 } 158 159 return 0; 160 } 161