From 32ed6077085aba501d27f34368b357a8d4b79366 Mon Sep 17 00:00:00 2001 From: Plex Date: Mon, 25 Oct 2021 20:57:13 +0200 Subject: mcping finished --- mcping.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'mcping.c') diff --git a/mcping.c b/mcping.c index c9372fa..e8adcf2 100644 --- a/mcping.c +++ b/mcping.c @@ -2,25 +2,16 @@ #include #include #include -#include -#include #include -#include -#include -#include +#include #include "mctypes.h" #include "mcnetwork.h" - - - int main(int argc, char *argv[]) { char *port_s, *address; unsigned short port; - size_t json_size; - int protocol_ver; - int p_flag = 0; + unsigned int protocol_ver, p_flag = 0; if (argc == 1) { printf ("Usage: mcping ADDRESS[:PORT]\nPings a Minecraft server using the PING protocol.\n\n -h\t\t\tdisplay this help and exit\n -p PROTOCOL NUMBER\tUses specified protocol number.\n"); @@ -56,10 +47,28 @@ int main(int argc, char *argv[]) connect_mc_server(s, address, port); send_handshake(s, protocol_ver, address, port, 1); - send_packet(s, 0x0, 0, NULL); // request packet (0x0 with no fields) + send_packet(s, 0x0, 0, NULL); // request packet (0x0 with no fields) + + packet response = recv_packet(s); +#ifdef _DEBUG + printf("length:\t%u\n", from_varint(response.length)); + printf("id:\t%d\n", from_varint(response.id)); + for (int i = 0; i < from_varint(response.length) - size_varint(response.id); ++i) { + printf("%02X ", ((unsigned char*) response.data)[i]); + } + printf("\n"); +#endif + string json = deserialize_string(&response.data); + +#ifdef _DEBUG + printf("json length:\t%u\n", from_varint(json.length)); +#endif + + for (int i = 0; i < from_varint(json.length); ++i) { + printf("%c", json.content[i]); + } + printf("\n"); - // json_size = from_varint(recv_varint(s)); - // printf("%lu\n", json_size); close(s); return 0; } -- cgit v1.2.3