unrealircd- supernets unrealircd source & configuration |
git clone git://git.acid.vegas/unrealircd.git |
Log | Files | Refs | Archive | README | LICENSE |
regonlyspeak.c (3039B)
1 /* 2 * Only registered users can speak UnrealIRCd Module (Channel Mode +M) 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 23 ModuleHeader MOD_HEADER 24 = { 25 "chanmodes/regonlyspeak", 26 "4.2", 27 "Channel Mode +M", 28 "UnrealIRCd Team", 29 "unrealircd-6", 30 }; 31 32 Cmode_t EXTCMODE_REGONLYSPEAK; 33 static char errMsg[2048]; 34 35 #define IsRegOnlySpeak(channel) (channel->mode.mode & EXTCMODE_REGONLYSPEAK) 36 37 int regonlyspeak_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype); 38 const char *regonlyspeak_part_message (Client *client, Channel *channel, const char *comment); 39 40 MOD_TEST() 41 { 42 return MOD_SUCCESS; 43 } 44 45 MOD_INIT() 46 { 47 CmodeInfo req; 48 49 memset(&req, 0, sizeof(req)); 50 req.paracount = 0; 51 req.letter = 'M'; 52 req.is_ok = extcmode_default_requirehalfop; 53 CmodeAdd(modinfo->handle, req, &EXTCMODE_REGONLYSPEAK); 54 55 HookAdd(modinfo->handle, HOOKTYPE_CAN_SEND_TO_CHANNEL, 0, regonlyspeak_can_send_to_channel); 56 HookAddConstString(modinfo->handle, HOOKTYPE_PRE_LOCAL_PART, 0, regonlyspeak_part_message); 57 58 59 MARK_AS_OFFICIAL_MODULE(modinfo); 60 return MOD_SUCCESS; 61 } 62 63 MOD_LOAD() 64 { 65 return MOD_SUCCESS; 66 } 67 68 MOD_UNLOAD() 69 { 70 return MOD_SUCCESS; 71 } 72 73 const char *regonlyspeak_part_message (Client *client, Channel *channel, const char *comment) 74 { 75 if (!comment) 76 return NULL; 77 78 if (IsRegOnlySpeak(channel) && !IsLoggedIn(client) && !ValidatePermissionsForPath("channel:override:message:regonlyspeak",client,NULL,NULL,NULL)) 79 return NULL; 80 81 return comment; 82 } 83 84 int regonlyspeak_can_send_to_channel(Client *client, Channel *channel, Membership *lp, const char **msg, const char **errmsg, SendType sendtype) 85 { 86 Hook *h; 87 int i; 88 89 if (IsRegOnlySpeak(channel) && 90 !op_can_override("channel:override:message:regonlyspeak",client,channel,NULL) && 91 !IsLoggedIn(client) && 92 !check_channel_access_membership(lp, "vhoaq")) 93 { 94 for (h = Hooks[HOOKTYPE_CAN_BYPASS_CHANNEL_MESSAGE_RESTRICTION]; h; h = h->next) 95 { 96 i = (*(h->func.intfunc))(client, channel, BYPASS_CHANMSG_MODERATED); 97 if (i == HOOK_ALLOW) 98 return HOOK_CONTINUE; /* bypass +M restriction */ 99 if (i != HOOK_CONTINUE) 100 break; 101 } 102 103 *errmsg = "You must have a registered nick (+r) to talk on this channel"; 104 return HOOK_DENY; /* BLOCK message */ 105 } 106 107 return HOOK_CONTINUE; 108 }