Mercurial > hg > early-roguelike
comparison arogue5/rip.c @ 143:7faf4568c295
Advanced Rogue family: overhaul privilege handling.
Advanced Rogue 5 and 7, and XRogue, now open the scorefile and logfile
at startup and then drop any set[ug]id privileges if the savedir is not
being used.
author | John "Elwin" Edwards |
---|---|
date | Sat, 16 May 2015 13:39:26 -0400 |
parents | ee250e3646fd |
children | 80a590e67206 |
comparison
equal
deleted
inserted
replaced
142:6b5fbd7c3ece | 143:7faf4568c295 |
---|---|
33 | 33 |
34 /* | 34 /* |
35 * If you change this structure, change the compatibility routines | 35 * If you change this structure, change the compatibility routines |
36 * scoreout() and scorein() to reflect the change. Also update SCORELEN. | 36 * scoreout() and scorein() to reflect the change. Also update SCORELEN. |
37 */ | 37 */ |
38 | |
39 extern int scorefd; | |
40 extern FILE *logfile; | |
38 | 41 |
39 struct sc_ent { | 42 struct sc_ent { |
40 unsigned long sc_score; | 43 unsigned long sc_score; |
41 char sc_name[LINELEN]; | 44 char sc_name[LINELEN]; |
42 char sc_system[SYSLEN]; | 45 char sc_system[SYSLEN]; |
199 | 202 |
200 /* | 203 /* |
201 * Open file and read list | 204 * Open file and read list |
202 */ | 205 */ |
203 | 206 |
204 if ((fd = open(score_file, O_RDWR | O_CREAT, 0666)) < 0) | 207 if ((fd = scorefd) < 0) |
205 { | 208 { |
206 printf("\nCannot open score_file.\n"); | 209 printf("\nCannot open score_file.\n"); |
207 return; | 210 return; |
208 } | 211 } |
209 outf = (FILE *) fdopen(fd, "w"); | 212 outf = (FILE *) fdopen(fd, "w"); |
574 } | 577 } |
575 } | 578 } |
576 | 579 |
577 void writelog(unsigned long amount, int flags, short monst) { | 580 void writelog(unsigned long amount, int flags, short monst) { |
578 #ifdef LOGFILE | 581 #ifdef LOGFILE |
579 FILE *logfi; | |
580 char fate[100]; | 582 char fate[100]; |
581 char *class; | 583 char *class; |
582 struct linked_list *item; | 584 struct linked_list *item; |
583 struct object *obj; | 585 struct object *obj; |
584 char had_quest = '0'; | 586 char had_quest = '0'; |
585 | 587 |
586 if (waswizard) | 588 if (waswizard) |
589 return; | |
590 if (logfile == NULL) | |
587 return; | 591 return; |
588 switch (player.t_ctype) { | 592 switch (player.t_ctype) { |
589 case C_FIGHTER: class = "Fighter"; | 593 case C_FIGHTER: class = "Fighter"; |
590 when C_MAGICIAN: class = "Magician"; | 594 when C_MAGICIAN: class = "Magician"; |
591 when C_CLERIC: class = "Cleric"; | 595 when C_CLERIC: class = "Cleric"; |
607 sprintf(fate, "escaped"); | 611 sprintf(fate, "escaped"); |
608 } | 612 } |
609 else | 613 else |
610 return; | 614 return; |
611 | 615 |
612 logfi = fopen(LOGFILE, "a"); | 616 fprintf(logfile, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount, |
613 if (logfi == NULL) { | |
614 perror(LOGFILE); | |
615 return; | |
616 } | |
617 fprintf(logfi, "%d %d %s %d %s %d %d %d %c %s\n", time(NULL), amount, | |
618 whoami, pstats.s_lvl, class, level, max_level, quest_item, had_quest, | 617 whoami, pstats.s_lvl, class, level, max_level, quest_item, had_quest, |
619 fate); | 618 fate); |
620 fclose(logfi); | 619 fclose(logfile); |
621 #endif | 620 #endif |
622 return; | 621 return; |
623 } | 622 } |
624 | 623 |
625 /* | 624 /* |