summaryrefslogtreecommitdiff
path: root/shared/rcon-protocol.h
blob: d6c2a4a6661ffde5dcc0e645dff9ff47011fc38e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef foorconprotocolhfoo
#define foorconprotocolhfoo

#include <stdbool.h>
#include <stdint.h>

/* clang-format off */
#define RCON_PACKET_LOGIN_FAIL_ID   -1
enum rcon_packet_type {
	RCON_PACKET_LOGIN	   = 3,
	RCON_PACKET_LOGIN_RESPONSE = 2,
	RCON_PACKET_COMMAND	   = 2,
	RCON_PACKET_RESPONSE	   = 0,
};
/* clang-format on */

#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_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);

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