summaryrefslogtreecommitdiff
path: root/src/console/rcon.h
blob: ffcbde7f58d80f3f57e0d8bf52d7864b08631019 (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
#ifndef UMBRELLA_RCON_H
#define UMBRELLA_RCON_H

/*
 * Valve RCON protocol implementation.
 * https://developer.valvesoftware.com/wiki/Source_RCON_Protocol
 *
 * RCON uses a simple TCP framing:
 *   [int32 size][int32 id][int32 type][string body][null][null]
 *
 * Types:
 *   SERVERDATA_AUTH           = 3
 *   SERVERDATA_AUTH_RESPONSE  = 2
 *   SERVERDATA_EXECCOMMAND    = 2 (same value as AUTH_RESPONSE — context-dependent)
 *   SERVERDATA_RESPONSE_VALUE = 0
 */

#define RCON_AUTH_REQUEST  3
#define RCON_AUTH_RESPONSE 2
#define RCON_EXEC_REQUEST  2
#define RCON_EXEC_RESPONSE 0

/*
 * rcon_exec: connect to an RCON server, authenticate, run a command,
 * collect the response, and disconnect.
 *
 * host     - server hostname or IP
 * port     - RCON port (usually 27015)
 * password - RCON password
 * command  - command string to execute
 * response - output buffer
 * resp_len - size of response buffer
 *
 * Returns 0 on success, -1 on failure.
 */
int rcon_exec(const char *host, int port, const char *password,
              const char *command, char *response, int resp_len);

#endif /* UMBRELLA_RCON_H */