aboutsummaryrefslogtreecommitdiff
path: root/client/libacron/include
diff options
context:
space:
mode:
authorTrumeet <yuuta@yuuta.moe>2022-07-20 18:12:22 -0700
committerTrumeet <yuuta@yuuta.moe>2022-07-20 18:12:22 -0700
commitb4afa06e383325f4a0c751a64ca896d769db07a8 (patch)
tree7647fdd73d4f487de778c27aea99bf890458b647 /client/libacron/include
parentda14a17298c67d83e6da4732f47304954acc26fc (diff)
downloadacron-b4afa06e383325f4a0c751a64ca896d769db07a8.tar
acron-b4afa06e383325f4a0c751a64ca896d769db07a8.tar.gz
acron-b4afa06e383325f4a0c751a64ca896d769db07a8.tar.bz2
acron-b4afa06e383325f4a0c751a64ca896d769db07a8.zip
libac: First Commit
Diffstat (limited to 'client/libacron/include')
-rw-r--r--client/libacron/include/common.h64
-rw-r--r--client/libacron/include/events.h51
-rw-r--r--client/libacron/include/ids.h26
-rw-r--r--client/libacron/include/libac.h34
-rw-r--r--client/libacron/include/net.h29
-rw-r--r--client/libacron/include/requests.h71
6 files changed, 275 insertions, 0 deletions
diff --git a/client/libacron/include/common.h b/client/libacron/include/common.h
new file mode 100644
index 0000000..89738c4
--- /dev/null
+++ b/client/libacron/include/common.h
@@ -0,0 +1,64 @@
+/*
+ * Created by yuuta on 7/13/22.
+ */
+
+#ifndef LIBAC_COMMON_H
+#define LIBAC_COMMON_H
+
+/* Library errors */
+/* OK */
+#define AC_E_OK 0
+/* The library is not initialized on that thread. */
+#define AC_E_NOT_INITIALIZED 1
+/* ac_init(): The library is already initialized on that thread. */
+#define AC_E_ALREADY_INITIALIZED 2
+/* Cannot allocate memory. */
+#define AC_E_MEMORY_ALLOCATION 3
+/* Library internal error. */
+#define AC_E_INTERNAL 4
+/* The server returns an invalid response. */
+#define AC_E_INVALID_RESPONSE 5
+/* The request is invalid. */
+#define AC_E_INVALID_REQUEST 6
+/* Network error */
+#define AC_E_NET 7
+
+/* Remote errors */
+#define AC_ER_BAD_REQUEST 400
+#define AC_ER_NOT_AUTHORIZED 401
+#define AC_ER_FORBIDDEN 403
+#define AC_ER_INTERNAL_ERROR 500
+
+/* General Structs */
+enum ac_world {
+ overworld,
+ nether,
+ end
+};
+
+typedef struct ac_vec3d {
+ double x;
+ double y;
+ double z;
+} ac_vec3d_t;
+
+typedef struct ac_vec2f {
+ double x;
+ double y;
+} ac_vec2f_t;
+
+typedef struct ac_entity {
+ char *name;
+ char *uuid;
+ ac_vec3d_t pos;
+ enum ac_world world;
+} ac_entity_t;
+
+typedef struct ac_config {
+ enum ac_world *world;
+ ac_vec3d_t *pos;
+ ac_vec2f_t *rot;
+ char *name;
+} ac_config_t;
+
+#endif /* LIBAC_COMMON_H */
diff --git a/client/libacron/include/events.h b/client/libacron/include/events.h
new file mode 100644
index 0000000..93a5184
--- /dev/null
+++ b/client/libacron/include/events.h
@@ -0,0 +1,51 @@
+/*
+ * Created by yuuta on 7/13/22.
+ */
+
+#ifndef LIBAC_EVENTS_H
+#define LIBAC_EVENTS_H
+
+#include "common.h"
+#include "ids.h"
+#include <stdint.h>
+
+/* Events */
+typedef struct ac_event {
+ uint8_t type;
+} ac_event_t;
+
+#define AC_EVENT_PLAYER_JOIN AC_ID(AC_TYPE_EVENT, 1 /* 0b0000001 */) /* 0b00000001 */
+typedef struct ac_event_player_join {
+ uint8_t type;
+ ac_entity_t player;
+} ac_event_player_join_t;
+
+#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;
+ char *reason;
+} ac_event_player_disconnect_t;
+
+#define AC_EVENT_ENTITY_DEATH AC_ID(AC_TYPE_EVENT, 3 /* 0b00000011 */) /* 0b00000011 */
+typedef struct ac_event_entity_death {
+ uint8_t type;
+ ac_entity_t entity;
+ char *message;
+} ac_event_entity_death_t;
+
+#define AC_EVENT_PLAYER_MESSAGE AC_ID(AC_TYPE_EVENT, 4 /* 0b00000100 */) /* 0b00000100 */
+typedef struct ac_event_player_message {
+ uint8_t type;
+ ac_entity_t player;
+ char *text;
+} ac_event_player_message_t;
+
+#define AC_EVENT_LAGGING AC_ID(AC_TYPE_EVENT, 5 /* 0b00000101 */) /* 0b00000101 */
+typedef struct ac_event_lagging {
+ uint8_t type;
+ int64_t ms;
+ int64_t ticks;
+} ac_event_lagging_t;
+
+#endif /* LIBAC_EVENTS_H */
diff --git a/client/libacron/include/ids.h b/client/libacron/include/ids.h
new file mode 100644
index 0000000..86fde47
--- /dev/null
+++ b/client/libacron/include/ids.h
@@ -0,0 +1,26 @@
+/*
+ * Created by yuuta on 7/19/22.
+ */
+
+#ifndef LIBAC_IDS_H
+#define LIBAC_IDS_H
+
+#define AC_TYPE_EVENT 0 /* 0b00000000 */
+#define AC_TYPE_REQUEST 64 /* 0b01000000 */
+#define AC_TYPE_RESPONSE 128 /* 0b10000000 */
+
+#define AC_ID(type, num) type + num
+
+#define AC_IS_EVENT(type) (type & 192) == AC_TYPE_EVENT
+#define AC_IS_REQUEST(type) (type & 192) == AC_TYPE_REQUEST
+#define AC_IS_RESPONSE(type) (type & 192) == AC_TYPE_RESPONSE
+
+#include <stdint.h>
+
+typedef struct ac_obj {
+ uint8_t type;
+} ac_obj_t;
+
+int ac_object_free(ac_obj_t *obj);
+
+#endif /* LIBAC_IDS_H */
diff --git a/client/libacron/include/libac.h b/client/libacron/include/libac.h
new file mode 100644
index 0000000..80734dc
--- /dev/null
+++ b/client/libacron/include/libac.h
@@ -0,0 +1,34 @@
+/*
+ * Created by yuuta on 7/13/22.
+ */
+
+#ifndef LIBAC_LIBAC_H
+#define LIBAC_LIBAC_H
+
+#include "common.h"
+#include "events.h"
+#include "net.h"
+#include "requests.h"
+#include "ids.h"
+
+#include <json-c/json_tokener.h>
+#include <stdio.h>
+
+typedef struct libac_config {
+ FILE *out;
+ json_tokener *tok;
+} libac_config_t;
+
+/**
+ * Initialize libac for the calling thread.
+ * @return 0 on success.
+ */
+int ac_init(const libac_config_t *config);
+
+/**
+ * Destroy libac configuration for the calling thread.
+ * @return 0 on success.
+ */
+int ac_free(void);
+
+#endif /* LIBAC_LIBAC_H */
diff --git a/client/libacron/include/net.h b/client/libacron/include/net.h
new file mode 100644
index 0000000..5b10470
--- /dev/null
+++ b/client/libacron/include/net.h
@@ -0,0 +1,29 @@
+/*
+ * Created by yuuta on 7/13/22.
+ */
+
+#ifndef LIBAC_NET_H
+#define LIBAC_NET_H
+
+#include "common.h"
+#include "events.h"
+#include "requests.h"
+
+/* Connection */
+
+typedef struct ac_connection_parameters {
+ /**
+ * ws://host:port/ws?id=id&token=token
+ * Currently wss is not supported.
+ * Port must be supplied, or libac will connect to port zero.
+ */
+ char *url;
+} ac_connection_parameters_t;
+
+int ac_connect(ac_connection_parameters_t parameters, void **out);
+
+int ac_disconnect(void *connection);
+
+int ac_receive(void *connection, ac_obj_t **response);
+
+#endif /* LIBAC_NET_H */
diff --git a/client/libacron/include/requests.h b/client/libacron/include/requests.h
new file mode 100644
index 0000000..40742e0
--- /dev/null
+++ b/client/libacron/include/requests.h
@@ -0,0 +1,71 @@
+/*
+ * Created by yuuta on 7/13/22.
+ */
+
+#ifndef LIBAC_REQUESTS_H
+#define LIBAC_REQUESTS_H
+
+#include "common.h"
+#include "ids.h"
+#include <stdbool.h>
+
+/* Responses */
+typedef struct ac_response {
+ uint8_t type;
+ int id;
+} ac_response_t;
+
+#define AC_RESPONSE_ERROR AC_ID(AC_TYPE_RESPONSE, 1 /* 0b00000001 */) /* 0b10000001 */
+typedef struct ac_response_error {
+ uint8_t type;
+ int id;
+ int code;
+ char *message;
+} ac_response_error_t;
+
+#define AC_RESPONSE_OK AC_ID(AC_TYPE_RESPONSE, 2 /* 0b00000010 */) /* 0b10000010 */
+typedef struct ac_response_ok {
+ uint8_t type;
+ int id;
+} ac_response_ok_t;
+
+#define AC_RESPONSE_CMD_OUT AC_ID(AC_TYPE_RESPONSE, 3 /* 0b00000011 */) /* 0b10000011 */
+typedef struct ac_response_cmd_out {
+ uint8_t type;
+ int id;
+ char *sender;
+ char *out;
+} ac_response_cmd_out_t;
+
+#define AC_RESPONSE_CMD_RESULT AC_ID(AC_TYPE_RESPONSE, 4 /* 0b00000100 */) /* 0b10000100 */
+typedef struct ac_response_cmd_result {
+ uint8_t type;
+ int id;
+ int result;
+ bool success;
+} ac_response_cmd_result_t;
+
+/* Requests */
+typedef struct ac_request {
+ uint8_t type;
+ int id;
+} ac_request_t;
+
+#define AC_REQUEST_CMD AC_ID(AC_TYPE_REQUEST, 1 /* 0b00000001 */) /* 0b01000001 */
+typedef struct ac_request_cmd {
+ uint8_t type;
+ int id;
+ ac_config_t *config;
+ char *cmd;
+} ac_request_cmd_t;
+
+#define AC_REQUEST_SET_CONFIG AC_ID(AC_TYPE_REQUEST, 2 /* 0b00000010 */) /* 0b01000010 */
+typedef struct ac_request_set_config {
+ uint8_t type;
+ int id;
+ ac_config_t config;
+} ac_request_set_config_t;
+
+int ac_request(void *connection, const ac_request_t *request);
+
+#endif /* LIBAC_REQUESTS_H */