summaryrefslogtreecommitdiff
path: root/shared/rcon-protocol.c
diff options
context:
space:
mode:
Diffstat (limited to 'shared/rcon-protocol.c')
-rw-r--r--shared/rcon-protocol.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/shared/rcon-protocol.c b/shared/rcon-protocol.c
index 0cf73fc..1941662 100644
--- a/shared/rcon-protocol.c
+++ b/shared/rcon-protocol.c
@@ -75,6 +75,35 @@ static void write_end(char **pos, size_t *len)
*len += RCON_END_LEN;
}
+bool rcon_protocol_verify_response(int32_t id_sent, int32_t id_recv,
+ enum rcon_packet_type t_sent,
+ enum rcon_packet_type t_recv,
+ const char **error)
+{
+ if (t_sent == RCON_PACKET_LOGIN) {
+ if (t_recv != RCON_PACKET_LOGIN_RESPONSE) {
+ *error = "invalid reply id";
+ return false;
+ } else if (id_recv == RCON_PACKET_LOGIN_FAIL_ID) {
+ *error = "login failure";
+ return false;
+ } else if (id_recv != id_sent) {
+ *error = "invalid reply id";
+ return false;
+ }
+ } else {
+ if (t_recv != RCON_PACKET_RESPONSE) {
+ *error = "invalid reply type";
+ return false;
+ } else if (id_recv != id_sent) {
+ *error = "invalid reply id";
+ return false;
+ }
+ }
+
+ return true;
+}
+
bool rcon_protocol_create_packet(char *buf, size_t len, size_t *rlen,
int32_t reqid, enum rcon_packet_type type,
const char *msg)