Files
where-are-my-friends/src/rcon.h
T

35 lines
1.1 KiB
C

#include <stdint.h>
#define RCON_SERVERDATA_EXECCOMMAND 2
#define RCON_SERVERDATA_AUTH 3
#define RCON_SERVERDATA_RESPONSE_VALUE 0
#define RCON_SERVERDATA_AUTH_RESPONSE 2
typedef struct {
// size of the remainder of the packet
int32_t size;
// packet id (client sets, server echoes, -1 on auth failure)
int32_t id;
// packet type (see the SERVERDATA_* constants)
int32_t type;
// null-terminated command string (for auth and exec) or response string (from server)
char body[4096];
// yet another null byte after the body (required by protocol)
uint8_t _padding;
} rcon_packet_t;
// Minimum and maximum values for the `size` field of a valid packet.
#define RCON_PACKET_MIN_SIZE (sizeof(int32_t) * 2 + 2)
#define RCON_PACKET_MAX_SIZE (sizeof(rcon_packet_t) - sizeof(int32_t))
int rcon_connect(const char* address, int port);
void send_packet(int sockfd, int32_t id, int32_t type, const char *body);
int recv_packet(int sockfd, rcon_packet_t *packet);
int rcon_authenticate(int sockfd, const char *password);
char* rcon_command_multipacket(int sockfd, const char *command);