2016-01-14 15:05:36 +01:00
|
|
|
/*
|
|
|
|
* Helpops system.
|
|
|
|
* -- kaniini
|
|
|
|
*/
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
using namespace ircd;
|
|
|
|
|
2016-03-09 08:29:41 +01:00
|
|
|
static const char helpops_desc[] = "The helpops system as used by freenode";
|
|
|
|
|
2016-01-14 15:05:36 +01:00
|
|
|
static rb_dlink_list helper_list = { NULL, NULL, 0 };
|
|
|
|
static void h_hdl_stats_request(hook_data_int *hdata);
|
2016-08-22 03:57:43 +02:00
|
|
|
static void h_hdl_new_remote_user(client::client *client_p);
|
2016-01-14 15:05:36 +01:00
|
|
|
static void h_hdl_client_exit(hook_data_client_exit *hdata);
|
|
|
|
static void h_hdl_umode_changed(hook_data_umode_changed *hdata);
|
|
|
|
static void h_hdl_whois(hook_data_client *hdata);
|
2016-08-23 02:37:07 +02:00
|
|
|
static void mo_dehelper(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
|
|
|
static void me_dehelper(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
|
|
|
static void do_dehelper(client::client &source, client::client &target_p);
|
2016-01-14 15:05:36 +01:00
|
|
|
|
|
|
|
mapi_hfn_list_av1 helpops_hfnlist[] = {
|
|
|
|
{ "doing_stats", (hookfn) h_hdl_stats_request },
|
|
|
|
{ "new_remote_user", (hookfn) h_hdl_new_remote_user },
|
|
|
|
{ "client_exit", (hookfn) h_hdl_client_exit },
|
|
|
|
{ "umode_changed", (hookfn) h_hdl_umode_changed },
|
|
|
|
{ "doing_whois", (hookfn) h_hdl_whois },
|
|
|
|
{ "doing_whois_global", (hookfn) h_hdl_whois },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int UMODE_HELPOPS = 0;
|
|
|
|
|
2016-01-14 22:16:29 +01:00
|
|
|
struct Message dehelper_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"DEHELPER", 0, 0, 0, 0,
|
2016-01-14 22:16:29 +01:00
|
|
|
{mg_unreg, mg_not_oper, mg_not_oper, mg_ignore, {me_dehelper, 2}, {mo_dehelper, 2}}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 helpops_clist[] = { &dehelper_msgtab, NULL };
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
mo_dehelper(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char **parv)
|
2016-01-14 22:16:29 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p;
|
2016-01-14 22:16:29 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
if (!IsOperAdmin(&source))
|
2016-01-14 22:16:29 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(ERR_NOPRIVS), me.name, source.name, "admin");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2016-01-14 22:16:29 +01:00
|
|
|
}
|
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
if(!(target_p = client::find_named_person(parv[1])))
|
2016-01-14 22:16:29 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), parv[1]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2016-01-14 22:16:29 +01:00
|
|
|
}
|
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my(*target_p))
|
2016-08-23 02:37:07 +02:00
|
|
|
do_dehelper(source, *target_p);
|
2016-01-14 22:16:29 +01:00
|
|
|
else
|
|
|
|
sendto_one(target_p, ":%s ENCAP %s DEHELPER %s",
|
2016-08-23 02:37:07 +02:00
|
|
|
use_id(&source), target_p->servptr->name, use_id(target_p));
|
2016-01-14 22:16:29 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
me_dehelper(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char **parv)
|
2016-01-14 22:16:29 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p = client::find_person(parv[1]);
|
2016-01-14 22:16:29 +01:00
|
|
|
if(!target_p)
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), parv[1]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2016-01-14 22:16:29 +01:00
|
|
|
}
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!my(*target_p))
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2016-01-14 22:16:29 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
do_dehelper(source, *target_p);
|
2016-01-14 22:16:29 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
do_dehelper(client::client &source, client::client &target)
|
2016-01-14 22:16:29 +01:00
|
|
|
{
|
|
|
|
const char *fakeparv[4];
|
|
|
|
|
2016-08-24 00:25:09 +02:00
|
|
|
if(!(target.mode & UMODE_HELPOPS))
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2016-01-14 22:16:29 +01:00
|
|
|
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_NETWIDE, "%s is using DEHELPER on %s",
|
2016-08-23 02:37:07 +02:00
|
|
|
source.name, target.name);
|
|
|
|
sendto_one_notice(&target, ":*** %s is using DEHELPER on you", source.name);
|
2016-01-14 22:16:29 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
fakeparv[0] = fakeparv[1] = target.name;
|
2016-01-14 22:16:29 +01:00
|
|
|
fakeparv[2] = "-H";
|
|
|
|
fakeparv[3] = NULL;
|
2016-08-23 02:37:07 +02:00
|
|
|
user_mode(&target, &target, 3, fakeparv);
|
2016-01-14 22:16:29 +01:00
|
|
|
}
|
|
|
|
|
2016-01-14 15:05:36 +01:00
|
|
|
static int
|
|
|
|
_modinit(void)
|
|
|
|
{
|
|
|
|
/* add the usermode to the available slot */
|
|
|
|
user_modes['H'] = UMODE_HELPOPS = find_umode_slot();
|
|
|
|
construct_umodebuf();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_moddeinit(void)
|
|
|
|
{
|
|
|
|
/* disable the umode and remove it from the available list */
|
|
|
|
user_modes['H'] = UMODE_HELPOPS = 0;
|
|
|
|
construct_umodebuf();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
h_hdl_stats_request(hook_data_int *hdata)
|
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p;
|
2016-01-14 15:05:36 +01:00
|
|
|
rb_dlink_node *helper_ptr;
|
|
|
|
unsigned int count = 0;
|
|
|
|
|
|
|
|
if (hdata->arg2 != 'p')
|
|
|
|
return;
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH (helper_ptr, helper_list.head)
|
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
target_p = (client::client *)helper_ptr->data;
|
2016-01-14 15:05:36 +01:00
|
|
|
|
2016-08-22 03:57:43 +02:00
|
|
|
if (away(user(*target_p)).size())
|
2016-01-14 15:05:36 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
sendto_one_numeric(hdata->client, RPL_STATSDEBUG,
|
|
|
|
"p :%s (%s@%s)",
|
|
|
|
target_p->name, target_p->username,
|
|
|
|
target_p->host);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendto_one_numeric(hdata->client, RPL_STATSDEBUG,
|
|
|
|
"p :%u staff members", count);
|
|
|
|
|
|
|
|
hdata->result = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-08-22 03:57:43 +02:00
|
|
|
h_hdl_new_remote_user(client::client *client_p)
|
2016-01-14 15:05:36 +01:00
|
|
|
{
|
2016-08-24 00:25:09 +02:00
|
|
|
if (client_p->mode & UMODE_HELPOPS)
|
2016-01-14 15:05:36 +01:00
|
|
|
rb_dlinkAddAlloc(client_p, &helper_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
h_hdl_client_exit(hook_data_client_exit *hdata)
|
|
|
|
{
|
2016-08-24 00:25:09 +02:00
|
|
|
if (hdata->target->mode & UMODE_HELPOPS)
|
2016-01-14 15:05:36 +01:00
|
|
|
rb_dlinkFindDestroy(hdata->target, &helper_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
h_hdl_umode_changed(hook_data_umode_changed *hdata)
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
client::client &source = *hdata->client;
|
2016-01-14 15:05:36 +01:00
|
|
|
|
|
|
|
/* didn't change +H umode, we don't need to do anything */
|
2016-08-24 00:25:09 +02:00
|
|
|
if (!((hdata->oldumodes ^ source.mode) & UMODE_HELPOPS))
|
2016-01-14 15:05:36 +01:00
|
|
|
return;
|
|
|
|
|
2016-08-24 00:25:09 +02:00
|
|
|
if (source.mode & UMODE_HELPOPS)
|
2016-01-14 15:05:36 +01:00
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if (my(source) && !HasPrivilege(&source, "usermode:helpops"))
|
2016-01-14 15:05:36 +01:00
|
|
|
{
|
2016-08-24 00:25:09 +02:00
|
|
|
source.mode &= umode(~UMODE_HELPOPS);
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(ERR_NOPRIVS), me.name, source.name, "usermode:helpops");
|
2016-01-14 15:05:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
rb_dlinkAddAlloc(&source, &helper_list);
|
2016-01-14 15:05:36 +01:00
|
|
|
}
|
2016-08-24 00:25:09 +02:00
|
|
|
else if (!(source.mode & UMODE_HELPOPS))
|
2016-08-23 02:37:07 +02:00
|
|
|
rb_dlinkFindDestroy(&source, &helper_list);
|
2016-01-14 15:05:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
h_hdl_whois(hook_data_client *hdata)
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
client::client &source = *hdata->client;
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p = hdata->target;
|
2016-01-14 15:05:36 +01:00
|
|
|
|
2016-08-24 00:25:09 +02:00
|
|
|
if ((target_p->mode & UMODE_HELPOPS) && away(user(*target_p)).empty())
|
2016-01-14 15:05:36 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, RPL_WHOISHELPOP, form_str(RPL_WHOISHELPOP), target_p->name);
|
2016-01-14 15:05:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-07 11:11:51 +01:00
|
|
|
DECLARE_MODULE_AV2(helpops, _modinit, _moddeinit, helpops_clist, NULL, helpops_hfnlist, NULL, NULL, helpops_desc);
|