From 973ae757342b91e3e6aafd07e0c0a24af84aad98 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Tue, 23 Jun 2020 15:46:23 +0200 Subject: Add skeleton of new mcserverctl binary --- config-parser.c | 2 -- mcserverctl.c | 41 +++++++++++++++++++++++++++++++++++++++++ meson.build | 10 ++++++++++ rcon-protocol.h | 3 +++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 mcserverctl.c 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 #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 +#include +#include +#include + +#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 +#include + enum rcon_packet_type { RCON_PACKET_LOGIN = 3, RCON_PACKET_LOGIN_OK = 2, -- cgit v1.2.3