]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/global.c
Finally i figured out how to deal with the last issue, This is a tracking module...
[irc/evilnet/x3.git] / src / global.c
index dc7dc4f0f381c73c3a9d3c842478f7cf3cbe7192..6c7d6939c71712480aa1792cb5c55b1f228e77ac 100644 (file)
@@ -1,7 +1,7 @@
 /* global.c - Global notice service
  * Copyright 2000-2004 srvx Development Team
  *
- * This file is part of srvx.
+ * This file is part of x3.
  *
  * srvx is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -55,16 +55,34 @@ static const struct message_entry msgtab[] = {
     { "GMSG_ID_INVALID", "$b%s$b is an invalid message ID." },
     { "GMSG_MESSAGE_COUNT", "$b%d$b messages found." },
     { "GMSG_NO_MESSAGES", "There are no messages for you." },
-    { "GMSG_NOTICE_SOURCE", "[$b%s$b] Notice from %s:" },
-    { "GMSG_MESSAGE_SOURCE", "[$b%s$b] Notice from %s, posted %s:" },
-    { "GMSG_MOTD_HEADER", "$b------------- MESSAGE(S) OF THE DAY --------------$b" },
-    { "GMSG_MOTD_FOOTER", "$b---------- END OF MESSAGE(S) OF THE DAY ----------$b" },
+    { "GMSG_NOTICE_SOURCE", "Notice to [$b%s$b] from %s:" },
+    { "GMSG_MESSAGE_SOURCE", "Notice to [$b%s$b] from %s, posted %s:" },
+    //{ "GMSG_MOTD_HEADER", "$b------------- MESSAGE(S) OF THE DAY --------------$b" },
+    { "GMSG_MOTD_HEADER", "$bNetwork Announcements$b" },
+    { "GMSG_MOTD_BAR",    "---------------------------------------" },
+    { "GMSG_MOTD_FOOTER", "--------------- Thank You--------------" },
     { NULL, NULL }
 };
 
-#define GLOBAL_SYNTAX()   svccmd_send_help(user, global, cmd)
+#define GLOBAL_SYNTAX()   svccmd_send_help_brief(user, global, cmd)
 #define GLOBAL_FUNC(NAME) MODCMD_FUNC(NAME)
 
+struct globalMessage
+{
+    unsigned long                              id;
+    long                               flags;
+
+    time_t                              posted;
+    char                               posted_s[24];
+    unsigned long                      duration;
+
+    char                               *from;
+    char                               *message;
+
+    struct globalMessage               *prev;
+    struct globalMessage               *next;
+};
+
 struct userNode *global;
 
 static struct module *global_module;
@@ -88,9 +106,9 @@ static struct globalMessage*
 message_add(long flags, time_t posted, unsigned long duration, char *from, const char *msg)
 {
     struct globalMessage *message;
+    struct tm tm;
 
     message = malloc(sizeof(struct globalMessage));
-
     if(!message)
     {
        return NULL;
@@ -103,11 +121,16 @@ message_add(long flags, time_t posted, unsigned long duration, char *from, const
     message->from = strdup(from);
     message->message = strdup(msg);
 
+    if ((flags & MESSAGE_OPTION_IMMEDIATE) == 0) {
+        localtime_r(&message->posted, &tm);
+        strftime(message->posted_s, sizeof(message->posted_s),
+                 "%I:%M %p, %m/%d/%Y", &tm);
+    }
+
     if(messageList)
     {
        messageList->prev = message;
     }
-
     message->prev = NULL;
     message->next = messageList;
 
@@ -152,9 +175,12 @@ message_create(struct userNode *user, unsigned int argc, char *argv[])
 {
     unsigned long duration = 0;
     char *text = NULL;
+    char *sender;
     long flags = 0;
     unsigned int i;
 
+    sender = user->handle_info->handle;
+
     for(i = 0; i < argc; i++)
     {
        if((i + 1) > argc)
@@ -194,6 +220,8 @@ message_create(struct userNode *user, unsigned int argc, char *argv[])
            }
        } else if (irccasecmp(argv[i], "duration") == 0) {
            duration = ParseInterval(argv[++i]);
+        } else if (irccasecmp(argv[i], "from") == 0) {
+            sender = argv[++i];
        } else {
            global_notice(user, "MSG_INVALID_CRITERIA", argv[i]);
            return NULL;
@@ -210,7 +238,7 @@ message_create(struct userNode *user, unsigned int argc, char *argv[])
        return NULL;
     }
 
-    return message_add(flags, now, duration, user->handle_info->handle, text);
+    return message_add(flags, now, duration, sender, text);
 }
 
 static const char *
@@ -257,12 +285,7 @@ notice_target(const char *target, struct globalMessage *message)
        }
        else
        {
-           char posted[24];
-           struct tm tm;
-
-           localtime_r(&message->posted, &tm);
-           strftime(posted, sizeof(posted), "%I:%M %p, %m/%d/%Y", &tm);
-           send_target_message(0, target, global, "GMSG_MESSAGE_SOURCE", messageType(message), message->from, posted);
+           send_target_message(0, target, global, "GMSG_MESSAGE_SOURCE", messageType(message), message->from, message->posted_s);
        }
     }
 
@@ -356,9 +379,11 @@ static GLOBAL_FUNC(cmd_notice)
 {
     struct globalMessage *message = NULL;
     const char *recipient = NULL, *text;
+    char *sender;
     long target = 0;
 
     assert(argc >= 3);
+    sender = user->handle_info->handle;
     if(!irccasecmp(argv[1], "all")) {
        target = MESSAGE_RECIPIENT_ALL;
     } else if(!irccasecmp(argv[1], "users")) {
@@ -377,17 +402,23 @@ static GLOBAL_FUNC(cmd_notice)
        global_notice(user, "GMSG_INVALID_TARGET", argv[1]);
        return 0;
     }
+    if(!irccasecmp(argv[2], "from")) {
+        if (argc < 5) {
+            reply("MSG_MISSING_PARAMS", argv[0]);
+            GLOBAL_SYNTAX();
+            return 0;
+        }
+        sender = argv[3];
+        text = unsplit_string(argv + 4, argc - 4, NULL);
+    } else {
+        text = unsplit_string(argv + 2, argc - 2, NULL);
+    }
 
-    text = unsplit_string(argv + 2, argc - 2, NULL);
-    message = message_add(target | MESSAGE_OPTION_IMMEDIATE, now, 0, user->handle_info->handle, text);
-
+    message = message_add(target | MESSAGE_OPTION_IMMEDIATE, now, 0, sender, text);
     if(!message)
-    {
        return 0;
-    }
 
     recipient = messageType(message);
-
     message_send(message);
     message_del(message);
 
@@ -503,7 +534,10 @@ send_messages(struct userNode *user, long mask, int obstreperize)
        if(message->flags & mask)
        {
             if (obstreperize && !count)
+           {
                 send_target_message(0, user->nick, global, "GMSG_MOTD_HEADER");
+                send_target_message(0, user->nick, global, "GMSG_MOTD_BAR");
+           }
            notice_target(user->nick, message);
            count++;
        }
@@ -674,7 +708,8 @@ init_global(const char *nick)
 
     if(nick)
     {
-        global = AddService(nick, "Global Services", NULL);
+        const char *modes = conf_get_data("services/global/modes", RECDB_QSTRING);
+        global = AddService(nick, modes ? modes : NULL, "Global Services", NULL);
         global_service = service_register(global);
     }
     saxdb_register("Global", global_saxdb_read, global_saxdb_write);