summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/entertain_config.c65
-rw-r--r--src/core/instance.c18
-rw-r--r--src/core/networks.c15
-rw-r--r--src/core/service.c3
4 files changed, 77 insertions, 24 deletions
diff --git a/src/core/entertain_config.c b/src/core/entertain_config.c
new file mode 100644
index 0000000..7f1e35e
--- /dev/null
+++ b/src/core/entertain_config.c
@@ -0,0 +1,65 @@
+#include "hybbx/entertain_config.h"
+#include "hybbx/instance.h"
+#include "hybbx/log.h"
+#include "hybbx/util.h"
+
+#include <string.h>
+
+static hybbx_entertain_config_t g_entertain;
+static int g_entertain_ready;
+
+void hybbx_entertain_config_defaults(hybbx_entertain_config_t *cfg)
+{
+ if (cfg == NULL) {
+ return;
+ }
+
+ memset(cfg, 0, sizeof(*cfg));
+ cfg->enabled = 0;
+}
+
+void hybbx_entertain_config_apply(const hybbx_config_t *config)
+{
+ hybbx_instance_role_t role;
+ const char *legacy;
+
+ hybbx_entertain_config_defaults(&g_entertain);
+ g_entertain_ready = 1;
+
+ if (config != NULL) {
+ g_entertain.enabled = hybbx_config_get_bool(config, "entertain",
+ "enabled", 0);
+ /* Legacy: [networks] entertain= — prefer [entertain] enabled= */
+ legacy = hybbx_config_get(config, "networks", "entertain", NULL);
+ if (legacy != NULL && legacy[0] != '\0' &&
+ !hybbx_config_get(config, "entertain", "enabled", NULL)) {
+ g_entertain.enabled = hybbx_bool_is_true(legacy);
+ hybbx_log_warn("[entertain] legacy [networks] entertain= — "
+ "use [entertain] enabled=yes");
+ }
+ }
+
+ role = hybbx_instance_role();
+ if (g_entertain.enabled && role != HYBBX_INSTANCE_MAIN) {
+ hybbx_log_warn("[entertain] Main / standalone Main only — forcing off "
+ "(role=%s)",
+ hybbx_instance_role_name());
+ g_entertain.enabled = 0;
+ }
+
+ hybbx_log_info("[entertain] enabled=%s (chess built-in; Main/standalone only)",
+ hybbx_bool_to_string(g_entertain.enabled));
+}
+
+const hybbx_entertain_config_t *hybbx_entertain_config_get(void)
+{
+ if (!g_entertain_ready) {
+ hybbx_entertain_config_defaults(&g_entertain);
+ }
+ return &g_entertain;
+}
+
+int hybbx_entertain_enabled(void)
+{
+ return hybbx_entertain_config_get()->enabled;
+}
diff --git a/src/core/instance.c b/src/core/instance.c
index 0b9f717..1734c4f 100644
--- a/src/core/instance.c
+++ b/src/core/instance.c
@@ -160,7 +160,7 @@ hybbx_result_t hybbx_networks_enforce_instance(hybbx_networks_config_t *networks
hybbx_instance_binary_name());
hybbx_log_info("[instance] binary=%s role=%s standalone=yes user_bbx=%s "
"telnet=%s ssh=%s ax25=%s baycom=%s ardop=%s crdop=%s "
- "websocket=%s circuit=%s mains_proxy=%s entertain=%s",
+ "websocket=%s circuit=%s mains_proxy=%s",
hybbx_instance_binary_name(),
hybbx_instance_role_name(),
hybbx_instance_offers_user_bbx() ? "yes" : "no",
@@ -172,8 +172,7 @@ hybbx_result_t hybbx_networks_enforce_instance(hybbx_networks_config_t *networks
hybbx_bool_to_string(networks->crdop),
hybbx_bool_to_string(networks->websocket),
hybbx_bool_to_string(networks->circuit),
- hybbx_bool_to_string(networks->mains_proxy),
- hybbx_bool_to_string(networks->entertain));
+ hybbx_bool_to_string(networks->mains_proxy));
return HYBBX_OK;
}
@@ -218,10 +217,6 @@ hybbx_result_t hybbx_networks_enforce_instance(hybbx_networks_config_t *networks
break;
case HYBBX_INSTANCE_SECONDARY:
- if (networks->entertain) {
- hybbx_log_warn("[instance] hybbxsd: entertain Main-only — forcing off");
- networks->entertain = 0;
- }
if (networks->telnet) {
hybbx_log_warn("[instance] hybbxsd: no user telnet — forcing off");
networks->telnet = 0;
@@ -243,10 +238,6 @@ hybbx_result_t hybbx_networks_enforce_instance(hybbx_networks_config_t *networks
break;
case HYBBX_INSTANCE_PROXY:
- if (networks->entertain) {
- hybbx_log_warn("[instance] hybbxpd: entertain Main-only — forcing off");
- networks->entertain = 0;
- }
if (networks->websocket) {
hybbx_log_warn("[instance] hybbxpd: WebSocket forbidden — forcing off");
networks->websocket = 0;
@@ -268,7 +259,7 @@ hybbx_result_t hybbx_networks_enforce_instance(hybbx_networks_config_t *networks
hybbx_log_info("[instance] binary=%s role=%s user_bbx=%s "
"telnet=%s ssh=%s ax25=%s baycom=%s ardop=%s crdop=%s "
- "websocket=%s circuit=%s mains_proxy=%s entertain=%s",
+ "websocket=%s circuit=%s mains_proxy=%s",
hybbx_instance_binary_name(),
hybbx_instance_role_name(),
hybbx_instance_offers_user_bbx() ? "yes" : "no",
@@ -280,8 +271,7 @@ hybbx_result_t hybbx_networks_enforce_instance(hybbx_networks_config_t *networks
hybbx_bool_to_string(networks->crdop),
hybbx_bool_to_string(networks->websocket),
hybbx_bool_to_string(networks->circuit),
- hybbx_bool_to_string(networks->mains_proxy),
- hybbx_bool_to_string(networks->entertain));
+ hybbx_bool_to_string(networks->mains_proxy));
return HYBBX_OK;
}
diff --git a/src/core/networks.c b/src/core/networks.c
index f61479e..dfc1370 100644
--- a/src/core/networks.c
+++ b/src/core/networks.c
@@ -1,4 +1,5 @@
#include "hybbx/networks.h"
+#include "hybbx/entertain_config.h"
#include "hybbx/instance.h"
#include "hybbx/config.h"
#include "hybbx/util.h"
@@ -54,7 +55,6 @@ void hybbx_networks_config_defaults(hybbx_networks_config_t *networks)
networks->websocket = 0;
networks->circuit = 1;
networks->mains_proxy = 0;
- networks->entertain = 0;
}
void hybbx_networks_config_apply(hybbx_networks_config_t *networks,
@@ -107,13 +107,8 @@ void hybbx_networks_config_apply(hybbx_networks_config_t *networks,
"mains_proxy", 0);
}
- if (networks_has_key(config, "entertain")) {
- networks->entertain = hybbx_config_get_bool(config, "networks",
- "entertain", 0);
- }
-
hybbx_log_info("[networks] telnet=%s ssh=%s ax25=%s baycom=%s ardop=%s "
- "crdop=%s websocket=%s circuit=%s mains_proxy=%s entertain=%s",
+ "crdop=%s websocket=%s circuit=%s mains_proxy=%s",
hybbx_bool_to_string(networks->telnet),
hybbx_bool_to_string(networks->ssh),
hybbx_bool_to_string(networks->ax25),
@@ -122,8 +117,7 @@ void hybbx_networks_config_apply(hybbx_networks_config_t *networks,
hybbx_bool_to_string(networks->crdop),
hybbx_bool_to_string(networks->websocket),
hybbx_bool_to_string(networks->circuit),
- hybbx_bool_to_string(networks->mains_proxy),
- hybbx_bool_to_string(networks->entertain));
+ hybbx_bool_to_string(networks->mains_proxy));
}
int hybbx_networks_is_static_transport(const char *plugin_name)
@@ -195,7 +189,8 @@ int hybbx_networks_transport_wanted(const char *plugin_name,
}
if (str_ieq(plugin_name, "entertain")) {
- return networks->entertain;
+ (void)networks;
+ return hybbx_entertain_enabled();
}
return 0;
diff --git a/src/core/service.c b/src/core/service.c
index dda6311..8d0233e 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -27,6 +27,7 @@ void hybbx_mains_proxy_plugin_tick(void);
#include "hybbx/instance.h"
#include "hybbx/log.h"
#include "hybbx/monitor.h"
+#include "hybbx/entertain_config.h"
#include <errno.h>
#include "hybbx/security.h"
#include "hybbx/security_ban.h"
@@ -1300,6 +1301,8 @@ hybbx_result_t hybbx_service_apply_config(hybbx_service_t *service,
return rc;
}
+ hybbx_entertain_config_apply(config);
+
rc = service_apply_circuit(svc, config);
if (rc != HYBBX_OK) {
return rc;
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com