From 839ab9c7c30c63c0bb584da4ab6fe41f54f22ac4 Mon Sep 17 00:00:00 2001 From: ThiefMaster Date: Sat, 7 Apr 2007 00:06:24 +0200 Subject: [PATCH] * Reject durations containing invalid characters (like "1day" instead of "1d"). * Add duration to opserv.block. --- src/opserv.c | 17 +++++++++++------ src/opserv.help | 4 ++-- src/tools.c | 14 ++++++++------ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/opserv.c b/src/opserv.c index d445077..d6aedf5 100644 --- a/src/opserv.c +++ b/src/opserv.c @@ -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; } diff --git a/src/opserv.help b/src/opserv.help index 3973e17..3e80b79 100644 --- a/src/opserv.help +++ b/src/opserv.help @@ -242,8 +242,8 @@ " GSYNC [${level/gsync}]", " REFRESHG [${level/refreshg}]", " UNGLINE [${level/ungline}]"); -"BLOCK" ("/msg $O BLOCK [reason]", - "GLINES the host of the specified nick for one hour If no reason is given, use a default reason.", +"BLOCK" ("/msg $O BLOCK [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 ", "Issues a GLINE (network ban) on the network for the speicified user@host for the specified duration (making the expiration time: net time + duration).", diff --git a/src/tools.c b/src/tools.c index d4dee86..983fe9f 100644 --- a/src/tools.c +++ b/src/tools.c @@ -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; -- 2.20.1