Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
/*.o
/virus
/ee
/*.swp
3 changes: 3 additions & 0 deletions config.l
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ cursor { return TYPE_CURSOR; }
"short_name" { return TYPE_GAME_SHORT_NAME; }
"game_id" { return TYPE_GAME_ID; }
"game_path" { return TYPE_PATH_GAME; }
"watch_path" { return TYPE_PATH_WATCH; }
"dglroot" { return TYPE_PATH_DGLDIR; }
"spooldir" { return TYPE_PATH_SPOOL; }
"banner" { return TYPE_PATH_BANNER; }
Expand All @@ -84,6 +85,7 @@ cursor { return TYPE_CURSOR; }
"lockfile" { return TYPE_PATH_LOCKFILE; }
"inprogressdir" { return TYPE_PATH_INPROGRESS; }
"game_args" { return TYPE_GAME_ARGS; }
"watch_args" { return TYPE_WATCH_ARGS; }
extra_info_file { return TYPE_EXTRA_INFO_FILE; }
"max_idle_time" { return TYPE_MAX_IDLE_TIME; }
"rc_fmt" { return TYPE_RC_FMT; }
Expand All @@ -94,6 +96,7 @@ sortmode { return TYPE_WATCH_SORTMODE; }
watch_columns { return TYPE_WATCH_COLUMNS; }
commands { return TYPE_CMDQUEUE; }
postcommands { return TYPE_POSTCMDQUEUE; }
watchcommands { return TYPE_WATCHCMDQUEUE; }
encoding { return TYPE_ENCODING; }
locale { return TYPE_LOCALE; }
default_term { return TYPE_DEFTERM; }
Expand Down
48 changes: 48 additions & 0 deletions config.y
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static int sortmode_number(const char *sortmode_name) {
%token <i> TYPE_DGLCMD0 TYPE_DGLCMD1 TYPE_DGLCMD2
%token TYPE_DEFINE_GAME
%token <i> TYPE_BOOL
%token TYPE_PATH_WATCH TYPE_WATCH_ARGS TYPE_WATCHCMDQUEUE

%%

Expand Down Expand Up @@ -450,11 +451,28 @@ game_definition : TYPE_CMDQUEUE
myconfig[ncnf]->postcmdqueue = curr_cmdqueue;
curr_cmdqueue = NULL;
}
| TYPE_WATCHCMDQUEUE
{
if (myconfig[ncnf]->watchcmdqueue) {
fprintf(stderr, "%s:%d: watchcommand queue defined twice, bailing out\n",
config, line);
exit(1);
}
}
'=' cmdlist
{
myconfig[ncnf]->watchcmdqueue = curr_cmdqueue;
curr_cmdqueue = NULL;
}

| TYPE_GAME_ARGS '=' game_args_list
{
/* nothing */
}
| TYPE_WATCH_ARGS '=' watch_args_list
{
/* nothing */
}
| TYPE_EXTRA_INFO_FILE '=' TYPE_VALUE
{
myconfig[ncnf]->extra_info_file = strdup($3);
Expand Down Expand Up @@ -486,6 +504,11 @@ game_definition : TYPE_CMDQUEUE
myconfig[ncnf]->game_path = strdup ($3);
break;

case TYPE_PATH_WATCH:
if (myconfig[ncnf]->watch_path) free(myconfig[ncnf]->watch_path);
myconfig[ncnf]->watch_path = strdup ($3);
break;

case TYPE_NAME_GAME:
if (myconfig[ncnf]->game_name) free (myconfig[ncnf]->game_name);
myconfig[ncnf]->game_name = strdup($3);
Expand Down Expand Up @@ -548,10 +571,32 @@ game_arg : TYPE_VALUE
}
;

watch_arg : TYPE_VALUE
{
char **tmpargs;
if (myconfig[ncnf]->watch_args) {
myconfig[ncnf]->num_wargs++;
tmpargs = calloc((myconfig[ncnf]->num_wargs+1), sizeof(char *));
memcpy(tmpargs, myconfig[ncnf]->watch_args, (myconfig[ncnf]->num_wargs * sizeof(char *)));
free(myconfig[ncnf]->watch_args);
myconfig[ncnf]->watch_args = tmpargs;
} else {
myconfig[ncnf]->num_wargs = 1;
myconfig[ncnf]->watch_args = calloc(2, sizeof(char *));
}
myconfig[ncnf]->watch_args[(myconfig[ncnf]->num_wargs)-1] = strdup($1);
myconfig[ncnf]->watch_args[(myconfig[ncnf]->num_wargs)] = 0;
}
;

game_args_list : game_arg
| game_arg ',' game_args_list
;

watch_args_list : watch_arg
| watch_arg ',' watch_args_list
;

game_definitions : game_definition
| game_definition game_definitions
;
Expand Down Expand Up @@ -649,6 +694,7 @@ KeyType : TYPE_SUSER { $$ = TYPE_SUSER; }
| TYPE_PATH_CHROOT { $$ = TYPE_PATH_CHROOT; }
| TYPE_ALLOW_REGISTRATION { $$ = TYPE_ALLOW_REGISTRATION; }
| TYPE_PATH_GAME { $$ = TYPE_PATH_GAME; }
| TYPE_PATH_WATCH { $$ = TYPE_PATH_WATCH; }
| TYPE_NAME_GAME { $$ = TYPE_NAME_GAME; }
| TYPE_GAME_SHORT_NAME { $$ = TYPE_GAME_SHORT_NAME; }
| TYPE_GAME_ID { $$ = TYPE_GAME_ID; }
Expand Down Expand Up @@ -685,6 +731,7 @@ const char* lookup_token (int t)
case TYPE_MENU_MAX_IDLE_TIME: return "menu_max_idle_time";
case TYPE_PATH_CHROOT: return "chroot_path";
case TYPE_PATH_GAME: return "game_path";
case TYPE_PATH_WATCH: return "watch_path";
case TYPE_NAME_GAME: return "game_name";
case TYPE_ALLOW_REGISTRATION: return "allow_new_nicks";
case TYPE_GAME_SHORT_NAME: return "short_name";
Expand All @@ -696,6 +743,7 @@ const char* lookup_token (int t)
case TYPE_PATH_TTYREC: return "ttyrecdir";
case TYPE_PATH_INPROGRESS: return "inprogressdir";
case TYPE_GAME_ARGS: return "game_args";
case TYPE_WATCH_ARGS: return "watch_args";
case TYPE_MAX_IDLE_TIME: return "max_idle_time";
case TYPE_RC_FMT: return "rc_fmt";
case TYPE_WATCH_SORTMODE: return "sortmode";
Expand Down
55 changes: 51 additions & 4 deletions dgamelaunch.c
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,11 @@ game_get_column_data(struct dg_game *game,
break;

case SORTMODE_WINDOWSIZE:
if (myconfig[game->gamenum]->watch_path) {
snprintf(data, bufsz, " N/A");
*hilite = CLR_GREEN;
break;
}
snprintf(data, bufsz, "%3dx%3d", game->ws_col, game->ws_row);
if (showplayers)
snprintf(data, bufsz, "%dx%d", game->ws_col, game->ws_row);
Expand Down Expand Up @@ -1039,7 +1044,7 @@ inprogressmenu (int gameid)

shm_init(&shm_dg_data, &shm_dg_game);

games = populate_games (gameid, &len, NULL); /* FIXME: should be 'me' instead of 'NULL' */
games = populate_games (gameid, &len, me);
shm_update(shm_dg_data, games, len);
games = sort_games (games, len, sortmode);

Expand Down Expand Up @@ -1274,7 +1279,49 @@ inprogressmenu (int gameid)
setproctitle("%s [watching %s]", me->username, chosen_name);
else
setproctitle("<Anonymous> [watching %s]", chosen_name);
ttyplay_main (ttyrecname, 1, resizex, resizey);
if (myconfig[games[idx]->gamenum]->watch_path) {
pid_t child;
int gnum = games[idx]->gamenum;
char **wargs = (char **)malloc(sizeof(char *) * (myconfig[gnum]->num_wargs+1));
dgl_exec_cmdqueue_w(myconfig[gnum]->watchcmdqueue, gnum, me, chosen_name);
/* fix the variables in the arguments */
for (i = 0; i < myconfig[gnum]->num_wargs; i++) {
wargs[i] = strdup(dgl_format_str(gnum, me, myconfig[gnum]->watch_args[i], chosen_name));
}
wargs[myconfig[gnum]->num_wargs] = NULL;
/* tidy up signals before launching external process */
signal(SIGWINCH, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
idle_alarm_set_enabled(0);
/* launch program */
child = fork();
if (child < 0) {
perror ("fork");
fail ();
}
if (child == 0) {
execvp (myconfig[gnum]->watch_path, wargs);
} else {
int status;
(void) wait(&status);
}
/* reset signals on return */
idle_alarm_set_enabled(1);
signal(SIGHUP, catch_sighup);
signal(SIGINT, catch_sighup);
signal(SIGQUIT, catch_sighup);
signal(SIGTERM, catch_sighup);
signal(SIGWINCH, sigwinch_func);
/* free temporary watch args */
for (i = 0; i < myconfig[gnum]->num_wargs; i++) {
free(wargs[i]);
}
free(wargs);
} else {
ttyplay_main (ttyrecname, 1, resizex, resizey);
}
if (loggedin)
setproctitle("%s", me->username);
else
Expand Down Expand Up @@ -1302,7 +1349,7 @@ inprogressmenu (int gameid)

if (selected >= 0 && selected < len)
selectedgame = strdup(games[selected]->name);
games = populate_games (gameid, &len, NULL); /* FIXME: should be 'me' instead of 'NULL' */
games = populate_games (gameid, &len, me);
shm_update(shm_dg_data, games, len);
games = sort_games (games, len, sortmode);
if (selectedgame) {
Expand Down Expand Up @@ -1345,7 +1392,7 @@ inprogressdisplay (int gameid)

shm_init(&shm_dg_data, &shm_dg_game);

games = populate_games (gameid, &len, NULL); /* FIXME: should be 'me' instead of 'NULL' */
games = populate_games (gameid, &len, me);
shm_update(shm_dg_data, games, len);
games = sort_games (games, len, sortmode);

Expand Down
7 changes: 7 additions & 0 deletions dgamelaunch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
#ifdef USE_NCURSES_COLOR
# define CLR_NORMAL COLOR_PAIR(11) | A_NORMAL
# define CLR_RED COLOR_PAIR(COLOR_RED) | A_NORMAL
# define CLR_GREEN COLOR_PAIR(COLOR_GREEN) | A_NORMAL
#else
# define CLR_NORMAL 0
# define CLR_RED 0
# define CLR_GREEN 0
#endif
extern int color_remap[];

Expand Down Expand Up @@ -198,6 +200,7 @@ struct dg_game
struct dg_config
{
char* game_path;
char* watch_path;
char* game_name;
char* game_id;
char* shortname;
Expand All @@ -206,10 +209,13 @@ struct dg_config
char* spool;
char* inprogressdir;
int num_args; /* # of bin_args */
int num_wargs; /* # of watch_args */
char **bin_args; /* args for game binary */
char **watch_args; /* args for watch binary */
char *rc_fmt;
struct dg_cmdpart *cmdqueue;
struct dg_cmdpart *postcmdqueue;
struct dg_cmdpart *watchcmdqueue;
int max_idle_time;
char *extra_info_file;
int encoding; // -1 = run --print-charset
Expand Down Expand Up @@ -301,6 +307,7 @@ 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 int dgl_exec_cmdqueue_w(struct dg_cmdpart *queue, int game, struct dg_user *me, char *playername);

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);
Expand Down
Loading