]> jfr.im git - solanum.git/blobdiff - modules/um_regonlymsg.c
Replace RPL_WHOISTEXT(337) with RPL_WHOISSPECIAL(320) (#419)
[solanum.git] / modules / um_regonlymsg.c
index 27d4653f38c6cde2da0f078786d4ae3cdf9e9ffd..a4056b2cc857858ec92fb9e6bd00c21ccced09ed 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,10 +72,13 @@ 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;
 
-       if (IsServer(source_p))
+       if (!IsPerson(source_p))
                return true;
 
        /* XXX: controversial?  allow opers to send through +R */
@@ -84,20 +94,60 @@ allow_message(struct Client *source_p, struct Client *target_p)
        return false;
 }
 
+static bool
+add_callerid_accept_for_source(enum message_type msgtype, struct Client *source_p, struct Client *target_p)
+{
+       if (!MyClient(source_p))
+               return true;
+
+       if(msgtype != MESSAGE_TYPE_NOTICE &&
+               IsSetRegOnlyMsg(source_p) &&
+               !accept_message(target_p, source_p) &&
+               !IsOperGeneral(target_p))
+       {
+               if(rb_dlink_list_length(&source_p->localClient->allow_list) <
+                               (unsigned long)ConfigFileEntry.max_accept)
+               {
+                       rb_dlinkAddAlloc(target_p, &source_p->localClient->allow_list);
+                       rb_dlinkAddAlloc(source_p, &target_p->on_allow_list);
+               }
+               else
+               {
+                       sendto_one_numeric(source_p, ERR_OWNMODE,
+                                       form_str(ERR_OWNMODE),
+                                       target_p->name, "+R");
+                       return false;
+               }
+       }
+
+       return true;
+}
+
 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;
+
+       if (!add_callerid_accept_for_source(MESSAGE_TYPE_PRIVMSG, source_p, target_p))
+       {
+               data->approved = ERR_NONONREG;
+               return;
+       }
 
        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
@@ -107,20 +157,29 @@ h_hdl_privmsg_user(void *vdata)
        struct Client *source_p = data->source_p;
        struct Client *target_p = data->target_p;
 
+       if (data->approved)
+               return;
+
+       if (!add_callerid_accept_for_source(data->msgtype, source_p, target_p))
+       {
+               data->approved = ERR_NONONREG;
+               return;
+       }
+
        if (allow_message(source_p, target_p))
                return;
 
+       data->approved = ERR_NONONREG;
+
        if (data->msgtype == MESSAGE_TYPE_NOTICE)
                return;
 
        sendto_one_numeric(source_p, ERR_NONONREG, form_str(ERR_NONONREG),
                           target_p->name);
-
-       data->approved = ERR_NONONREG;
 }
 
 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 }
 };