1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-07 02:03:14 +02:00
Files
unrealircd/src/modules/chanmodes/permanent.c
T
Bram Matthys 4ac8015f84 Remove 'cptr' from all commands, hooks, etc. It only confuses people and
'sptr' is sufficient and in most cases the only one you should care about.
Should you need it, you can access sptr->direction in cases where you
need the old information (usually only for some sendto_* functions
and some protoctl checks), so 'cptr' was redundant too.

[!] This change likely introduces some bugs. This was many hours of work.
I only cut some corners in 4 functions, which will be fixed at a later
stage..... yes, more major changes to come.

On the plus side, I likely fixed some bugs in the process. Situations
where cptr vs sptr usage was incorrect. Eg using cptr->name (near server)
when sptr->name should be used (the actual source server), etc....
2019-10-02 14:25:40 +02:00

95 lines
2.4 KiB
C

/*
* UnrealIRCd, src/modules/chanmodes/permanent.c
* Copyright (c) 2013 William Pitcock <nenolod@dereferenced.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "unrealircd.h"
ModuleHeader MOD_HEADER
= {
"chanmodes/permanent",
"4.2",
"Permanent channel mode (+P)",
"UnrealIRCd Team",
"unrealircd-5",
};
static Cmode_t EXTMODE_PERMANENT = 0L;
static int permanent_channel_destroy(Channel *chptr, int *should_destroy)
{
if (chptr->mode.extmode & EXTMODE_PERMANENT)
*should_destroy = 0;
return 0;
}
static int permanent_is_ok(Client *cptr, Channel *chptr, char mode, char *para, int checkt, int what)
{
if (!IsOper(cptr))
{
if (checkt == EXCHK_ACCESS_ERR)
sendnumeric(cptr, ERR_NOPRIVILEGES);
return EX_DENY;
}
return EX_ALLOW;
}
int permanent_chanmode(Client *sptr, Channel *chptr, MessageTag *mtags, char *modebuf, char *parabuf, time_t sendts, int samode)
{
/* Destroy the channel if it was set '(SA)MODE #chan -P' with nobody in it (#4442) */
if (!(chptr->mode.extmode & EXTMODE_PERMANENT) && (chptr->users <= 0))
sub1_from_channel(chptr);
return 0;
}
/* This is called on module init, before Server Ready */
MOD_INIT()
{
CmodeInfo req;
MARK_AS_OFFICIAL_MODULE(modinfo);
memset(&req, 0, sizeof(req));
req.paracount = 0;
req.flag = 'P';
req.is_ok = permanent_is_ok;
CmodeAdd(modinfo->handle, req, &EXTMODE_PERMANENT);
HookAdd(modinfo->handle, HOOKTYPE_CHANNEL_DESTROY, -100000, permanent_channel_destroy);
HookAdd(modinfo->handle, HOOKTYPE_LOCAL_CHANMODE, 1000000, permanent_chanmode);
HookAdd(modinfo->handle, HOOKTYPE_REMOTE_CHANMODE, 1000000, permanent_chanmode);
return MOD_SUCCESS;
}
/* Is first run when server is 100% ready */
MOD_LOAD()
{
return MOD_SUCCESS;
}
/* Called when module is unloaded */
MOD_UNLOAD()
{
return MOD_SUCCESS;
}