From de777030b05e203e87ee43e719996dc047141522 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Fri, 12 Jun 2026 01:59:58 +0900 Subject: [PATCH] rcon: use correct packet type for auth responses --- src/rcon.c | 2 +- src/rcon.h | 5 +++-- test/test_rcon.c | 7 +++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/rcon.c b/src/rcon.c index 32092b6..bcbf64e 100644 --- a/src/rcon.c +++ b/src/rcon.c @@ -160,7 +160,7 @@ int rcon_authenticate(int sockfd, const char *password) { printf("received auth packet: id=%d, type=%d\n", response.id, response.type); - if (response.type != RCON_SERVERDATA_RESPONSE_VALUE) { + if (response.type != RCON_SERVERDATA_AUTH_RESPONSE) { fprintf(stderr, "authentication failed - unexpected initial packet type: %d\n", response.type); return -1; } diff --git a/src/rcon.h b/src/rcon.h index 3559f2b..ece946a 100644 --- a/src/rcon.h +++ b/src/rcon.h @@ -1,9 +1,10 @@ #include -#define RCON_SERVERDATA_AUTH 3 -#define RCON_SERVERDATA_AUTH_RESPONSE 2 #define RCON_SERVERDATA_EXECCOMMAND 2 +#define RCON_SERVERDATA_AUTH 3 + #define RCON_SERVERDATA_RESPONSE_VALUE 0 +#define RCON_SERVERDATA_AUTH_RESPONSE 2 typedef struct { // size of the remainder of the packet diff --git a/test/test_rcon.c b/test/test_rcon.c index cc299e7..9cfd627 100644 --- a/test/test_rcon.c +++ b/test/test_rcon.c @@ -162,7 +162,6 @@ static void test_authenticate_successful_flow(void **state) { const char *password = "hunter2"; - send_raw_packet(sockets.server, 1, RCON_SERVERDATA_RESPONSE_VALUE, ""); send_raw_packet(sockets.server, 1, RCON_SERVERDATA_AUTH_RESPONSE, ""); assert_int_equal(rcon_authenticate(sockets.client, password), 0); @@ -178,7 +177,7 @@ static void test_authenticate_invalid_password(void **state) { const char *password = "wrong-password"; - send_raw_packet(sockets.server, -1, RCON_SERVERDATA_RESPONSE_VALUE, ""); + send_raw_packet(sockets.server, -1, RCON_SERVERDATA_AUTH_RESPONSE, ""); assert_int_equal(rcon_authenticate(sockets.client, password), -1); receive_auth_response(sockets.server, password); @@ -193,7 +192,7 @@ static void test_authenticate_unexpected_packet_type(void **state) { const char *password = "hunter2"; - send_raw_packet(sockets.server, 1, RCON_SERVERDATA_EXECCOMMAND, ""); + send_raw_packet(sockets.server, 1, RCON_SERVERDATA_RESPONSE_VALUE, ""); assert_int_equal(rcon_authenticate(sockets.client, password), -1); receive_auth_response(sockets.server, password); @@ -208,7 +207,7 @@ static void test_authenticate_mismatched_response_id(void **state) { const char *password = "hunter2"; - send_raw_packet(sockets.server, 2, RCON_SERVERDATA_RESPONSE_VALUE, ""); + send_raw_packet(sockets.server, 2, RCON_SERVERDATA_AUTH_RESPONSE, ""); assert_int_equal(rcon_authenticate(sockets.client, password), -1); receive_auth_response(sockets.server, password);