From 7608ef493330f1504f7df0ba5e8da05ca96812f6 Mon Sep 17 00:00:00 2001 From: Valery Yatsko Date: Sun, 27 Jul 2008 12:10:48 +0400 Subject: [PATCH] A very draft version of extensions, which are adding can_join hooks for custom channel modes --- extensions/chm_operonly.c | 67 +++++++++++++++++++++++++++++++++++++++ include/chmode.h | 6 ++++ modules/core/m_join.c | 10 +++++- src/chmode.c | 1 + 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 extensions/chm_operonly.c diff --git a/extensions/chm_operonly.c b/extensions/chm_operonly.c new file mode 100644 index 0000000..1ba7aaf --- /dev/null +++ b/extensions/chm_operonly.c @@ -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; + } +} + diff --git a/include/chmode.h b/include/chmode.h index 94f7ea7..e3b386b 100644 --- a/include/chmode.h +++ b/include/chmode.h @@ -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); diff --git a/modules/core/m_join.c b/modules/core/m_join.c index 911439b..ff4750f 100644 --- a/modules/core/m_join.c +++ b/modules/core/m_join.c @@ -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)) { - sendto_one(source_p, form_str(i), me.name, source_p->name, name); + /* 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); } diff --git a/src/chmode.c b/src/chmode.c index 60fc901..c736093 100644 --- a/src/chmode.c +++ b/src/chmode.c @@ -69,6 +69,7 @@ char cflagsbuf[256]; char cflagsmyinfo[256]; int chmode_flags[256]; + /* OPTIMIZE ME! -- dwr */ void construct_noparam_modes(void)