summaryrefslogtreecommitdiff
path: root/plugins/entertain/entertain.c
blob: 23f61b124e2659499326bec382e98303351e54ed (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * Entertain plugin — entertain.c
 * Feature plugin (not a transport): init / tick / on_command.
 * Chess is the first Entertain feature. Main / standalone Main only.
 */
#include "hybbx/plugin.h"
#include "hybbx/service.h"
#include "hybbx/session.h"
#include "hybbx/command.h"
#include "hybbx/log.h"
#include "entertain_chess.h"

#include <string.h>

static struct hybbx_service *g_service;

extern hybbx_result_t entertain_cmd_chess(struct hybbx_service *service,
                                          struct hybbx_session *session,
                                          const struct hybbx_parsed_command *cmd);

static int verb_is_chess(const char *verb)
{
    if (verb == NULL) {
        return 0;
    }
    return strcmp(verb, "chess") == 0 ||
           strcmp(verb, "play") == 0 ||
           strcmp(verb, "mv") == 0;
}

static hybbx_result_t entertain_init(struct hybbx_service *service)
{
    g_service = service;
    chess_init(CHESS_DEFAULT_MAX);
    hybbx_log_info("[entertain] plugin loaded — chess_max_games=%u",
                   (unsigned)CHESS_DEFAULT_MAX);
    return HYBBX_OK;
}

static void entertain_shutdown(void)
{
    chess_shutdown();
    g_service = NULL;
    hybbx_log_info("[entertain] plugin unloaded");
}

static void entertain_tick(struct hybbx_service *service)
{
    chess_tick(service);
}

static hybbx_result_t entertain_on_command(struct hybbx_service *service,
                                           struct hybbx_session *session,
                                           const struct hybbx_parsed_command *cmd)
{
    if (cmd == NULL || cmd->verb == NULL) {
        return HYBBX_ERR_NOT_FOUND;
    }

    /* Future: chess over mains_proxy mesh — stub only. */
    if (strcmp(cmd->verb, "proxychess") == 0) {
        if (session != NULL) {
            hybbx_session_write_line(session,
                "proxychess: not implemented yet (Main mesh stub).");
        }
        return HYBBX_OK;
    }

    if (verb_is_chess(cmd->verb)) {
        return entertain_cmd_chess(service, session, cmd);
    }

    return HYBBX_ERR_NOT_FOUND;
}

const hybbx_transport_plugin_t hybbx_plugin_entertain = {
    .name = "entertain",
    .kind = 0, /* feature plugin — not a wire transport */
    .version = 1,
    .init = entertain_init,
    .shutdown = entertain_shutdown,
    .start = NULL,
    .stop = NULL,
    .write = NULL,
    .tick = entertain_tick,
    .on_command = entertain_on_command,
};
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com