aboutsummaryrefslogtreecommitdiff
path: root/client/libacron/ids.c
blob: 89fff9ab1fcf529bc43f5f5ce9a5b7a8492be1e7 (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
/*
 * Created by yuuta on 7/19/22.
 */

#include "log.h"
#include "common.h"
#include "libac.h"

#include <stdlib.h>

int ac_object_free(ac_obj_t *obj) {
    switch (obj->type & 192 /* 0b11000000 */) {
        case AC_TYPE_EVENT: {
            switch (obj->type) {
                case AC_EVENT_PLAYER_JOIN: {
                    ac_event_player_join_t *v = (ac_event_player_join_t *) obj;
                    if (v->player.name) free(v->player.name);
                    if (v->player.uuid) free(v->player.uuid);
                    goto ok;
                }
                case AC_EVENT_PLAYER_DISCONNECT: {
                    ac_event_player_disconnect_t *v = (ac_event_player_disconnect_t *) obj;
                    if (v->player.name) free(v->player.name);
                    if (v->player.uuid) free(v->player.uuid);
                    if (v->reason) free(v->reason);
                    goto ok;
                }
                case AC_EVENT_ENTITY_DEATH: {
                    ac_event_entity_death_t *v = (ac_event_entity_death_t *) obj;
                    if (v->entity.name) free(v->entity.name);
                    if (v->entity.uuid) free(v->entity.uuid);
                    if (v->message) free(v->message);
                    goto ok;
                }
                case AC_EVENT_PLAYER_MESSAGE: {
                    ac_event_player_message_t *v = (ac_event_player_message_t *) obj;
                    if (v->player.name) free(v->player.name);
                    if (v->player.uuid) free(v->player.uuid);
                    if (v->text) free(v->text);
                    goto ok;
                }
                case AC_EVENT_LAGGING: {
                    goto ok;
                }
            }
        }
        case AC_TYPE_REQUEST:
            /* Request objects are user-allocated. Do not free them and report an error. */
            break;
        case AC_TYPE_RESPONSE: {
            switch (obj->type) {
                case AC_RESPONSE_CMD_RESULT: {
                    goto ok;
                }
                case AC_RESPONSE_CMD_OUT: {
                    ac_response_cmd_out_t *v = (ac_response_cmd_out_t *) obj;
                    if (v->sender) free(v->sender);
                    if (v->out) free(v->out);
                    goto ok;
                }
                case AC_RESPONSE_ERROR: {
                    ac_response_error_t *v = (ac_response_error_t *) obj;
                    if (v->message) free(v->message);
                    goto ok;
                }
                case AC_RESPONSE_OK: {
                    goto ok;
                }
            }
            break;
        }
    }
    LOGE("Invalid type passed to ac_obj_free function.");
    return AC_E_INVALID_REQUEST;
    ok:
    {
        free(obj);
        return AC_E_OK;
    };
}