From 7a8bee84bd1f41bf349f9077617e20c3560b7c62 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Tue, 23 Jun 2020 15:19:44 +0200 Subject: Split out rcon protocol handling to separate file --- rcon-protocol.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 rcon-protocol.h (limited to 'rcon-protocol.h') diff --git a/rcon-protocol.h b/rcon-protocol.h new file mode 100644 index 0000000..fd83d79 --- /dev/null +++ b/rcon-protocol.h @@ -0,0 +1,38 @@ +#ifndef foorconprotocolhfoo +#define foorconprotocolhfoo + +enum rcon_packet_type { + RCON_PACKET_LOGIN = 3, + RCON_PACKET_LOGIN_OK = 2, + RCON_PACKET_LOGIN_FAIL = -1, + RCON_PACKET_COMMAND = 2, + RCON_PACKET_RESPONSE = 0, +}; + +#define RCON_INT_LEN 4 + +#define RCON_END_LEN 2 + +#define RCON_HDR_LEN 4 + +/* header + reqid + type + end */ +#define RCON_PKT_MIN_LEN (RCON_HDR_LEN + 2 * RCON_INT_LEN + RCON_END_LEN) + +static inline size_t +rcon_protocol_packet_len(size_t msglen) +{ + /* header + reqid + type + msg + end */ + return (RCON_PKT_MIN_LEN + msglen); +} + +bool rcon_protocol_create_packet(char *buf, size_t len, size_t *rlen, + int32_t reqid, enum rcon_packet_type type, + const char *msg); + +int32_t rcon_protocol_packet_complete(const char *buf, size_t len); + +bool rcon_protocol_read_packet(const char *buf, size_t len, int32_t *id, + int32_t *type, const char **rmsg, + const char **error); + +#endif -- cgit v1.2.3