Mercurial > hg > early-roguelike
comparison srogue/rip.c @ 173:78fa1d0e5d25
srogue: open the score and log files when the program starts.
Super-Rogue can now use the same privilege-dropping scheme as the other
games.
| author | John "Elwin" Edwards |
|---|---|
| date | Sat, 01 Aug 2015 15:12:11 -0400 |
| parents | 458df24e973d |
| children | f4f6734771e0 |
comparison
equal
deleted
inserted
replaced
| 172:c199a15a2c70 | 173:78fa1d0e5d25 |
|---|---|
| 44 " *| * * * * |*", | 44 " *| * * * * |*", |
| 45 " ________)\\\\//\\//\\)/\\//\\)/\\//\\)/\\//\\)/\\//\\//(________", | 45 " ________)\\\\//\\//\\)/\\//\\)/\\//\\)/\\//\\)/\\//\\//(________", |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 #define RIP_LINES (sizeof rip / (sizeof (char *))) | 48 #define RIP_LINES (sizeof rip / (sizeof (char *))) |
| 49 | |
| 50 extern int scorefd; | |
| 51 extern FILE *logfile; | |
| 49 | 52 |
| 50 char *killname(); | 53 char *killname(); |
| 51 void writelog(int amount, int aflag, char monst); | 54 void writelog(int amount, int aflag, char monst); |
| 52 | 55 |
| 53 /* | 56 /* |
| 138 showpack(FALSE, packend); | 141 showpack(FALSE, packend); |
| 139 } | 142 } |
| 140 /* | 143 /* |
| 141 * Open file and read list | 144 * Open file and read list |
| 142 */ | 145 */ |
| 143 if ((fd = open(scorefile, O_RDWR | O_CREAT, 0666)) < 0) | 146 if ((fd = scorefd) < 0) |
| 144 return; | 147 return; |
| 145 outf = (FILE *) fdopen(fd, "w"); | 148 outf = (FILE *) fdopen(fd, "w"); |
| 146 for (scp = top_ten; scp <= &top_ten[9]; scp++) { | 149 for (scp = top_ten; scp <= &top_ten[9]; scp++) { |
| 147 scp->sc_score = 0; | 150 scp->sc_score = 0; |
| 148 for (i = 0; i < 80; i++) | 151 for (i = 0; i < 80; i++) |
| 219 | 222 |
| 220 void writelog(int amount, int aflag, char monst) | 223 void writelog(int amount, int aflag, char monst) |
| 221 { | 224 { |
| 222 char logmessage[220], ltemp[80], mlev[40]; | 225 char logmessage[220], ltemp[80], mlev[40]; |
| 223 char *killer; | 226 char *killer; |
| 224 FILE *logfi; | |
| 225 | 227 |
| 226 if (waswizard) | 228 if (waswizard) |
| 227 return; | 229 return; |
| 228 #ifdef LOGFILE | 230 #ifdef LOGFILE |
| 231 if (logfile == NULL) | |
| 232 return; | |
| 229 sprintf(logmessage, "%d %d %s %d ", time(NULL), amount, whoami, | 233 sprintf(logmessage, "%d %d %s %d ", time(NULL), amount, whoami, |
| 230 him->s_lvl); | 234 him->s_lvl); |
| 231 if (amulet) | 235 if (amulet) |
| 232 sprintf(mlev, " [max %d] with the Amulet", max_level); | 236 sprintf(mlev, " [max %d] with the Amulet", max_level); |
| 233 else | 237 else |
| 245 max_level); | 249 max_level); |
| 246 } | 250 } |
| 247 else | 251 else |
| 248 return; | 252 return; |
| 249 strcat(logmessage, ltemp); | 253 strcat(logmessage, ltemp); |
| 250 logfi = fopen(LOGFILE, "a"); | 254 fprintf(logfile, "%s", logmessage); |
| 251 if (logfi == NULL) | 255 fclose(logfile); |
| 252 return; | |
| 253 fprintf(logfi, "%s", logmessage); | |
| 254 fclose(logfi); | |
| 255 #endif | 256 #endif |
| 256 return; | 257 return; |
| 257 } | 258 } |
| 258 | 259 |
| 259 /* | 260 /* |
