Skip to content

Commit

Permalink
node.c: Allow new node connections to be toggled on/off.
Browse files Browse the repository at this point in the history
Add the "nodeconnects" CLI command, which allows new node
connections to be enabled/disabled. Useful if the sysop
wants to temporarily disable new node connections.
  • Loading branch information
InterLinked1 committed Jan 25, 2025
1 parent 02435a1 commit d4768b6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bbs/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#define DEFAULT_MAX_NODES 64

static int shutting_down = 0;
static int new_node_connects = 1; /* Whether new node connections are allowed */

static RWLIST_HEAD_STATIC(nodes, bbs_node);

Expand Down Expand Up @@ -276,6 +277,9 @@ struct bbs_node *__bbs_node_request(int fd, const char *protname, struct sockadd
* but before I/O modules are unloaded, bail now. */
bbs_warning("Declining node allocation due to active shutdown\n");
return NULL;
} else if (!new_node_connects) {
bbs_notice("Declining node allocation since new connections are currently disabled\n");
return NULL;
}

/* We want to allocate a node with the smallest node number available.
Expand Down Expand Up @@ -986,6 +990,14 @@ static int cli_kickall(struct bbs_cli_args *a)
return bbs_node_shutdown_all(0);
}

static int cli_nodeconnects(struct bbs_cli_args *a)
{
int enabled = !bbs_falsy_value(a->argv[1]); /* Default to true if input is unrecognized */
bbs_dprintf(a->fdout, "New node connections were previously %s and are now %s\n", new_node_connects ? "enabled" : "disabled", enabled ? "enabled" : "disabled");
new_node_connects = enabled;
return 0;
}

static int node_info(int fd, unsigned int nodenum)
{
char elapsed[24];
Expand Down Expand Up @@ -2368,6 +2380,7 @@ static struct bbs_cli_entry cli_commands_nodes[] = {
BBS_CLI_COMMAND(cli_interrupt, "interrupt", 2, "Interrupt specified node", "interrupt <nodenum>"),
BBS_CLI_COMMAND(cli_kick, "kick", 2, "Kick specified node", "kick <nodenum>"),
BBS_CLI_COMMAND(cli_kickall, "kickall", 1, "Kick all nodes", NULL),
BBS_CLI_COMMAND(cli_nodeconnects, "nodeconnects", 2, "Enable or disable node connects", "nodeconnects <enabled|disabled>"),
BBS_CLI_COMMAND(cli_spy, "spy", 2, "Spy on specified node (^C to stop)", "spy <nodenum>"),
BBS_CLI_COMMAND(cli_node_set_speed, "speed", 3, "Set emulated speed of specified node (0 = unthrottled)", "speed <nodenum> <bps>"),
/* User commands */
Expand Down
18 changes: 18 additions & 0 deletions bbs/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ int __attribute__ ((format (gnu_printf, 2, 3))) dyn_str_append_fmt(struct dyn_st
return len;
}

int bbs_truthy_value(const char *s)
{
if (strlen_zero(s)) {
return 0;
}

return !strcasecmp(s, "1") || !strcasecmp(s, "yes") || !strcasecmp(s, "y") || !strcasecmp(s, "true") || !strcasecmp(s, "t") || !strcasecmp(s, "on") || !strcasecmp(s, "enabled");
}

int bbs_falsy_value(const char *s)
{
if (strlen_zero(s)) {
return 0;
}

return !strcasecmp(s, "0") || !strcasecmp(s, "no") || !strcasecmp(s, "n") || !strcasecmp(s, "false") || !strcasecmp(s, "f") || !strcasecmp(s, "off") || !strcasecmp(s, "disabled");
}

int bbs_parse_url(struct bbs_url *url, char *restrict s)
{
char *tmp;
Expand Down
6 changes: 6 additions & 0 deletions include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ int __attribute__ ((format (gnu_printf, 2, 3))) dyn_str_append_fmt(struct dyn_st
*/
#define dyn_str_len(dynstr) (dynstr->used)

/*! \brief Whether s is a "truthy" value */
int bbs_truthy_value(const char *s);

/*! \brief Whether s is a "falsy" value */
int bbs_falsy_value(const char *s);

struct bbs_url {
const char *prot;
const char *user;
Expand Down

0 comments on commit d4768b6

Please sign in to comment.