]> jfr.im git - solanum.git/commitdiff
extensions/helpops: implement DEHELPER command
authorWilliam Pitcock <redacted>
Thu, 14 Jan 2016 21:16:29 +0000 (15:16 -0600)
committerWilliam Pitcock <redacted>
Thu, 14 Jan 2016 21:16:29 +0000 (15:16 -0600)
extensions/helpops.c

index 4bf862087cde0f2a41607a8a6ea07d172b5b6e80..e3a77a02f470483ff9fc1a18e2d1bc48e32a0309 100644 (file)
@@ -20,6 +20,9 @@ static void h_hdl_new_remote_user(struct Client *client_p);
 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);
+static int mo_dehelper(struct Client *, struct Client *, int, const char **);
+static int me_dehelper(struct Client *, struct Client *, int, const char **);
+static int do_dehelper(struct Client *source_p, struct Client *target_p);
 
 mapi_hfn_list_av1 helpops_hfnlist[] = {
        { "doing_stats", (hookfn) h_hdl_stats_request },
@@ -33,6 +36,71 @@ mapi_hfn_list_av1 helpops_hfnlist[] = {
 
 static int UMODE_HELPOPS = 0;
 
+struct Message dehelper_msgtab = {
+       "DEHELPER", 0, 0, 0, MFLG_SLOW,
+       {mg_unreg, mg_not_oper, mg_not_oper, mg_ignore, {me_dehelper, 2}, {mo_dehelper, 2}}
+};
+
+mapi_clist_av1 helpops_clist[] = { &dehelper_msgtab, NULL };
+
+static int mo_dehelper(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+{
+       struct Client *target_p;
+
+       if (!IsOperAdmin(source_p))
+       {
+               sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin");
+               return 0;
+       }
+
+       if(!(target_p = find_named_person(parv[1])))
+       {
+               sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), parv[1]);
+               return 0;
+       }
+
+       if(MyClient(target_p))
+               do_dehelper(source_p, target_p);
+       else
+               sendto_one(target_p, ":%s ENCAP %s DEHELPER %s",
+                               use_id(source_p), target_p->servptr->name, use_id(target_p));
+
+       return 0;
+}
+
+static int me_dehelper(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+{
+       struct Client *target_p = find_person(parv[1]);
+       if(!target_p)
+       {
+               sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), parv[1]);
+               return 0;
+       }
+       if(!MyClient(target_p))
+               return 0;
+
+       do_dehelper(source_p, target_p);
+       return 0;
+}
+
+static int do_dehelper(struct Client *source_p, struct Client *target_p)
+{
+       const char *fakeparv[4];
+
+       if(!(target_p->umodes & UMODE_HELPOPS))
+               return 0;
+
+       sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is using DEHELPER on %s",
+                       source_p->name, target_p->name);
+       sendto_one_notice(target_p, ":*** %s is using DEHELPER on you", source_p->name);
+
+       fakeparv[0] = fakeparv[1] = target_p->name;
+       fakeparv[2] = "-H";
+       fakeparv[3] = NULL;
+       user_mode(target_p, target_p, 3, fakeparv);
+       return 0;
+}
+
 static int
 _modinit(void)
 {
@@ -135,4 +203,4 @@ h_hdl_whois(hook_data_client *hdata)
        }
 }
 
-DECLARE_MODULE_AV1(helpops, _modinit, _moddeinit, NULL, NULL, helpops_hfnlist, "");
+DECLARE_MODULE_AV1(helpops, _modinit, _moddeinit, helpops_clist, NULL, helpops_hfnlist, "");