]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/mod-memoserv.c
tweaks
[irc/evilnet/x3.git] / src / mod-memoserv.c
index 8bbf67f63aed4b6b3d07f4577e4094aa3af3a373..4c9011f4a38f2e3024c5af7d9d4ae3e8ae931d9b 100644 (file)
@@ -42,6 +42,7 @@
 #include "conf.h"
 #include "modcmd.h"
 #include "nickserv.h"
+#include "opserv.h"
 #include "saxdb.h"
 #include "timeq.h"
 
@@ -108,6 +109,8 @@ static const struct message_entry msgtab[] = {
     { "MSMSG_LIST_END",        "--------------End of Memos--------------" },
     { "MSMSG_BAR",             "----------------------------------------"},
 
+    { "MSMSG_DEFCON_NO_NEW_MEMOS", "You cannot send new memos at this time, please try again soon." },
+
     { NULL, NULL }
 };
 
@@ -128,6 +131,15 @@ struct history {
     unsigned long id;
 };
 
+struct userNode *memoserv;
+
+#define MEMOSERV_FUNC(NAME)         MODCMD_FUNC(NAME)
+#define MEMOSERV_SYNTAX()           svccmd_send_help_brief(user, memoserv, cmd)
+#define MEMOSERV_MIN_PARAMS(N)      if(argc < (N)) {            \
+                                     reply("MSG_MISSING_PARAMS", argv[0]); \
+                                     MEMOSERV_SYNTAX(); \
+                                     return 0; }
+
 DECLARE_LIST(memoList, struct memo*);
 DEFINE_LIST(memoList, struct memo*);
 DECLARE_LIST(historyList, struct history*);
@@ -157,7 +169,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;
@@ -390,6 +402,13 @@ static MODCMD_FUNC(cmd_send)
     struct memo_account *ma, *sender;
     struct memo *memo;
 
+    MEMOSERV_MIN_PARAMS(3);
+
+    if (checkDefCon(DEFCON_NO_NEW_MEMOS) && !IsOper(user)) {
+        reply("MSMSG_DEFCON_NO_NEW_MEMOS");
+        return 0;
+    }
+
     if (!(hi = modcmd_get_handle_info(user, argv[1])))
         return 0;
 
@@ -528,7 +547,7 @@ static MODCMD_FUNC(cmd_read)
     if (!(memo = find_memo(user, cmd, ma, argv[1], &memoid)))
         return 0;
 
-    if (argv[2]) {
+    if (argc > 2) {
         char *argtwo = argv[2];
         while (*argtwo) {
             switch (*argtwo) {
@@ -600,6 +619,8 @@ static MODCMD_FUNC(cmd_delete)
     struct memo *memo;
     unsigned int memoid;
 
+    MEMOSERV_MIN_PARAMS(2);
+
     if (!(ma = memoserv_get_account(user->handle_info)))
         return 0;
     if (!irccasecmp(argv[1], "*") || !irccasecmp(argv[1], "all")) {
@@ -628,6 +649,8 @@ static MODCMD_FUNC(cmd_cancel)
     struct memo *memo;
     struct memo_account *ma;
 
+    MEMOSERV_MIN_PARAMS(2);
+
     if (isdigit(argv[1][0])) {
         id = strtoul(argv[1], NULL, 0);
     } else {
@@ -686,21 +709,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)
@@ -710,7 +733,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;
     }
 
@@ -719,7 +742,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)
@@ -727,11 +750,13 @@ static MODCMD_FUNC(cmd_oset)
     struct handle_info *hi;
     option_func_t *opt;
 
-    if (!(hi = get_victim_oper(user, argv[1])))
+    MEMOSERV_MIN_PARAMS(2);
+
+    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;
     }
 
@@ -740,7 +765,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)
@@ -757,13 +782,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;
 }
 
@@ -781,13 +806,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;
 }
 
@@ -805,13 +830,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;
 }
 
@@ -829,13 +854,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;
 }
 
@@ -853,13 +878,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;
 }
 
@@ -878,7 +903,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;
 }
 
@@ -1215,8 +1240,8 @@ memoserv_check_messages(struct userNode *user, UNUSED_ARG(struct handle_info *ol
             if (!memo->is_read)
                 unseen++;
         }
-        if (ma->recvd.used && memoserv_conf.bot)
-            if(unseen) send_message(user, memoserv_conf.bot, "MSMSG_MEMOS_INBOX", unseen, ma->recvd.used - unseen);
+        if (ma->recvd.used && memoserv)
+            if(unseen) send_message(user, memoserv, "MSMSG_MEMOS_INBOX", unseen, ma->recvd.used - unseen);
     }
 }
 
@@ -1297,13 +1322,17 @@ memoserv_finalize(void) {
     }
 
     str = database_get_data(conf_node, "bot", RECDB_QSTRING);
-    if (str)
-        memoserv_conf.bot = GetUserH(str);
+    if (str) {
+        memoserv = memoserv_conf.bot;
+    } else {
+        log_module(MS_LOG, LOG_ERROR, "database_get_data for memoserv_conf.bot failed!");
+        exit(1);
+    }
 
-    if (autojoin_channels && memoserv_conf.bot) {
+    if (autojoin_channels && memoserv) {
         for (i = 0; i < autojoin_channels->used; i++) {
             chan = AddChannel(autojoin_channels->list[i], now, "+nt", NULL, NULL);
-            AddChannelUser(memoserv_conf.bot, chan)->modes |= MODE_CHANOP;
+            AddChannelUser(memoserv, chan)->modes |= MODE_CHANOP;
         }
     }