mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 23:44:01 +01:00
A very draft version of extensions, which are adding can_join hooks for custom channel modes
This commit is contained in:
parent
c24efdc0b7
commit
acdf71d9d2
4 changed files with 83 additions and 1 deletions
67
extensions/chm_operonly.c
Normal file
67
extensions/chm_operonly.c
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include "stdinc.h"
|
||||
#include "modules.h"
|
||||
#include "hook.h"
|
||||
#include "client.h"
|
||||
#include "ircd.h"
|
||||
#include "send.h"
|
||||
#include "s_conf.h"
|
||||
#include "s_user.h"
|
||||
#include "s_serv.h"
|
||||
#include "numeric.h"
|
||||
#include "chmode.h"
|
||||
|
||||
/* gcc -fPIC -DPIC -shared -I. -I../include -I../libratbox/include -O0 -Wall -std=gnu99 -g -DIRCD_PREFIX=\"/home/dwr/build/charybdis\" chm_operonly.c -o chm_operonly.so */
|
||||
|
||||
static void h_can_join(hook_data_channel *);
|
||||
|
||||
mapi_hfn_list_av1 operonly_hfnlist[] = {
|
||||
{ "can_join", (hookfn) h_can_join },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* This is a simple example of how to use dynamic channel modes.
|
||||
* Not tested enough yet, use at own risk.
|
||||
* -- dwr
|
||||
*/
|
||||
static int
|
||||
_modinit(void)
|
||||
{
|
||||
/* add the channel mode to the available slot */
|
||||
chmode_table['O'].mode_type = find_cflag_slot();
|
||||
chmode_table['O'].set_func = chm_simple;
|
||||
|
||||
construct_noparam_modes();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Well, the first ugly thing is that we changle chmode_table in _modinit
|
||||
* and chmode_flags in _moddeinit (different arrays) - must be fixed.
|
||||
* -- dwr
|
||||
*/
|
||||
static void
|
||||
_moddeinit(void)
|
||||
{
|
||||
/* disable the channel mode and remove it from the available list */
|
||||
chmode_table['O'].mode_type = 0;
|
||||
|
||||
construct_noparam_modes();
|
||||
}
|
||||
|
||||
DECLARE_MODULE_AV1(chm_operonly, _modinit, _moddeinit, NULL, NULL, operonly_hfnlist, "$Revision$");
|
||||
|
||||
static void
|
||||
h_can_join(hook_data_channel *data)
|
||||
{
|
||||
struct Client *source_p = data->client;
|
||||
struct Channel *chptr = data->chptr;
|
||||
|
||||
if((chptr->mode.mode & chmode_flags['O']) && !IsOper(source_p)) {
|
||||
sendto_one_notice(source_p, ":Only IRC Operators could join this channel!");
|
||||
data->approved = ERR_CUSTOM;
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +28,12 @@
|
|||
#ifndef INCLUDED_chmode_h
|
||||
#define INCLUDED_chmode_h
|
||||
|
||||
/* something not included in messages.tab
|
||||
* to change some hooks behaviour when needed
|
||||
* -- dwr
|
||||
*/
|
||||
#define ERR_CUSTOM 1000
|
||||
|
||||
extern void chm_nosuch(struct Client *source_p, struct Channel *chptr,
|
||||
int alevel, int parc, int *parn,
|
||||
const char **parv, int *errors, int dir, char c, long mode_type);
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "parse.h"
|
||||
#include "modules.h"
|
||||
#include "packet.h"
|
||||
#include "chmode.h"
|
||||
|
||||
static int m_join(struct Client *, struct Client *, int, const char **);
|
||||
static int ms_join(struct Client *, struct Client *, int, const char **);
|
||||
|
@ -302,11 +303,18 @@ m_join(struct Client *client_p, struct Client *source_p, int parc, const char *p
|
|||
if ((i != ERR_NEEDREGGEDNICK && i != ERR_THROTTLE && i != ERR_INVITEONLYCHAN && i != ERR_CHANNELISFULL) ||
|
||||
(!ConfigChannel.use_forward || (chptr = check_forward(source_p, chptr, key)) == NULL))
|
||||
{
|
||||
/* might be wrong, but is there any other better location for such?
|
||||
* see extensions/chm_operonly.c for other comments on this
|
||||
* -- dwr
|
||||
*/
|
||||
if(i != ERR_CUSTOM)
|
||||
sendto_one(source_p, form_str(i), me.name, source_p->name, name);
|
||||
|
||||
if(successful_join_count > 0)
|
||||
successful_join_count--;
|
||||
continue;
|
||||
}
|
||||
|
||||
sendto_one_numeric(source_p, ERR_LINKCHANNEL, form_str(ERR_LINKCHANNEL), name, chptr->chname);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ char cflagsbuf[256];
|
|||
char cflagsmyinfo[256];
|
||||
|
||||
int chmode_flags[256];
|
||||
|
||||
/* OPTIMIZE ME! -- dwr */
|
||||
void
|
||||
construct_noparam_modes(void)
|
||||
|
|
Loading…
Reference in a new issue