summaryrefslogtreecommitdiff
path: root/server.h
blob: b104ef1145737103aebcca9253679f56e877dae4 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef fooserverhfoo
#define fooserverhfoo

enum server_state {
	SERVER_STATE_INIT,
	SERVER_STATE_CFG_OK,
	SERVER_STATE_RUNNING,
	SERVER_STATE_STOPPED,
	SERVER_STATE_DEAD,
};

enum server_type {
	SERVER_TYPE_UNDEFINED,
	SERVER_TYPE_ANNOUNCE,
	SERVER_TYPE_PROXY,
};

enum server_stop_method {
	SERVER_STOP_METHOD_UNDEFINED,
	SERVER_STOP_METHOD_RCON,
	SERVER_STOP_METHOD_SYSTEMD,
	SERVER_STOP_METHOD_EXEC,
};

enum server_start_method {
	SERVER_START_METHOD_UNDEFINED,
	SERVER_START_METHOD_SYSTEMD,
	SERVER_START_METHOD_EXEC,
};

struct server {
	enum server_type type;
	char *name;
	char *pretty_name;
	uint16_t announce_port;
	struct list_head locals;
	struct list_head remotes;
	struct list_head proxys;
	struct list_head rcons;
	struct list_head dnslookups;
	enum server_state state;
	struct cfg *cfg;
	
	enum server_stop_method stop_method;
	enum server_start_method start_method;

	/* For calling external start/stop executables */
	char *stop_exec;
	char *start_exec;
	struct uring_task exec_task;

	/* For systemd services */
	char *systemd_service;
	char *systemd_obj;

	/* For rcon connections */
	struct rcon *rcon;
	char *rcon_password;

	/* For announce messages */
	struct uring_task ann_task;
	struct uring_task_buf ann_buf;

	/* For checking idle status */
	struct uring_task idle_task;
	struct connection idle_conn;
	struct uring_task_buf idle_buf;
	unsigned idle_timeout;
	unsigned idle_count;

	/* For reading config files */
	struct uring_task task;
	struct uring_task_buf tbuf;

	struct list_head list;
};

void server_refdump(struct server *server);

void server_delete(struct cfg *cfg, struct server *server);

void server_delete_by_name(struct cfg *cfg, const char *name);

bool server_start(struct cfg *cfg, struct server *server);

bool server_stop(struct cfg *cfg, struct server *server);

void server_set_active_players(struct cfg *cfg, struct server *server,
			       int count);

bool server_idle_check(struct cfg *cfg, struct server *server);

bool server_announce(struct cfg *cfg, struct server *server, int fd);

bool server_commit(struct cfg *cfg, struct server *server);

bool server_add_remote(struct cfg *cfg, struct server *server,
		       struct saddr *remote);

bool server_add_local(struct cfg *cfg, struct server *server,
		      struct saddr *saddr);

bool server_add_rcon(struct cfg *cfg, struct server *server,
		     struct saddr *rcon);

bool server_set_rcon_password(struct cfg *cfg, struct server *server,
			      const char *password);

bool server_set_systemd_service(struct cfg *cfg, struct server *server,
				const char *service);

bool server_set_stop_method(struct cfg *cfg, struct server *server,
			    enum server_stop_method stop_method);

bool server_set_start_method(struct cfg *cfg, struct server *server,
			     enum server_start_method start_method);

bool server_set_stop_exec(struct cfg *cfg, struct server *server, const char *cmd);

bool server_set_start_exec(struct cfg *cfg, struct server *server, const char *cmd);

bool server_set_idle_timeout(struct cfg *cfg, struct server *server, uint16_t timeout);

bool server_set_port(struct cfg *cfg, struct server *server, uint16_t port);

bool server_set_type(struct cfg *cfg, struct server *server,
		     enum server_type type);

bool server_set_pretty_name(struct cfg *cfg, struct server *server,
			    const char *pretty_name);

struct server *server_new(struct cfg *cfg, const char *name);

#endif