From cbf4f61f93bc092b0c9b74e847422c62fb10ea16 Mon Sep 17 00:00:00 2001 From: "Rob Swindell (on Windows)" <rob@synchro.net> Date: Wed, 9 Aug 2023 18:24:33 -0700 Subject: [PATCH] New MQTT topics that the terminal server will subscribe to for node changes <nelgin> can I push an intr instruction to a node with mqtt? node/#/set/status - set the node status value (to an integer) node/#/set/errors - set the node error counter (to an integer, e.g. "0") node/#/set/misc - set the node's miscellaneous attributes/flags value (hexadecimal values can be set by including "0x" prefix) The message (payload) doesn't matter for the following topics: node/#/set/lock - lock a node (no one but sysop can login) node/#/set/intr - interrupt a node (disconnect a user) node/#/set/down - down a node (not available for connections) node/#/set/rerun - rerun a node (reload config upon next connection) --- src/sbbs3/mqtt.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/sbbs3/mqtt.c b/src/sbbs3/mqtt.c index 3fbb3f3a37..15e14b82b0 100644 --- a/src/sbbs3/mqtt.c +++ b/src/sbbs3/mqtt.c @@ -25,6 +25,7 @@ #include "startup.h" #include "xpdatetime.h" #include "date_str.h" +#include "userdat.h" const char* server_type_desc(enum server_type type) { @@ -472,6 +473,36 @@ static void mqtt_message_received(struct mosquitto* mosq, void* cbdata, const st if(mqtt->startup->type == SERVER_TERM) { bbs_startup_t* bbs_startup = (bbs_startup_t*)mqtt->startup; + for(int i = bbs_startup->first_node; i <= bbs_startup->last_node; i++) { + if(strcmp(msg->topic, mqtt_topic(mqtt, TOPIC_BBS, topic, sizeof(topic), "node/%d/set/status", i)) == 0) { + set_node_status(mqtt->cfg, i, strtoul(msg->payload, NULL, 0)); + return; + } + if(strcmp(msg->topic, mqtt_topic(mqtt, TOPIC_BBS, topic, sizeof(topic), "node/%d/set/errors", i)) == 0) { + set_node_errors(mqtt->cfg, i, strtoul(msg->payload, NULL, 0)); + return; + } + if(strcmp(msg->topic, mqtt_topic(mqtt, TOPIC_BBS, topic, sizeof(topic), "node/%d/set/misc", i)) == 0) { + set_node_misc(mqtt->cfg, i, strtoul(msg->payload, NULL, 0)); + return; + } + if(strcmp(msg->topic, mqtt_topic(mqtt, TOPIC_BBS, topic, sizeof(topic), "node/%d/set/lock", i)) == 0) { + set_node_lock(mqtt->cfg, i, TRUE); + return; + } + if(strcmp(msg->topic, mqtt_topic(mqtt, TOPIC_BBS, topic, sizeof(topic), "node/%d/set/intr", i)) == 0) { + set_node_interrupt(mqtt->cfg, i, TRUE); + return; + } + if(strcmp(msg->topic, mqtt_topic(mqtt, TOPIC_BBS, topic, sizeof(topic), "node/%d/set/down", i)) == 0) { + set_node_down(mqtt->cfg, i, TRUE); + return; + } + if(strcmp(msg->topic, mqtt_topic(mqtt, TOPIC_BBS, topic, sizeof(topic), "node/%d/set/rerun", i)) == 0) { + set_node_rerun(mqtt->cfg, i, TRUE); + return; + } + } for(int i = bbs_startup->first_node; i <= bbs_startup->last_node; i++) { mqtt_topic(mqtt, TOPIC_BBS, topic, sizeof(topic), "node/%d/input", i); if(strcmp(msg->topic, topic) != 0) @@ -542,6 +573,7 @@ int mqtt_startup(struct mqtt* mqtt, scfg_t* cfg, struct startup* startup, const char str[128]; for(int i = bbs_startup->first_node; i <= bbs_startup->last_node; i++) { mqtt_subscribe(mqtt, TOPIC_BBS, str, sizeof(str), "node/%d/input", i); + mqtt_subscribe(mqtt, TOPIC_BBS, str, sizeof(str), "node/%d/set/#", i); } } mqtt_pub_noval(mqtt, TOPIC_SERVER, "recycle"); -- GitLab