diff options
author | Plex <thinkplex@riseup.net> | 2021-10-25 20:57:13 +0200 |
---|---|---|
committer | Plex <thinkplex@riseup.net> | 2021-10-25 20:57:13 +0200 |
commit | 32ed6077085aba501d27f34368b357a8d4b79366 (patch) | |
tree | 56045e9090ed770eabb1e33c6e46e19fda310457 /mcping.c | |
parent | d23f7f0aaa97103670e229abd402ad66a6e703de (diff) |
mcping finished
Diffstat (limited to 'mcping.c')
-rw-r--r-- | mcping.c | 37 |
1 files changed, 23 insertions, 14 deletions
@@ -2,25 +2,16 @@ #include <getopt.h> #include <stdlib.h> #include <stdio.h> -#include <unistd.h> -#include <sys/types.h> #include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#include <arpa/inet.h> +#include <unistd.h> #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; } |