void build_score(high_score *entry, const char *died_from, time_t *death_time) { memset(entry, 0, sizeof(high_score)); /* Save the version */ strnfmt(entry->what, sizeof(entry->what), "%s", buildid); /* Calculate and save the points */ strnfmt(entry->pts, sizeof(entry->pts), "%9u", total_points()); /* Save the current gold */ strnfmt(entry->gold, sizeof(entry->gold), "%9u", player->au); /* Save the current turn */ strnfmt(entry->turns, sizeof(entry->turns), "%9u", turn); /* Time of death */ if (death_time) strftime(entry->day, sizeof(entry->day), "@%Y%m%d", localtime(death_time)); else my_strcpy(entry->day, "TODAY", sizeof(entry->day)); /* Save the player name (15 chars) */ strnfmt(entry->who, sizeof(entry->who), "%-.15s", player->full_name); /* Save the player info XXX XXX XXX */ strnfmt(entry->uid, sizeof(entry->uid), "%7u", player_uid); strnfmt(entry->p_r, sizeof(entry->p_r), "%2d", player->race->ridx); strnfmt(entry->p_c, sizeof(entry->p_c), "%2d", player->class->cidx); /* Save the level and such */ strnfmt(entry->cur_lev, sizeof(entry->cur_lev), "%3d", player->lev); strnfmt(entry->cur_dun, sizeof(entry->cur_dun), "%3d", player->depth); strnfmt(entry->max_lev, sizeof(entry->max_lev), "%3d", player->max_lev); strnfmt(entry->max_dun, sizeof(entry->max_dun), "%3d", player->max_depth); /* No cause of death */ my_strcpy(entry->how, died_from, sizeof(entry->how)); }
static void build_score(high_score *entry, const char *died_from, time_t *death_time) { WIPE(entry, high_score); /* Save the version */ strnfmt(entry->what, sizeof(entry->what), "%s", VERSION_STRING); /* Calculate and save the points */ strnfmt(entry->pts, sizeof(entry->pts), "%9lu", (long)total_points()); /* Save the current gold */ strnfmt(entry->gold, sizeof(entry->gold), "%9lu", (long)p_ptr->au); /* Save the current turn */ strnfmt(entry->turns, sizeof(entry->turns), "%9lu", (long)turn); /* Time of death */ if (death_time) strftime(entry->day, sizeof(entry->day), "@%Y%m%d", localtime(death_time)); else my_strcpy(entry->day, "TODAY", sizeof(entry->day)); /* Save the player name (15 chars) */ strnfmt(entry->who, sizeof(entry->who), "%-.15s", op_ptr->full_name); /* Save the player info XXX XXX XXX */ strnfmt(entry->uid, sizeof(entry->uid), "%7u", player_uid); strnfmt(entry->sex, sizeof(entry->sex), "%c", (p_ptr->psex ? 'm' : 'f')); strnfmt(entry->p_r, sizeof(entry->p_r), "%2d", p_ptr->prace); strnfmt(entry->p_c, sizeof(entry->p_c), "%2d", p_ptr->pclass); /* Save the level and such */ strnfmt(entry->cur_lev, sizeof(entry->cur_lev), "%3d", p_ptr->lev); strnfmt(entry->cur_dun, sizeof(entry->cur_dun), "%3d", p_ptr->depth); strnfmt(entry->max_lev, sizeof(entry->max_lev), "%3d", p_ptr->max_lev); strnfmt(entry->max_dun, sizeof(entry->max_dun), "%3d", p_ptr->max_depth); /* No cause of death */ my_strcpy(entry->how, died_from, sizeof(entry->how)); }
errr report_score(void) { #ifdef MACINTOSH OSStatus err; #else errr err = 0; #endif #ifdef WINDOWS WSADATA wsaData; WORD wVersionRequested =(WORD) (( 1) | ( 1 << 8)); #endif BUF *score; int sd; char seikakutmp[128]; score = buf_new(); sprintf(seikakutmp, "%s ", ap_ptr->title); buf_sprintf(score, "name: %s\n", player_name); buf_sprintf(score, "version: Hengband %d.%d.%d\n", FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH); buf_sprintf(score, "score: %d\n", total_points()); buf_sprintf(score, "level: %d\n", p_ptr->lev); buf_sprintf(score, "depth: %d\n", dun_level); buf_sprintf(score, "maxlv: %d\n", p_ptr->max_plv); buf_sprintf(score, "maxdp: %d\n", max_dlv[DUNGEON_ANGBAND]); buf_sprintf(score, "au: %d\n", p_ptr->au); buf_sprintf(score, "turns: %d\n", turn_real(turn)); buf_sprintf(score, "sex: %d\n", p_ptr->psex); buf_sprintf(score, "race: %s\n", rp_ptr->title); buf_sprintf(score, "class: %s\n", cp_ptr->title); buf_sprintf(score, "seikaku: %s\n", seikakutmp); buf_sprintf(score, "realm1: %s\n", realm_names[p_ptr->realm1]); buf_sprintf(score, "realm2: %s\n", realm_names[p_ptr->realm2]); buf_sprintf(score, "killer: %s\n", p_ptr->died_from); buf_sprintf(score, "-----charcter dump-----\n"); make_dump(score); if (screen_dump) { buf_sprintf(score, "-----screen shot-----\n"); buf_append(score, screen_dump, strlen(screen_dump)); } #ifdef WINDOWS if (WSAStartup(wVersionRequested, &wsaData)) { msg_print("Report: WSAStartup failed."); goto report_end; } #endif #ifdef MACINTOSH #if TARGET_API_MAC_CARBON err = InitOpenTransportInContext(kInitOTForApplicationMask, NULL); #else err = InitOpenTransport(); #endif if (err != noErr) { msg_print("Report: OpenTransport failed."); return 1; } #endif Term_clear(); while (1) { char buff[160]; prt("connecting...", 0, 0); Term_fresh(); /* プロキシを設定する */ set_proxy(HTTP_PROXY, HTTP_PROXY_PORT); /* Connect to the score server */ sd = connect_server(HTTP_TIMEOUT, SCORE_SERVER, SCORE_PORT); if (!(sd < 0)) break; sprintf(buff, "Failed to connect to the score server.(%s)", soc_err()); prt(buff, 0, 0); (void)inkey(); if (!get_check_strict("Try again? ", CHECK_NO_HISTORY)) { err = 1; goto report_end; } } prt("Sending the score...", 0, 0); Term_fresh(); http_post(sd, SCORE_PATH, score); disconnect_server(sd); report_end: #ifdef WINDOWS WSACleanup(); #endif #ifdef MACINTOSH #if TARGET_API_MAC_CARBON CloseOpenTransportInContext(NULL); #else CloseOpenTransport(); #endif #endif return err; }
void top_twenty(integer this_many) { /*{ Enters a players name on the top twenty list -JWT- }*/ string list[MAX_HIGH_SCORES+2]; integer players_line = 0; integer i1,i2,i3,i4; int n1; vtype o1,s1; FILE *f1; boolean flag; char ch; if (py.misc.cheated) { exit_game(); } clear_screen(); if (!read_top_scores(&f1, MORIA_TOP, list, MAX_HIGH_SCORES, &n1, s1)) { prt(s1,2,1); prt("",3,1); } else { i3 = total_points(); flag = false; if (i3 == 0) { i1 = n1; } else { for (i1=1; (i1 <= n1) && !flag ; ) { /* XXXX check for corruption */ sscanf(&(list[i1][13]),"%ld",&i4); if (i4 < i3) { flag = true; } else { i1++; } } } if ((i3 > 0) && ((flag) || (n1 == 0) || (n1 < MAX_HIGH_SCORES))) { for (i2 = MAX_HIGH_SCORES-1; i2 >= i1 ; i2--) { strcpy(list[i2+1], list[i2]); } user_name(o1); format_top_score(list[i1], o1, i3, PM.diffic, PM.name, PM.lev, PM.race, PM.tclass); if (n1 < MAX_HIGH_SCORES) { n1++; } max_score = n1; players_line = i1; flag = false; write_top_scores(&f1, list, n1); } else { /* did not get a high score */ max_score = 20; } if (!close_top_scores(&f1)) { prt("Error unlocking score file.",2,1); prt("",3,1); } put_buffer("Username Points Diff Character name Level Race Class",1,1); put_buffer("____________ ________ _ ________________________ __ __________ ________________",2,1); i2 = 3; if (max_score > n1) { max_score = n1; } if (this_many > 0) { if (this_many > MAX_HIGH_SCORES) { max_score = MAX_HIGH_SCORES; } else { max_score = this_many; } } for (i1 = 1; i1 <= max_score; i1++) { /*insert_str(list[i1],chr(7),''); XXXX why? */ if (i1 == players_line) { put_buffer_attr(list[i1],i2,1, A_REVERSE); } else { put_buffer(list[i1],i2,1); } if ((i1 != 1) && ((i1 % 20) == 0) && (i1 != max_score)) { prt("[Press any key to continue, or <Control>-Z to exit]", 24,1); ch = inkey(); switch (ch) { case 3: case 25: case 26: erase_line(24,1); put_buffer(" ",23,13); exit_game(); break; } clear_rc(3,1); i2 = 2; } i2++; } /* end for */ erase_line(23,1); put_qio(); } /* end if read_top_scores */ };
/* * Predict the players location, and display it. */ errr predict_score(void) { int j; high_score the_score; /* No score file */ if (highscore_fd < 0) { msg_print("Score file unavailable."); msg_print(NULL); return (0); } /* Save the version */ sprintf(the_score.what, "%u.%u.%u", VER_MAJOR, VER_MINOR, VER_PATCH); /* Calculate and save the points */ sprintf(the_score.pts, "%9ld", (long)total_points()); /* Save the current gold */ sprintf(the_score.gold, "%9d", p_ptr->au); /* Save the current turn */ sprintf(the_score.turns, "%9d", turn_real(turn)); /* Hack -- no time needed */ strcpy(the_score.day, "TODAY"); /* Save the player name (15 chars) */ sprintf(the_score.who, "%-.15s", player_name); /* Save the player info XXX XXX XXX */ sprintf(the_score.uid, "%7u", player_uid); sprintf(the_score.sex, "%c", (p_ptr->psex ? 'm' : 'f')); sprintf(the_score.p_r, "%2d", p_ptr->prace); sprintf(the_score.p_c, "%2d", p_ptr->pclass); sprintf(the_score.p_a, "%2d", p_ptr->personality); /* Save the level and such */ sprintf(the_score.cur_lev, "%3d", p_ptr->lev); sprintf(the_score.cur_dun, "%3d", dun_level); sprintf(the_score.max_lev, "%3d", p_ptr->max_plv); sprintf(the_score.max_dun, "%3d", max_dlv[dungeon_type]); /* Hack -- no cause of death */ strcpy(the_score.how, "nobody (yet!)"); /* See where the entry would be placed */ j = highscore_where(&the_score); /* Hack -- Display the top fifteen scores */ if (j < 10) { display_scores_aux(0, 15, j, &the_score); } /* Display some "useful" scores */ else { display_scores_aux(0, 5, -1, NULL); display_scores_aux(j - 2, j + 7, j, &the_score); } /* Success */ return (0); }
/* * Enters a players name on a hi-score table, if "legal", and in any * case, displays some relevant portion of the high score list. * * Assumes "signals_ignore_tstp()" has been called. */ errr top_twenty(void) { int j; high_score the_score; 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", VER_MAJOR, VER_MINOR, VER_PATCH); /* Calculate and save the points */ sprintf(the_score.pts, "%9ld", (long)total_points()); the_score.pts[9] = '\0'; /* Save the current gold */ sprintf(the_score.gold, "%9d", p_ptr->au); the_score.gold[9] = '\0'; /* Save the current turn */ sprintf(the_score.turns, "%9d", turn_real(turn)); the_score.turns[9] = '\0'; #ifdef HIGHSCORE_DATE_HACK /* Save the date in a hacked up form (9 chars) */ (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)); */ /* Save the date in standard encoded form (9 chars) */ strftime(the_score.day, 10, "@%Y%m%d", localtime(&ct)); #endif /* Save the player name (15 chars) */ sprintf(the_score.who, "%-.15s", player_name); /* Save the player info XXX XXX XXX */ sprintf(the_score.uid, "%7u", player_uid); sprintf(the_score.sex, "%c", (p_ptr->psex ? 'm' : 'f')); sprintf(the_score.p_r, "%2d", p_ptr->prace); sprintf(the_score.p_c, "%2d", p_ptr->pclass); sprintf(the_score.p_a, "%2d", p_ptr->personality); /* Save the level and such */ sprintf(the_score.cur_lev, "%3d", p_ptr->lev); sprintf(the_score.cur_dun, "%3d", dun_level); sprintf(the_score.max_lev, "%3d", p_ptr->max_plv); sprintf(the_score.max_dun, "%3d", max_dlv[dungeon_type]); /* Save the cause of death (31 chars) */ if (strlen(p_ptr->died_from) >= sizeof(the_score.how)) { my_strcpy(the_score.how, p_ptr->died_from, sizeof(the_score.how) - 3); strcat(the_score.how, "..."); } else { strcpy(the_score.how, p_ptr->died_from); } /* Grab permissions */ safe_setuid_grab(); /* Lock (for writing) the highscore file, or fail */ 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 */ err = fd_lock(highscore_fd, F_UNLCK); /* Drop permissions */ safe_setuid_drop(); if (err) return (1); /* Hack -- Display the top fifteen scores */ if (j < 10) { display_scores_aux(0, 15, j, NULL); } /* Display the scores surrounding the player */ else { display_scores_aux(0, 5, j, NULL); display_scores_aux(j - 2, j + 7, j, NULL); } /* Success */ return (0); }