/* 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"
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;
}
#ifdef JP
/*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
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)",
/* 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);
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);
bool send_world_score(bool do_send)
{
#ifdef WORLD_SCORE
- if(send_score && do_send)
+ if(send_score && do_send)
{
if(easy_band)
{
#endif
}
#ifdef JP
- else if(get_check_strict("¥¹¥³¥¢¤ò¥¹¥³¥¢¡¦¥µ¡¼¥Ð¤ËÅÐÏ¿¤·¤Þ¤¹¤«? ", 2))
+ 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;
(void)inkey();
}
else return FALSE;
- }
+ }
#endif
return TRUE;
}
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());
sprintf(the_score.max_dun, "%3d", max_dlv[dungeon_type]);
/* Save the cause of death (31 chars) */
-#ifdef JP
-#if 0
+ if (strlen(p_ptr->died_from) >= sizeof(the_score.how))
{
- /* 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)
- {
- 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 */
/* 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());
/* 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
* 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);
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
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];
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);
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)
*/
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
/* 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;
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);
}