📄 hack.end.c
字号:
if(!done_stopprint) if(rank0 > 0){ if(rank0 <= 10) puts("You made the top ten list!\n"); else printf("You reached the %d%s place on the top %d list.\n\n", rank0, ordin(rank0), ENTRYMAX); } } if(rank0 == 0) rank0 = rank1; if(rank0 <= 0) rank0 = rank; if(!done_stopprint) outheader(); t1 = tt_head; for(rank = 1; t1->points != 0; rank++, t1 = t1->tt_next) { if(flg) fprintf(rfile,"%6s %d %d %d %d %d %ld %c%c %s,%s\n", t1->date, t1->uid, t1->level, t1->maxlvl, t1->hp, t1->maxhp, t1->points, t1->plchar, t1->sex, t1->name, t1->death); if(done_stopprint) continue; if(rank > flags.end_top && (rank < rank0-flags.end_around || rank > rank0+flags.end_around) && (!flags.end_own ||#ifdef PERS_IS_UID t1->uid != t0->uid ))#else strncmp(t1->name, t0->name, NAMSZ)))#endif PERS_IS_UID continue; if(rank == rank0-flags.end_around && rank0 > flags.end_top+flags.end_around+1 && !flags.end_own) (void) putchar('\n'); if(rank != rank0) (void) outentry(rank, t1, 0); else if(!rank1) (void) outentry(rank, t1, 1); else { int t0lth = outentry(0, t0, -1); int t1lth = outentry(rank, t1, t0lth); if(t1lth > t0lth) t0lth = t1lth; (void) outentry(0, t0, t0lth); } } if(rank0 >= rank) if(!done_stopprint) (void) outentry(0, t0, 1); (void) fclose(rfile);unlock: (void) unlink(reclock);}outheader() {char linebuf[BUFSZ];register char *bp; (void) strcpy(linebuf, "Number Points Name"); bp = eos(linebuf); while(bp < linebuf + COLNO - 9) *bp++ = ' '; (void) strcpy(bp, "Hp [max]"); puts(linebuf);}/* so>0: standout line; so=0: ordinary line; so<0: no output, return lth */intoutentry(rank,t1,so) register struct toptenentry *t1; {boolean quit = FALSE, killed = FALSE, starv = FALSE;char linebuf[BUFSZ]; linebuf[0] = 0; if(rank) Sprintf(eos(linebuf), "%3d", rank); else Sprintf(eos(linebuf), " "); Sprintf(eos(linebuf), " %6ld %8s", t1->points, t1->name); if(t1->plchar == 'X') Sprintf(eos(linebuf), " "); else Sprintf(eos(linebuf), "-%c ", t1->plchar); if(!strncmp("escaped", t1->death, 7)) { if(!strcmp(" (with amulet)", t1->death+7)) Sprintf(eos(linebuf), "escaped the dungeon with amulet"); else Sprintf(eos(linebuf), "escaped the dungeon [max level %d]", t1->maxlvl); } else { if(!strncmp(t1->death,"quit",4)) { quit = TRUE; if(t1->maxhp < 3*t1->hp && t1->maxlvl < 4) Sprintf(eos(linebuf), "cravenly gave up"); else Sprintf(eos(linebuf), "quit"); } else if(!strcmp(t1->death,"choked")) Sprintf(eos(linebuf), "choked on %s food", (t1->sex == 'F') ? "her" : "his"); else if(!strncmp(t1->death,"starv",5)) Sprintf(eos(linebuf), "starved to death"), starv = TRUE; else Sprintf(eos(linebuf), "was killed"), killed = TRUE; Sprintf(eos(linebuf), " on%s level %d", (killed || starv) ? "" : " dungeon", t1->level); if(t1->maxlvl != t1->level) Sprintf(eos(linebuf), " [max %d]", t1->maxlvl); if(quit && t1->death[4]) Sprintf(eos(linebuf), t1->death + 4); } if(killed) Sprintf(eos(linebuf), " by %s%s", (!strncmp(t1->death, "trick", 5) || !strncmp(t1->death, "the ", 4)) ? "" : index(vowels,*t1->death) ? "an " : "a ", t1->death); Sprintf(eos(linebuf), "."); if(t1->maxhp) { register char *bp = eos(linebuf); char hpbuf[10]; int hppos; Sprintf(hpbuf, (t1->hp > 0) ? itoa(t1->hp) : "-"); hppos = COLNO - 7 - strlen(hpbuf); if(bp <= linebuf + hppos) { while(bp < linebuf + hppos) *bp++ = ' '; (void) strcpy(bp, hpbuf); Sprintf(eos(bp), " [%d]", t1->maxhp); } } if(so == 0) puts(linebuf); else if(so > 0) { register char *bp = eos(linebuf); if(so >= COLNO) so = COLNO-1; while(bp < linebuf + so) *bp++ = ' '; *bp = 0; standoutbeg(); fputs(linebuf,stdout); standoutend(); (void) putchar('\n'); } return(strlen(linebuf));}char *itoa(a) int a; {static char buf[12]; Sprintf(buf,"%d",a); return(buf);}char *ordin(n) int n; {register int d = n%10; return((d==0 || d>3 || n/10==1) ? "th" : (d==1) ? "st" : (d==2) ? "nd" : "rd");}clearlocks(){register x; (void) signal(SIGHUP,SIG_IGN); for(x = maxdlevel; x >= 0; x--) { glo(x); (void) unlink(lock); /* not all levels need be present */ }}#ifdef NOSAVEONHANGUPhangup(){ (void) signal(SIGINT, SIG_IGN); clearlocks(); exit(1);}#endif NOSAVEONHANGUPchar *eos(s)register char *s;{ while(*s) s++; return(s);}/* it is the callers responsibility to check that there is room for c */charcat(s,c) register char *s, c; { while(*s) s++; *s++ = c; *s = 0;}/* * Called with args from main if argc >= 0. In this case, list scores as * requested. Otherwise, find scores for the current player (and list them * if argc == -1). */prscore(argc,argv) int argc; char **argv; { extern char *hname; char **players; int playerct; int rank; register struct toptenentry *t1, *t2; char *recfile = RECORD; FILE *rfile; register flg = 0; register int i;#ifdef nonsense long total_score = 0L; char totchars[10]; int totcharct = 0;#endif nonsense int outflg = (argc >= -1);#ifdef PERS_IS_UID int uid = -1;#else char *player0;#endif PERS_IS_UID if(!(rfile = fopen(recfile,"r"))){ puts("Cannot open record file!"); return; } if(argc > 1 && !strncmp(argv[1], "-s", 2)){ if(!argv[1][2]){ argc--; argv++; } else if(!argv[1][3] && index("CFKSTWX", argv[1][2])) { argv[1]++; argv[1][0] = '-'; } else argv[1] += 2; } if(argc <= 1){#ifdef PERS_IS_UID uid = getuid(); playerct = 0;#else player0 = plname; if(!*player0) player0 = "hackplayer"; playerct = 1; players = &player0;#endif PERS_IS_UID } else { playerct = --argc; players = ++argv; } if(outflg) putchar('\n'); t1 = tt_head = newttentry(); for(rank = 1; ; rank++) { if(fscanf(rfile, "%6s %d %d %d %d %d %ld %c%c %[^,],%[^\n]", t1->date, &t1->uid, &t1->level, &t1->maxlvl, &t1->hp, &t1->maxhp, &t1->points, &t1->plchar, &t1->sex, t1->name, t1->death) != 11) t1->points = 0; if(t1->points == 0) break;#ifdef PERS_IS_UID if(!playerct && t1->uid == uid) flg++; else#endif PERS_IS_UID for(i = 0; i < playerct; i++){ if(strcmp(players[i], "all") == 0 || strncmp(t1->name, players[i], NAMSZ) == 0 || (players[i][0] == '-' && players[i][1] == t1->plchar && players[i][2] == 0) || (digit(players[i][0]) && rank <= atoi(players[i]))) flg++; } t1 = t1->tt_next = newttentry(); } (void) fclose(rfile); if(!flg) { if(outflg) { printf("Cannot find any entries for "); if(playerct < 1) printf("you.\n"); else { if(playerct > 1) printf("any of "); for(i=0; i<playerct; i++) printf("%s%s", players[i], (i<playerct-1)?", ":".\n"); printf("Call is: %s -s [playernames]\n", hname); } } return; } if(outflg) outheader(); t1 = tt_head; for(rank = 1; t1->points != 0; rank++, t1 = t2) { t2 = t1->tt_next;#ifdef PERS_IS_UID if(!playerct && t1->uid == uid) goto outwithit; else#endif PERS_IS_UID for(i = 0; i < playerct; i++){ if(strcmp(players[i], "all") == 0 || strncmp(t1->name, players[i], NAMSZ) == 0 || (players[i][0] == '-' && players[i][1] == t1->plchar && players[i][2] == 0) || (digit(players[i][0]) && rank <= atoi(players[i]))){ outwithit: if(outflg) (void) outentry(rank, t1, 0);#ifdef nonsense total_score += t1->points; if(totcharct < sizeof(totchars)-1) totchars[totcharct++] = t1->plchar;#endif nonsense break; } } free((char *) t1); }#ifdef nonsense totchars[totcharct] = 0; /* We would like to determine whether he is experienced. However, the information collected here only tells about the scores/roles that got into the topten (top 100?). We should maintain a .hacklog or something in his home directory. */ flags.beginner = (total_score < 6000); for(i=0; i<6; i++) if(!index(totchars, "CFKSTWX"[i])) { flags.beginner = 1; if(!pl_character[0]) pl_character[0] = "CFKSTWX"[i]; break; }#endif nonsense}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -