]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/scores.c
clean up import, fix up Ids
[bsdgames-darwin.git] / larn / scores.c
1 #ifndef lint
2 static char rcsid[] = "$NetBSD: scores.c,v 1.4 1995/03/23 08:34:15 cgd Exp $";
3 #endif /* not lint */
4
5 /* scores.c Larn is copyrighted 1986 by Noah Morgan.
6 *
7 * Functions in this file are:
8 *
9 * readboard() Function to read in the scoreboard into a static buffer
10 * writeboard() Function to write the scoreboard from readboard()'s buffer
11 * makeboard() Function to create a new scoreboard (wipe out old one)
12 * hashewon() Function to return 1 if player has won a game before, else 0
13 * long paytaxes(x) Function to pay taxes if any are due
14 * winshou() Subroutine to print out the winning scoreboard
15 * shou(x) Subroutine to print out the non-winners scoreboard
16 * showscores() Function to show the scoreboard on the terminal
17 * showallscores() Function to show scores and the iven lists that go with them
18 * sortboard() Function to sort the scoreboard
19 * newscore(score, whoo, whyded, winner) Function to add entry to scoreboard
20 * new1sub(score,i,whoo,taxes) Subroutine to put player into a
21 * new2sub(score,i,whoo,whyded) Subroutine to put player into a
22 * died(x) Subroutine to record who played larn, and what the score was
23 * diedsub(x) Subroutine to print out a line showing player when he is killed
24 * diedlog() Subroutine to read a log file and print it out in ascii format
25 * getplid(name) Function to get players id # from id file
26 *
27 */
28 #include <sys/types.h>
29 #include <sys/times.h>
30 #include <sys/stat.h>
31 #include "header.h"
32
33 struct scofmt /* This is the structure for the scoreboard */
34 {
35 long score; /* the score of the player */
36 long suid; /* the user id number of the player */
37 short what; /* the number of the monster that killed player */
38 short level; /* the level player was on when he died */
39 short hardlev; /* the level of difficulty player played at */
40 short order; /* the relative ordering place of this entry */
41 char who[40]; /* the name of the character */
42 char sciv[26][2]; /* this is the inventory list of the character */
43 };
44 struct wscofmt /* This is the structure for the winning scoreboard */
45 {
46 long score; /* the score of the player */
47 long timeused; /* the time used in mobuls to win the game */
48 long taxes; /* taxes he owes to LRS */
49 long suid; /* the user id number of the player */
50 short hardlev; /* the level of difficulty player played at */
51 short order; /* the relative ordering place of this entry */
52 char who[40]; /* the name of the character */
53 };
54
55 struct log_fmt /* 102 bytes struct for the log file */
56 {
57 long score; /* the players score */
58 long diedtime; /* time when game was over */
59 short cavelev; /* level in caves */
60 short diff; /* difficulty player played at */
61 #ifdef EXTRA
62 long elapsedtime; /* real time of game in seconds */
63 long bytout; /* bytes input and output */
64 long bytin;
65 long moves; /* number of moves made by player */
66 short ac; /* armor class of player */
67 short hp,hpmax; /* players hitpoints */
68 short cputime; /* cpu time needed in seconds */
69 short killed,spused;/* monsters killed and spells cast */
70 short usage; /* usage of the cpu in % */
71 short lev; /* player level */
72 #endif
73 char who[12]; /* player name */
74 char what[46]; /* what happened to player */
75 };
76
77 static struct scofmt sco[SCORESIZE]; /* the structure for the scoreboard */
78 static struct wscofmt winr[SCORESIZE]; /* struct for the winning scoreboard */
79 static struct log_fmt logg; /* structure for the log file */
80 static char *whydead[] = {
81 "quit", "suspended", "self - annihilated", "shot by an arrow",
82 "hit by a dart", "fell into a pit", "fell into a bottomless pit",
83 "a winner", "trapped in solid rock", "killed by a missing save file",
84 "killed by an old save file", "caught by the greedy cheater checker trap",
85 "killed by a protected save file","killed his family and committed suicide",
86 "erased by a wayward finger", "fell through a bottomless trap door",
87 "fell through a trap door", "drank some poisonous water",
88 "fried by an electric shock", "slipped on a volcano shaft",
89 "killed by a stupid act of frustration", "attacked by a revolting demon",
90 "hit by his own magic", "demolished by an unseen attacker",
91 "fell into the dreadful sleep", "killed by an exploding chest",
92 /*26*/ "killed by a missing maze data file", "annihilated in a sphere",
93 "died a post mortem death","wasted by a malloc() failure"
94 };
95
96 /*
97 * readboard() Function to read in the scoreboard into a static buffer
98 *
99 * returns -1 if unable to read in the scoreboard, returns 0 if all is OK
100 */
101 readboard()
102 {
103 if (lopen(scorefile)<0)
104 { lprcat("Can't read scoreboard\n"); lflush(); return(-1); }
105 lrfill((char*)sco,sizeof(sco)); lrfill((char*)winr,sizeof(winr));
106 lrclose(); lcreat((char*)0); return(0);
107 }
108
109 /*
110 * writeboard() Function to write the scoreboard from readboard()'s buffer
111 *
112 * returns -1 if unable to write the scoreboard, returns 0 if all is OK
113 */
114 writeboard()
115 {
116 set_score_output();
117 if (lcreat(scorefile)<0)
118 { lprcat("Can't write scoreboard\n"); lflush(); return(-1); }
119 lwrite((char*)sco,sizeof(sco)); lwrite((char*)winr,sizeof(winr));
120 lwclose(); lcreat((char*)0); return(0);
121 }
122
123 /*
124 * makeboard() Function to create a new scoreboard (wipe out old one)
125 *
126 * returns -1 if unable to write the scoreboard, returns 0 if all is OK
127 */
128 makeboard()
129 {
130 register int i;
131 for (i=0; i<SCORESIZE; i++)
132 {
133 winr[i].taxes = winr[i].score = sco[i].score = 0;
134 winr[i].order = sco[i].order = i;
135 }
136 if (writeboard()) return(-1);
137 chmod(scorefile,0660);
138 return(0);
139 }
140
141 /*
142 * hashewon() Function to return 1 if player has won a game before, else 0
143 *
144 * This function also sets c[HARDGAME] to appropriate value -- 0 if not a
145 * winner, otherwise the next level of difficulty listed in the winners
146 * scoreboard. This function also sets outstanding_taxes to the value in
147 * the winners scoreboard.
148 */
149 hashewon()
150 {
151 register int i;
152 c[HARDGAME] = 0;
153 if (readboard() < 0) return(0); /* can't find scoreboard */
154 for (i=0; i<SCORESIZE; i++) /* search through winners scoreboard */
155 if (winr[i].suid == userid)
156 if (winr[i].score > 0)
157 {
158 c[HARDGAME]=winr[i].hardlev+1; outstanding_taxes=winr[i].taxes;
159 return(1);
160 }
161 return(0);
162 }
163
164 /*
165 * long paytaxes(x) Function to pay taxes if any are due
166 *
167 * Enter with the amount (in gp) to pay on the taxes.
168 * Returns amount actually paid.
169 */
170 long paytaxes(x)
171 long x;
172 {
173 register int i;
174 register long amt;
175 if (x<0) return(0L);
176 if (readboard()<0) return(0L);
177 for (i=0; i<SCORESIZE; i++)
178 if (winr[i].suid == userid) /* look for players winning entry */
179 if (winr[i].score>0) /* search for a winning entry for the player */
180 {
181 amt = winr[i].taxes;
182 if (x < amt) amt=x; /* don't overpay taxes (Ughhhhh) */
183 winr[i].taxes -= amt;
184 outstanding_taxes -= amt;
185 if (writeboard()<0) return(0);
186 return(amt);
187 }
188 return(0L); /* couldn't find user on winning scoreboard */
189 }
190
191 /*
192 * winshou() Subroutine to print out the winning scoreboard
193 *
194 * Returns the number of players on scoreboard that were shown
195 */
196 winshou()
197 {
198 register struct wscofmt *p;
199 register int i,j,count;
200 for (count=j=i=0; i<SCORESIZE; i++) /* is there anyone on the scoreboard? */
201 if (winr[i].score != 0)
202 { j++; break; }
203 if (j)
204 {
205 lprcat("\n Score Difficulty Time Needed Larn Winners List\n");
206
207 for (i=0; i<SCORESIZE; i++) /* this loop is needed to print out the */
208 for (j=0; j<SCORESIZE; j++) /* winners in order */
209 {
210 p = &winr[j]; /* pointer to the scoreboard entry */
211 if (p->order == i)
212 {
213 if (p->score)
214 {
215 count++;
216 lprintf("%10d %2d %5d Mobuls %s \n",
217 (long)p->score,(long)p->hardlev,(long)p->timeused,p->who);
218 }
219 break;
220 }
221 }
222 }
223 return(count); /* return number of people on scoreboard */
224 }
225
226 /*
227 * shou(x) Subroutine to print out the non-winners scoreboard
228 * int x;
229 *
230 * Enter with 0 to list the scores, enter with 1 to list inventories too
231 * Returns the number of players on scoreboard that were shown
232 */
233 shou(x)
234 int x;
235 {
236 register int i,j,n,k;
237 int count;
238 for (count=j=i=0; i<SCORESIZE; i++) /* is the scoreboard empty? */
239 if (sco[i].score!= 0)
240 { j++; break; }
241 if (j)
242 {
243 lprcat("\n Score Difficulty Larn Visitor Log\n");
244 for (i=0; i<SCORESIZE; i++) /* be sure to print them out in order */
245 for (j=0; j<SCORESIZE; j++)
246 if (sco[j].order == i)
247 {
248 if (sco[j].score)
249 {
250 count++;
251 lprintf("%10d %2d %s ",
252 (long)sco[j].score,(long)sco[j].hardlev,sco[j].who);
253 if (sco[j].what < 256) lprintf("killed by a %s",monster[sco[j].what].name);
254 else lprintf("%s",whydead[sco[j].what - 256]);
255 if (x != 263) lprintf(" on %s",levelname[sco[j].level]);
256 if (x)
257 {
258 for (n=0; n<26; n++) { iven[n]=sco[j].sciv[n][0]; ivenarg[n]=sco[j].sciv[n][1]; }
259 for (k=1; k<99; k++)
260 for (n=0; n<26; n++)
261 if (k==iven[n]) { srcount=0; show3(n); }
262 lprcat("\n\n");
263 }
264 else lprc('\n');
265 }
266 j=SCORESIZE;
267 }
268 }
269 return(count); /* return the number of players just shown */
270 }
271
272 /*
273 * showscores() Function to show the scoreboard on the terminal
274 *
275 * Returns nothing of value
276 */
277 static char esb[] = "The scoreboard is empty.\n";
278 showscores()
279 {
280 register int i,j;
281 lflush(); lcreat((char*)0); if (readboard()<0) return;
282 i=winshou(); j=shou(0);
283 if (i+j == 0) lprcat(esb); else lprc('\n');
284 lflush();
285 }
286
287 /*
288 * showallscores() Function to show scores and the iven lists that go with them
289 *
290 * Returns nothing of value
291 */
292 showallscores()
293 {
294 register int i,j;
295 lflush(); lcreat((char*)0); if (readboard()<0) return;
296 c[WEAR] = c[WIELD] = c[SHIELD] = -1; /* not wielding or wearing anything */
297 for (i=0; i<MAXPOTION; i++) potionname[i]=potionhide[i];
298 for (i=0; i<MAXSCROLL; i++) scrollname[i]=scrollhide[i];
299 i=winshou(); j=shou(1);
300 if (i+j==0) lprcat(esb); else lprc('\n');
301 lflush();
302 }
303
304 /*
305 * sortboard() Function to sort the scoreboard
306 *
307 * Returns 0 if no sorting done, else returns 1
308 */
309 sortboard()
310 {
311 register int i,j,pos;
312 long jdat;
313 for (i=0; i<SCORESIZE; i++) sco[i].order = winr[i].order = -1;
314 pos=0; while (pos < SCORESIZE)
315 {
316 jdat=0;
317 for (i=0; i<SCORESIZE; i++)
318 if ((sco[i].order < 0) && (sco[i].score >= jdat))
319 { j=i; jdat=sco[i].score; }
320 sco[j].order = pos++;
321 }
322 pos=0; while (pos < SCORESIZE)
323 {
324 jdat=0;
325 for (i=0; i<SCORESIZE; i++)
326 if ((winr[i].order < 0) && (winr[i].score >= jdat))
327 { j=i; jdat=winr[i].score; }
328 winr[j].order = pos++;
329 }
330 return(1);
331 }
332
333 /*
334 * newscore(score, whoo, whyded, winner) Function to add entry to scoreboard
335 * int score, winner, whyded;
336 * char *whoo;
337 *
338 * Enter with the total score in gp in score, players name in whoo,
339 * died() reason # in whyded, and TRUE/FALSE in winner if a winner
340 * ex. newscore(1000, "player 1", 32, 0);
341 */
342 newscore(score, whoo, whyded, winner)
343 long score;
344 int winner, whyded;
345 char *whoo;
346 {
347 register int i;
348 long taxes;
349 if (readboard() < 0) return; /* do the scoreboard */
350 /* if a winner then delete all non-winning scores */
351 if (cheat) winner=0; /* if he cheated, don't let him win */
352 if (winner)
353 {
354 for (i=0; i<SCORESIZE; i++) if (sco[i].suid == userid) sco[i].score=0;
355 taxes = score*TAXRATE;
356 score += 100000*c[HARDGAME]; /* bonus for winning */
357 /* if he has a slot on the winning scoreboard update it if greater score */
358 for (i=0; i<SCORESIZE; i++) if (winr[i].suid == userid)
359 { new1sub(score,i,whoo,taxes); return; }
360 /* he had no entry. look for last entry and see if he has a greater score */
361 for (i=0; i<SCORESIZE; i++) if (winr[i].order == SCORESIZE-1)
362 { new1sub(score,i,whoo,taxes); return; }
363 }
364 else if (!cheat) /* for not winning scoreboard */
365 {
366 /* if he has a slot on the scoreboard update it if greater score */
367 for (i=0; i<SCORESIZE; i++) if (sco[i].suid == userid)
368 { new2sub(score,i,whoo,whyded); return; }
369 /* he had no entry. look for last entry and see if he has a greater score */
370 for (i=0; i<SCORESIZE; i++) if (sco[i].order == SCORESIZE-1)
371 { new2sub(score,i,whoo,whyded); return; }
372 }
373 }
374
375 /*
376 * new1sub(score,i,whoo,taxes) Subroutine to put player into a
377 * int score,i,whyded,taxes; winning scoreboard entry if his score
378 * char *whoo; is high enough
379 *
380 * Enter with the total score in gp in score, players name in whoo,
381 * died() reason # in whyded, and TRUE/FALSE in winner if a winner
382 * slot in scoreboard in i, and the tax bill in taxes.
383 * Returns nothing of value
384 */
385 new1sub(score,i,whoo,taxes)
386 long score,taxes;
387 int i;
388 char *whoo;
389 {
390 register struct wscofmt *p;
391 p = &winr[i];
392 p->taxes += taxes;
393 if ((score >= p->score) || (c[HARDGAME] > p->hardlev))
394 {
395 strcpy(p->who,whoo); p->score=score;
396 p->hardlev=c[HARDGAME]; p->suid=userid;
397 p->timeused=gtime/100;
398 }
399 }
400
401 /*
402 * new2sub(score,i,whoo,whyded) Subroutine to put player into a
403 * int score,i,whyded,taxes; non-winning scoreboard entry if his
404 * char *whoo; score is high enough
405 *
406 * Enter with the total score in gp in score, players name in whoo,
407 * died() reason # in whyded, and slot in scoreboard in i.
408 * Returns nothing of value
409 */
410 new2sub(score,i,whoo,whyded)
411 long score;
412 int i,whyded;
413 char *whoo;
414 {
415 register int j;
416 register struct scofmt *p;
417 p = &sco[i];
418 if ((score >= p->score) || (c[HARDGAME] > p->hardlev))
419 {
420 strcpy(p->who,whoo); p->score=score;
421 p->what=whyded; p->hardlev=c[HARDGAME];
422 p->suid=userid; p->level=level;
423 for (j=0; j<26; j++)
424 { p->sciv[j][0]=iven[j]; p->sciv[j][1]=ivenarg[j]; }
425 }
426 }
427
428 /*
429 * died(x) Subroutine to record who played larn, and what the score was
430 * int x;
431 *
432 * if x < 0 then don't show scores
433 * died() never returns! (unless c[LIFEPROT] and a reincarnatable death!)
434 *
435 * < 256 killed by the monster number
436 * 256 quit
437 * 257 suspended
438 * 258 self - annihilated
439 * 259 shot by an arrow
440 * 260 hit by a dart
441 * 261 fell into a pit
442 * 262 fell into a bottomless pit
443 * 263 a winner
444 * 264 trapped in solid rock
445 * 265 killed by a missing save file
446 * 266 killed by an old save file
447 * 267 caught by the greedy cheater checker trap
448 * 268 killed by a protected save file
449 * 269 killed his family and killed himself
450 * 270 erased by a wayward finger
451 * 271 fell through a bottomless trap door
452 * 272 fell through a trap door
453 * 273 drank some poisonous water
454 * 274 fried by an electric shock
455 * 275 slipped on a volcano shaft
456 * 276 killed by a stupid act of frustration
457 * 277 attacked by a revolting demon
458 * 278 hit by his own magic
459 * 279 demolished by an unseen attacker
460 * 280 fell into the dreadful sleep
461 * 281 killed by an exploding chest
462 * 282 killed by a missing maze data file
463 * 283 killed by a sphere of annihilation
464 * 284 died a post mortem death
465 * 285 malloc() failure
466 * 300 quick quit -- don't put on scoreboard
467 */
468
469 static int scorerror;
470 died(x)
471 int x;
472 {
473 register int f,win;
474 char ch,*mod;
475 long zzz,i;
476 struct tms cputime;
477 if (c[LIFEPROT]>0) /* if life protection */
478 {
479 switch((x>0) ? x : -x)
480 {
481 case 256: case 257: case 262: case 263: case 265: case 266:
482 case 267: case 268: case 269: case 271: case 282: case 284:
483 case 285: case 300: goto invalid; /* can't be saved */
484 };
485 --c[LIFEPROT]; c[HP]=1; --c[CONSTITUTION];
486 cursors(); lprcat("\nYou feel wiiieeeeerrrrrd all over! "); beep();
487 lflush(); sleep(4);
488 return; /* only case where died() returns */
489 }
490 invalid:
491 clearvt100(); lflush(); f=0;
492 if (ckpflag) unlink(ckpfile); /* remove checkpoint file if used */
493 if (x<0) { f++; x = -x; } /* if we are not to display the scores */
494 if ((x == 300) || (x == 257)) exit(); /* for quick exit or saved game */
495 if (x == 263) win = 1; else win = 0;
496 c[GOLD] += c[BANKACCOUNT]; c[BANKACCOUNT] = 0;
497 /* now enter the player at the end of the scoreboard */
498 newscore(c[GOLD], logname, x, win);
499 diedsub(x); /* print out the score line */ lflush();
500
501 set_score_output();
502 if ((wizard == 0) && (c[GOLD] > 0)) /* wizards can't score */
503 {
504 #ifndef NOLOG
505 if (lappend(logfile)<0) /* append to file */
506 {
507 if (lcreat(logfile)<0) /* and can't create new log file */
508 {
509 lcreat((char*)0);
510 lprcat("\nCan't open record file: I can't post your score.\n");
511 sncbr(); resetscroll(); lflush(); exit();
512 }
513 chmod(logfile,0660);
514 }
515 strcpy(logg.who,loginname);
516 logg.score = c[GOLD]; logg.diff = c[HARDGAME];
517 if (x < 256)
518 {
519 ch = *monster[x].name;
520 if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
521 mod="an"; else mod="a";
522 sprintf(logg.what,"killed by %s %s",mod,monster[x].name);
523 }
524 else sprintf(logg.what,"%s",whydead[x - 256]);
525 logg.cavelev=level;
526 time(&zzz); /* get cpu time -- write out score info */
527 logg.diedtime=zzz;
528 #ifdef EXTRA
529 times(&cputime); /* get cpu time -- write out score info */
530 logg.cputime = i = (cputime.tms_utime + cputime.tms_stime)/60 + c[CPUTIME];
531 logg.lev=c[LEVEL]; logg.ac=c[AC];
532 logg.hpmax=c[HPMAX]; logg.hp=c[HP];
533 logg.elapsedtime=(zzz-initialtime+59)/60;
534 logg.usage=(10000*i)/(zzz-initialtime);
535 logg.bytin=c[BYTESIN]; logg.bytout=c[BYTESOUT];
536 logg.moves=c[MOVESMADE]; logg.spused=c[SPELLSCAST];
537 logg.killed=c[MONSTKILLED];
538 #endif
539 lwrite((char*)&logg,sizeof(struct log_fmt)); lwclose();
540 #endif NOLOG
541
542 /* now for the scoreboard maintenance -- not for a suspended game */
543 if (x != 257)
544 {
545 if (sortboard()) scorerror = writeboard();
546 }
547 }
548 if ((x==256) || (x==257) || (f != 0)) exit();
549 if (scorerror == 0) showscores(); /* if we updated the scoreboard */
550 if (x == 263) mailbill(); exit();
551 }
552
553 /*
554 * diedsub(x) Subroutine to print out the line showing the player when he is killed
555 * int x;
556 */
557 diedsub(x)
558 int x;
559 {
560 register char ch,*mod;
561 lprintf("Score: %d, Diff: %d, %s ",(long)c[GOLD],(long)c[HARDGAME],logname);
562 if (x < 256)
563 {
564 ch = *monster[x].name;
565 if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
566 mod="an"; else mod="a";
567 lprintf("killed by %s %s",mod,monster[x].name);
568 }
569 else lprintf("%s",whydead[x - 256]);
570 if (x != 263) lprintf(" on %s\n",levelname[level]); else lprc('\n');
571 }
572
573 /*
574 * diedlog() Subroutine to read a log file and print it out in ascii format
575 */
576 diedlog()
577 {
578 register int n;
579 register char *p;
580 struct stat stbuf;
581 lcreat((char*)0);
582 if (lopen(logfile)<0)
583 {
584 lprintf("Can't locate log file <%s>\n",logfile);
585 return;
586 }
587 if (fstat(fd,&stbuf) < 0)
588 {
589 lprintf("Can't stat log file <%s>\n",logfile);
590 return;
591 }
592 for (n=stbuf.st_size/sizeof(struct log_fmt); n>0; --n)
593 {
594 lrfill((char*)&logg,sizeof(struct log_fmt));
595 p = ctime(&logg.diedtime); p[16]='\n'; p[17]=0;
596 lprintf("Score: %d, Diff: %d, %s %s on %d at %s",(long)(logg.score),(long)(logg.diff),logg.who,logg.what,(long)(logg.cavelev),p+4);
597 #ifdef EXTRA
598 if (logg.moves<=0) logg.moves=1;
599 lprintf(" Experience Level: %d, AC: %d, HP: %d/%d, Elapsed Time: %d minutes\n",(long)(logg.lev),(long)(logg.ac),(long)(logg.hp),(long)(logg.hpmax),(long)(logg.elapsedtime));
600 lprintf(" CPU time used: %d seconds, Machine usage: %d.%02d%%\n",(long)(logg.cputime),(long)(logg.usage/100),(long)(logg.usage%100));
601 lprintf(" BYTES in: %d, out: %d, moves: %d, deaths: %d, spells cast: %d\n",(long)(logg.bytin),(long)(logg.bytout),(long)(logg.moves),(long)(logg.killed),(long)(logg.spused));
602 lprintf(" out bytes per move: %d, time per move: %d ms\n",(long)(logg.bytout/logg.moves),(long)((logg.cputime*1000)/logg.moves));
603 #endif
604 }
605 lflush(); lrclose(); return;
606 }
607
608 #ifndef UIDSCORE
609 /*
610 * getplid(name) Function to get players id # from id file
611 *
612 * Enter with the name of the players character in name.
613 * Returns the id # of the players character, or -1 if failure.
614 * This routine will try to find the name in the id file, if its not there,
615 * it will try to make a new entry in the file. Only returns -1 if can't
616 * find him in the file, and can't make a new entry in the file.
617 * Format of playerids file:
618 * Id # in ascii \n character name \n
619 */
620 static int havepid= -1; /* playerid # if previously done */
621 getplid(nam)
622 char *nam;
623 {
624 int fd7,high=999,no;
625 register char *p,*p2;
626 char name[80];
627 if (havepid != -1) return(havepid); /* already did it */
628 lflush(); /* flush any pending I/O */
629 sprintf(name,"%s\n",nam); /* append a \n to name */
630 if (lopen(playerids) < 0) /* no file, make it */
631 {
632 if ((fd7=creat(playerids,0666)) < 0) return(-1); /* can't make it */
633 close(fd7); goto addone; /* now append new playerid record to file */
634 }
635 for (;;) /* now search for the name in the player id file */
636 {
637 p = lgetl(); if (p==NULL) break; /* EOF? */
638 no = atoi(p); /* the id # */
639 p2= lgetl(); if (p2==NULL) break; /* EOF? */
640 if (no>high) high=no; /* accumulate highest id # */
641 if (strcmp(p2,name)==0) /* we found him */
642 {
643 return(no); /* his id number */
644 }
645 }
646 lrclose();
647 /* if we get here, we didn't find him in the file -- put him there */
648 addone:
649 if (lappend(playerids) < 0) return(-1); /* can't open file for append */
650 lprintf("%d\n%s",(long)++high,name); /* new id # and name */
651 lwclose();
652 lcreat((char*)0); /* re-open terminal channel */
653 return(high);
654 }
655 #endif UIDSCORE
656