forked from paxed/dgamelaunch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dgamelaunch.h
364 lines (309 loc) · 8.62 KB
/
dgamelaunch.h
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/* IMPORTANT defines */
#ifndef __DGAMELAUNCH_H
#define __DGAMELAUNCH_H
#include "config.h"
#include <sys/param.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#ifdef USE_SHMEM
#include <semaphore.h>
#endif
#ifndef ARRAY_SIZE
# define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#endif
#define dglsign(x) (x < 0 ? -1 : (x > 0 ? 1 : 0))
#define DGL_PLAYERNAMELEN 30 /* max. length of player name */
#define DGL_PASSWDLEN 20 /* max. length of passwords */
#define DGL_MAILMSGLEN 80 /* max. length of mail message */
#define DGL_MAXWATCHCOLS 10
#define DGL_BANNER_LINELEN 256 /* max. length of banner lines*/
#ifdef USE_NCURSES_COLOR
# define CLR_NORMAL COLOR_PAIR(11) | A_NORMAL
# define CLR_RED COLOR_PAIR(COLOR_RED) | A_NORMAL
#else
# define CLR_NORMAL 0
# define CLR_RED 0
#endif
extern int color_remap[];
typedef enum
{
DGLACCT_ADMIN = 0x01, /* admin account */
DGLACCT_LOGIN_LOCK = 0x02, /* account is banned and cannot login */
DGLACCT_PASSWD_LOCK = 0x04, /* account password cannot be changed */
DGLACCT_EMAIL_LOCK = 0x08 /* account email cannot be changed */
} dgl_acct_flag;
typedef enum
{
DGLTIME_DGLSTART = 0, /* when someone telnets in */
DGLTIME_LOGIN, /* right after user login */
DGLTIME_REGISTER, /* right after new nick is registered */
DGLTIME_GAMESTART, /* right before a game is started */
DGLTIME_GAMEEND, /* right after a game is ended */
NUM_DGLTIMES
} dglcmd_times;
typedef enum
{
DGLCMD_NONE = 0,
DGLCMD_RAWPRINT, /* rawprint "foo" */
DGLCMD_MKDIR, /* mkdir foo */
DGLCMD_CHDIR, /* chdir foo */
DGLCMD_IF_NX_CP, /* ifnxcp foo bar */
DGLCMD_CP, /* cp foo bar */
DGLCMD_UNLINK, /* unlink foo */
DGLCMD_EXEC, /* exec foo bar */
DGLCMD_SETENV, /* setenv foo bar */
DGLCMD_WATCH_MENU, /* watch_menu */
DGLCMD_LOGIN, /* ask_login */
DGLCMD_REGISTER, /* ask_register */
DGLCMD_QUIT, /* quit */
DGLCMD_CHMAIL, /* chmail */
DGLCMD_CHPASSWD, /* chpasswd */
DGLCMD_PLAYGAME, /* play_game "foo" */
DGLCMD_SUBMENU, /* submenu "foo" */
DGLCMD_RETURN /* return */
} dglcmd_actions;
typedef enum
{
SORTMODE_NONE = 0,
SORTMODE_USERNAME,
SORTMODE_GAMENUM,
SORTMODE_WINDOWSIZE,
SORTMODE_STARTTIME,
SORTMODE_DURATION,
SORTMODE_IDLETIME,
SORTMODE_EXTRA_INFO,
#ifdef USE_SHMEM
SORTMODE_WATCHERS,
#endif
NUM_SORTMODES
} dg_sortmode;
static const char *SORTMODE_NAME[NUM_SORTMODES] = {
"Unsorted",
"Username",
"Game",
"Windowsize",
"Starttime",
"Duration",
"Idletime",
"Extrainfo",
#ifdef USE_SHMEM
"Watchers",
#endif
};
struct dg_banner_var {
char *name;
char *value;
int special;
struct dg_banner_var *next;
};
struct dg_cmdpart
{
dglcmd_actions cmd;
char *param1;
char *param2;
struct dg_cmdpart *next;
};
struct dg_user
{
#ifdef USE_SQLITE3
long id;
#endif
char *username;
char *email;
char *env;
char *password;
int flags; /* dgl_acct_flag bitmask */
};
struct dg_banner
{
char **lines;
unsigned int len;
};
struct dg_menuoption
{
char *keys;
struct dg_cmdpart *cmdqueue;
struct dg_menuoption *next;
};
struct dg_menu
{
char *banner_fn;
struct dg_banner banner;
int cursor_x, cursor_y;
struct dg_menuoption *options;
};
struct dg_menulist
{
char *menuname;
struct dg_menu *menu;
struct dg_menulist *next;
};
struct dg_shm
{
#ifdef USE_SHMEM
sem_t dg_sem;
#endif
long max_n_games;
long cur_n_games;
};
struct dg_shm_game
{
long in_use;
long nwatchers;
char ttyrec_fn[150];
};
struct dg_game
{
char *ttyrec_fn;
char *name;
char *date;
char *time;
time_t idle_time;
int ws_row, ws_col; /* Window size */
int gamenum;
int is_in_shm;
int shm_idx;
int nwatchers;
char *extra_info;
int extra_info_weight;
};
struct dg_config
{
char* game_path;
char* game_name;
char* shortname;
char* rcfile;
char* ttyrecdir;
char* spool;
char* inprogressdir;
int num_args; /* # of bin_args */
char **bin_args; /* args for game binary */
char *rc_fmt;
struct dg_cmdpart *cmdqueue;
struct dg_cmdpart *postcmdqueue;
int max_idle_time;
char *extra_info_file;
int encoding; // -1 = run --print-charset
};
struct dg_watchcols {
int dat;
int sortmode;
int x;
char *colname;
char *fmt;
};
struct dg_globalconfig
{
char* chroot;
char* dglroot;
char* banner;
unsigned long max;
int max_newnick_len; /* maximum length of new registered names. must be less than 20 chars. */
char* shed_user;
char* shed_group;
uid_t shed_uid;
gid_t shed_gid;
char* passwd;
char* lockfile;
int allow_registration; /* allow registering new nicks */
int sortmode; /* default watching-screen sortmode */
struct dg_banner_var *banner_var_list;
char *locale;
int utf8esc; /* send select-utf8-charset escape code */
char *defterm; /* default TERM in case user TERM is unknown */
int flowctrl; /* XON/XOFF for games? */
struct dg_cmdpart *cmdqueue[NUM_DGLTIMES];
/* NULL terminated list of dg_watchcols pointers */
struct dg_watchcols *watch_columns[DGL_MAXWATCHCOLS + 1];
int n_watch_columns;
struct dg_menulist *menulist;
int menu_max_idle_time;
};
/* Global variables */
extern int shm_n_games; /* TODO: make configurable */
extern char* config; /* file path */
extern struct dg_config **myconfig;
extern char *chosen_name;
extern int loggedin;
extern int silent;
extern int set_max;
extern int selected_game;
extern int return_from_submenu;
extern struct dg_globalconfig globalconfig;
extern int num_games;
extern mode_t default_fmode;
extern int dgl_local_COLS;
extern int dgl_local_LINES;
extern char last_ttyrec[512];
/* dgamelaunch.c */
extern void create_config(void);
extern void ttyrec_getmaster(void);
extern char *get_mainmenu_name(void);
extern char *gen_ttyrec_filename(void);
extern char *gen_inprogress_lock(int game, pid_t pid, char *ttyrec_filename);
extern void catch_sighup(int signum);
extern void loadbanner(char *fname, struct dg_banner *ban);
extern void drawbanner(struct dg_banner *ban);
extern void banner_var_add(char *name, char *value, int special);
extern char *banner_var_value(char *name);
extern void banner_var_free(void);
extern int check_retard(int reset);
extern char *dgl_format_str(int game, struct dg_user *me, char *str, char *plrname);
extern void term_resize_check();
extern void sigwinch_func(int sig);
extern struct dg_menu *dgl_find_menu(char *menuname);
extern int dgl_exec_cmdqueue(struct dg_cmdpart *queue, int game, struct dg_user *me);
extern void free_populated_games(struct dg_game **games, int len);
extern struct dg_game **populate_games(int game, int *l, struct dg_user *me);
#ifdef USE_DEBUGFILE
extern void debug_write(char *str);
#else
#define debug_write(str)
#endif
extern struct dg_game **sort_games(struct dg_game **games, int len, dg_sortmode sortmode);
int runmenuloop(struct dg_menu *menu);
extern void signals_block(void);
extern void signals_release(void);
extern void shm_sem_wait(struct dg_shm *shm_dg_data);
extern void shm_sem_post(struct dg_shm *shm_dg_data);
extern void shm_update(struct dg_shm *shm_dg_data, struct dg_game **games, int len);
extern void shm_mk_keys(key_t *shm_key, key_t *shm_sem_key);
extern void shm_init(struct dg_shm **shm_dg_data, struct dg_shm_game **shm_dg_game);
extern int dgl_getch(void);
extern void idle_alarm_set_enabled(int enabled);
extern void idle_alarm_reset(void);
extern void inprogressmenu(int gameid);
extern void change_email(void);
extern int changepw(int dowrite);
extern void domailuser(char *username);
extern void drawmenu(void);
extern void freefile(void);
extern void initcurses(void);
extern void loginprompt(int from_ttyplay);
extern void newuser(void);
extern void autologin(char *user, char *pass);
extern int passwordgood(char *cpw);
extern int readfile(int nolock);
extern struct dg_user *userexist(char *cname, int isnew);
extern void write_canned_rcfile(int game, char *target);
extern void writefile(int requirenew);
extern void graceful_exit(int status);
extern int purge_stale_locks(int game);
/*extern int menuloop(void);*/
extern void ttyrec_getpty(void);
#ifndef HAVE_SETENV
extern int mysetenv (const char* name, const char* value, int overwrite);
#else
# define mysetenv setenv
#endif
#ifndef HAVE_SETPROCTITLE
void compat_init_setproctitle(int argc, char *argv[]);
void setproctitle(const char *fmt, ...);
#endif
/* strlcpy.c */
extern size_t strlcpy (char *dst, const char *src, size_t siz);
extern size_t strlcat (char *dst, const char *src, size_t siz);
/* mygetnstr.c */
extern int mygetnstr(char *buf, int maxlen, int doecho);
#endif