]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/mod-memoserv.c
make sure commands always reply from the same nick you /msgd
[irc/evilnet/x3.git] / src / mod-memoserv.c
index 2fde9f53c800876b8e2d1034e3f53945c640b8da..150632dd6b98297c327c35c1fab40d9f085c4899 100644 (file)
@@ -62,6 +62,7 @@
 
 static const struct message_entry msgtab[] = {
     { "MSMSG_CANNOT_SEND", "You cannot send to account $b%s$b." },
+    { "MSMSG_UNKNOWN_SEND_FLAG", "Unreccognised send flag '%c', message not sent." },
     { "MSMSG_MEMO_SENT", "Message sent to $b%s$b (ID# %d)." },
     { "MSMSG_NO_MESSAGES", "You have no messages." },
     { "MSMSG_MEMOS_FOUND", "Found $b%d$b matches.\nUse /msg $S READ <ID> to read a message." },
@@ -156,7 +157,7 @@ static struct {
 } memoserv_conf;
 
 #define MEMOSERV_FUNC(NAME) MODCMD_FUNC(NAME)
-#define OPTION_FUNC(NAME) int NAME(struct userNode *user, struct handle_info *hi, UNUSED_ARG(unsigned int override), unsigned int argc, char *argv[])
+#define OPTION_FUNC(NAME) int NAME(struct svccmd *cmd, struct userNode *user, struct handle_info *hi, UNUSED_ARG(unsigned int override), unsigned int argc, char *argv[])
 typedef OPTION_FUNC(option_func_t);
 
 unsigned long memo_id;
@@ -384,7 +385,6 @@ static struct memo *find_memo(struct userNode *user, struct svccmd *cmd, struct
 static MODCMD_FUNC(cmd_send)
 {
     char *message;
-    int s = 0, brk = 0;
     int reciept = 0, inc = 2;
     struct handle_info *hi;
     struct memo_account *ma, *sender;
@@ -402,33 +402,25 @@ static MODCMD_FUNC(cmd_send)
     if (!(memoserv_can_send(cmd->parent->bot, user, ma)))
         return 0;
 
-    char *flags = argv[2];
-    while (*flags) {
-        switch (*flags) {
-            case '-':
-                if (s != 0)
-                    brk = 1;
-                break;
-
-            case 'r':
-                if (s > 0)
+    inc = 2; /* Start of message on 3rd ([2]) word */
+    if(argv[2][0] == '-' && argv[2][1] != '-') { /* first word is flags ('-r')*/
+        char *flags = argv[2];
+        inc++; /* Start of message is now 1 word later */
+        for(flags++;*flags;flags++) {
+            switch (*flags) {
+                case 'r':
                     reciept = 1;
                 break;
 
             default:
-                break;
-        }
-
-        if (brk == 1)
-            break;
-        else {
-            s++;
-            flags++;
+                /* Unknown mode. Give an error */
+                reply("MSMSG_UNKNOWN_SEND_FLAG", *flags);
+                return 0;
+            }
         }
     }
-
-    if (s > 0)
-        inc = 3;
+    else
+        inc = 2; /* Start of message is word 2 */
 
     message = unsplit_string(argv + inc, argc - inc, NULL);
     memo = add_memo(now, ma, sender, message, 1);
@@ -694,21 +686,21 @@ static MODCMD_FUNC(cmd_expiry)
 
 
 static void
-set_list(struct userNode *user, struct handle_info *hi, int override)
+set_list(struct svccmd *cmd, struct userNode *user, struct handle_info *hi, int override)
 {
     option_func_t *opt;
     unsigned int i;
     char *set_display[] = {"AUTHNOTIFY", "NOTIFY", "PRIVATE", "LIMIT",
                            "IGNORERECIEPTS", "SENDRECIEPTS"};
 
-    send_message(user, memoserv_conf.bot, "MSMSG_SET_OPTIONS");
-    send_message(user, memoserv_conf.bot, "MSMSG_BAR");
+    reply("MSMSG_SET_OPTIONS");
+    reply("MSMSG_BAR");
 
     /* Do this so options are presented in a consistent order. */
     for (i = 0; i < ArrayLength(set_display); ++i)
         if ((opt = dict_find(memoserv_opt_dict, set_display[i], NULL)))
-            opt(user, hi, override, 0, NULL);
-    send_message(user, memoserv_conf.bot, "MSMSG_SET_OPTIONS_END");
+            opt(cmd, user, hi, override, 0, NULL);
+    reply("MSMSG_SET_OPTIONS_END");
 }
 
 static MODCMD_FUNC(cmd_set)
@@ -718,7 +710,7 @@ static MODCMD_FUNC(cmd_set)
 
     hi = user->handle_info;
     if (argc < 2) {
-        set_list(user, hi, 0);
+        set_list(cmd, user, hi, 0);
         return 1;
     }
 
@@ -727,7 +719,7 @@ static MODCMD_FUNC(cmd_set)
         return 0;
     }
 
-    return opt(user, hi, 0, argc-1, argv+1);
+    return opt(cmd, user, hi, 0, argc-1, argv+1);
 }
 
 static MODCMD_FUNC(cmd_oset)
@@ -735,11 +727,11 @@ static MODCMD_FUNC(cmd_oset)
     struct handle_info *hi;
     option_func_t *opt;
 
-    if (!(hi = get_victim_oper(user, argv[1])))
+    if (!(hi = get_victim_oper(cmd, user, argv[1])))
         return 0;
 
     if (argc < 3) {
-        set_list(user, hi, 0);
+        set_list(cmd, user, hi, 0);
         return 1;
     }
 
@@ -748,7 +740,7 @@ static MODCMD_FUNC(cmd_oset)
         return 0;
     }
 
-    return opt(user, hi, 1, argc-2, argv+2);
+    return opt(cmd, user, hi, 1, argc-2, argv+2);
 }
 
 static OPTION_FUNC(opt_notify)
@@ -765,13 +757,13 @@ static OPTION_FUNC(opt_notify)
         } else if (disabled_string(choice)) {
             ma->flags &= ~MEMO_NOTIFY_NEW;
         } else {
-            send_message(user, memoserv_conf.bot, "MSMSG_INVALID_BINARY", choice);
+            reply("MSMSG_INVALID_BINARY", choice);
             return 0;
         }
     }
 
     choice = (ma->flags & MEMO_NOTIFY_NEW) ? "on" : "off";
-    send_message(user, memoserv_conf.bot, "MSMSG_SET_NOTIFY", choice);
+    reply("MSMSG_SET_NOTIFY", choice);
     return 1;
 }
 
@@ -789,13 +781,13 @@ static OPTION_FUNC(opt_authnotify)
         } else if (disabled_string(choice)) {
             ma->flags &= ~MEMO_NOTIFY_LOGIN;
         } else {
-            send_message(user, memoserv_conf.bot, "MSMSG_INVALID_BINARY", choice);
+            reply("MSMSG_INVALID_BINARY", choice);
             return 0;
         }
     }
 
     choice = (ma->flags & MEMO_NOTIFY_LOGIN) ? "on" : "off";
-    send_message(user, memoserv_conf.bot, "MSMSG_SET_AUTHNOTIFY", choice);
+    reply("MSMSG_SET_AUTHNOTIFY", choice);
     return 1;
 }
 
@@ -813,13 +805,13 @@ static OPTION_FUNC(opt_ignorereciepts)
         } else if (disabled_string(choice)) {
             ma->flags &= ~MEMO_IGNORE_RECIEPTS;
         } else {
-            send_message(user, memoserv_conf.bot, "MSMSG_INVALID_BINARY", choice);
+            reply("MSMSG_INVALID_BINARY", choice);
             return 0;
         }
     }
 
     choice = (ma->flags & MEMO_IGNORE_RECIEPTS) ? "on" : "off";
-    send_message(user, memoserv_conf.bot, "MSMSG_SET_IGNORERECIEPTS", choice);
+    reply("MSMSG_SET_IGNORERECIEPTS", choice);
     return 1;
 }
 
@@ -837,13 +829,13 @@ static OPTION_FUNC(opt_sendreciepts)
         } else if (disabled_string(choice)) {
             ma->flags &= ~MEMO_ALWAYS_RECIEPTS;
         } else {
-            send_message(user, memoserv_conf.bot, "MSMSG_INVALID_BINARY", choice);
+            reply("MSMSG_INVALID_BINARY", choice);
             return 0;
         }
     }
 
     choice = (ma->flags & MEMO_ALWAYS_RECIEPTS) ? "on" : "off";
-    send_message(user, memoserv_conf.bot, "MSMSG_SET_SENDRECIEPTS", choice);
+    reply("MSMSG_SET_SENDRECIEPTS", choice);
     return 1;
 }
 
@@ -861,13 +853,13 @@ static OPTION_FUNC(opt_private)
         } else if (disabled_string(choice)) {
             ma->flags &= ~MEMO_DENY_NONCHANNEL;
         } else {
-            send_message(user, memoserv_conf.bot, "MSMSG_INVALID_BINARY", choice);
+            reply("MSMSG_INVALID_BINARY", choice);
             return 0;
         }
     }
 
     choice = (ma->flags & MEMO_DENY_NONCHANNEL) ? "on" : "off";
-    send_message(user, memoserv_conf.bot, "MSMSG_SET_PRIVATE", choice);
+    reply("MSMSG_SET_PRIVATE", choice);
     return 1;
 }
 
@@ -886,7 +878,7 @@ static OPTION_FUNC(opt_limit)
         ma->limit = choice;
     }
 
-    send_message(user, memoserv_conf.bot, "MSMSG_SET_LIMIT", ma->limit);
+    reply("MSMSG_SET_LIMIT", ma->limit);
     return 1;
 }
 
@@ -1307,6 +1299,8 @@ memoserv_finalize(void) {
     str = database_get_data(conf_node, "bot", RECDB_QSTRING);
     if (str)
         memoserv_conf.bot = GetUserH(str);
+    else
+        log_module(MS_LOG, LOG_ERROR, "database_get_data for memoserv_conf.bot failed!");
 
     if (autojoin_channels && memoserv_conf.bot) {
         for (i = 0; i < autojoin_channels->used; i++) {