]> jfr.im git - solanum.git/blobdiff - modules/um_regonlymsg.c
Combine stats A output parameters (#35)
[solanum.git] / modules / um_regonlymsg.c
index 79ca4cd6eb884e377a434d17b992a4d1e6be8c04..3b31006a3b665a6d349158b11c383aa6b0741875 100644 (file)
@@ -40,6 +40,7 @@
 #include "numeric.h"
 #include "privilege.h"
 #include "s_newconf.h"
+#include "logger.h"
 
 static int
 um_regonlymsg_modinit(void)
@@ -47,6 +48,12 @@ um_regonlymsg_modinit(void)
        user_modes['R'] = find_umode_slot();
        construct_umodebuf();
 
+       if (!user_modes['R'])
+       {
+               ierror("um_regonlymsg: unable to allocate usermode slot for +R, unloading module");
+               return -1;
+       }
+
        return 0;
 }
 
@@ -65,6 +72,9 @@ static const char um_regonlymsg_desc[] =
 static bool
 allow_message(struct Client *source_p, struct Client *target_p)
 {
+       if (!MyClient(target_p))
+               return true;
+
        if (!IsSetRegOnlyMsg(target_p))
                return true;
 
@@ -85,11 +95,12 @@ allow_message(struct Client *source_p, struct Client *target_p)
 }
 
 static void
-h_can_invite(void *vdata)
+h_hdl_invite(void *vdata)
 {
        hook_data_channel_approval *data = vdata;
        struct Client *source_p = data->client;
        struct Client *target_p = data->target;
+       static char errorbuf[BUFSIZE];
 
        if (data->approved)
                return;
@@ -97,10 +108,11 @@ h_can_invite(void *vdata)
        if (allow_message(source_p, target_p))
                return;
 
-       sendto_one_numeric(source_p, ERR_NONONREG, form_str(ERR_NONONREG),
-                          target_p->name);
+       snprintf(errorbuf, sizeof errorbuf, form_str(ERR_NONONREG),
+                target_p->name);
 
        data->approved = ERR_NONONREG;
+       data->error = errorbuf;
 }
 
 static void
@@ -126,7 +138,7 @@ h_hdl_privmsg_user(void *vdata)
 }
 
 static mapi_hfn_list_av1 um_regonlymsg_hfnlist[] = {
-       { "can_invite", h_can_invite },
+       { "invite", h_hdl_invite },
        { "privmsg_user", h_hdl_privmsg_user },
        { NULL, NULL }
 };