comparison rogue5/main.c @ 34:655c317b6237

rogue5: add savedir, logfile, bugfixes
author elwin
date Mon, 24 May 2010 20:16:15 +0000
parents f502bf60e6e4
children 24e6beb9e7aa
comparison
equal deleted inserted replaced
33:f502bf60e6e4 34:655c317b6237
40 argc--; 40 argc--;
41 } 41 }
42 42
43 #endif 43 #endif
44 44
45 /* Check to see if savefiles should be stored in the system location */
46 #ifdef SAVEDIR
47 if (argc >= 3 && !strcmp(argv[1], "-n"))
48 {
49 use_savedir = TRUE;
50 strncpy(whoami, argv[2], MAXSTR);
51 whoami[MAXSTR-1] = '\0';
52 snprintf(file_name, MAXSTR, "%s/%d-%.10s.r5sav", SAVEDIR,
53 md_getuid(), whoami);
54 }
55 #endif
56
57 open_score();
58 open_log();
59
45 /* 60 /*
46 * get home and options from environment 61 * get home and options from environment
47 */ 62 */
48 63
49 strcpy(home, md_gethomedir()); 64 strcpy(home, md_gethomedir());
50 65
51 if (strlen(home) > MAXSTR - strlen("rogue.save") - 1) 66 if (strlen(home) > MAXSTR - strlen("rogue5.save") - 1)
52 *home = 0; 67 *home = 0;
53 68
54 strcpy(file_name, home); 69 if (!use_savedir)
55 strcat(file_name, "rogue.save"); 70 {
71 md_normaluser();
72 strcpy(file_name, home);
73 strcat(file_name, "rogue5.save");
74 }
56 75
57 if ((env = getenv("ROGUEOPTS")) != NULL) 76 if ((env = getenv("ROGUEOPTS")) != NULL)
58 parse_opts(env); 77 parse_opts(env);
59 if (env == NULL || whoami[0] == '\0') 78 if (!use_savedir && (env == NULL || whoami[0] == '\0'))
60 strucpy(whoami, md_getusername(), strlen(md_getusername())); 79 strucpy(whoami, md_getusername(), strlen(md_getusername()));
61 lowtime = time(NULL); 80 lowtime = time(NULL);
62 if (getenv("SEED") != NULL) 81 if (getenv("SEED") != NULL)
63 { 82 {
64 dnum = atoi(getenv("SEED")); 83 dnum = atoi(getenv("SEED"));
66 } 85 }
67 else 86 else
68 dnum = (unsigned int) lowtime + md_getpid(); 87 dnum = (unsigned int) lowtime + md_getpid();
69 seed = dnum; 88 seed = dnum;
70 89
71 open_score();
72
73 /*
74 * Drop setuid/setgid after opening the scoreboard file.
75 */
76
77 md_normaluser();
78
79 /* 90 /*
80 * check for print-score option 91 * check for print-score option
81 */ 92 */
82
83 md_normaluser(); /* we drop any setgid/setuid priveldges here */
84 93
85 if (argc == 2) 94 if (argc == 2)
86 { 95 {
87 if (strcmp(argv[1], "-s") == 0) 96 if (strcmp(argv[1], "-s") == 0)
88 { 97 {
103 exit(0); 112 exit(0);
104 } 113 }
105 } 114 }
106 115
107 init_check(); /* check for legal startup */ 116 init_check(); /* check for legal startup */
108 if (argc == 2) 117 if (use_savedir)
118 {
119 /* If there is a saved game, restore() will not return. If it
120 * returns 1, there isn't a game, so start one. If 0, there was
121 * an error. */
122 if (!restore(file_name))
123 my_exit(1);
124 }
125 else if (argc == 2)
109 if (!restore(argv[1])) /* Note: restore will never return */ 126 if (!restore(argv[1])) /* Note: restore will never return */
110 my_exit(1); 127 my_exit(1);
111 #ifdef MASTER 128 #ifdef MASTER
112 if (wizard) 129 if (wizard)
113 printf("Hello %s, welcome to dungeon #%d", whoami, dnum); 130 printf("Hello %s, welcome to dungeon #%d\n", whoami, dnum);
114 else 131 else
115 #endif 132 #endif
116 printf("Hello %s, just a moment while I dig the dungeon...", whoami); 133 printf("Hello %s, just a moment while I dig the dungeon...\n", whoami);
117 fflush(stdout); 134 fflush(stdout);
118 135
119 initscr(); /* Start up cursor package */ 136 initscr(); /* Start up cursor package */
120 init_probs(); /* Set up prob tables for objects */ 137 init_probs(); /* Set up prob tables for objects */
121 init_player(); /* Set up initial player stats */ 138 init_player(); /* Set up initial player stats */
233 * start back up again 250 * start back up again
234 */ 251 */
235 md_tstpresume(); 252 md_tstpresume();
236 raw(); 253 raw();
237 noecho(); 254 noecho();
255 nonl();
238 keypad(stdscr,1); 256 keypad(stdscr,1);
239 playltchars(); 257 playltchars();
240 clearok(curscr, TRUE); 258 clearok(curscr, TRUE);
241 wrefresh(curscr); 259 wrefresh(curscr);
242 getyx(curscr, y, x); 260 getyx(curscr, y, x);
309 signal(SIGINT, leave); 327 signal(SIGINT, leave);
310 clear(); 328 clear();
311 mvprintw(LINES - 2, 0, "You quit with %d gold pieces", purse); 329 mvprintw(LINES - 2, 0, "You quit with %d gold pieces", purse);
312 move(LINES - 1, 0); 330 move(LINES - 1, 0);
313 refresh(); 331 refresh();
332 writelog(purse, 1, 0);
314 score(purse, 1, 0); 333 score(purse, 1, 0);
315 my_exit(0); 334 my_exit(0);
316 } 335 }
317 else 336 else
318 { 337 {
375 */ 394 */
376 md_shellescape(); 395 md_shellescape();
377 396
378 noecho(); 397 noecho();
379 raw(); 398 raw();
399 nonl();
380 keypad(stdscr,1); 400 keypad(stdscr,1);
381 playltchars(); 401 playltchars();
382 in_shell = FALSE; 402 in_shell = FALSE;
383 clearok(stdscr, TRUE); 403 clearok(stdscr, TRUE);
384 } 404 }