From 76be23aa5ce4dc0be31a1d0377cd57c9bacb04f2 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Mon, 3 Oct 2011 15:53:34 +0000 Subject: [PATCH] Add option -i to initialize a player externally. (Marc H. Thoben ) git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@607 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- dgamelaunch.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/dgamelaunch.c b/dgamelaunch.c index 9f3986c..9a8df87 100644 --- a/dgamelaunch.c +++ b/dgamelaunch.c @@ -101,6 +101,7 @@ extern int yyparse (); char * __progname; int g_idle_alarm_enabled = 0; int showplayers = 0; +int initplayer = 0; void (*g_chain_winch)(int); #ifndef USE_SQLITE3 @@ -1624,7 +1625,7 @@ autologin (char* user, char *pass) tmp = userexist(user, 0); if (tmp) { me = cpy_me(tmp); - if (passwordgood(pass) && !(me->flags & DGLACCT_LOGIN_LOCK)) { + if ((passwordgood(pass) || initplayer == 1) && !(me->flags & DGLACCT_LOGIN_LOCK)) { loggedin = 1; setproctitle ("%s", me->username); dgl_exec_cmdqueue(globalconfig.cmdqueue[DGLTIME_LOGIN], 0, me); @@ -2539,7 +2540,7 @@ main (int argc, char** argv) __progname = basename(strdup(argv[0])); - while ((c = getopt(argc, argv, "sqh:pf:aeW:SD")) != -1) + while ((c = getopt(argc, argv, "sqh:pf:i:aeW:SD")) != -1) { switch (c) { @@ -2560,6 +2561,19 @@ main (int argc, char** argv) config = strdup(optarg); break; + case 'i': + if (optarg && *optarg != '\0') { + if (p && *p != '\0') + *p = '\0'; + + p = strdup(optarg); + initplayer = 1; + + if (auth && *auth != '\0') + *auth = '\0'; + } + break; + case 'W': wall_email_str = strdup(optarg); break; @@ -2700,6 +2714,25 @@ main (int argc, char** argv) dgl_exec_cmdqueue(globalconfig.cmdqueue[DGLTIME_DGLSTART], 0, NULL); + if (initplayer) { + char *user, *pass; + + user = strdup(p); + pass = strdup(p); + + autologin(user, pass); + + if (loggedin) { + dgl_exec_cmdqueue(globalconfig.cmdqueue[DGLTIME_REGISTER], 0, me); + fprintf(stdout, "Setup of %s succeeded.\n", me->username); + graceful_exit(0); + } + else { + fprintf(stdout, "Setup of %s failed.\n", p); + graceful_exit(1); + } + } + /* simple login routine, uses ncurses */ if (readfile (0)) { debug_write("log in fail");