xref: /dragonfly/games/phantasia/gamesupport.c (revision f02303f9)
1 /*
2  * gamesupport.c - auxiliary routines for support of Phantasia
3  *
4  * $FreeBSD: src/games/phantasia/gamesupport.c,v 1.6 1999/11/16 02:57:33 billf Exp $
5  * $DragonFly: src/games/phantasia/gamesupport.c,v 1.3 2005/05/31 00:06:26 swildner Exp $
6  */
7 
8 #include <string.h>
9 #include "include.h"
10 
11 /* functions which we need to know about */
12 /* interplayer.c */
13 extern	void	userlist(bool);
14 /* io.c */
15 extern	int	getanswer(const char *, bool);
16 extern	void	getstring(char *, int);
17 extern	double	infloat(void);
18 extern	void	more(int);
19 /* main.c */
20 extern	void	cleanup(bool);
21 /* misc.c */
22 extern	const char	*descrstatus(struct player *);
23 extern	const char	*descrtype(struct player *, bool);
24 extern	void	error(const char *);
25 extern	long	findname(char *, struct player *);
26 extern	void	freerecord(struct player *, long);
27 extern	void	truncstring(char *);
28 extern	void	writerecord(struct player *, long);
29 
30 void	changestats(bool);
31 void	monstlist(void);
32 void	scorelist(void);
33 void	activelist(void);
34 void	purgeoldplayers(void);
35 void	enterscore(void);
36 
37 /************************************************************************
38 /
39 / FUNCTION NAME: changestats()
40 /
41 / FUNCTION: examine/change statistics for a player
42 /
43 / AUTHOR: E. A. Estes, 12/4/85
44 /
45 / ARGUMENTS:
46 /	bool ingameflag - set if called while playing game (Wizard only)
47 /
48 / RETURN VALUE: none
49 /
50 / MODULES CALLED: freerecord(), writerecord(), descrstatus(), truncstring(),
51 /	time(), more(), wmove(), wclear(), strcmp(), printw(), strcpy(),
52 /	infloat(), waddstr(), cleanup(), findname(), userlist(), mvprintw(),
53 /	localtime(), getanswer(), descrtype(), getstring()
54 /
55 / GLOBAL INPUTS: LINES, *Login, Other, Wizard, Player, *stdscr, Databuf[],
56 /	Fileloc
57 /
58 / GLOBAL OUTPUTS: Echo
59 /
60 / DESCRIPTION:
61 /	Prompt for player name to examine/change.
62 /	If the name is NULL, print a list of all players.
63 /	If we are called from within the game, check for the
64 /	desired name being the same as the current player's name.
65 /	Only the 'Wizard' may alter players.
66 /	Items are changed only if a non-zero value is specified.
67 /	To change an item to 0, use 0.1; it will be truncated later.
68 /
69 /	Players may alter their names and passwords, if the following
70 /	are true:
71 /	    - current login matches the character's logins
72 /	    - the password is known
73 /	    - the player is not in the middle of the game (ingameflag == FALSE)
74 /
75 /	The last condition is imposed for two reasons:
76 /	    - the game could possibly get a bit hectic if a player were
77 /	      continually changing his/her name
78 /	    - another player structure would be necessary to check for names
79 /	      already in use
80 /
81 *************************************************************************/
82 
83 void
84 changestats(bool ingameflag)
85 {
86 static char	flag[2] = /* for printing values of bools */
87 	{'F', 'T'};
88 struct player	*playerp;/* pointer to structure to alter */
89 const char	*prompt;	/* pointer to prompt string */
90 int	c;			/* input */
91 int	today;			/* day of year of today */
92 int	temp;			/* temporary variable */
93 long	loc;			/* location in player file */
94 time_t	now;			/* time now */
95 double	dtemp;			/* temporary variable */
96 bool	*bptr;			/* pointer to bool item to change */
97 double	*dptr;			/* pointer to double item to change */
98 short	*sptr;			/* pointer to short item to change */
99 
100     clear();
101 
102     for (;;)
103 	/* get name of player to examine/alter */
104 	{
105 	mvaddstr(5, 0, "Which character do you want to look at ? ");
106 	getstring(Databuf, SZ_DATABUF);
107 	truncstring(Databuf);
108 
109 	if (Databuf[0] == '\0')
110 	    userlist(ingameflag);
111 	else
112 	    break;
113 	}
114 
115     loc = -1L;
116 
117     if (!ingameflag)
118 	/* use 'Player' structure */
119 	playerp = &Player;
120     else if (strcmp(Databuf, Player.p_name) == 0)
121 	/* alter/examine current player */
122 	{
123 	playerp = &Player;
124 	loc = Fileloc;
125 	}
126     else
127 	/* use 'Other' structure */
128 	playerp = &Other;
129 
130     /* find player on file */
131     if (loc < 0L && (loc = findname(Databuf, playerp)) < 0L)
132 	/* didn't find player */
133 	{
134 	clear();
135 	mvaddstr(11, 0, "Not found.");
136 	return;
137 	}
138 
139     time(&now);
140     today = localtime(&now)->tm_yday;
141 
142     clear();
143 
144     for (;;)
145 	/* print player structure, and prompt for action */
146 	{
147 	mvprintw(0, 0,"A:Name         %s\n", playerp->p_name);
148 
149 	if (Wizard)
150 	    printw("B:Password     %s\n", playerp->p_password);
151 	else
152 	    addstr("B:Password     XXXXXXXX\n");
153 
154 	printw(" :Login        %s\n", playerp->p_login);
155 
156 	printw("C:Experience   %.0f\n", playerp->p_experience);
157 	printw("D:Level        %.0f\n", playerp->p_level);
158 	printw("E:Strength     %.0f\n", playerp->p_strength);
159 	printw("F:Sword        %.0f\n", playerp->p_sword);
160 	printw(" :Might        %.0f\n", playerp->p_might);
161 	printw("G:Energy       %.0f\n", playerp->p_energy);
162 	printw("H:Max-Energy   %.0f\n", playerp->p_maxenergy);
163 	printw("I:Shield       %.0f\n", playerp->p_shield);
164 	printw("J:Quickness    %.0f\n", playerp->p_quickness);
165 	printw("K:Quicksilver  %.0f\n", playerp->p_quksilver);
166 	printw(" :Speed        %.0f\n", playerp->p_speed);
167 	printw("L:Magic Level  %.0f\n", playerp->p_magiclvl);
168 	printw("M:Mana         %.0f\n", playerp->p_mana);
169 	printw("N:Brains       %.0f\n", playerp->p_brains);
170 
171 	if (Wizard || playerp->p_specialtype != SC_VALAR)
172 	    mvaddstr(0, 40, descrstatus(playerp));
173 
174 	mvprintw(1, 40, "O:Poison       %0.3f\n", playerp->p_poison);
175 	mvprintw(2, 40, "P:Gold         %.0f\n", playerp->p_gold);
176 	mvprintw(3, 40, "Q:Gem          %.0f\n", playerp->p_gems);
177 	mvprintw(4, 40, "R:Sin          %0.3f\n", playerp->p_sin);
178 	if (Wizard)
179 	    {
180 	    mvprintw(5, 40, "S:X-coord      %.0f\n", playerp->p_x);
181 	    mvprintw(6, 40, "T:Y-coord      %.0f\n", playerp->p_y);
182 	    }
183 	else
184 	    {
185 	    mvaddstr(5, 40, "S:X-coord      ?\n");
186 	    mvaddstr(6, 40, "T:Y-coord      ?\n");
187 	    }
188 
189 	mvprintw(7, 40, "U:Age          %ld\n", playerp->p_age);
190 	mvprintw(8, 40, "V:Degenerated  %d\n", playerp->p_degenerated);
191 
192 	mvprintw(9, 40, "W:Type         %d (%s)\n",
193 	    playerp->p_type, descrtype(playerp, FALSE) + 1);
194 	mvprintw(10, 40, "X:Special Type %d\n", playerp->p_specialtype);
195 	mvprintw(11, 40, "Y:Lives        %d\n", playerp->p_lives);
196 	mvprintw(12, 40, "Z:Crowns       %d\n", playerp->p_crowns);
197 	mvprintw(13, 40, "0:Charms       %d\n", playerp->p_charms);
198 	mvprintw(14, 40, "1:Amulets      %d\n", playerp->p_amulets);
199 	mvprintw(15, 40, "2:Holy Water   %d\n", playerp->p_holywater);
200 
201 	temp = today - playerp->p_lastused;
202 	if (temp < 0)
203 	    /* last year */
204 	    temp += 365;
205 	mvprintw(16, 40, "3:Lastused     %d  (%d)\n", playerp->p_lastused,  temp);
206 
207 	mvprintw(18, 8, "4:Palantir %c  5:Blessing %c  6:Virgin %c  7:Blind %c",
208 	    flag[playerp->p_palantir],
209 	    flag[playerp->p_blessing],
210 	    flag[playerp->p_virgin],
211 	    flag[playerp->p_blindness]);
212 
213 	if (!Wizard)
214 	    mvprintw(19, 8, "8:Ring    %c",
215 		flag[playerp->p_ring.ring_type != R_NONE]);
216 	else
217 	    mvprintw(19, 8, "8:Ring    %d  9:Duration %d",
218 		playerp->p_ring.ring_type, playerp->p_ring.ring_duration);
219 
220 	if (!Wizard
221 	    /* not wizard */
222 	    && (ingameflag || strcmp(Login, playerp->p_login) != 0))
223 	    /* in game or not examining own character */
224 	    {
225 	    if (ingameflag)
226 		{
227 		more(LINES - 1);
228 		clear();
229 		return;
230 		}
231 	    else
232 		cleanup(TRUE);
233 		/*NOTREACHED*/
234 	    }
235 
236 	mvaddstr(20, 0, "!:Quit       ?:Delete");
237 	mvaddstr(21, 0, "What would you like to change ? ");
238 
239 	if (Wizard)
240 	    c = getanswer(" ", TRUE);
241 	else
242 	    /* examining own player; allow to change name and password */
243 	    c = getanswer("!BA", FALSE);
244 
245 	switch (c)
246 	    {
247 	    case 'A':	/* change name */
248 	    case 'B':	/* change password */
249 		if (!Wizard)
250 		    /* prompt for password */
251 		    {
252 		    mvaddstr(23, 0, "Password ? ");
253 		    Echo = FALSE;
254 		    getstring(Databuf, 9);
255 		    Echo = TRUE;
256 		    if (strcmp(Databuf, playerp->p_password) != 0)
257 			continue;
258 		    }
259 
260 		if (c == 'A')
261 		    /* get new name */
262 		    {
263 		    mvaddstr(23, 0, "New name: ");
264 		    getstring(Databuf, SZ_NAME);
265 		    truncstring(Databuf);
266 		    if (Databuf[0] != '\0')
267 			if (Wizard || findname(Databuf, &Other) < 0L)
268 			    strcpy(playerp->p_name, Databuf);
269 		    }
270 		else
271 		    /* get new password */
272 		    {
273 		    if (!Wizard)
274 			Echo = FALSE;
275 
276 		    do
277 			/* get two copies of new password until they match */
278 			{
279 			/* get first copy */
280 			mvaddstr(23, 0, "New password ? ");
281 			getstring(Databuf, SZ_PASSWORD);
282 			if (Databuf[0] == '\0')
283 			    break;
284 
285 			/* get second copy */
286 			mvaddstr(23, 0, "One more time ? ");
287 			getstring(playerp->p_password, SZ_PASSWORD);
288 			}
289 		    while (strcmp(playerp->p_password, Databuf) != 0);
290 
291 		    Echo = TRUE;
292 		    }
293 
294 		continue;
295 
296 	    case 'C':	/* change experience */
297 		prompt = "experience";
298 		dptr = &playerp->p_experience;
299 		goto DALTER;
300 
301 	    case 'D':	/* change level */
302 		prompt = "level";
303 		dptr = &playerp->p_level;
304 		goto DALTER;
305 
306 	    case 'E':	/* change strength */
307 		prompt = "strength";
308 		dptr = &playerp->p_strength;
309 		goto DALTER;
310 
311 	    case 'F':	/* change swords */
312 		prompt = "sword";
313 		dptr = &playerp->p_sword;
314 		goto DALTER;
315 
316 	    case 'G':	/* change energy */
317 		prompt = "energy";
318 		dptr = &playerp->p_energy;
319 		goto DALTER;
320 
321 	    case 'H':	/* change maximum energy */
322 		prompt = "max energy";
323 		dptr = &playerp->p_maxenergy;
324 		goto DALTER;
325 
326 	    case 'I':	/* change shields */
327 		prompt = "shield";
328 		dptr = &playerp->p_shield;
329 		goto DALTER;
330 
331 	    case 'J':	/* change quickness */
332 		prompt = "quickness";
333 		dptr = &playerp->p_quickness;
334 		goto DALTER;
335 
336 	    case 'K':	/* change quicksilver */
337 		prompt = "quicksilver";
338 		dptr = &playerp->p_quksilver;
339 		goto DALTER;
340 
341 	    case 'L':	/* change magic */
342 		prompt = "magic level";
343 		dptr = &playerp->p_magiclvl;
344 		goto DALTER;
345 
346 	    case 'M':	/* change mana */
347 		prompt = "mana";
348 		dptr = &playerp->p_mana;
349 		goto DALTER;
350 
351 	    case 'N':	/* change brains */
352 		prompt = "brains";
353 		dptr = &playerp->p_brains;
354 		goto DALTER;
355 
356 	    case 'O':	/* change poison */
357 		prompt = "poison";
358 		dptr = &playerp->p_poison;
359 		goto DALTER;
360 
361 	    case 'P':	/* change gold */
362 		prompt = "gold";
363 		dptr = &playerp->p_gold;
364 		goto DALTER;
365 
366 	    case 'Q':	/* change gems */
367 		prompt = "gems";
368 		dptr = &playerp->p_gems;
369 		goto DALTER;
370 
371 	    case 'R':	/* change sin */
372 		prompt = "sin";
373 		dptr = &playerp->p_sin;
374 		goto DALTER;
375 
376 	    case 'S':	/* change x coord */
377 		prompt = "x";
378 		dptr = &playerp->p_x;
379 		goto DALTER;
380 
381 	    case 'T':	/* change y coord */
382 		prompt = "y";
383 		dptr = &playerp->p_y;
384 		goto DALTER;
385 
386 	    case 'U':	/* change age */
387 		mvprintw(23, 0, "age = %ld; age = ", playerp->p_age);
388 		dtemp = infloat();
389 		if (dtemp != 0.0)
390 		    playerp->p_age = (long) dtemp;
391 		continue;
392 
393 	    case 'V':	/* change degen */
394 		mvprintw(23, 0, "degen = %d; degen = ", playerp->p_degenerated);
395 		dtemp = infloat();
396 		if (dtemp != 0.0)
397 		    playerp->p_degenerated = (int) dtemp;
398 		continue;
399 
400 	    case 'W':	/* change type */
401 		prompt = "type";
402 		sptr = &playerp->p_type;
403 		goto SALTER;
404 
405 	    case 'X':	/* change special type */
406 		prompt = "special type";
407 		sptr = &playerp->p_specialtype;
408 		goto SALTER;
409 
410 	    case 'Y':	/* change lives */
411 		prompt = "lives";
412 		sptr = &playerp->p_lives;
413 		goto SALTER;
414 
415 	    case 'Z':	/* change crowns */
416 		prompt = "crowns";
417 		sptr = &playerp->p_crowns;
418 		goto SALTER;
419 
420 	    case '0':	/* change charms */
421 		prompt = "charm";
422 		sptr = &playerp->p_charms;
423 		goto SALTER;
424 
425 	    case '1':	/* change amulet */
426 		prompt = "amulet";
427 		sptr = &playerp->p_amulets;
428 		goto SALTER;
429 
430 	    case '2':	/* change holy water */
431 		prompt = "holy water";
432 		sptr = &playerp->p_holywater;
433 		goto SALTER;
434 
435 	    case '3':	/* change last-used */
436 		prompt = "last-used";
437 		sptr = &playerp->p_lastused;
438 		goto SALTER;
439 
440 	    case '4':	/* change palantir */
441 		prompt = "palantir";
442 		bptr = &playerp->p_palantir;
443 		goto BALTER;
444 
445 	    case '5':	/* change blessing */
446 		prompt = "blessing";
447 		bptr = &playerp->p_blessing;
448 		goto BALTER;
449 
450 	    case '6':	/* change virgin */
451 		prompt = "virgin";
452 		bptr = &playerp->p_virgin;
453 		goto BALTER;
454 
455 	    case '7':	/* change blindness */
456 		prompt = "blindness";
457 		bptr = &playerp->p_blindness;
458 		goto BALTER;
459 
460 	    case '8':	/* change ring type */
461 		prompt = "ring-type";
462 		sptr = &playerp->p_ring.ring_type;
463 		goto SALTER;
464 
465 	    case '9':	/* change ring duration */
466 		prompt = "ring-duration";
467 		sptr = &playerp->p_ring.ring_duration;
468 		goto SALTER;
469 
470 	    case '!':	/* quit, update */
471 		if (Wizard &&
472 		    (!ingameflag || playerp != &Player))
473 		    /* turn off status if not modifying self */
474 		    {
475 		    playerp->p_status = S_OFF;
476 		    playerp->p_tampered = T_OFF;
477 		    }
478 
479 		writerecord(playerp, loc);
480 		clear();
481 		return;
482 
483 	    case '?':	/* delete player */
484 		if (ingameflag && playerp == &Player)
485 		    /* cannot delete self */
486 		    continue;
487 
488 		freerecord(playerp, loc);
489 		clear();
490 		return;
491 
492 	    default:
493 		continue;
494 	    }
495 DALTER:
496 	mvprintw(23, 0, "%s = %f; %s = ", prompt, *dptr, prompt);
497 	dtemp = infloat();
498 	if (dtemp != 0.0)
499 	    *dptr = dtemp;
500 	continue;
501 
502 SALTER:
503 	mvprintw(23, 0, "%s = %d; %s = ", prompt, *sptr, prompt);
504 	dtemp = infloat();
505 	if (dtemp != 0.0)
506 	    *sptr = (short) dtemp;
507 	continue;
508 
509 BALTER:
510 	mvprintw(23, 0, "%s = %c; %s = ", prompt, flag[*bptr], prompt);
511 	c = getanswer("\nTF", TRUE);
512 	if (c == 'T')
513 	    *bptr = TRUE;
514 	else if (c == 'F')
515 	    *bptr = FALSE;
516 	continue;
517 	}
518 }
519 /**/
520 /************************************************************************
521 /
522 / FUNCTION NAME: monstlist()
523 /
524 / FUNCTION: print a monster listing
525 /
526 / AUTHOR: E. A. Estes, 2/27/86
527 /
528 / ARGUMENTS: none
529 /
530 / RETURN VALUE: none
531 /
532 / MODULES CALLED: puts(), fread(), fseek(), printf()
533 /
534 / GLOBAL INPUTS: Curmonster, *Monstfp
535 /
536 / GLOBAL OUTPUTS: none
537 /
538 / DESCRIPTION:
539 /	Read monster file, and print a monster listing on standard output.
540 /
541 *************************************************************************/
542 
543 void
544 monstlist(void)
545 {
546 int 	count = 0;		/* count in file */
547 
548     puts(" #)  Name                 Str  Brain  Quick  Energy  Exper  Treas  Type  Flock%\n");
549     fseek(Monstfp, 0L, 0);
550     while (fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp) == 1)
551 	printf("%2d)  %-20.20s%4.0f   %4.0f     %2.0f   %5.0f  %5.0f     %2d    %2d     %3.0f\n", count++,
552 	    Curmonster.m_name, Curmonster.m_strength, Curmonster.m_brains,
553 	    Curmonster.m_speed, Curmonster.m_energy, Curmonster.m_experience,
554 	    Curmonster.m_treasuretype, Curmonster.m_type, Curmonster.m_flock);
555 }
556 /**/
557 /************************************************************************
558 /
559 / FUNCTION NAME: scorelist()
560 /
561 / FUNCTION: print player score board
562 /
563 / AUTHOR: E. A. Estes, 12/4/85
564 /
565 / ARGUMENTS: none
566 /
567 / RETURN VALUE: none
568 /
569 / MODULES CALLED: fread(), fopen(), printf(), fclose()
570 /
571 / GLOBAL INPUTS:
572 /
573 / GLOBAL OUTPUTS: none
574 /
575 / DESCRIPTION:
576 /	Read the scoreboard file and print the contents.
577 /
578 *************************************************************************/
579 
580 void
581 scorelist(void)
582 {
583 struct	scoreboard	sbuf;	/* for reading entries */
584 FILE	*fp;		/* to open the file */
585 
586     if ((fp = fopen(_PATH_SCORE, "r")) != NULL)
587 	{
588 	while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
589 	    printf("%-20s   (%-9s)  Level: %6.0f  Type: %s\n",
590 		sbuf.sb_name, sbuf.sb_login, sbuf.sb_level, sbuf.sb_type);
591 	fclose(fp);
592 	}
593 }
594 /**/
595 /************************************************************************
596 /
597 / FUNCTION NAME: activelist()
598 /
599 / FUNCTION: print list of active players to standard output
600 /
601 / AUTHOR: E. A. Estes, 3/7/86
602 /
603 / ARGUMENTS: none
604 /
605 / RETURN VALUE: none
606 /
607 / MODULES CALLED: descrstatus(), fread(), fseek(), printf(), descrtype()
608 /
609 / GLOBAL INPUTS: Other, *Playersfp
610 /
611 / GLOBAL OUTPUTS: none
612 /
613 / DESCRIPTION:
614 /	Read player file, and print list of active records to standard output.
615 /
616 *************************************************************************/
617 
618 void
619 activelist(void)
620 {
621     fseek(Playersfp, 0L, 0);
622     printf("Current characters on file are:\n\n");
623 
624     while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1)
625 	if (Other.p_status != S_NOTUSED)
626 	    printf("%-20s   (%-9s)  Level: %6.0f  %s  (%s)\n",
627 		Other.p_name, Other.p_login, Other.p_level,
628 		descrtype(&Other, FALSE), descrstatus(&Other));
629 
630 }
631 /**/
632 /************************************************************************
633 /
634 / FUNCTION NAME: purgeoldplayers()
635 /
636 / FUNCTION: purge inactive players from player file
637 /
638 / AUTHOR: E. A. Estes, 12/4/85
639 /
640 / ARGUMENTS: none
641 /
642 / RETURN VALUE: none
643 /
644 / MODULES CALLED: freerecord(), time(), fread(), fseek(), localtime()
645 /
646 / GLOBAL INPUTS: Other, *Playersfp
647 /
648 / GLOBAL OUTPUTS: none
649 /
650 / DESCRIPTION:
651 /	Delete characters which have not been used with the last
652 /	three weeks.
653 /
654 *************************************************************************/
655 
656 void
657 purgeoldplayers(void)
658 {
659 int	today;		/* day of year for today */
660 int	daysold;	/* how many days since the character has been used */
661 time_t	ltime;		/* time in seconds */
662 long	loc = 0L;	/* location in file */
663 
664     time(&ltime);
665     today = localtime(&ltime)->tm_yday;
666 
667     for (;;)
668 	{
669 	fseek(Playersfp, loc, 0);
670 	if (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) != 1)
671 	    break;
672 
673 	daysold = today - Other.p_lastused;
674 	if (daysold < 0)
675 	    daysold += 365;
676 
677 	if (daysold > N_DAYSOLD)
678 	    /* player hasn't been used in a while; delete */
679 	    freerecord(&Other, loc);
680 
681 	loc += SZ_PLAYERSTRUCT;
682 	}
683 }
684 /**/
685 /************************************************************************
686 /
687 / FUNCTION NAME: enterscore()
688 /
689 / FUNCTION: enter player into scoreboard
690 /
691 / AUTHOR: E. A. Estes, 12/4/85
692 /
693 / ARGUMENTS: none
694 /
695 / RETURN VALUE: none
696 /
697 / MODULES CALLED: fread(), fseek(), fopen(), error(), strcmp(), fclose(),
698 /	strcpy(), fwrite(), descrtype()
699 /
700 / GLOBAL INPUTS: Player
701 /
702 / GLOBAL OUTPUTS: none
703 /
704 / DESCRIPTION:
705 /	The scoreboard keeps track of the highest character on a
706 /	per-login basis.
707 /	Search the scoreboard for an entry for the current login,
708 /	if an entry is found, and it is lower than the current player,
709 /	replace it, otherwise create an entry.
710 /
711 *************************************************************************/
712 
713 void
714 enterscore(void)
715 {
716 struct	scoreboard sbuf;		/* buffer to read in scoreboard entries */
717 FILE	*fp;				/* to open scoreboard file */
718 long	loc = 0L;			/* location in scoreboard file */
719 bool	found = FALSE;			/* set if we found an entry for this login */
720 
721     if ((fp = fopen(_PATH_SCORE, "r+")) != NULL)
722 	{
723 	while (fread((char *) &sbuf, SZ_SCORESTRUCT, 1, fp) == 1)
724 	    if (strcmp(Player.p_login, sbuf.sb_login) == 0)
725 		{
726 		found = TRUE;
727 		break;
728 		}
729 	    else
730 		loc += SZ_SCORESTRUCT;
731 	}
732     else
733 	{
734 	error(_PATH_SCORE);
735 	/*NOTREACHED*/
736 	}
737 
738     /*
739      * At this point, 'loc' will either indicate a point beyond
740      * the end of file, or the place where the previous entry
741      * was found.
742      */
743 
744     if ((!found) || Player.p_level > sbuf.sb_level)
745 	/* put new entry in for this login */
746 	{
747 	strcpy(sbuf.sb_login, Player.p_login);
748 	strcpy(sbuf.sb_name, Player.p_name);
749 	sbuf.sb_level = Player.p_level;
750 	strcpy(sbuf.sb_type, descrtype(&Player, TRUE));
751 	}
752 
753     /* update entry */
754     fseek(fp, loc, 0);
755     fwrite((char *) &sbuf, SZ_SCORESTRUCT, 1, fp);
756     fclose(fp);
757 }
758