From 3a0825c6a8d7dc03e79e7619503fefbf344e791e Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Thu, 15 Aug 2019 05:36:40 +0000 Subject: [PATCH] Created sbbs_t::count_nodes() which just returns the number of "in-use" nodes, optionally including the current (your) node. New @-codes: "ANODES" (active-nodes count), aliases: "ANODE" and "AN" "ONODES" (other-active-nodes count), aliases: "ONODE" and "ON" Make "NN" an alias for "NODE" and "TN" and alias for "TNODE". Add "TNODES" alias for "TNODE" as well, for symmetry. --- src/sbbs3/atcodes.cpp | 13 ++++++++++--- src/sbbs3/getnode.cpp | 17 +++++++++++++++++ src/sbbs3/sbbs.h | 1 + 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/sbbs3/atcodes.cpp b/src/sbbs3/atcodes.cpp index 878f7520ef..74d5a9daea 100644 --- a/src/sbbs3/atcodes.cpp +++ b/src/sbbs3/atcodes.cpp @@ -321,15 +321,22 @@ const char* sbbs_t::atcode(char* sp, char* str, size_t maxlen, long* pmode) if(!strcmp(sp,"LOCATION")) return(cfg.sys_location); - if(!strcmp(sp,"NODE")) { + if(strcmp(sp,"NODE") == 0 || strcmp(sp,"NN") == 0) { safe_snprintf(str,maxlen,"%u",cfg.node_num); return(str); } - - if(!strcmp(sp,"TNODE")) { + if(strcmp(sp, "TNODES") == 0 || strcmp(sp, "TNODE") == 0 || strcmp(sp, "TN") == 0) { safe_snprintf(str,maxlen,"%u",cfg.sys_nodes); return(str); } + if(strcmp(sp, "ANODES") == 0 || strcmp(sp, "ANODE") == 0 || strcmp(sp, "AN") == 0) { + safe_snprintf(str, maxlen, "%u", count_nodes(/* self: */true)); + return str; + } + if(strcmp(sp, "ONODES") == 0 || strcmp(sp, "ONODE") == 0 || strcmp(sp, "ON") == 0) { + safe_snprintf(str, maxlen, "%u", count_nodes(/* self: */false)); + return str; + } if(strcmp(sp, "PAGER") == 0) return (thisnode.misc&NODE_POFF) ? text[Off] : text[On]; diff --git a/src/sbbs3/getnode.cpp b/src/sbbs3/getnode.cpp index c09096b1d5..dff1d6ff23 100644 --- a/src/sbbs3/getnode.cpp +++ b/src/sbbs3/getnode.cpp @@ -661,3 +661,20 @@ void sbbs_t::printnodedat(uint number, node_t* node) attr(LIGHTGRAY); CRLF; } + +uint sbbs_t::count_nodes(bool self) +{ + uint count = 0; + + for(int i=1; i<=cfg.sys_nodes && i<=cfg.sys_lastnode; i++) { + node_t node; + if(getnodedat(i, &node, false) != 0) + continue; + if(!self && i==cfg.node_num) + continue; + if(node.status != NODE_INUSE) + continue; + count++; + } + return count; +} diff --git a/src/sbbs3/sbbs.h b/src/sbbs3/sbbs.h index d5c30254f5..72549d9c60 100644 --- a/src/sbbs3/sbbs.h +++ b/src/sbbs3/sbbs.h @@ -819,6 +819,7 @@ public: void nodesync(bool clearline = false); user_t nodesync_user; bool nodesync_inside; + uint count_nodes(bool self = true); /* putnode.cpp */ int putnodedat(uint number, node_t * node); -- GitLab