unrealircd

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

permanent.c (2678B)

      1 /*
      2  * UnrealIRCd, src/modules/chanmodes/permanent.c
      3  * Copyright (c) 2013 William Pitcock <nenolod@dereferenced.org>
      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/permanent",
     25 	"4.2",
     26 	"Permanent channel mode (+P)", 
     27 	"UnrealIRCd Team",
     28 	"unrealircd-6",
     29     };
     30 
     31 static Cmode_t EXTMODE_PERMANENT = 0L;
     32 
     33 static int permanent_channel_destroy(Channel *channel, int *should_destroy)
     34 {
     35 	if (channel->mode.mode & EXTMODE_PERMANENT)
     36 		*should_destroy = 0;
     37 	
     38 	return 0;
     39 }
     40 
     41 static int permanent_is_ok(Client *client, Channel *channel, char mode, const char *para, int checkt, int what)
     42 {
     43 	if (!IsOper(client))
     44 	{
     45 		if (checkt == EXCHK_ACCESS_ERR)
     46 			sendnumeric(client, ERR_NOPRIVILEGES);
     47 
     48 		return EX_DENY;
     49 	}
     50 
     51 	return EX_ALLOW;
     52 }
     53 
     54 int permanent_chanmode(Client *client, Channel *channel, MessageTag *mtags, const char *modebuf, const char *parabuf, time_t sendts, int samode, int *destroy_channel)
     55 {
     56 	if (samode == -1)
     57 		return 0; /* SJOIN server-sync, already has its own way of destroying the channel */
     58 
     59 	/* Destroy the channel if it was set '(SA)MODE #chan -P' with nobody in it (#4442) */
     60 	if (!(channel->mode.mode & EXTMODE_PERMANENT) && (channel->users <= 0))
     61 	{
     62 		sub1_from_channel(channel);
     63 		*destroy_channel = 1;
     64 	}
     65 	
     66 	return 0;
     67 }
     68 
     69 /* This is called on module init, before Server Ready */
     70 MOD_INIT()
     71 {
     72 CmodeInfo req;
     73 
     74 	MARK_AS_OFFICIAL_MODULE(modinfo);
     75 
     76 	memset(&req, 0, sizeof(req));
     77 	req.paracount = 0;
     78 	req.letter = 'P';
     79 	req.is_ok = permanent_is_ok;
     80 	CmodeAdd(modinfo->handle, req, &EXTMODE_PERMANENT);
     81 
     82 	HookAdd(modinfo->handle, HOOKTYPE_CHANNEL_DESTROY, -100000, permanent_channel_destroy);
     83 	HookAdd(modinfo->handle, HOOKTYPE_LOCAL_CHANMODE, 1000000, permanent_chanmode);
     84 	HookAdd(modinfo->handle, HOOKTYPE_REMOTE_CHANMODE, 1000000, permanent_chanmode);
     85 
     86 	return MOD_SUCCESS;
     87 }
     88 
     89 /* Is first run when server is 100% ready */
     90 MOD_LOAD()
     91 {
     92 	return MOD_SUCCESS;
     93 }
     94 
     95 /* Called when module is unloaded */
     96 MOD_UNLOAD()
     97 {
     98 	return MOD_SUCCESS;
     99 }
    100