]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/mod-memoserv.c
improve stats routing command
[irc/evilnet/x3.git] / src / mod-memoserv.c
index 150632dd6b98297c327c35c1fab40d9f085c4899..2ede913e5765f027ee1a2d30293c35fce9844100 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*);
@@ -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 {
@@ -727,6 +750,8 @@ static MODCMD_FUNC(cmd_oset)
     struct handle_info *hi;
     option_func_t *opt;
 
+    MEMOSERV_MIN_PARAMS(2);
+
     if (!(hi = get_victim_oper(cmd, user, argv[1])))
         return 0;
 
@@ -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,15 +1322,20 @@ memoserv_finalize(void) {
     }
 
     str = database_get_data(conf_node, "bot", RECDB_QSTRING);
-    if (str)
-        memoserv_conf.bot = GetUserH(str);
-    else
+    if (str) {
+        memoserv = memoserv_conf.bot;
+        const char *modes = conf_get_data("modules/memoserv/modes", RECDB_QSTRING);
+        memoserv = AddService(str, modes ? modes : NULL, "User-User Memorandum Services", NULL);
+
+    } 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;
         }
     }