unrealircd- supernets unrealircd source & configuration |
git clone git://git.acid.vegas/unrealircd.git |
Log | Files | Refs | Archive | README | LICENSE |
noknock.c (2639B)
1 /* 2 * Disallow knocks UnrealIRCd Module (Channel Mode +K) 3 * (C) Copyright 2014 Travis McArthur (Heero) 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 ModuleHeader MOD_HEADER 23 = { 24 "chanmodes/noknock", 25 "4.2", 26 "Channel Mode +K", 27 "UnrealIRCd Team", 28 "unrealircd-6", 29 }; 30 31 Cmode_t EXTCMODE_NOKNOCK; 32 33 #define IsNoKnock(channel) (channel->mode.mode & EXTCMODE_NOKNOCK) 34 35 int noknock_check_knock(Client *client, Channel *channel, const char **reason); 36 int noknock_mode_allow(Client *client, Channel *channel, char mode, const char *para, int checkt, int what); 37 int noknock_mode_del (Channel *channel, int modeChar); 38 39 MOD_TEST() 40 { 41 return MOD_SUCCESS; 42 } 43 44 MOD_INIT() 45 { 46 CmodeInfo req; 47 48 memset(&req, 0, sizeof(req)); 49 req.paracount = 0; 50 req.letter = 'K'; 51 req.is_ok = noknock_mode_allow; 52 CmodeAdd(modinfo->handle, req, &EXTCMODE_NOKNOCK); 53 54 HookAdd(modinfo->handle, HOOKTYPE_PRE_KNOCK, 0, noknock_check_knock); 55 HookAdd(modinfo->handle, HOOKTYPE_MODECHAR_DEL, 0, noknock_mode_del); 56 57 58 MARK_AS_OFFICIAL_MODULE(modinfo); 59 return MOD_SUCCESS; 60 } 61 62 MOD_LOAD() 63 { 64 return MOD_SUCCESS; 65 } 66 67 MOD_UNLOAD() 68 { 69 return MOD_SUCCESS; 70 } 71 72 73 int noknock_check_knock (Client *client, Channel *channel, const char **reason) 74 { 75 if (MyUser(client) && IsNoKnock(channel)) 76 { 77 sendnumeric(client, ERR_CANNOTKNOCK, channel->name, "No knocks are allowed! (+K)"); 78 return HOOK_DENY; 79 } 80 81 return HOOK_CONTINUE; 82 } 83 84 int noknock_mode_del (Channel *channel, int modeChar) 85 { 86 // Remove noknock when we're removing invite only 87 if (modeChar == 'i') 88 channel->mode.mode &= ~EXTCMODE_NOKNOCK; 89 90 return 0; 91 } 92 93 int noknock_mode_allow(Client *client, Channel *channel, char mode, const char *para, int checkt, int what) 94 { 95 if (!has_channel_mode(channel, 'i')) 96 { 97 if (checkt == EXCHK_ACCESS_ERR) 98 { 99 sendnumeric(client, ERR_CANNOTCHANGECHANMODE, 'K', "+i must be set"); 100 } 101 return EX_DENY; 102 } 103 104 return extcmode_default_requirehalfop(client, channel, mode, para, checkt, what); 105 }