From 300f5bee2d958e384e4241185bee15af7cf79db1 Mon Sep 17 00:00:00 2001 From: Ari Johnson Date: Wed, 16 Dec 2015 14:12:37 -0500 Subject: [PATCH] Improved lports() --- hdrs/mushtype.h | 3 +++ src/bsd.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/hdrs/mushtype.h b/hdrs/mushtype.h index 6f0e67b..3547064 100644 --- a/hdrs/mushtype.h +++ b/hdrs/mushtype.h @@ -36,6 +36,9 @@ for(d = descriptor_list;(d);d=(d)->next) \ if((d)->connected) +#define DESC_ITER(d) \ + for(d = descriptor_list;(d);d=(d)->next) + /** Is a descriptor hidden? */ #define Hidden(d) ((d->hide == 1) && Can_Hide(d->player)) diff --git a/src/bsd.c b/src/bsd.c index d95c835..876d08a 100644 --- a/src/bsd.c +++ b/src/bsd.c @@ -4665,14 +4665,56 @@ FUNCTION(fun_lports) { DESC *d; int first = 1; + dbref victim; + int powered = 1; + int online = 1; + int offline = 0; - if (!Priv_Who(executor) - && !(Inherit_Powers(executor) && Priv_Who(Owner(executor)))) { + if (!Priv_Who(executor)) { safe_str(T(e_perm), buff, bp); return; } - DESC_ITER_CONN(d) { + if (nargs && args[0] && *args[0]) { + /* An argument was given. Find the victim and adjust perms */ + if ((victim = + noisy_match_result(executor, args[0], NOTYPE, + MAT_EVERYTHING)) == NOTHING) { + safe_str(T(e_notvis), buff, bp); + return; + } + + if (!Priv_Who(executor)) + powered = 0; + } + + if (nargs > 1 && args[1] && *args[1]) { + if (string_prefix("all", args[1])) { + offline = online = 1; + } else if (strlen(args[1]) < 2) { + safe_str(T("#-1 INVALID SECOND ARGUMENT"), buff, bp); + return; + } else if (string_prefix("online", args[1])) { + online = 1; + offline = 0; + } else if (string_prefix("offline", args[1])) { + online = 0; + offline = 1; + } else { + safe_str(T("#-1 INVALID SECOND ARGUMENT"), buff, bp); + return; + } + if (offline && !powered) { + safe_str(T(e_perm), buff, bp); + return; + } + } + + DESC_ITER(d) { + if ((d->connected && !online) || (!d->connected && !offline)) + continue; + if (!powered && (d->connected && Hidden(d))) + continue; if (first) first = 0; else -- 2.30.2