summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-23 15:46:23 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-23 15:46:23 +0200
commit973ae757342b91e3e6aafd07e0c0a24af84aad98 (patch)
tree0b3b108d741d81f3971f1a7426c531ed37d1fbbb
parent7a8bee84bd1f41bf349f9077617e20c3560b7c62 (diff)
Add skeleton of new mcserverctl binary
-rw-r--r--config-parser.c2
-rw-r--r--mcserverctl.c41
-rw-r--r--meson.build10
-rw-r--r--rcon-protocol.h3
4 files changed, 54 insertions, 2 deletions
diff --git a/config-parser.c b/config-parser.c
index 0d38789..ffed7f1 100644
--- a/config-parser.c
+++ b/config-parser.c
@@ -9,9 +9,7 @@
#include <inttypes.h>
#include "main.h"
-#include "uring.h"
#include "config-parser.h"
-#include "server.h"
static void
eat_whitespace_and_comments(char **pos)
diff --git a/mcserverctl.c b/mcserverctl.c
new file mode 100644
index 0000000..8a799a2
--- /dev/null
+++ b/mcserverctl.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <inttypes.h>
+
+#include "rcon-protocol.h"
+
+
+int
+main(int argc, char **argv)
+{
+ char buf[4096];
+ size_t len;
+ int32_t id, type;
+ const char *msg, *error;
+
+ fprintf(stderr, "Started\n");
+
+ if (!rcon_protocol_create_packet(buf, sizeof(buf), &len,
+ 1, RCON_PACKET_LOGIN,
+ "test")) {
+ fprintf(stderr, "Failed to create packet\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (!rcon_protocol_packet_complete(buf, len)) {
+ fprintf(stderr, "Packet not complete\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (!rcon_protocol_read_packet(buf, len, &id, &type, &msg, &error)) {
+ fprintf(stderr, "Packet parsing failed: %s\n", error);
+ exit(EXIT_FAILURE);
+ }
+
+ fprintf(stderr, "Packet - id: %" PRIi32 ", type: %" PRIi32 ", msg: %s\n",
+ id, type, msg);
+
+ exit(EXIT_SUCCESS);
+}
+
diff --git a/meson.build b/meson.build
index 3d82301..eb446fe 100644
--- a/meson.build
+++ b/meson.build
@@ -50,6 +50,11 @@ mcproxy_sources = [
'utils.c'
]
+mcserverctl_sources = [
+ 'mcserverctl.c',
+ 'rcon-protocol.c',
+]
+
executable('mcproxy',
mcproxy_sources,
link_args: [ '-lanl' ],
@@ -62,3 +67,8 @@ executable('mcproxy',
],
)
+executable('mcserverctl',
+ mcserverctl_sources,
+ include_directories : configuration_inc,
+)
+
diff --git a/rcon-protocol.h b/rcon-protocol.h
index fd83d79..35997c4 100644
--- a/rcon-protocol.h
+++ b/rcon-protocol.h
@@ -1,6 +1,9 @@
#ifndef foorconprotocolhfoo
#define foorconprotocolhfoo
+#include <stdbool.h>
+#include <stdint.h>
+
enum rcon_packet_type {
RCON_PACKET_LOGIN = 3,
RCON_PACKET_LOGIN_OK = 2,