| 1 |
/* |
| 2 |
* Copyright (c) 2010 William Pitcock <[email protected]>. |
| 3 |
* Rights to this code are as documented in doc/LICENSE. |
| 4 |
* |
| 5 |
* Implements a named-successor ACL flag. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "atheme.h" |
| 9 |
|
| 10 |
DECLARE_MODULE_V1 |
| 11 |
( |
| 12 |
"chanserv/successor_acl", true, _modinit, NULL, |
| 13 |
PACKAGE_STRING, |
| 14 |
VENDOR_STRING |
| 15 |
); |
| 16 |
|
| 17 |
static unsigned int successor_flag = 0; |
| 18 |
|
| 19 |
static void channel_pick_successor_hook(hook_channel_succession_req_t *req) |
| 20 |
{ |
| 21 |
return_if_fail(req != NULL); |
| 22 |
return_if_fail(req->mc != NULL); |
| 23 |
|
| 24 |
/* maybe some other module already chose a new successor. */ |
| 25 |
if (req->mu != NULL) |
| 26 |
return; |
| 27 |
|
| 28 |
req->mu = mychan_pick_candidate(req->mc, successor_flag); |
| 29 |
if (req->mu == NULL) |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
static void channel_succession_hook(hook_channel_succession_req_t *req) |
| 34 |
{ |
| 35 |
return_if_fail(req != NULL); |
| 36 |
return_if_fail(req->mc != NULL); |
| 37 |
return_if_fail(req->mu != NULL); |
| 38 |
|
| 39 |
/* Remove the successor flag from the new founder. */ |
| 40 |
chanacs_change_simple(req->mc, entity(req->mu), NULL, 0, successor_flag, NULL); |
| 41 |
} |
| 42 |
|
| 43 |
void _modinit(module_t *m) |
| 44 |
{ |
| 45 |
m->mflags = MODTYPE_CORE; |
| 46 |
|
| 47 |
if ((successor_flag = flags_associate('S', 0, false, "successor")) == 0) |
| 48 |
{ |
| 49 |
slog(LG_ERROR, "chanserv/successor_acl: Inserting +S into flagset failed."); |
| 50 |
exit(EXIT_FAILURE); |
| 51 |
} |
| 52 |
|
| 53 |
slog(LG_DEBUG, "chanserv/successor_acl: +S has been inserted with bitmask 0x%x", successor_flag); |
| 54 |
hook_add_first_channel_pick_successor(channel_pick_successor_hook); |
| 55 |
hook_add_channel_succession(channel_succession_hook); |
| 56 |
} |