From 040936288e42fec5e86e6c6fc2d1e6910e4a17a8 Mon Sep 17 00:00:00 2001 From: Rick L Bird Date: Sat, 14 May 2011 13:52:31 -0400 Subject: [PATCH] Author: talvo@talvo.com Date: Sun Jan 10 00:18:16 2010 +0000 Issue 193, andflags, orlpowers, etc, return #-1 when given an invalid flag/power Refs #205 I'm just reffing this one because I think this may need a little testing before its really accepted as resolved and completed. --- hdrs/externs.h | 2 ++ src/bsd.c | 5 ++--- src/flags.c | 20 ++++++-------------- src/function.c | 4 ++-- src/fundb.c | 51 +++++++++++++++++++++++++++++++------------------- src/funmisc.c | 5 +++++ src/notify.c | 25 +++++++++++++++++++++++++ 7 files changed, 74 insertions(+), 38 deletions(-) diff --git a/hdrs/externs.h b/hdrs/externs.h index cf79caa..e4fdad1 100644 --- a/hdrs/externs.h +++ b/hdrs/externs.h @@ -63,6 +63,8 @@ extern DESC *port_desc(int port); /* find descriptors */ extern void WIN32_CDECL flag_broadcast(const char *flag1, const char *flag2, const char *fmt, ...) __attribute__ ((__format__(__printf__, 3, 4))); +extern void WIN32_CDECL level_broadcast(int minlevel, const char *fmt, ...) + __attribute__ ((__format__(__printf__, 2, 3))); extern void raw_notify(dbref player, const char *msg); extern void notify_list(dbref speaker, dbref thing, const char *atr, diff --git a/src/bsd.c b/src/bsd.c index 6d57383..1a5351d 100644 --- a/src/bsd.c +++ b/src/bsd.c @@ -1114,8 +1114,7 @@ shovechars(Port_t port __attribute__ ((__unused__)), if (WIFSIGNALED(dump_status)) { do_rawlog(LT_ERR, T("ERROR! forking dump exited with signal %d"), WTERMSIG(dump_status)); - flag_broadcast("ROYALTY WIZARD", 0, - T("GAME: ERROR! Forking database save failed!")); + level_broadcast(LEVEL_ADMIN, T("GAME: ERROR! Forking database save failed!")); } else if (WIFEXITED(dump_status)) { if (WEXITSTATUS(dump_status) == 0) { time(&globals.last_dump_time); @@ -1125,7 +1124,7 @@ shovechars(Port_t port __attribute__ ((__unused__)), do_rawlog(LT_ERR, T("ERROR! forking dump exited with exit code %d"), WEXITSTATUS(dump_status)); - flag_broadcast("ROYALTY WIZARD", 0, + level_broadcast(LEVEL_ADMIN, T("GAME: ERROR! Forking database save failed!")); } } diff --git a/src/flags.c b/src/flags.c index c2f2867..50955b1 100644 --- a/src/flags.c +++ b/src/flags.c @@ -1810,7 +1810,7 @@ flaglist_check(const char *ns, dbref player, dbref it, const char *fstr, if (!*s) /* We got a '!' that wasn't followed by a letter. * Fail the check. */ - return (type == 1) ? 0 : ret; + return -1; /* Find the flag. */ fp = letter_to_flagptr(n, *s, Typeof(it)); if (!fp) { @@ -1832,10 +1832,7 @@ flaglist_check(const char *ns, dbref player, dbref it, const char *fstr, * we couldn't find that flag. For AND, since we've failed * a check, we can return false. Otherwise we just go on. */ - if (type == 1) - return 0; - else - continue; + return -1; } } else { if (type == 1) @@ -1852,7 +1849,7 @@ flaglist_check(const char *ns, dbref player, dbref it, const char *fstr, * it, or we don't have a flag and we want it. Since it's * AND, we return false. */ - return 0; + ret = 0; } else if ((type == 0) && ((!negate && temp) || (negate && !temp))) { /* We've found something we want, in an OR. We OR a * true with the current value. @@ -1911,8 +1908,7 @@ flaglist_check_long(const char *ns, dbref player, dbref it, const char *fstr, if (!*s) { /* We got a '!' that wasn't followed by a string. * Fail the check. */ - if (type == 1) - ret = 0; + ret = -1; break; } /* Find the flag. */ @@ -1921,11 +1917,8 @@ flaglist_check_long(const char *ns, dbref player, dbref it, const char *fstr, * we couldn't find that flag. For AND, since we've failed * a check, we can return false. Otherwise we just go on. */ - if (type == 1) { - ret = 0; - break; - } else - continue; + ret = -1; + break; } else { /* does the object have this flag? There's a special case * here, as we want (for consistency with flaglist_check) @@ -1948,7 +1941,6 @@ flaglist_check_long(const char *ns, dbref player, dbref it, const char *fstr, * AND, we return false. */ ret = 0; - break; } else if ((type == 0) && ((!negate && temp) || (negate && !temp))) { /* We've found something we want, in an OR. We OR a * true with the current value. diff --git a/src/function.c b/src/function.c index dd368ba..e45b1a4 100644 --- a/src/function.c +++ b/src/function.c @@ -321,7 +321,7 @@ FUNTAB flist[] = { {"AND", fun_and, 2, INT_MAX, FN_REG}, {"ANDFLAGS", fun_andflags, 2, 2, FN_REG}, {"ANDLFLAGS", fun_andlflags, 2, 2, FN_REG}, - {"ANDLPOWERS", fun_andlflags, 2, 2, FN_REG}, + {"ANDLPOWERS", fun_unimp, 2, 2, FN_REG}, {"ANSI", fun_ansi, 2, -2, FN_REG}, #ifdef ANSI_DEBUG {"ANSIINSPECT", fun_ansiinspect, 1, 2, FN_REG}, @@ -607,7 +607,7 @@ FUNTAB flist[] = { {"ORD", fun_ord, 1, 1, FN_REG}, {"ORFLAGS", fun_orflags, 2, 2, FN_REG}, {"ORLFLAGS", fun_orlflags, 2, 2, FN_REG}, - {"ORLPOWERS", fun_orlflags, 2, 2, FN_REG}, + {"ORLPOWERS", fun_unimp, 2, 2, FN_REG}, {"OOREF", fun_ooref, 0, 0, FN_REG}, {"OWNER", fun_owner, 1, 1, FN_REG}, {"PARENT", fun_parent, 1, 2, FN_REG}, diff --git a/src/fundb.c b/src/fundb.c index 86e49e6..4c34ea4 100644 --- a/src/fundb.c +++ b/src/fundb.c @@ -1073,49 +1073,62 @@ FUNCTION(fun_hastype) } /* ARGSUSED */ -FUNCTION(fun_orflags) +FUNCTION(fun_orlflags) { dbref it = match_thing(executor, args[0]); - if (!strcmp(called_as, "ORPOWERS")) - safe_boolean(flaglist_check("POWER", executor, it, args[1], 0), buff, bp); + int hasflag; + if (!strcmp(called_as, "ORLPOWERS")) + hasflag = flaglist_check_long("POWER", executor, it, args[1], 0); else - safe_boolean(flaglist_check("FLAG", executor, it, args[1], 0), buff, bp); + hasflag = flaglist_check_long("FLAG", executor, it, args[1], 0); + if (hasflag == -1) + if (!strcmp(called_as, "ORLPOWERS")) + safe_str(T("#-1 INVALID POWER"), buff, bp); + else + safe_str(T("#-1 INVALID FLAG"), buff, bp); + else + safe_boolean(hasflag, buff, bp); } + /* ARGSUSED */ -FUNCTION(fun_andflags) +FUNCTION(fun_orflags) { dbref it = match_thing(executor, args[0]); - if (!strcmp(called_as, "ANDPOWERS")) - safe_boolean(flaglist_check("POWER", executor, it, args[1], 1), buff, bp); + int hasflag; + hasflag = flaglist_check("FLAG", executor, it, args[1], 0); + if (hasflag == -1) + safe_str(T("#-1 INVALID FLAG"), buff, bp); else - safe_boolean(flaglist_check("FLAG", executor, it, args[1], 1), buff, bp); + safe_boolean(hasflag, buff, bp); } /* ARGSUSED */ -FUNCTION(fun_orlflags) +FUNCTION(fun_andflags) { dbref it = match_thing(executor, args[0]); - if (!strcmp(called_as, "ORLPOWERS")) - safe_boolean(flaglist_check_long("POWER", executor, it, args[1], 0), buff, - bp); + int hasflag; + hasflag = flaglist_check("FLAG", executor, it, args[1], 1); + if (hasflag == -1) + safe_str(T("#-1 INVALID FLAG"), buff, bp); else - safe_boolean(flaglist_check_long("FLAG", executor, it, args[1], 0), buff, - bp); + safe_boolean(hasflag, buff, bp); } /* ARGSUSED */ FUNCTION(fun_andlflags) { dbref it = match_thing(executor, args[0]); - if (!strcmp(called_as, "ANDLPOWERS")) - safe_boolean(flaglist_check_long("POWER", executor, it, args[1], 1), buff, - bp); + int hasflag; + + hasflag = flaglist_check_long("FLAG", executor, it, args[1], 1); + if (hasflag == -1) + safe_str(T("#-1 INVALID FLAG"), buff, bp); else - safe_boolean(flaglist_check_long("FLAG", executor, it, args[1], 1), buff, - bp); + safe_boolean(hasflag, buff, bp); } + static lock_type get_locktype(str) char *str; diff --git a/src/funmisc.c b/src/funmisc.c index 2242ad1..87807c2 100644 --- a/src/funmisc.c +++ b/src/funmisc.c @@ -40,6 +40,11 @@ extern char cf_motd_msg[BUFFER_LEN], cf_downmotd_msg[BUFFER_LEN], cf_fullmotd_msg[BUFFER_LEN]; extern HASHTAB htab_function; +FUNCTION(fun_unimp) { + /* Dummy function for unimplemented stuff */ + safe_str("#-1 UNIMPLEMENTED", buff, bp); +} + /* ARGSUSED */ FUNCTION(fun_valid) { diff --git a/src/notify.c b/src/notify.c index 724153b..b873520 100644 --- a/src/notify.c +++ b/src/notify.c @@ -1145,6 +1145,7 @@ raw_notify(dbref player, const char *msg) notify_anything(GOD, na_one, &player, NULL, NA_NOLISTEN, msg); } + /** Notify all connected players with the given flag(s). * If no flags are given, everyone is notified. If one flag list is given, * all connected players with some flag in that list are notified. @@ -1184,6 +1185,30 @@ flag_broadcast(const char *flag1, const char *flag2, const char *fmt, ...) } } +void WIN32_CDECL +level_broadcast(dbref minlevel, const char *fmt, ...) { + va_list args; + char tbuf1[BUFFER_LEN]; + DESC *d; + int ok; + + va_start(args, fmt); +#ifdef HAS_VSNPRINTF + (void) vsnprintf(tbuf1, sizeof tbuf1, fmt, args); +#else + (void) vsprintf(tbuf1, fmt, args); +#endif + va_end(args); + tbuf1[BUFFER_LEN - 1] = '\0'; + + DESC_ITER_CONN(d) { + if (GoodObject(d->player) && (minlevel == 0 || LEVEL(d->player) >= minlevel)) { + queue_string_eol(d, tbuf1); + process_output(d); + } + } +} + slab *text_block_slab = NULL; /**< Slab for 'struct text_block' allocations */ static struct text_block * -- 2.30.2