Integrate Global "from" option; reorganize code
authorZoot <zoot@gamesurge.net>
Wed, 1 Jun 2005 19:05:39 +0000 (19:05 +0000)
committerZoot <zoot@gamesurge.net>
Wed, 1 Jun 2005 19:05:39 +0000 (19:05 +0000)
 * src/global.c: Integrate SF.net patch #1211520 (from bruder2k) with a small
   bug fix; this patch adds a "from" option to Global notices and messages.

 * src/global.c, src/global.h: Make struct globalMessage private; cache text
   form of message's post date/time to avoid repeated strftime() calls.
git-archimport-id: srvx@srvx.net--2005-srvx/srvx--devo--1.3--patch-22

ChangeLog
src/global.c
src/global.h
src/global.help

index a11f7191f6ae4548bf1256d7ca986f896bcc6f4f..1604fd9dc9d42daf7644e82abe3e54e6536a555c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,23 @@
 # arch-tag: automatic-ChangeLog--srvx@srvx.net--2005-srvx/srvx--devo--1.3
 #
 
+2005-06-01 19:05:39 GMT        Zoot <zoot@gamesurge.net>       patch-22
+
+    Summary:
+      Integrate Global "from" option; reorganize code
+    Revision:
+      srvx--devo--1.3--patch-22
+
+     * src/global.c: Integrate SF.net patch #1211520 (from bruder2k) with a small
+       bug fix; this patch adds a "from" option to Global notices and messages.
+    
+     * src/global.c, src/global.h: Make struct globalMessage private; cache text
+       form of message's post date/time to avoid repeated strftime() calls.
+
+    modified files:
+     ChangeLog src/global.c src/global.h src/global.help
+
+
 2005-05-30 15:14:56 GMT        Michael Poole <mdpoole@troilus.org>     patch-21
 
     Summary:
index 75e82457480d43f2195c583a1d403a283e9b25d5..d92e5bd6f150f58a1d35bed30b1bc72f531f1a73 100644 (file)
@@ -65,6 +65,22 @@ static const struct message_entry msgtab[] = {
 #define GLOBAL_SYNTAX()   svccmd_send_help(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 +104,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 +119,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 +173,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 +218,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 +236,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 +283,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 +377,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 +400,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);
 
index df3ed64b7f95a3966e4af2f816c5d27594bc5362..b4bf81bb72b55b906daae7d256b1110f698289e5 100644 (file)
 #define MESSAGE_RECIPIENT_STAFF                        (MESSAGE_RECIPIENT_HELPERS | MESSAGE_RECIPIENT_OPERS)
 #define MESSAGE_RECIPIENT_ALL                  (MESSAGE_RECIPIENT_LUSERS | MESSAGE_RECIPIENT_CHANNELS)
 
-struct globalMessage
-{
-    unsigned long                              id;
-    long                               flags;
-
-    time_t                             posted;
-    unsigned long                      duration;
-
-    char                               *from;
-    char                               *message;
-
-    struct globalMessage               *prev;
-    struct globalMessage               *next;
-};
-
 void init_global(const char *nick);
 
 void global_message(long targets, char *text);
index 12824391456acfac992a34e47e45f6ebec3122ff..3887d41c970ce61d8daf6bcee692fdbadcf8a505 100644 (file)
         "$uSee Also:$u message, messages, remove");
 "MESSAGE" ("/msg $G MESSAGE [<options> <value>] text <message>",
         "Adds a notice to the $b$G$b database. Messages are sent to users as they enter the network or the target class. $bMessage$b takes several options, which must be preceded by the name of the option being used. Options include:",
+        "$bFROM$b:     Sets the message's stated source.",
         "$bTARGET$b:   Controls the recipients of the message. This option may be used multiple times. See the $bTARGET$b help entry for details.",
         "$bDURATION$b: This option sets the length of time for which the message is valid. After this time, the message will be deleted from the $b$G$b database.",
         "$uSee Also:$u list, messages, remove, target");
 "MESSAGES" ("/msg $G MESSAGES",
         "Sends you all messages addressed to your user class.");
-"NOTICE" ("/msg $G NOTICE <target> <message>",
+"NOTICE" ("/msg $G NOTICE <target> [from <source>] <message>",
         "Immediately sends a notice to a specific target. See $btarget$b for a list of targets.",
         "$uSee Also:$u target");
 "REMOVE" ("/msg $G REMOVE <message id>",