diff --git a/src/bbs.c b/src/bbs.c index f14d671..b9a9f0f 100644 --- a/src/bbs.c +++ b/src/bbs.c @@ -882,24 +882,6 @@ void runbbs_real(int socket, char *ip, int ssh) { int tries; int fno; - // initialize mqtt - if (conf.broadcast_enable && conf.broadcast_address != NULL && conf.broadcast_port != 0) { - mosquitto_lib_init(); - mosq = mosquitto_new(NULL, 1, NULL); - if (conf.broadcast_user != NULL && conf.broadcast_pass != NULL) { - mosquitto_username_pw_set(mosq, conf.broadcast_user, conf.broadcast_pass); - } - if(mosquitto_connect(mosq, conf.broadcast_address, conf.broadcast_port, 60)){ - dolog("Unable to connect to MQTT server."); - conf.broadcast_enable = 0; - } else { - if (mosquitto_loop_start(mosq) != MOSQ_ERR_SUCCESS) { - dolog("Unable to start MQTT loop."); - conf.broadcast_enable = 0; - } - } - } - atexit(exit_bbs); usertimeout = 10; @@ -977,7 +959,25 @@ void runbbs_real(int socket, char *ip, int ssh) { } exit(1); } - + + // initialize mqtt + if (conf.broadcast_enable && conf.broadcast_address != NULL && conf.broadcast_port != 0) { + mosquitto_lib_init(); + mosq = mosquitto_new(NULL, 1, NULL); + if (conf.broadcast_user != NULL && conf.broadcast_pass != NULL) { + mosquitto_username_pw_set(mosq, conf.broadcast_user, conf.broadcast_pass); + } + if(mosquitto_connect(mosq, conf.broadcast_address, conf.broadcast_port, 60)){ + dolog("Unable to connect to MQTT server."); + conf.broadcast_enable = 0; + } else { + if (mosquitto_loop_start(mosq) != MOSQ_ERR_SUCCESS) { + dolog("Unable to start MQTT loop."); + conf.broadcast_enable = 0; + } + } + } + broadcast("USER: unknown; NODE:%d; STATUS: Logging in.", mynode); dolog("Incoming %s connection on node %d", (ssh ? "SSH" : "Telnet"), mynode);