From: Rick L Bird Date: Fri, 6 May 2011 01:43:18 +0000 (-0400) Subject: Author: talvo@talvo.com X-Git-Url: https://git.theari.com/?a=commitdiff_plain;h=e452ac999e9734f0858276f2f25e0f2fb887ebaf;p=cobramush.git Author: talvo@talvo.com Date: Fri Nov 27 21:47:37 2009 +0000 Issue 147, lwho() and lports() can include unconnected ports Also updated all functions appropriately to handle Inherit_Powers Fixes #144 --- diff --git a/hdrs/mushtype.h b/hdrs/mushtype.h index 506d680..a348d9f 100644 --- a/hdrs/mushtype.h +++ b/hdrs/mushtype.h @@ -32,6 +32,10 @@ #define DESC_ITER_CONN(d) \ 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 7dc130f..b864be0 100644 --- a/src/bsd.c +++ b/src/bsd.c @@ -4088,7 +4088,6 @@ visible_short_page(dbref player, const char *match) return target; } -/* LWHO() function - really belongs elsewhere but needs stuff declared here */ /* ARGSUSED */ FUNCTION(fun_nwho) @@ -4096,7 +4095,7 @@ FUNCTION(fun_nwho) DESC *d; dbref victim; int count = 0; - int powered = (*(called_as + 1) != 'M') && Priv_Who(executor); + int powered = ((*(called_as + 1) != 'M') && Priv_Who(executor)); if (nargs && args[0] && *args[0]) { /* An argument was given. Find the victim and choose the lowest @@ -4110,8 +4109,10 @@ FUNCTION(fun_nwho) safe_str(T(e_notvis), buff, bp); return; } - if (!Priv_Who(victim)) - powered = 0; + + if (!Priv_Who(executor) + && !(Inherit_Powers(executor) && Priv_Who(Owner(executor)))) + powered = 0; } DESC_ITER_CONN(d) { @@ -4130,10 +4131,14 @@ FUNCTION(fun_lwho) dbref victim; int first; int start = 0, count = 0; - int powered = !(strchr(called_as, 'M') != NULL) && Priv_Who(executor); int xwho = *called_as == 'X'; int objid = (strchr(called_as, 'D') != NULL); + int powered = 0; + if (!(strchr(called_as, 'M') != NULL) && !Priv_Who(executor) + && !(Inherit_Powers(executor) && Priv_Who(Owner(executor)))) + powered = 1; + first = 1; if (!xwho && nargs && args[0] && *args[0]) { if (!powered) { @@ -4151,7 +4156,8 @@ FUNCTION(fun_lwho) safe_str(T(e_perm), buff, bp); return; } - if (!Priv_Who(victim)) + if (!Priv_Who(executor) + && !(Inherit_Powers(executor) && Priv_Who(Owner(executor)))) powered = 0; } else victim = executor; @@ -4708,6 +4714,10 @@ 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)))) { @@ -4715,13 +4725,51 @@ FUNCTION(fun_lports) return; } - DESC_ITER_CONN(d) { - if (first) - first = 0; - else - safe_chr(' ', buff, bp); - safe_integer(d->descriptor, buff, bp); + 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) + && !(Inherit_Powers(executor) && Priv_Who(Owner(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("#-1 PERMISSION DENIED"), 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 + safe_chr(' ', buff, bp); + safe_integer(d->descriptor, buff, bp); + } } /* ARGSUSED */ diff --git a/src/function.c b/src/function.c index 21c3840..29aebb9 100644 --- a/src/function.c +++ b/src/function.c @@ -513,7 +513,7 @@ FUNTAB flist[] = { {"LOCKS", fun_locks, 1, 1, FN_REG}, {"LPARENT", fun_lparent, 1, 1, FN_REG}, {"LPLAYERS", fun_dbwalker, 1, 1, FN_REG}, - {"LPORTS", fun_lports, 0, 1, FN_REG}, + {"LPORTS", fun_lports, 0, 2, FN_REG}, {"LPOS", fun_lpos, 2, 2, FN_REG}, {"LTHINGS", fun_dbwalker, 1, 1, FN_REG}, {"LSEARCH", fun_lsearch, 1, INT_MAX, FN_REG}, @@ -525,7 +525,7 @@ FUNTAB flist[] = { {"LVEXITS", fun_dbwalker, 1, 1, FN_REG}, {"LVPLAYERS", fun_dbwalker, 1, 1, FN_REG}, {"LVTHINGS", fun_dbwalker, 1, 1, FN_REG}, - {"LWHO", fun_lwho, 0, 1, FN_REG}, + {"LWHO", fun_lwho, 0, 2, FN_REG}, {"LWHOID", fun_lwho, 0, 1, FN_REG}, #ifdef USE_MAILER {"MAIL", fun_mail, 0, 2, FN_REG},