aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrumeet <yuuta@yuuta.moe>2022-07-29 11:55:40 -0700
committerTrumeet <yuuta@yuuta.moe>2022-07-29 11:55:40 -0700
commit41d27344c3b489466632bd2f1314fd69ff0a363c (patch)
tree4fbb1e118593da7b78813fbd9184d9c7a0c450d6
parentb897bfe9f99872c701924f3cce269e6a36ea5bb5 (diff)
downloadacron-41d27344c3b489466632bd2f1314fd69ff0a363c.tar
acron-41d27344c3b489466632bd2f1314fd69ff0a363c.tar.gz
acron-41d27344c3b489466632bd2f1314fd69ff0a363c.tar.bz2
acron-41d27344c3b489466632bd2f1314fd69ff0a363c.zip
fix(libacron): spec incompliance: player is optional in disconnect events
API:CHANGE
-rw-r--r--client/helloworld/main.c20
-rw-r--r--client/libacron/ids.c9
-rw-r--r--client/libacron/include/events.h2
-rw-r--r--client/libacron/private/serializer.c16
4 files changed, 30 insertions, 17 deletions
diff --git a/client/helloworld/main.c b/client/helloworld/main.c
index c112fcb..cba7e30 100644
--- a/client/helloworld/main.c
+++ b/client/helloworld/main.c
@@ -120,13 +120,17 @@ static void handle_event(const ac_event_t *event) {
}
case AC_EVENT_PLAYER_DISCONNECT: {
ac_event_player_disconnect_t *o = (ac_event_player_disconnect_t *) event;
- printf("Player '%s' disconnected at %s(%.2f, %.2f, %.2f): %s.\n",
- o->player.name,
- world_name(o->player.world),
- o->player.pos.x,
- o->player.pos.y,
- o->player.pos.z,
- o->reason);
+ if (!o->player) {
+ printf("Unknown player disconnected: %s.\n", o->reason);
+ } else {
+ printf("Player '%s' disconnected at %s(%.2f, %.2f, %.2f): %s.\n",
+ o->player->name,
+ world_name(o->player->world),
+ o->player->pos.x,
+ o->player->pos.y,
+ o->player->pos.z,
+ o->reason);
+ }
break;
}
case AC_EVENT_PLAYER_JOIN: {
@@ -367,4 +371,4 @@ int main(int argc, char **argv) {
mtx_destroy(&mtx_conn);
#endif
return r;
-} \ No newline at end of file
+}
diff --git a/client/libacron/ids.c b/client/libacron/ids.c
index 89fff9a..7af471d 100644
--- a/client/libacron/ids.c
+++ b/client/libacron/ids.c
@@ -20,8 +20,11 @@ int ac_object_free(ac_obj_t *obj) {
}
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->player) {
+ if (v->player->name) free(v->player->name);
+ if (v->player->uuid) free(v->player->uuid);
+ free(v->player);
+ }
if (v->reason) free(v->reason);
goto ok;
}
@@ -77,4 +80,4 @@ int ac_object_free(ac_obj_t *obj) {
free(obj);
return AC_E_OK;
};
-} \ No newline at end of file
+}
diff --git a/client/libacron/include/events.h b/client/libacron/include/events.h
index 93a5184..17ecd74 100644
--- a/client/libacron/include/events.h
+++ b/client/libacron/include/events.h
@@ -23,7 +23,7 @@ typedef struct ac_event_player_join {
#define AC_EVENT_PLAYER_DISCONNECT AC_ID(AC_TYPE_EVENT, 2 /* 0b0000010 */) /* 0b00000010 */
typedef struct ac_event_player_disconnect {
uint8_t type;
- ac_entity_t player;
+ ac_entity_t *player;
char *reason;
} ac_event_player_disconnect_t;
diff --git a/client/libacron/private/serializer.c b/client/libacron/private/serializer.c
index 9196305..d5171ba 100644
--- a/client/libacron/private/serializer.c
+++ b/client/libacron/private/serializer.c
@@ -269,14 +269,20 @@ static int deserialize_event(json_object *obj, const char *type_str, ac_event_t
}
disconnect->type = AC_EVENT_PLAYER_DISCONNECT;
- json_object *arg;
- if ((r = get_child(obj, "player", json_type_object, true, &arg))) {
+ json_object *arg = NULL;
+ if ((r = get_child(obj, "player", json_type_object, false, &arg))) {
ac_object_free((ac_obj_t *) disconnect);
goto fail;
}
- if ((r = deserialize_entity(arg, &disconnect->player))) {
- ac_object_free((ac_obj_t *) disconnect);
- goto fail;
+ if (arg) {
+ if ((r = SALLOC(ac_entity_t, &disconnect->player))) {
+ ac_object_free((ac_obj_t *) disconnect);
+ goto fail;
+ }
+ if ((r = deserialize_entity(arg, disconnect->player))) {
+ ac_object_free((ac_obj_t *) disconnect);
+ goto fail;
+ }
}
if ((r = get_child(obj, "reason", json_type_string, true, &arg))) {