summaryrefslogtreecommitdiff
path: root/minecproxy
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-07-01 21:29:06 +0200
committerDavid Härdeman <david@hardeman.nu>2020-07-01 21:29:06 +0200
commit7e728d971b95f115c7e9c2def21815034d9bde54 (patch)
treeef719c2cc2a42ff765b43e888fddc2f5f54ed9d7 /minecproxy
parent2ca520b06a1a80497dd39c98533ae21c165752c2 (diff)
Reduce some rcon duplication by using a common function
Diffstat (limited to 'minecproxy')
-rw-r--r--minecproxy/server-rcon.c36
1 files changed, 11 insertions, 25 deletions
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;
}