X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fscores.c;h=8b40f21dbaa43765f8ae71a4bb75b48d87394b9a;hb=c604646ea324593ac15733b70d4c0e4cfc699d38;hp=3778f5900610adbcfe76b23756ae76bdaca27256;hpb=2236a858ecf93d5f0d411468c70cb9708aad9bdd;p=hengband%2Fhengband.git diff --git a/src/scores.c b/src/scores.c index 3778f5900..8b40f21db 100644 --- a/src/scores.c +++ b/src/scores.c @@ -1,15 +1,15 @@ /* File: scores.c */ -/* Purpose: Highscores handling */ - /* - * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke + * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke * - * This software may be copied and distributed for educational, research, and - * not for profit purposes provided that this copyright and statement are - * included in all such copies. + * This software may be copied and distributed for educational, research, + * and not for profit purposes provided that this copyright and statement + * are included in all such copies. Other copyrights may also apply. */ +/* Purpose: Highscores handling */ + #include "angband.h" @@ -68,7 +68,7 @@ static int highscore_where(high_score *score) int old_score; if (highscore_read(&the_score)) return (i); old_score = atoi(the_score.pts); -// if (strcmp(the_score.pts, score->pts) < 0) return (i); +/* if (strcmp(the_score.pts, score->pts) < 0) return (i); */ if (my_score > old_score) return (i); } @@ -139,6 +139,10 @@ void display_scores_aux(int from, int to, int note, high_score *score) char out_val[256]; char tmp_val[160]; + int wid, hgt, per_screen; + + Term_get_size(&wid, &hgt); + per_screen = (hgt - 4) / 4; /* Paranoia -- it may not have opened */ if (highscore_fd < 0) return; @@ -166,8 +170,8 @@ void display_scores_aux(int from, int to, int note, high_score *score) if (i > to) i = to; - /* Show 5 per page, until "done" */ - for (k = from, place = k+1; k < i; k += 5) + /* Show per_screen per page, until "done" */ + for (k = from, place = k+1; k < i; k += per_screen) { /* Clear screen */ Term_clear(); @@ -192,8 +196,8 @@ sprintf(tmp_val, "( %d put_str(tmp_val, 0, 40); } - /* Dump 5 entries */ - for (j = k, n = 0; j < i && n < 5; place++, j++, n++) + /* Dump per_screen entries */ + for (j = k, n = 0; j < i && n < per_screen; place++, j++, n++) { int pr, pc, pa, clev, mlev, cdun, mdun; @@ -243,26 +247,26 @@ sprintf(tmp_val, "( %d if ((*when == '@') && strlen(when) == 9) { sprintf(tmp_val, "%.4s-%.2s-%.2s", - when + 1, when + 5, when + 7); + when + 1, when + 5, when + 7); when = tmp_val; } /* Dump some info */ #ifdef JP -//sprintf(out_val, "%3d.%9s %s%s%s¤È¤¤¤¦Ì¾¤Î%s¤Î%s (¥ì¥Ù¥ë %d)", +/*sprintf(out_val, "%3d.%9s %s%s%s¤È¤¤¤¦Ì¾¤Î%s¤Î%s (¥ì¥Ù¥ë %d)", */ sprintf(out_val, "%3d.%9s %s%s%s - %s%s (¥ì¥Ù¥ë %d)", - place, the_score.pts, - seikaku_info[pa].title, (seikaku_info[pa].no ? "¤Î" : ""), + place, the_score.pts, + seikaku_info[pa].title, (seikaku_info[pa].no ? "¤Î" : ""), the_score.who, race_info[pr].title, class_info[pc].title, - clev); + clev); #else sprintf(out_val, "%3d.%9s %s %s the %s %s, Level %d", - place, the_score.pts, + place, the_score.pts, seikaku_info[pa].title, the_score.who, race_info[pr].title, class_info[pc].title, - clev); + clev); #endif @@ -285,31 +289,33 @@ if (mlev > clev) strcat(out_val, format(" ( sprintf(out_val, " "); - /* »àË´¸¶°ø¤ò¥ª¥ê¥¸¥Ê¥ë¤è¤êºÙ¤«¤¯É½¼¨ */ - if (streq(the_score.how, "yet")) - { - sprintf(out_val+13, " ¤Þ¤ÀÀ¸¤­¤Æ¤¤¤ë (%d%s)", - cdun, "³¬"); - } - else + /* »àË´¸¶°ø¤ò¥ª¥ê¥¸¥Ê¥ë¤è¤êºÙ¤«¤¯É½¼¨ */ + if (streq(the_score.how, "yet")) + { + sprintf(out_val+13, " ¤Þ¤ÀÀ¸¤­¤Æ¤¤¤ë (%d%s)", + cdun, "³¬"); + } + else if (streq(the_score.how, "ripe")) { - sprintf(out_val+13, " ¾¡Íø¤Î¸å¤Ë°úÂà (%d%s)", - cdun, "³¬"); + sprintf(out_val+13, " ¾¡Íø¤Î¸å¤Ë°úÂà (%d%s)", + cdun, "³¬"); } else if (streq(the_score.how, "Seppuku")) { - sprintf(out_val+13, " ¾¡Íø¤Î¸å¤ËÀÚÊ¢ (%d%s)", - cdun, "³¬"); + sprintf(out_val+13, " ¾¡Íø¤Î¸å¤ËÀÚÊ¢ (%d%s)", + cdun, "³¬"); } else { - /* Some people die outside of the dungeon */ - if (!cdun) - sprintf(out_val+13, " ÃϾå¤Ç%s¤Ë»¦¤µ¤ì¤¿", the_score.how); - else - sprintf(out_val+13, " %d³¬¤Ç%s¤Ë»¦¤µ¤ì¤¿", - cdun, the_score.how); + codeconv(the_score.how); + + /* Some people die outside of the dungeon */ + if (!cdun) + sprintf(out_val+13, " ÃϾå¤Ç%s¤Ë»¦¤µ¤ì¤¿", the_score.how); + else + sprintf(out_val+13, " %d³¬¤Ç%s¤Ë»¦¤µ¤ì¤¿", + cdun, the_score.how); } #else @@ -332,23 +338,23 @@ if (mlev > clev) strcat(out_val, format(" ( /* And still another line of info */ #ifdef JP - { - char buf[11]; - - /* ÆüÉÕ¤ò 19yy/mm/dd ¤Î·Á¼°¤ËÊѹ¹¤¹¤ë */ - if (strlen(when) == 8 && when[2] == '/' && when[5] == '/') { - sprintf(buf, "%d%s/%.5s", 19 + (when[6] < '8'), when + 6, when); - when = buf; - } - sprintf(out_val, - " (¥æ¡¼¥¶¡¼:%s, ÆüÉÕ:%s, ½ê»ý¶â:%s, ¥¿¡¼¥ó:%s)", - user, when, gold, aged); - } + { + char buf[11]; + + /* ÆüÉÕ¤ò 19yy/mm/dd ¤Î·Á¼°¤ËÊѹ¹¤¹¤ë */ + if (strlen(when) == 8 && when[2] == '/' && when[5] == '/') { + sprintf(buf, "%d%s/%.5s", 19 + (when[6] < '8'), when + 6, when); + when = buf; + } + sprintf(out_val, + " (¥æ¡¼¥¶¡¼:%s, ÆüÉÕ:%s, ½ê»ý¶â:%s, ¥¿¡¼¥ó:%s)", + user, when, gold, aged); + } #else sprintf(out_val, - " (User %s, Date %s, Gold %s, Turn %s).", - user, when, gold, aged); + " (User %s, Date %s, Gold %s, Turn %s).", + user, when, gold, aged); #endif c_put_str(attr, out_val, n*4 + 4, 0); @@ -357,13 +363,13 @@ if (mlev > clev) strcat(out_val, format(" ( /* Wait for response */ #ifdef JP -prt("[ ESC¤ÇÃæÃÇ, ¤½¤Î¾¤Î¥­¡¼¤Ç³¤±¤Þ¤¹ ]", 23, 21); +prt("[ ESC¤ÇÃæÃÇ, ¤½¤Î¾¤Î¥­¡¼¤Ç³¤±¤Þ¤¹ ]", hgt - 1, 21); #else - prt("[Press ESC to quit, any other key to continue.]", 23, 17); + prt("[Press ESC to quit, any other key to continue.]", hgt - 1, 17); #endif j = inkey(); - prt("", 23, 0); + prt("", hgt - 1, 0); /* Hack -- notice Escape */ if (j == ESCAPE) break; @@ -382,7 +388,7 @@ void display_scores(int from, int to) char buf[1024]; /* Build the filename */ - path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw"); + path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw"); /* Open the binary high score file, for reading */ highscore_fd = fd_open(buf, O_RDONLY); @@ -416,7 +422,7 @@ if (highscore_fd < 0) quit(" bool send_world_score(bool do_send) { #ifdef WORLD_SCORE - if(send_score && do_send) + if(send_score && do_send) { if(easy_band) { @@ -427,9 +433,9 @@ bool send_world_score(bool do_send) #endif } #ifdef JP - else if(get_check("¥¹¥³¥¢¤ò¥¹¥³¥¢¡¦¥µ¡¼¥Ð¤ËÅÐÏ¿¤·¤Þ¤¹¤«? ")) + else if(get_check_strict("¥¹¥³¥¢¤ò¥¹¥³¥¢¡¦¥µ¡¼¥Ð¤ËÅÐÏ¿¤·¤Þ¤¹¤«? ", (CHECK_NO_ESCAPE | CHECK_NO_HISTORY))) #else - else if(get_check("Do you send score to the world score sever? ")) + else if(get_check_strict("Do you send score to the world score sever? ", (CHECK_NO_ESCAPE | CHECK_NO_HISTORY))) #endif { errr err; @@ -455,7 +461,7 @@ bool send_world_score(bool do_send) (void)inkey(); } else return FALSE; - } + } #endif return TRUE; } @@ -474,12 +480,14 @@ errr top_twenty(void) time_t ct = time((time_t*)0); + errr err; + /* Clear the record */ (void)WIPE(&the_score, high_score); /* Save the version */ sprintf(the_score.what, "%u.%u.%u", - VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); + FAKE_VER_MAJOR, FAKE_VER_MINOR, FAKE_VER_PATCH); /* Calculate and save the points */ sprintf(the_score.pts, "%9ld", (long)total_points()); @@ -498,7 +506,7 @@ errr top_twenty(void) (void)sprintf(the_score.day, "%-.6s %-.2s", ctime(&ct) + 4, ctime(&ct) + 22); #else /* Save the date in standard form (8 chars) */ -// (void)strftime(the_score.day, 9, "%m/%d/%y", localtime(&ct)); +/* (void)strftime(the_score.day, 9, "%m/%d/%y", localtime(&ct)); */ /* Save the date in standard encoded form (9 chars) */ strftime(the_score.day, 10, "@%Y%m%d", localtime(&ct)); #endif @@ -520,49 +528,45 @@ errr top_twenty(void) sprintf(the_score.max_dun, "%3d", max_dlv[dungeon_type]); /* Save the cause of death (31 chars) */ -#ifdef JP -#if 0 - { - /* 2byte ʸ»ú¤ò¹Íθ¤·¤Ê¤¬¤é¥³¥Ô¡¼(EUC ¤ò²¾Äê) */ - int cnt = 0; - unsigned char *d = (unsigned char*)died_from; - unsigned char *h = (unsigned char*)the_score.how; - while(*d && cnt < 31){ - if(iskanji(*d)){ - if(cnt + 2 > 31) break; - *h++ = *d++; - *h++ = *d++; - cnt += 2; - }else{ - if(cnt + 1 > 31) break; - *h++ = *d++; - cnt++; - } - } - *h = '\0'; - } -#endif - if (strlen(died_from) >= 39) + if (strlen(p_ptr->died_from) >= sizeof(the_score.how)) { - mb_strlcpy(the_score.how, died_from, 37+1); +#ifdef JP + my_strcpy(the_score.how, p_ptr->died_from, sizeof(the_score.how) - 2); strcat(the_score.how, "¡Ä"); - } - else - strcpy(the_score.how, died_from); - #else - sprintf(the_score.how, "%-.31s", died_from); + my_strcpy(the_score.how, p_ptr->died_from, sizeof(the_score.how) - 3); + strcat(the_score.how, "..."); #endif + } + else + { + strcpy(the_score.how, p_ptr->died_from); + } + /* Grab permissions */ + safe_setuid_grab(); /* Lock (for writing) the highscore file, or fail */ - if (fd_lock(highscore_fd, F_WRLCK)) return (1); + err = fd_lock(highscore_fd, F_WRLCK); + + /* Drop permissions */ + safe_setuid_drop(); + + if (err) return (1); /* Add a new entry to the score list, see where it went */ j = highscore_add(&the_score); + /* Grab permissions */ + safe_setuid_grab(); + /* Unlock the highscore file, or fail */ - if (fd_lock(highscore_fd, F_UNLCK)) return (1); + err = fd_lock(highscore_fd, F_UNLCK); + + /* Drop permissions */ + safe_setuid_drop(); + + if (err) return (1); /* Hack -- Display the top fifteen scores */ @@ -610,7 +614,7 @@ msg_print(" /* Save the version */ sprintf(the_score.what, "%u.%u.%u", - VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); + FAKE_VER_MAJOR, FAKE_VER_MINOR, FAKE_VER_PATCH); /* Calculate and save the points */ sprintf(the_score.pts, "%9ld", (long)total_points()); @@ -647,8 +651,8 @@ strcpy(the_score.day, " /* Hack -- no cause of death */ #ifdef JP - /* ¤Þ¤À»à¤ó¤Ç¤¤¤Ê¤¤¤È¤­¤Î¼±ÊÌʸ»ú */ - strcpy(the_score.how, "yet"); + /* ¤Þ¤À»à¤ó¤Ç¤¤¤Ê¤¤¤È¤­¤Î¼±ÊÌʸ»ú */ + strcpy(the_score.how, "yet"); #else strcpy(the_score.how, "nobody (yet!)"); #endif @@ -683,18 +687,18 @@ strcpy(the_score.day, " * show_highclass - selectively list highscores based on class * -KMW- */ -void show_highclass(int building) +void show_highclass(void) { register int i = 0, j, m = 0; - int pr, pc, pa, clev/*, al*/; + int pr, clev/*, al*/; high_score the_score; char buf[1024], out_val[256]; screen_save(); /* Build the filename */ - path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw"); + path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw"); highscore_fd = fd_open(buf, O_RDONLY); @@ -724,8 +728,6 @@ msg_print(" if (highscore_seek(j)) break; if (highscore_read(&the_score)) break; pr = atoi(the_score.p_r); - pc = atoi(the_score.p_c); - pa = atoi(the_score.p_a); clev = atoi(the_score.cur_lev); #ifdef JP @@ -773,7 +775,7 @@ msg_print(" void race_score(int race_num) { register int i = 0, j, m = 0; - int pr, pc, pa, clev, lastlev; + int pr, clev, lastlev; high_score the_score; char buf[1024], out_val[256], tmp_str[80]; @@ -789,7 +791,7 @@ sprintf(tmp_str," prt(tmp_str, 5, 15); /* Build the filename */ - path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw"); + path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw"); highscore_fd = fd_open(buf, O_RDONLY); @@ -820,8 +822,6 @@ msg_print(" if (highscore_seek(j)) break; if (highscore_read(&the_score)) break; pr = atoi(the_score.p_r); - pc = atoi(the_score.p_c); - pa = atoi(the_score.p_a); clev = atoi(the_score.cur_lev); if (pr == race_num) @@ -891,16 +891,20 @@ msg_print(" */ void kingly(void) { + int wid, hgt; + int cx, cy; + bool seppuku = streq(p_ptr->died_from, "Seppuku"); + /* Hack -- retire in town */ dun_level = 0; /* Fake death */ - if (!streq(died_from, "Seppuku")) + if (!seppuku) #ifdef JP - /* °úÂष¤¿¤È¤­¤Î¼±ÊÌʸ»ú */ - (void)strcpy(died_from, "ripe"); + /* °úÂष¤¿¤È¤­¤Î¼±ÊÌʸ»ú */ + (void)strcpy(p_ptr->died_from, "ripe"); #else - (void)strcpy(died_from, "Ripe Old Age"); + (void)strcpy(p_ptr->died_from, "Ripe Old Age"); #endif @@ -910,6 +914,10 @@ void kingly(void) /* Restore the level */ p_ptr->lev = p_ptr->max_plv; + Term_get_size(&wid, &hgt); + cy = hgt / 2; + cx = wid / 2; + /* Hack -- Instant Gold */ p_ptr->au += 10000000L; @@ -917,42 +925,46 @@ void kingly(void) Term_clear(); /* Display a crown */ - put_str("#", 1, 34); - put_str("#####", 2, 32); - put_str("#", 3, 34); - put_str(",,, $$$ ,,,", 4, 28); - put_str(",,=$ \"$$$$$\" $=,,", 5, 24); - put_str(",$$ $$$ $$,", 6, 22); - put_str("*> <*> <*", 7, 22); - put_str("$$ $$$ $$", 8, 22); - put_str("\"$$ $$$ $$\"", 9, 22); - put_str("\"$$ $$$ $$\"", 10, 23); - put_str("*#########*#########*", 11, 24); - put_str("*#########*#########*", 12, 24); + put_str("#", cy - 11, cx - 1); + put_str("#####", cy - 10, cx - 3); + put_str("#", cy - 9, cx - 1); + put_str(",,, $$$ ,,,", cy - 8, cx - 7); + put_str(",,=$ \"$$$$$\" $=,,", cy - 7, cx - 11); + put_str(",$$ $$$ $$,", cy - 6, cx - 13); + put_str("*> <*> <*", cy - 5, cx - 13); + put_str("$$ $$$ $$", cy - 4, cx - 13); + put_str("\"$$ $$$ $$\"", cy - 3, cx - 13); + put_str("\"$$ $$$ $$\"", cy - 2, cx - 12); + put_str("*#########*#########*", cy - 1, cx - 11); + put_str("*#########*#########*", cy, cx - 11); /* Display a message */ #ifdef JP -put_str("Veni, Vidi, Vici!", 15, 26); -put_str("Í褿¡¢¸«¤¿¡¢¾¡¤Ã¤¿¡ª", 16, 25); -put_str(format("°ÎÂç¤Ê¤ë%sËüºÐ¡ª", sp_ptr->winner), 17, 22); + put_str("Veni, Vidi, Vici!", cy + 3, cx - 9); + put_str("Í褿¡¢¸«¤¿¡¢¾¡¤Ã¤¿¡ª", cy + 4, cx - 10); + put_str(format("°ÎÂç¤Ê¤ë%sËüºÐ¡ª", sp_ptr->winner), cy + 5, cx - 11); #else - put_str("Veni, Vidi, Vici!", 15, 26); - put_str("I came, I saw, I conquered!", 16, 21); - put_str(format("All Hail the Mighty %s!", sp_ptr->winner), 17, 22); + put_str("Veni, Vidi, Vici!", cy + 3, cx - 9); + put_str("I came, I saw, I conquered!", cy + 4, cx - 14); + put_str(format("All Hail the Mighty %s!", sp_ptr->winner), cy + 5, cx - 13); #endif + /* If player did Seppuku, that is already written in playrecord */ + if (!seppuku) + { #ifdef JP - do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥À¥ó¥¸¥ç¥ó¤Îõº÷¤«¤é°úÂष¤¿¡£"); - do_cmd_write_nikki(NIKKI_GAMESTART, 1, "-------- ¥²¡¼¥à¥ª¡¼¥Ð¡¼ --------"); + do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥À¥ó¥¸¥ç¥ó¤Îõº÷¤«¤é°úÂष¤¿¡£"); + do_cmd_write_nikki(NIKKI_GAMESTART, 1, "-------- ¥²¡¼¥à¥ª¡¼¥Ð¡¼ --------"); #else - do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "retire exploring dungeons."); - do_cmd_write_nikki(NIKKI_GAMESTART, 1, "-------- Game Over --------"); + do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "retired exploring dungeons."); + do_cmd_write_nikki(NIKKI_GAMESTART, 1, "-------- Game Over --------"); #endif - do_cmd_write_nikki(NIKKI_BUNSHOU, 1, "\n\n\n\n"); + do_cmd_write_nikki(NIKKI_BUNSHOU, 1, "\n\n\n\n"); + } /* Flush input */ flush(); /* Wait for response */ - pause_line(23); + pause_line(hgt - 1); }