From 7e728d971b95f115c7e9c2def21815034d9bde54 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Wed, 1 Jul 2020 21:29:06 +0200 Subject: Reduce some rcon duplication by using a common function --- minecproxy/server-rcon.c | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) (limited to 'minecproxy') diff --git a/minecproxy/server-rcon.c b/minecproxy/server-rcon.c index 1f3acfa..4c9da48 100644 --- a/minecproxy/server-rcon.c +++ b/minecproxy/server-rcon.c @@ -55,7 +55,7 @@ static void rcon_stop_reply(struct uring_task *task, int res) struct server *server = container_of(task, struct server, rcon_task); int32_t id; int32_t type; - const char *msg; + const char *msg, *error; assert_return(task); assert_task_alive(DBG_RCON, task); @@ -63,19 +63,13 @@ static void rcon_stop_reply(struct uring_task *task, int res) if (!rcon_check_reply(task, res, &id, &type, &msg)) return; - if (id != 2) { - error("rcon(%s): stop cmd failed, reply id (%" PRIi32 ")", - server->name, id); - goto out; - } else if (type != RCON_PACKET_RESPONSE) { - error("rcon(%s): stop cmd failed, reply type (%" PRIi32 ")", - server->name, type); - goto out; - } - - verbose("rcon(%s): stop command sent, reply: %s", server->name, msg); + if (!rcon_protocol_verify_response(2, id, RCON_PACKET_COMMAND, type, + &error)) + error("rcon(%s): stop cmd failed - %s", server->name, error); + else + verbose("rcon(%s): stop command sent, reply: %s", + server->name, msg); -out: uring_task_close_fd(task); } @@ -102,7 +96,7 @@ static void rcon_login_reply(struct uring_task *task, int res) struct server *server = container_of(task, struct server, rcon_task); int32_t id; int32_t type; - const char *msg; + const char *msg, *error; assert_return(task); assert_task_alive(DBG_RCON, task); @@ -110,17 +104,9 @@ static void rcon_login_reply(struct uring_task *task, int res) if (!rcon_check_reply(task, res, &id, &type, &msg)) return; - if (id != 1) { - error("rcon(%s): login failed, reply id (%" PRIi32 ")", - server->name, id); - goto error; - } else if (type == RCON_PACKET_LOGIN_FAIL) { - error("rcon(%s): login failed, incorrect password", - server->name); - goto error; - } else if (type != RCON_PACKET_LOGIN_OK) { - error("rcon(%s): login failed, reply type (%" PRIi32 ")", - server->name, type); + if (!rcon_protocol_verify_response(1, id, RCON_PACKET_LOGIN, type, + &error)) { + error("rcon(%s): login failed - %s", server->name, error); goto error; } -- cgit v1.2.3