ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/hiscore.C
(Generate patch)

Comparing deliantra/server/server/hiscore.C (file contents):
Revision 1.4 by root, Sun Sep 3 00:18:42 2006 UTC vs.
Revision 1.19 by root, Sun Mar 18 03:05:40 2007 UTC

1/* 1/*
2 * static char *rcsid_hiscore_c =
3 * "$Id: hiscore.C,v 1.4 2006/09/03 00:18:42 root Exp $";
4 */
5
6/*
7 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
8 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
9 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
10 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
11 7 *
12 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version. 11 * (at your option) any later version.
16 12 *
17 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details. 16 * GNU General Public License for more details.
21 17 *
22 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 21 *
26 The authors can be reached via e-mail at crossfire-devel@real-time.com 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
27*/ 23 */
28 24
29#include <global.h> 25#include <global.h>
30#ifndef __CEXTRACT__
31#include <sproto.h> 26#include <sproto.h>
32#endif
33 27
34/* 28/*
35 * The score structure is used when treating new high-scores 29 * The score structure is used when treating new high-scores
36 */ 30 */
37
38typedef struct scr { 31typedef struct scr
39 char name[BIG_NAME]; /* name */ 32{
40 char title[BIG_NAME]; /* Title */ 33 char name[64]; // name */
34 char title[64]; // Title */
41 char killer[BIG_NAME]; /* name (+ title) or "quit" */ 35 char killer[64]; // name (+ title) or "quit" */
42 sint64 exp; /* Experience */ 36 sint64 exp; // Experience */
43 char maplevel[BIG_NAME]; /* Killed on what level */ 37 char maplevel[128]; // Killed on what level */
44 int maxhp,maxsp,maxgrace; /* Max hp, sp, grace when killed */ 38 int maxhp, maxsp, maxgrace; // Max hp, sp, grace when killed */
45 int position; /* Position in the highscore list */ 39 int position; // Position in the highscore list */
46} score; 40} score;
47 41
48/* 42/*
49 * spool works mostly like strtok(char *, ":"), but it can also 43 * spool works mostly like strtok(char *, ":"), but it can also
50 * log a specified error message if something goes wrong. 44 * log a specified error message if something goes wrong.
51 */ 45 */
52 46char *
53char *spool(char *bp,char *error) { 47spool (char *bp, const char *error)
48{
54 static char *prev_pos = NULL; 49 static char *prev_pos = NULL;
55 char *next_pos; 50 char *next_pos;
51
56 if (bp == NULL) { 52 if (bp == NULL)
53 {
57 if (prev_pos == NULL) { 54 if (prev_pos == NULL)
55 {
58 LOG(llevError, "Called spool (%s) with NULL without previous call.\n", 56 LOG (llevError, "Called spool (%s) with NULL without previous call.\n", error);
59 error); 57 return NULL;
58 }
59 bp = prev_pos;
60 }
61 if (*bp == '\0')
62 {
63 LOG (llevError, "spool: End of line at %s\n", error);
60 return NULL; 64 return NULL;
61 } 65 }
62 bp = prev_pos;
63 }
64 if (*bp == '\0') {
65 LOG(llevError, "spool: End of line at %s\n", error);
66 return NULL;
67 }
68 if ((next_pos = strchr(bp, ':')) != NULL) { 66 if ((next_pos = strchr (bp, ':')) != NULL)
67 {
69 *next_pos = '\0'; 68 *next_pos = '\0';
70 prev_pos = next_pos + 1; 69 prev_pos = next_pos + 1;
70 }
71 } else 71 else
72 prev_pos = NULL; 72 prev_pos = NULL;
73 return bp; 73 return bp;
74} 74}
75 75
76/* 76/*
77 * Does what it says, copies the contents of the first score structure 77 * Does what it says, copies the contents of the first score structure
78 * to the second one. 78 * to the second one.
79 */ 79 */
80 80static void
81static void copy_score(score *sc1,score *sc2) { 81copy_score (score *sc1, score *sc2)
82 strncpy(sc2->name, sc1->name, BIG_NAME); 82{
83 sc2->name[BIG_NAME - 1] = '\0'; 83 assign (sc2->name , sc1->name);
84 strncpy(sc2->title, sc1->title, BIG_NAME); 84 assign (sc2->title , sc1->title);
85 sc2->title[BIG_NAME - 1] = '\0'; 85 assign (sc2->killer , sc1->killer);
86 strncpy(sc2->killer, sc1->killer, BIG_NAME); 86 assign (sc2->maplevel, sc1->maplevel);
87 sc2->killer[BIG_NAME - 1] = '\0';
88 sc2->exp = sc1->exp; 87 sc2->exp = sc1->exp;
89 strcpy(sc2->maplevel,sc1->maplevel);
90 sc2->maxhp = sc1->maxhp; 88 sc2->maxhp = sc1->maxhp;
91 sc2->maxsp = sc1->maxsp; 89 sc2->maxsp = sc1->maxsp;
92 sc2->maxgrace = sc1->maxgrace; 90 sc2->maxgrace = sc1->maxgrace;
93} 91}
94 92
95/* 93/*
96 * Writes the given score structure to a static buffer, and returns 94 * Writes the given score structure to a static buffer, and returns
97 * a pointer to it. 95 * a pointer to it.
98 */ 96 */
99 97static char *
100static char *put_score(score *sc) { 98put_score (score *sc)
99{
101 static char buf[MAX_BUF]; 100 static char buf[MAX_BUF];
102 sprintf(buf,"%s:%s:%lld:%s:%s:%d:%d:%d",sc->name,sc->title, (long long)sc->exp,sc->killer,sc->maplevel, 101
102 sprintf (buf, "%s:%s:%" PRId64 ":%s:%s:%d:%d:%d",
103 sc->name, sc->title, (sint64)sc->exp, sc->killer,
103 sc->maxhp,sc->maxsp,sc->maxgrace); 104 sc->maplevel, sc->maxhp, sc->maxsp, sc->maxgrace);
104 return buf; 105 return buf;
105} 106}
106 107
107/* 108/*
108 * The oposite of put_score, get_score reads from the given buffer into 109 * The oposite of put_score, get_score reads from the given buffer into
109 * a static score structure, and returns a pointer to it. 110 * a static score structure, and returns a pointer to it.
110 */ 111 */
111 112
112static score *get_score(char *bp) { 113static score *
114get_score (char *bp)
115{
113 static score sc; 116 static score sc;
114 char *cp; 117 char *cp;
115 118
116 if((cp=strchr(bp,'\n'))!=NULL) 119 if ((cp = strchr (bp, '\n')) != NULL)
117 *cp='\0'; 120 *cp = '\0';
118 121
119 if ((cp = spool(bp, "name")) == NULL) 122 if ((cp = spool (bp, "name")) == NULL)
120 return NULL; 123 return 0;
121 strncpy(sc.name,cp,BIG_NAME);
122 sc.name[BIG_NAME - 1] = '\0';
123 124
125 assign (sc.name, cp);
126
124 if ((cp = spool(NULL, "title")) == NULL) 127 if ((cp = spool (0, "title")) == NULL)
125 return NULL; 128 return 0;
126 strncpy(sc.title,cp,BIG_NAME);
127 sc.title[BIG_NAME - 1] = '\0';
128 129
130 assign (sc.title, cp);
131
129 if ((cp = spool(NULL, "score")) == NULL) 132 if ((cp = spool (0, "score")) == NULL)
130 return NULL; 133 return 0;
131 long long exp;
132 sscanf(cp,"%lld", &exp); sc.exp = exp;
133 134
135 sscanf (cp, "%" SCNd64, &sc.exp);
136
134 if ((cp = spool(NULL, "killer")) == NULL) 137 if ((cp = spool (0, "killer")) == NULL)
135 return NULL; 138 return 0;
136 strncpy(sc.killer, cp, BIG_NAME);
137 sc.killer[BIG_NAME - 1] = '\0';
138 139
140 assign (sc.killer, cp);
141
139 if ((cp = spool(NULL, "map")) == NULL) 142 if ((cp = spool (0, "map")) == NULL)
140 return NULL; 143 return 0;
141 strncpy(sc.maplevel, cp, BIG_NAME);
142 sc.maplevel[BIG_NAME - 1] = '\0';
143 144
145 assign (sc.maplevel, cp);
146
144 if ((cp = spool(NULL, "maxhp")) == NULL) 147 if ((cp = spool (0, "maxhp")) == NULL)
145 return NULL; 148 return 0;
149
146 sscanf(cp, "%d", &sc.maxhp); 150 sscanf (cp, "%d", &sc.maxhp);
147 151
148 if ((cp = spool(NULL, "maxsp")) == NULL) 152 if ((cp = spool (0, "maxsp")) == NULL)
149 return NULL; 153 return 0;
154
150 sscanf(cp, "%d", &sc.maxsp); 155 sscanf (cp, "%d", &sc.maxsp);
151 156
152 if ((cp = spool(NULL, "maxgrace")) == NULL) 157 if ((cp = spool (0, "maxgrace")) == NULL)
153 return NULL; 158 return 0;
159
154 sscanf(cp, "%d", &sc.maxgrace); 160 sscanf (cp, "%d", &sc.maxgrace);
155 return &sc; 161 return &sc;
156} 162}
157 163
164static char *
158static char * draw_one_high_score(score *sc) { 165draw_one_high_score (score *sc)
166{
159 static char retbuf[MAX_BUF]; 167 static char retbuf[MAX_BUF];
160 168
161 if(!strncmp(sc->killer,"quit",MAX_NAME)) 169 if (!strncmp (sc->killer, "quit", MAX_NAME))
162 sprintf(retbuf,"%3d %10lld %s the %s quit the game on map %s [%d][%d][%d].", 170 sprintf (retbuf, "%3d %10lld %s the %s quit the game on map %s [%d][%d][%d].",
163 sc->position, (long long)sc->exp,sc->name,sc->title,sc->maplevel,sc->maxhp,sc->maxsp, 171 sc->position, (long long) sc->exp, sc->name, sc->title, sc->maplevel, sc->maxhp, sc->maxsp, sc->maxgrace);
164 sc->maxgrace);
165 else if(!strncmp(sc->killer,"left",MAX_NAME)) 172 else if (!strncmp (sc->killer, "left", MAX_NAME))
166 sprintf(retbuf,"%3d %10lld %s the %s left the game on map %s [%d][%d][%d].", 173 sprintf (retbuf, "%3d %10lld %s the %s left the game on map %s [%d][%d][%d].",
167 sc->position, (long long)sc->exp,sc->name,sc->title,sc->maplevel,sc->maxhp,sc->maxsp, 174 sc->position, (long long) sc->exp, sc->name, sc->title, sc->maplevel, sc->maxhp, sc->maxsp, sc->maxgrace);
168 sc->maxgrace);
169 else 175 else
170 sprintf(retbuf,"%3d %10lld %s the %s was killed by %s on map %s [%d][%d][%d].", 176 sprintf (retbuf, "%3d %10lld %s the %s was killed by %s on map %s [%d][%d][%d].",
171 sc->position, (long long)sc->exp,sc->name,sc->title,sc->killer,sc->maplevel, 177 sc->position, (long long) sc->exp, sc->name, sc->title, sc->killer, sc->maplevel, sc->maxhp, sc->maxsp, sc->maxgrace);
172 sc->maxhp,sc->maxsp,sc->maxgrace);
173 return retbuf; 178 return retbuf;
174} 179}
180
175/* 181/*
176 * add_score() adds the given score-structure to the high-score list, but 182 * add_score() adds the given score-structure to the high-score list, but
177 * only if it was good enough to deserve a place. 183 * only if it was good enough to deserve a place.
178 */ 184 */
179 185
186static score *
180static score *add_score(score *new_score) { 187add_score (score *new_score)
188{
181 FILE *fp; 189 FILE *fp;
182 static score old_score; 190 static score old_score;
183 score *tmp_score,pscore[HIGHSCORE_LENGTH]; 191 score *tmp_score, pscore[HIGHSCORE_LENGTH];
184 char buf[MAX_BUF], filename[MAX_BUF], *bp; 192 char buf[MAX_BUF], filename[MAX_BUF], *bp;
185 int nrofscores=0,flag=0,i,comp; 193 int nrofscores = 0, flag = 0, i, comp;
186 194
187 new_score->position=HIGHSCORE_LENGTH+1; 195 new_score->position = HIGHSCORE_LENGTH + 1;
188 old_score.position= -1; 196 old_score.position = -1;
189 sprintf(filename,"%s/%s",settings.localdir,HIGHSCORE); 197 sprintf (filename, "%s/%s", settings.localdir, HIGHSCORE);
190 if((fp=open_and_uncompress(filename,1,&comp))!=NULL) { 198 if ((fp = open_and_uncompress (filename, 1, &comp)) != NULL)
199 {
191 while(fgets(buf,MAX_BUF,fp)!=NULL&&nrofscores<HIGHSCORE_LENGTH) { 200 while (fgets (buf, MAX_BUF, fp) != NULL && nrofscores < HIGHSCORE_LENGTH)
201 {
192 if((tmp_score=get_score(buf))==NULL) break; 202 if ((tmp_score = get_score (buf)) == NULL)
193 if(!flag&&new_score->exp>=tmp_score->exp) {
194 copy_score(new_score,&pscore[nrofscores]);
195 new_score->position=nrofscores;
196 flag=1;
197 if(++nrofscores>=HIGHSCORE_LENGTH)
198 break; 203 break;
199 } 204 if (!flag && new_score->exp >= tmp_score->exp)
205 {
206 copy_score (new_score, &pscore[nrofscores]);
207 new_score->position = nrofscores;
208 flag = 1;
209 if (++nrofscores >= HIGHSCORE_LENGTH)
210 break;
211 }
200 if(!strcmp(new_score->name,tmp_score->name)) { /* Another entry */ 212 if (!strcmp (new_score->name, tmp_score->name))
213 { /* Another entry */
201 copy_score(tmp_score,&old_score); 214 copy_score (tmp_score, &old_score);
202 old_score.position=nrofscores; 215 old_score.position = nrofscores;
203 if(flag) 216 if (flag)
204 continue; 217 continue;
205 } 218 }
206 copy_score(tmp_score,&pscore[nrofscores++]); 219 copy_score (tmp_score, &pscore[nrofscores++]);
207 } 220 }
208 close_and_delete(fp, comp); 221 close_and_delete (fp, comp);
209 } 222 }
210 if(old_score.position!=-1&&old_score.exp>=new_score->exp) 223 if (old_score.position != -1 && old_score.exp >= new_score->exp)
211 return &old_score; /* Did not beat old score */ 224 return &old_score; /* Did not beat old score */
212 if(!flag&&nrofscores<HIGHSCORE_LENGTH) 225 if (!flag && nrofscores < HIGHSCORE_LENGTH)
213 copy_score(new_score,&pscore[nrofscores++]); 226 copy_score (new_score, &pscore[nrofscores++]);
214 if((fp=fopen(filename,"w"))==NULL) { 227 if ((fp = fopen (filename, "w")) == NULL)
228 {
215 LOG(llevError, "Cannot write to highscore file %s: %s\n", filename, strerror(errno)); 229 LOG (llevError, "Cannot write to highscore file %s: %s\n", filename, strerror (errno));
216 return NULL; 230 return NULL;
217 } 231 }
218 for(i=0;i<nrofscores;i++) { 232 for (i = 0; i < nrofscores; i++)
233 {
219 bp=put_score(&pscore[i]); 234 bp = put_score (&pscore[i]);
220 fprintf(fp,"%s\n",bp); 235 fprintf (fp, "%s\n", bp);
221 } 236 }
222 fclose(fp); 237 fclose (fp);
223 if(flag) { 238 if (flag)
239 {
240
224/* Eneq(@csd.uu.se): Patch to fix error in adding a new score to the 241/* Eneq(@csd.uu.se): Patch to fix error in adding a new score to the
225 hiscore-list */ 242 hiscore-list */
226 if(old_score.position==-1) 243 if (old_score.position == -1)
227 return new_score; 244 return new_score;
245 return &old_score;
246 }
247 new_score->position = -1;
248 if (old_score.position != -1)
228 return &old_score; 249 return &old_score;
229 } 250 if (nrofscores)
230 new_score->position= -1; 251 {
231 if(old_score.position!=-1) 252 copy_score (&pscore[nrofscores - 1], &old_score);
232 return &old_score; 253 return &old_score;
233 if(nrofscores) {
234 copy_score(&pscore[nrofscores-1],&old_score);
235 return &old_score;
236 } 254 }
237 LOG(llevError,"Highscore error.\n"); 255 LOG (llevError, "Highscore error.\n");
238 return NULL; 256 return NULL;
239} 257}
240 258
259void
241void check_score(object *op) { 260check_score (object *op)
261{
242 score new_score; 262 score new_score;
243 score *old_score; 263 score *old_score;
244 264
245 if(op->stats.exp==0) 265 if (op->stats.exp == 0)
246 return; 266 return;
247 267
248 if(!op->contr->name_changed) { 268 assign (new_score.name, op->name);
249 if(op->stats.exp>0) { 269 assign (new_score.title, op->title.length () ? &op->title : op->contr->title);
250 new_draw_info(NDI_UNIQUE, 0,op,"As you haven't changed your name, you won't"); 270 assign (new_score.killer, op->contr->killer[0] ? op->contr->killer : "a dungeon collapse");
251 new_draw_info(NDI_UNIQUE, 0,op,"get into the high-score list."); 271 assign (new_score.maplevel, op->map ? op->map->name ? &op->map->name : &op->map->path : "");
252 } 272
253 return;
254 }
255 if(QUERY_FLAG(op,FLAG_WAS_WIZ)) {
256 new_draw_info(NDI_UNIQUE, 0,op,"Since you have been in wizard mode,");
257 new_draw_info(NDI_UNIQUE, 0,op,"you can't enter the high-score list.");
258 return;
259 }
260 if (op->contr->explore) {
261 new_draw_info(NDI_UNIQUE, 0,op,"Since you were in explore mode,");
262 new_draw_info(NDI_UNIQUE, 0,op,"you can't enter the high-score list.");
263 return;
264 }
265 strncpy(new_score.name,op->name,BIG_NAME);
266 new_score.name[BIG_NAME-1] = '\0';
267 strncpy(new_score.title,op->contr->own_title,BIG_NAME);
268 if(new_score.title[0]=='\0')
269 strncpy(new_score.title,op->contr->title,BIG_NAME);
270 new_score.title[BIG_NAME-1] = '\0';
271 strncpy(new_score.killer,op->contr->killer,BIG_NAME);
272 if(new_score.killer[0]=='\0')
273 strcpy(new_score.killer,"a dungeon collapse");
274 new_score.killer[BIG_NAME-1] = '\0';
275 new_score.exp=op->stats.exp; 273 new_score.exp = op->stats.exp;
276 if(op->map == NULL)
277 *new_score.maplevel = '\0';
278 else {
279 strncpy(new_score.maplevel,
280 op->map->name?op->map->name:op->map->path,
281 BIG_NAME-1);
282 new_score.maplevel[BIG_NAME-1] = '\0';
283 }
284 new_score.maxhp=(int) op->stats.maxhp; 274 new_score.maxhp = op->stats.maxhp;
285 new_score.maxsp=(int) op->stats.maxsp; 275 new_score.maxsp = op->stats.maxsp;
286 new_score.maxgrace=(int) op->stats.maxgrace; 276 new_score.maxgrace = op->stats.maxgrace;
277
287 if((old_score=add_score(&new_score))==NULL) { 278 if ((old_score = add_score (&new_score)) == NULL)
279 {
288 new_draw_info(NDI_UNIQUE, 0,op,"Error in the highscore list."); 280 new_draw_info (NDI_UNIQUE, 0, op, "Error in the highscore list.");
289 return; 281 return;
290 } 282 }
283
291 if(new_score.position == -1) { 284 if (new_score.position == -1)
285 {
292 new_score.position = HIGHSCORE_LENGTH+1; /* Not strictly correct... */ 286 new_score.position = HIGHSCORE_LENGTH + 1; /* Not strictly correct... */
293 if(!strcmp(old_score->name,new_score.name)) 287 if (!strcmp (old_score->name, new_score.name))
294 new_draw_info(NDI_UNIQUE, 0,op,"You didn't beat your last highscore:"); 288 new_draw_info (NDI_UNIQUE, 0, op, "You didn't beat your last highscore:");
295 else 289 else
296 new_draw_info(NDI_UNIQUE, 0,op,"You didn't enter the highscore list:"); 290 new_draw_info (NDI_UNIQUE, 0, op, "You didn't enter the highscore list:");
297 new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(old_score)); 291 new_draw_info (NDI_UNIQUE, 0, op, draw_one_high_score (old_score));
298 new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(&new_score)); 292 new_draw_info (NDI_UNIQUE, 0, op, draw_one_high_score (&new_score));
299 return; 293 return;
300 } 294 }
295
301 if(old_score->exp>=new_score.exp) 296 if (old_score->exp >= new_score.exp)
302 new_draw_info(NDI_UNIQUE, 0,op,"You didn't beat your last score:"); 297 new_draw_info (NDI_UNIQUE, 0, op, "You didn't beat your last score:");
303 else 298 else
304 new_draw_info(NDI_UNIQUE, 0,op,"You beat your last score:"); 299 new_draw_info (NDI_UNIQUE, 0, op, "You beat your last score:");
305 300
306 new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(old_score)); 301 new_draw_info (NDI_UNIQUE, 0, op, draw_one_high_score (old_score));
307 new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(&new_score)); 302 new_draw_info (NDI_UNIQUE, 0, op, draw_one_high_score (&new_score));
308} 303}
309
310
311 304
312/* displays the high score file. object is the calling object 305/* displays the high score file. object is the calling object
313 * (null if being called via command line.) max is the maximum 306 * (null if being called via command line.) max is the maximum
314 * number of scores to display. match, if set, is the name or class 307 * number of scores to display. match, if set, is the name or class
315 * to match to. 308 * to match to.
316 */ 309 */
317 310
311void
318void display_high_score(object *op,int max, const char *match) { 312display_high_score (object *op, int max, const char *match)
313{
319 const size_t maxchar = 80; 314 const size_t maxchar = 80;
320 FILE *fp; 315 FILE *fp;
321 char buf[MAX_BUF],*scorebuf, *bp, *cp; 316 char buf[MAX_BUF], *scorebuf, *bp, *cp;
322 int i=0,j=0,comp; 317 int i = 0, j = 0, comp;
323 score *sc; 318 score *sc;
324 319
325 sprintf(buf,"%s/%s",settings.localdir,HIGHSCORE); 320 sprintf (buf, "%s/%s", settings.localdir, HIGHSCORE);
326 if((fp=open_and_uncompress(buf,0,&comp))==NULL) { 321 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
322 {
327 LOG(llevError, "Cannot open highscore file %s: %s\n", buf, strerror(errno)); 323 LOG (llevError, "Cannot open highscore file %s: %s\n", buf, strerror (errno));
328 if(op!=NULL) 324 if (op != NULL)
329 new_draw_info(NDI_UNIQUE, 0,op,"There is no highscore file."); 325 new_draw_info (NDI_UNIQUE, 0, op, "There is no highscore file.");
330 return; 326 return;
331 } 327 }
332 if(op != NULL) 328 if (op != NULL)
333 clear_win_info(op); 329 clear_win_info (op);
334 new_draw_info(NDI_UNIQUE, 0,op,"Nr Score Who [max hp][max sp][max grace]"); 330 new_draw_info (NDI_UNIQUE, 0, op, "Nr Score Who [max hp][max sp][max grace]");
335 331
336 while(fgets(buf,MAX_BUF,fp)!=NULL) { 332 while (fgets (buf, MAX_BUF, fp) != NULL)
333 {
337 if(j>=HIGHSCORE_LENGTH||i>=(max-1)) 334 if (j >= HIGHSCORE_LENGTH || i >= (max - 1))
338 break; 335 break;
339 if((sc=get_score(buf))==NULL) 336 if ((sc = get_score (buf)) == NULL)
340 break; 337 break;
341 sc->position=++j; 338 sc->position = ++j;
342 if (match==NULL) { 339 if (match == NULL)
340 {
343 scorebuf=draw_one_high_score(sc); 341 scorebuf = draw_one_high_score (sc);
344 i++; 342 i++;
343 }
345 } else { 344 else
345 {
346 if (!strcasecmp(sc->name, match) || !strcasecmp(sc->title, match)) { 346 if (!strcasecmp (sc->name, match) || !strcasecmp (sc->title, match))
347 {
347 scorebuf=draw_one_high_score(sc); 348 scorebuf = draw_one_high_score (sc);
348 i++; 349 i++;
349 } 350 }
351 else
350 else continue; 352 continue;
351 } 353 }
352 /* Replaced what seemed to an overly complicated word wrap method 354 /* Replaced what seemed to an overly complicated word wrap method
353 * still word wraps, but assumes at most 2 lines of data. 355 * still word wraps, but assumes at most 2 lines of data.
354 * mw - 2-12-97 356 * mw - 2-12-97
355 */ 357 */
356 strncpy(buf,scorebuf,MAX_BUF); 358 assign (buf, scorebuf);
357 buf[MAX_BUF-1] = '\0'; 359
358 cp=buf; 360 cp = buf;
359 while (strlen(cp)> maxchar) { 361 while (strlen (cp) > maxchar)
362 {
360 bp = cp+maxchar-1; 363 bp = cp + maxchar - 1;
361 while (*bp != ' ' && bp>cp) bp--; 364 while (*bp != ' ' && bp > cp)
365 bp--;
362 *bp='\0'; 366 *bp = '\0';
367
363 if (op == NULL) { 368 if (op == NULL)
364 LOG(llevDebug, "%s\n", cp); 369 LOG (llevDebug, "%s\n", cp);
365 }
366 else { 370 else
367 new_draw_info(NDI_UNIQUE, 0,op,cp); 371 new_draw_info (NDI_UNIQUE, 0, op, cp);
368 } 372
369 sprintf(buf, " %s", bp+1); 373 sprintf (buf, " %s", bp + 1);
370 cp = buf; 374 cp = buf;
371 i++; 375 i++;
372 } 376 }
377
373 if(op == NULL) 378 if (op == NULL)
374 LOG(llevDebug, "%s\n", buf); 379 LOG (llevDebug, "%s\n", buf);
375 else 380 else
376 new_draw_info(NDI_UNIQUE, 0,op,buf); 381 new_draw_info (NDI_UNIQUE, 0, op, buf);
377 } 382 }
383
378 close_and_delete(fp, comp); 384 close_and_delete (fp, comp);
379} 385}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines