Add per-game "postcommand" hook, executed right after the game ends.

git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@588 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
Pasi Kallinen 2011-08-31 14:36:22 +00:00
parent 61e3e65647
commit b1e40ba5b7
6 changed files with 80 additions and 47 deletions

7
TODO
View File

@ -1,4 +1,11 @@
[22:45] < kerio> paxed: dgamelaunch bug! :D - you *need* a file called dgamelaunch in the root of the jail -
otherwise the shared memory craps out
[22:48] < kerio> anyway, /dgldir/shmkey would've been better
-when no banner file given, try to make a banner automagically? -when no banner file given, try to make a banner automagically?
(needs some way to name the options given as keys... maybe another (needs some way to name the options given as keys... maybe another
format for the keys that includes a string to be used as the name) format for the keys that includes a string to be used as the name)

View File

@ -89,6 +89,7 @@ cursor { return TYPE_CURSOR; }
server_id { return TYPE_SERVER_ID; } server_id { return TYPE_SERVER_ID; }
sortmode { return TYPE_WATCH_SORTMODE; } sortmode { return TYPE_WATCH_SORTMODE; }
commands { return TYPE_CMDQUEUE; } commands { return TYPE_CMDQUEUE; }
postcommands { return TYPE_POSTCMDQUEUE; }
yes { yylval.i = 1; return TYPE_BOOL; } yes { yylval.i = 1; return TYPE_BOOL; }
no { yylval.i = 0; return TYPE_BOOL; } no { yylval.i = 0; return TYPE_BOOL; }
dglstart { yylval.i = DGLTIME_DGLSTART; return TYPE_CMDQUEUENAME; } dglstart { yylval.i = DGLTIME_DGLSTART; return TYPE_CMDQUEUENAME; }

View File

@ -41,6 +41,7 @@ static const char* lookup_token (int t);
%token TYPE_PATH_PASSWD TYPE_PATH_LOCKFILE TYPE_PATH_TTYREC %token TYPE_PATH_PASSWD TYPE_PATH_LOCKFILE TYPE_PATH_TTYREC
%token TYPE_MALSTRING TYPE_PATH_INPROGRESS TYPE_GAME_ARGS TYPE_RC_FMT %token TYPE_MALSTRING TYPE_PATH_INPROGRESS TYPE_GAME_ARGS TYPE_RC_FMT
%token TYPE_CMDQUEUE TYPE_DEFINE_MENU TYPE_BANNER_FILE TYPE_CURSOR %token TYPE_CMDQUEUE TYPE_DEFINE_MENU TYPE_BANNER_FILE TYPE_CURSOR
%token TYPE_POSTCMDQUEUE
%token TYPE_MAX_IDLE_TIME TYPE_MENU_MAX_IDLE_TIME %token TYPE_MAX_IDLE_TIME TYPE_MENU_MAX_IDLE_TIME
%token <s> TYPE_VALUE %token <s> TYPE_VALUE
%token <i> TYPE_NUMBER TYPE_CMDQUEUENAME %token <i> TYPE_NUMBER TYPE_CMDQUEUENAME
@ -356,6 +357,20 @@ game_definition : TYPE_CMDQUEUE
myconfig[ncnf]->cmdqueue = curr_cmdqueue; myconfig[ncnf]->cmdqueue = curr_cmdqueue;
curr_cmdqueue = NULL; curr_cmdqueue = NULL;
} }
| TYPE_POSTCMDQUEUE
{
if (myconfig[ncnf]->postcmdqueue) {
fprintf(stderr, "%s:%d: postcommand queue defined twice, bailing out\n",
config, line);
exit(1);
}
}
'=' cmdlist
{
myconfig[ncnf]->postcmdqueue = curr_cmdqueue;
curr_cmdqueue = NULL;
}
| TYPE_GAME_ARGS '=' game_args_list | TYPE_GAME_ARGS '=' game_args_list
{ {
/* nothing */ /* nothing */

View File

@ -49,9 +49,56 @@ typedef enum
NUM_DGLTIMES NUM_DGLTIMES
} dglcmd_times; } dglcmd_times;
typedef enum
{
DGLCMD_NONE = 0,
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_IDLETIME,
#ifdef USE_SHMEM
SORTMODE_WATCHERS,
#endif
NUM_SORTMODES
} dg_sortmode;
static const char *SORTMODE_NAME[NUM_SORTMODES] = {
"Unsorted",
"Username",
"Game",
"Windowsize",
"Starttime",
"Idletime",
#ifdef USE_SHMEM
"Watchers",
#endif
};
struct dg_cmdpart struct dg_cmdpart
{ {
dglcmd_times cmd; dglcmd_actions cmd;
char *param1; char *param1;
char *param2; char *param2;
struct dg_cmdpart *next; struct dg_cmdpart *next;
@ -140,6 +187,7 @@ struct dg_config
char **bin_args; /* args for game binary */ char **bin_args; /* args for game binary */
char *rc_fmt; char *rc_fmt;
struct dg_cmdpart *cmdqueue; struct dg_cmdpart *cmdqueue;
struct dg_cmdpart *postcmdqueue;
int max_idle_time; int max_idle_time;
}; };
@ -166,52 +214,6 @@ struct dg_globalconfig
int menu_max_idle_time; int menu_max_idle_time;
}; };
typedef enum
{
DGLCMD_NONE = 0,
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_IDLETIME,
#ifdef USE_SHMEM
SORTMODE_WATCHERS,
#endif
NUM_SORTMODES
} dg_sortmode;
static const char *SORTMODE_NAME[NUM_SORTMODES] = {
"Unsorted",
"Username",
"Game",
"Windowsize",
"Starttime",
"Idletime",
#ifdef USE_SHMEM
"Watchers",
#endif
};
/* Global variables */ /* Global variables */

View File

@ -46,6 +46,7 @@ struct dg_config defconfig = {
/* bin_args = */ NULL, /* bin_args = */ NULL,
/* rc_fmt = */ "%rrcfiles/%n.nethackrc", /* [dglroot]rcfiles/[username].nethackrc */ /* rc_fmt = */ "%rrcfiles/%n.nethackrc", /* [dglroot]rcfiles/[username].nethackrc */
/* cmdqueue = */ NULL, /* cmdqueue = */ NULL,
/* postcmdqueue = */ NULL,
/* max_idle_time = */ 0 /* max_idle_time = */ 0
}; };
@ -365,6 +366,8 @@ dgl_exec_cmdqueue(struct dg_cmdpart *queue, int game, struct dg_user *me)
signal (SIGTERM, catch_sighup); signal (SIGTERM, catch_sighup);
signal(SIGWINCH, sigwinch_func); signal(SIGWINCH, sigwinch_func);
dgl_exec_cmdqueue(myconfig[userchoice]->postcmdqueue, userchoice, me);
dgl_exec_cmdqueue(globalconfig.cmdqueue[DGLTIME_GAMEEND], userchoice, me); dgl_exec_cmdqueue(globalconfig.cmdqueue[DGLTIME_GAMEEND], userchoice, me);
setproctitle ("%s", me->username); setproctitle ("%s", me->username);

View File

@ -81,6 +81,7 @@ lockfile = "/dgl-lock"
# login = when user has logged in # login = when user has logged in
# register = right after a new user is registered # register = right after a new user is registered
# gamestart = just before a game is started # gamestart = just before a game is started
# gameend = after a game ends (see also per-game "postcommand" define)
# #
# <command> is: # <command> is:
# mkdir "foo" = create a directory "foo" # mkdir "foo" = create a directory "foo"
@ -211,6 +212,10 @@ menu["watchmenu_help"] {
# # We can also define per-game commands, that are executed # # We can also define per-game commands, that are executed
# # when the game starts: # # when the game starts:
# # commands = chdir "/dgldir", mkdir "foo_%u_%g" # # commands = chdir "/dgldir", mkdir "foo_%u_%g"
#
# # We can also define per-game commands executed after the game ends,
# # but before commands[gameend]
# postcommands = chdir "/"
#} #}