* Reject durations containing invalid characters (like "1day" instead of "1d").
authorThiefMaster <thiefmaster@gamesurge.net>
Fri, 6 Apr 2007 22:06:24 +0000 (00:06 +0200)
committerMichael Poole <mdpoole@troilus.org>
Mon, 28 May 2007 18:46:03 +0000 (14:46 -0400)
* Add duration to opserv.block.

src/opserv.c
src/opserv.help
src/tools.c

index d445077b7a132b7fa325f41514af3172d531c8d6..d6aedf50ed7fe9ee83a46902ea13026ba93d8c60 100644 (file)
@@ -767,18 +767,23 @@ static MODCMD_FUNC(cmd_block)
     struct userNode *target;
     struct gline *gline;
     char *reason;
+    unsigned long duration = 0;
+    unsigned int offset = 2;
 
     target = GetUserH(argv[1]);
     if (!target) {
-       reply("MSG_NICK_UNKNOWN", argv[1]);
-       return 0;
+        reply("MSG_NICK_UNKNOWN", argv[1]);
+        return 0;
     }
     if (IsService(target)) {
-       reply("MSG_SERVICE_IMMUNE", target->nick);
-       return 0;
+        reply("MSG_SERVICE_IMMUNE", target->nick);
+        return 0;
+    }
+    if(argc > 2 && (duration = ParseInterval(argv[2]))) {
+        offset = 3;
     }
-    reason = (argc > 2) ? unsplit_string(argv+2, argc-2, NULL) : NULL;
-    gline = opserv_block(target, user->handle_info->handle, reason, 0);
+    reason = (argc > offset) ? unsplit_string(argv+offset, argc-offset, NULL) : NULL;
+    gline = opserv_block(target, user->handle_info->handle, reason, duration);
     reply("OSMSG_GLINE_ISSUED", gline->target);
     return 1;
 }
index 3973e17c9817979d425f2a9ff68ebf093818f5a2..3e80b79134053213dc7a44135038f82441fb829d 100644 (file)
         "  GSYNC    [${level/gsync}]",
         "  REFRESHG [${level/refreshg}]",
         "  UNGLINE  [${level/ungline}]");
-"BLOCK" ("/msg $O BLOCK <nick> [reason]",
-        "GLINES the host of the specified nick for one hour  If no reason is given, use a default reason.",
+"BLOCK" ("/msg $O BLOCK <nick> [duration] [reason]",
+        "GLINES the host of the specified nick for one hour if no duration is given.  If no reason is given, use a default reason.",
         "$uSee Also:$u gline, ungline");
 "GLINE" ("/msg $O GLINE <user@host> <duration> <reason>",
         "Issues a GLINE (network ban) on the network for the speicified user@host for the specified duration (making the expiration time: net time + duration).",
index d4dee86d65e221cd39357f1121752dce95e845ad..983fe9fbddcd72c436e8ba04049b61b946e97854 100644 (file)
@@ -794,12 +794,14 @@ ParseInterval(const char *interval)
 
     /* process the string, resetting the count if we find a unit character */
     while ((c = *interval++)) {
-       if (isdigit((int)c)) {
-           partial = partial*10 + c - '0';
-       } else {
-           seconds += TypeLength(c) * partial;
-           partial = 0;
-       }
+        if (isdigit((int)c)) {
+            partial = partial*10 + c - '0';
+        } else if (strchr("yMwdhms", c)) {
+            seconds += TypeLength(c) * partial;
+            partial = 0;
+        } else {
+            return 0;
+        }
     }
     /* assume the last chunk is seconds (the normal case) */
     return seconds + partial;