summaryrefslogtreecommitdiff
path: root/src/core/entertain_config.c
blob: 7f1e35e7388487af10031b033017f46f07592350 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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;
}
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com