]> jfr.im git - solanum.git/blobdiff - extensions/helpops.c
Merge pull request #288 from edk0/umode-o-split
[solanum.git] / extensions / helpops.c
index 5633420e7cb1898ef40f7ee96a44da171f6845b7..e33509ebfb7a49d3526ccbaf15e595397eb50176 100644 (file)
@@ -53,9 +53,9 @@ mo_dehelper(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *sou
 {
        struct Client *target_p;
 
-       if (!IsOperAdmin(source_p))
+       if (!HasPrivilege(source_p, "oper:dehelper"))
        {
-               sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin");
+               sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "dehelper");
                return;
        }
 
@@ -108,17 +108,31 @@ do_dehelper(struct Client *source_p, struct Client *target_p)
 static int
 _modinit(void)
 {
+       rb_dlink_node *ptr;
+
        user_modes[UMODECHAR_HELPOPS] = find_umode_slot();
        construct_umodebuf();
 
+       RB_DLINK_FOREACH (ptr, global_client_list.head)
+       {
+               struct Client *client_p = ptr->data;
+               if (IsPerson(client_p) && (client_p->umodes & user_modes[UMODECHAR_HELPOPS]))
+                       helper_add(client_p);
+       }
+
        return 0;
 }
 
 static void
 _moddeinit(void)
 {
+       rb_dlink_node *n, *tn;
+
        user_modes[UMODECHAR_HELPOPS] = 0;
        construct_umodebuf();
+
+       RB_DLINK_FOREACH_SAFE(n, tn, helper_list.head)
+               rb_dlinkDestroy(n, &helper_list);
 }
 
 static void
@@ -206,8 +220,7 @@ h_hdl_umode_changed(hook_data_umode_changed *hdata)
        struct Client *source_p = hdata->client;
 
        /* didn't change +H umode, we don't need to do anything */
-       if (!((hdata->oldumodes ^ source_p->umodes) & user_modes[UMODECHAR_HELPOPS]))
-               return;
+       bool changed = (hdata->oldumodes ^ source_p->umodes) & user_modes[UMODECHAR_HELPOPS];
 
        if (source_p->umodes & user_modes[UMODECHAR_HELPOPS])
        {
@@ -215,13 +228,19 @@ h_hdl_umode_changed(hook_data_umode_changed *hdata)
                {
                        source_p->umodes &= ~user_modes[UMODECHAR_HELPOPS];
                        sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "usermode:helpops");
+                       /* they didn't ask for +H so we must be removing it */
+                       if (!changed)
+                               helper_delete(source_p);
                        return;
                }
 
-               helper_add(source_p);
+               if (changed)
+                       helper_add(source_p);
        }
-       else if (!(source_p->umodes & user_modes[UMODECHAR_HELPOPS]))
+       else if (changed)
+       {
                helper_delete(source_p);
+       }
 }
 
 static void