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.3 by root, Wed Aug 30 16:30:37 2006 UTC vs.
Revision 1.18 by pippijn, Mon Jan 15 21:06:20 2007 UTC

1/* 1/*
2 * static char *rcsid_hiscore_c =
3 * "$Id: hiscore.C,v 1.3 2006/08/30 16:30:37 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 46
47char *
53char *spool(char *bp,char *error) { 48spool (char *bp, char *error)
49{
54 static char *prev_pos = NULL; 50 static char *prev_pos = NULL;
55 char *next_pos; 51 char *next_pos;
52
56 if (bp == NULL) { 53 if (bp == NULL)
54 {
57 if (prev_pos == NULL) { 55 if (prev_pos == NULL)
56 {
58 LOG(llevError, "Called spool (%s) with NULL without previous call.\n", 57 LOG (llevError, "Called spool (%s) with NULL without previous call.\n", error);
59 error); 58 return NULL;
59 }
60 bp = prev_pos;
61 }
62 if (*bp == '\0')
63 {
64 LOG (llevError, "spool: End of line at %s\n", error);
60 return NULL; 65 return NULL;
61 } 66 }
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) { 67 if ((next_pos = strchr (bp, ':')) != NULL)
68 {
69 *next_pos = '\0'; 69 *next_pos = '\0';
70 prev_pos = next_pos + 1; 70 prev_pos = next_pos + 1;
71 }
71 } else 72 else
72 prev_pos = NULL; 73 prev_pos = NULL;
73 return bp; 74 return bp;
74} 75}
75 76
76/* 77/*
77 * Does what it says, copies the contents of the first score structure 78 * Does what it says, copies the contents of the first score structure
78 * to the second one. 79 * to the second one.
79 */ 80 */
80 81
82static void
81static void copy_score(score *sc1,score *sc2) { 83copy_score (score *sc1, score *sc2)
82 strncpy(sc2->name, sc1->name, BIG_NAME); 84{
83 sc2->name[BIG_NAME - 1] = '\0'; 85 assign (sc2->name , sc1->name);
84 strncpy(sc2->title, sc1->title, BIG_NAME); 86 assign (sc2->title , sc1->title);
85 sc2->title[BIG_NAME - 1] = '\0'; 87 assign (sc2->killer , sc1->killer);
86 strncpy(sc2->killer, sc1->killer, BIG_NAME); 88 assign (sc2->maplevel, sc1->maplevel);
87 sc2->killer[BIG_NAME - 1] = '\0';
88 sc2->exp = sc1->exp; 89 sc2->exp = sc1->exp;
89 strcpy(sc2->maplevel,sc1->maplevel);
90 sc2->maxhp = sc1->maxhp; 90 sc2->maxhp = sc1->maxhp;
91 sc2->maxsp = sc1->maxsp; 91 sc2->maxsp = sc1->maxsp;
92 sc2->maxgrace = sc1->maxgrace; 92 sc2->maxgrace = sc1->maxgrace;
93} 93}
94 94
95/* 95/*
96 * Writes the given score structure to a static buffer, and returns 96 * Writes the given score structure to a static buffer, and returns
97 * a pointer to it. 97 * a pointer to it.
98 */ 98 */
99 99
100static char *put_score(score *sc) { 100static char *
101put_score (score *sc)
102{
101 static char buf[MAX_BUF]; 103 static char buf[MAX_BUF];
102#ifndef WIN32 104
103 sprintf(buf,"%s:%s:%lld:%s:%s:%d:%d:%d",sc->name,sc->title,sc->exp,sc->killer,sc->maplevel, 105 sprintf (buf, "%s:%s:%" PRId64 ":%s:%s:%d:%d:%d",
106 sc->name, sc->title, (sint64)sc->exp, sc->killer,
104 sc->maxhp,sc->maxsp,sc->maxgrace); 107 sc->maplevel, sc->maxhp, sc->maxsp, sc->maxgrace);
105#else
106 sprintf(buf,"%s:%s:%I64d:%s:%s:%d:%d:%d",sc->name,sc->title,sc->exp,sc->killer,sc->maplevel,
107 sc->maxhp,sc->maxsp,sc->maxgrace);
108#endif
109 return buf; 108 return buf;
110} 109}
111 110
112/* 111/*
113 * The oposite of put_score, get_score reads from the given buffer into 112 * The oposite of put_score, get_score reads from the given buffer into
114 * a static score structure, and returns a pointer to it. 113 * a static score structure, and returns a pointer to it.
115 */ 114 */
116 115
117static score *get_score(char *bp) { 116static score *
117get_score (char *bp)
118{
118 static score sc; 119 static score sc;
119 char *cp; 120 char *cp;
120 121
121 if((cp=strchr(bp,'\n'))!=NULL) 122 if ((cp = strchr (bp, '\n')) != NULL)
122 *cp='\0'; 123 *cp = '\0';
123 124
124 if ((cp = spool(bp, "name")) == NULL) 125 if ((cp = spool (bp, "name")) == NULL)
125 return NULL; 126 return 0;
126 strncpy(sc.name,cp,BIG_NAME);
127 sc.name[BIG_NAME - 1] = '\0';
128 127
128 assign (sc.name, cp);
129
129 if ((cp = spool(NULL, "title")) == NULL) 130 if ((cp = spool (0, "title")) == NULL)
130 return NULL; 131 return 0;
131 strncpy(sc.title,cp,BIG_NAME);
132 sc.title[BIG_NAME - 1] = '\0';
133 132
133 assign (sc.title, cp);
134
134 if ((cp = spool(NULL, "score")) == NULL) 135 if ((cp = spool (0, "score")) == NULL)
135 return NULL; 136 return 0;
136#ifndef WIN32 137
137 sscanf(cp,"%lld",&sc.exp);
138#else
139 sscanf(cp,"%I64d",&sc.exp); 138 sscanf (cp, "%" SCNd64, &sc.exp);
140#endif
141 139
142 if ((cp = spool(NULL, "killer")) == NULL) 140 if ((cp = spool (0, "killer")) == NULL)
143 return NULL; 141 return 0;
144 strncpy(sc.killer, cp, BIG_NAME);
145 sc.killer[BIG_NAME - 1] = '\0';
146 142
143 assign (sc.killer, cp);
144
147 if ((cp = spool(NULL, "map")) == NULL) 145 if ((cp = spool (0, "map")) == NULL)
148 return NULL; 146 return 0;
149 strncpy(sc.maplevel, cp, BIG_NAME);
150 sc.maplevel[BIG_NAME - 1] = '\0';
151 147
148 assign (sc.maplevel, cp);
149
152 if ((cp = spool(NULL, "maxhp")) == NULL) 150 if ((cp = spool (0, "maxhp")) == NULL)
153 return NULL; 151 return 0;
152
154 sscanf(cp, "%d", &sc.maxhp); 153 sscanf (cp, "%d", &sc.maxhp);
155 154
156 if ((cp = spool(NULL, "maxsp")) == NULL) 155 if ((cp = spool (0, "maxsp")) == NULL)
157 return NULL; 156 return 0;
157
158 sscanf(cp, "%d", &sc.maxsp); 158 sscanf (cp, "%d", &sc.maxsp);
159 159
160 if ((cp = spool(NULL, "maxgrace")) == NULL) 160 if ((cp = spool (0, "maxgrace")) == NULL)
161 return NULL; 161 return 0;
162
162 sscanf(cp, "%d", &sc.maxgrace); 163 sscanf (cp, "%d", &sc.maxgrace);
163 return &sc; 164 return &sc;
164} 165}
165 166
167static char *
166static char * draw_one_high_score(score *sc) { 168draw_one_high_score (score *sc)
169{
167 static char retbuf[MAX_BUF]; 170 static char retbuf[MAX_BUF];
168 171
169 if(!strncmp(sc->killer,"quit",MAX_NAME)) 172 if (!strncmp (sc->killer, "quit", MAX_NAME))
170 sprintf(retbuf,"%3d %10lld %s the %s quit the game on map %s [%d][%d][%d].", 173 sprintf (retbuf, "%3d %10lld %s the %s quit the game on map %s [%d][%d][%d].",
171 sc->position,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);
172 sc->maxgrace);
173 else if(!strncmp(sc->killer,"left",MAX_NAME)) 175 else if (!strncmp (sc->killer, "left", MAX_NAME))
174 sprintf(retbuf,"%3d %10lld %s the %s left the game on map %s [%d][%d][%d].", 176 sprintf (retbuf, "%3d %10lld %s the %s left the game on map %s [%d][%d][%d].",
175 sc->position,sc->exp,sc->name,sc->title,sc->maplevel,sc->maxhp,sc->maxsp, 177 sc->position, (long long) sc->exp, sc->name, sc->title, sc->maplevel, sc->maxhp, sc->maxsp, sc->maxgrace);
176 sc->maxgrace);
177 else 178 else
178 sprintf(retbuf,"%3d %10lld %s the %s was killed by %s on map %s [%d][%d][%d].", 179 sprintf (retbuf, "%3d %10lld %s the %s was killed by %s on map %s [%d][%d][%d].",
179 sc->position,sc->exp,sc->name,sc->title,sc->killer,sc->maplevel, 180 sc->position, (long long) sc->exp, sc->name, sc->title, sc->killer, sc->maplevel, sc->maxhp, sc->maxsp, sc->maxgrace);
180 sc->maxhp,sc->maxsp,sc->maxgrace);
181 return retbuf; 181 return retbuf;
182} 182}
183
183/* 184/*
184 * add_score() adds the given score-structure to the high-score list, but 185 * add_score() adds the given score-structure to the high-score list, but
185 * only if it was good enough to deserve a place. 186 * only if it was good enough to deserve a place.
186 */ 187 */
187 188
189static score *
188static score *add_score(score *new_score) { 190add_score (score *new_score)
191{
189 FILE *fp; 192 FILE *fp;
190 static score old_score; 193 static score old_score;
191 score *tmp_score,pscore[HIGHSCORE_LENGTH]; 194 score *tmp_score, pscore[HIGHSCORE_LENGTH];
192 char buf[MAX_BUF], filename[MAX_BUF], *bp; 195 char buf[MAX_BUF], filename[MAX_BUF], *bp;
193 int nrofscores=0,flag=0,i,comp; 196 int nrofscores = 0, flag = 0, i, comp;
194 197
195 new_score->position=HIGHSCORE_LENGTH+1; 198 new_score->position = HIGHSCORE_LENGTH + 1;
196 old_score.position= -1; 199 old_score.position = -1;
197 sprintf(filename,"%s/%s",settings.localdir,HIGHSCORE); 200 sprintf (filename, "%s/%s", settings.localdir, HIGHSCORE);
198 if((fp=open_and_uncompress(filename,1,&comp))!=NULL) { 201 if ((fp = open_and_uncompress (filename, 1, &comp)) != NULL)
202 {
199 while(fgets(buf,MAX_BUF,fp)!=NULL&&nrofscores<HIGHSCORE_LENGTH) { 203 while (fgets (buf, MAX_BUF, fp) != NULL && nrofscores < HIGHSCORE_LENGTH)
204 {
200 if((tmp_score=get_score(buf))==NULL) break; 205 if ((tmp_score = get_score (buf)) == NULL)
201 if(!flag&&new_score->exp>=tmp_score->exp) {
202 copy_score(new_score,&pscore[nrofscores]);
203 new_score->position=nrofscores;
204 flag=1;
205 if(++nrofscores>=HIGHSCORE_LENGTH)
206 break; 206 break;
207 } 207 if (!flag && new_score->exp >= tmp_score->exp)
208 {
209 copy_score (new_score, &pscore[nrofscores]);
210 new_score->position = nrofscores;
211 flag = 1;
212 if (++nrofscores >= HIGHSCORE_LENGTH)
213 break;
214 }
208 if(!strcmp(new_score->name,tmp_score->name)) { /* Another entry */ 215 if (!strcmp (new_score->name, tmp_score->name))
216 { /* Another entry */
209 copy_score(tmp_score,&old_score); 217 copy_score (tmp_score, &old_score);
210 old_score.position=nrofscores; 218 old_score.position = nrofscores;
211 if(flag) 219 if (flag)
212 continue; 220 continue;
213 } 221 }
214 copy_score(tmp_score,&pscore[nrofscores++]); 222 copy_score (tmp_score, &pscore[nrofscores++]);
215 } 223 }
216 close_and_delete(fp, comp); 224 close_and_delete (fp, comp);
217 } 225 }
218 if(old_score.position!=-1&&old_score.exp>=new_score->exp) 226 if (old_score.position != -1 && old_score.exp >= new_score->exp)
219 return &old_score; /* Did not beat old score */ 227 return &old_score; /* Did not beat old score */
220 if(!flag&&nrofscores<HIGHSCORE_LENGTH) 228 if (!flag && nrofscores < HIGHSCORE_LENGTH)
221 copy_score(new_score,&pscore[nrofscores++]); 229 copy_score (new_score, &pscore[nrofscores++]);
222 if((fp=fopen(filename,"w"))==NULL) { 230 if ((fp = fopen (filename, "w")) == NULL)
231 {
223 LOG(llevError, "Cannot write to highscore file %s: %s\n", filename, strerror(errno)); 232 LOG (llevError, "Cannot write to highscore file %s: %s\n", filename, strerror (errno));
224 return NULL; 233 return NULL;
225 } 234 }
226 for(i=0;i<nrofscores;i++) { 235 for (i = 0; i < nrofscores; i++)
236 {
227 bp=put_score(&pscore[i]); 237 bp = put_score (&pscore[i]);
228 fprintf(fp,"%s\n",bp); 238 fprintf (fp, "%s\n", bp);
229 } 239 }
230 fclose(fp); 240 fclose (fp);
231 if(flag) { 241 if (flag)
242 {
243
232/* Eneq(@csd.uu.se): Patch to fix error in adding a new score to the 244/* Eneq(@csd.uu.se): Patch to fix error in adding a new score to the
233 hiscore-list */ 245 hiscore-list */
234 if(old_score.position==-1) 246 if (old_score.position == -1)
235 return new_score; 247 return new_score;
248 return &old_score;
249 }
250 new_score->position = -1;
251 if (old_score.position != -1)
236 return &old_score; 252 return &old_score;
237 } 253 if (nrofscores)
238 new_score->position= -1; 254 {
239 if(old_score.position!=-1) 255 copy_score (&pscore[nrofscores - 1], &old_score);
240 return &old_score; 256 return &old_score;
241 if(nrofscores) {
242 copy_score(&pscore[nrofscores-1],&old_score);
243 return &old_score;
244 } 257 }
245 LOG(llevError,"Highscore error.\n"); 258 LOG (llevError, "Highscore error.\n");
246 return NULL; 259 return NULL;
247} 260}
248 261
262void
249void check_score(object *op) { 263check_score (object *op)
264{
250 score new_score; 265 score new_score;
251 score *old_score; 266 score *old_score;
252 267
253 if(op->stats.exp==0) 268 if (op->stats.exp == 0)
254 return; 269 return;
255 270
256 if(!op->contr->name_changed) { 271 assign (new_score.name, op->name);
257 if(op->stats.exp>0) { 272 assign (new_score.title, op->title.length () ? &op->title : op->contr->title);
258 new_draw_info(NDI_UNIQUE, 0,op,"As you haven't changed your name, you won't"); 273 assign (new_score.killer, op->contr->killer[0] ? op->contr->killer : "a dungeon collapse");
259 new_draw_info(NDI_UNIQUE, 0,op,"get into the high-score list."); 274 assign (new_score.maplevel, op->map ? op->map->name ? &op->map->name : &op->map->path : "");
260 } 275
261 return;
262 }
263 if(QUERY_FLAG(op,FLAG_WAS_WIZ)) {
264 new_draw_info(NDI_UNIQUE, 0,op,"Since you have been in wizard mode,");
265 new_draw_info(NDI_UNIQUE, 0,op,"you can't enter the high-score list.");
266 return;
267 }
268 if (op->contr->explore) {
269 new_draw_info(NDI_UNIQUE, 0,op,"Since you were in explore mode,");
270 new_draw_info(NDI_UNIQUE, 0,op,"you can't enter the high-score list.");
271 return;
272 }
273 strncpy(new_score.name,op->name,BIG_NAME);
274 new_score.name[BIG_NAME-1] = '\0';
275 strncpy(new_score.title,op->contr->own_title,BIG_NAME);
276 if(new_score.title[0]=='\0')
277 strncpy(new_score.title,op->contr->title,BIG_NAME);
278 new_score.title[BIG_NAME-1] = '\0';
279 strncpy(new_score.killer,op->contr->killer,BIG_NAME);
280 if(new_score.killer[0]=='\0')
281 strcpy(new_score.killer,"a dungeon collapse");
282 new_score.killer[BIG_NAME-1] = '\0';
283 new_score.exp=op->stats.exp; 276 new_score.exp = op->stats.exp;
284 if(op->map == NULL)
285 *new_score.maplevel = '\0';
286 else {
287 strncpy(new_score.maplevel,
288 op->map->name?op->map->name:op->map->path,
289 BIG_NAME-1);
290 new_score.maplevel[BIG_NAME-1] = '\0';
291 }
292 new_score.maxhp=(int) op->stats.maxhp; 277 new_score.maxhp = op->stats.maxhp;
293 new_score.maxsp=(int) op->stats.maxsp; 278 new_score.maxsp = op->stats.maxsp;
294 new_score.maxgrace=(int) op->stats.maxgrace; 279 new_score.maxgrace = op->stats.maxgrace;
280
295 if((old_score=add_score(&new_score))==NULL) { 281 if ((old_score = add_score (&new_score)) == NULL)
282 {
296 new_draw_info(NDI_UNIQUE, 0,op,"Error in the highscore list."); 283 new_draw_info (NDI_UNIQUE, 0, op, "Error in the highscore list.");
297 return; 284 return;
298 } 285 }
286
299 if(new_score.position == -1) { 287 if (new_score.position == -1)
288 {
300 new_score.position = HIGHSCORE_LENGTH+1; /* Not strictly correct... */ 289 new_score.position = HIGHSCORE_LENGTH + 1; /* Not strictly correct... */
301 if(!strcmp(old_score->name,new_score.name)) 290 if (!strcmp (old_score->name, new_score.name))
302 new_draw_info(NDI_UNIQUE, 0,op,"You didn't beat your last highscore:"); 291 new_draw_info (NDI_UNIQUE, 0, op, "You didn't beat your last highscore:");
303 else 292 else
304 new_draw_info(NDI_UNIQUE, 0,op,"You didn't enter the highscore list:"); 293 new_draw_info (NDI_UNIQUE, 0, op, "You didn't enter the highscore list:");
305 new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(old_score)); 294 new_draw_info (NDI_UNIQUE, 0, op, draw_one_high_score (old_score));
306 new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(&new_score)); 295 new_draw_info (NDI_UNIQUE, 0, op, draw_one_high_score (&new_score));
307 return; 296 return;
308 } 297 }
298
309 if(old_score->exp>=new_score.exp) 299 if (old_score->exp >= new_score.exp)
310 new_draw_info(NDI_UNIQUE, 0,op,"You didn't beat your last score:"); 300 new_draw_info (NDI_UNIQUE, 0, op, "You didn't beat your last score:");
311 else 301 else
312 new_draw_info(NDI_UNIQUE, 0,op,"You beat your last score:"); 302 new_draw_info (NDI_UNIQUE, 0, op, "You beat your last score:");
313 303
314 new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(old_score)); 304 new_draw_info (NDI_UNIQUE, 0, op, draw_one_high_score (old_score));
315 new_draw_info(NDI_UNIQUE, 0,op, draw_one_high_score(&new_score)); 305 new_draw_info (NDI_UNIQUE, 0, op, draw_one_high_score (&new_score));
316} 306}
317
318
319 307
320/* displays the high score file. object is the calling object 308/* displays the high score file. object is the calling object
321 * (null if being called via command line.) max is the maximum 309 * (null if being called via command line.) max is the maximum
322 * number of scores to display. match, if set, is the name or class 310 * number of scores to display. match, if set, is the name or class
323 * to match to. 311 * to match to.
324 */ 312 */
325 313
314void
326void display_high_score(object *op,int max, const char *match) { 315display_high_score (object *op, int max, const char *match)
316{
327 const size_t maxchar = 80; 317 const size_t maxchar = 80;
328 FILE *fp; 318 FILE *fp;
329 char buf[MAX_BUF],*scorebuf, *bp, *cp; 319 char buf[MAX_BUF], *scorebuf, *bp, *cp;
330 int i=0,j=0,comp; 320 int i = 0, j = 0, comp;
331 score *sc; 321 score *sc;
332 322
333 sprintf(buf,"%s/%s",settings.localdir,HIGHSCORE); 323 sprintf (buf, "%s/%s", settings.localdir, HIGHSCORE);
334 if((fp=open_and_uncompress(buf,0,&comp))==NULL) { 324 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
325 {
335 LOG(llevError, "Cannot open highscore file %s: %s\n", buf, strerror(errno)); 326 LOG (llevError, "Cannot open highscore file %s: %s\n", buf, strerror (errno));
336 if(op!=NULL) 327 if (op != NULL)
337 new_draw_info(NDI_UNIQUE, 0,op,"There is no highscore file."); 328 new_draw_info (NDI_UNIQUE, 0, op, "There is no highscore file.");
338 return; 329 return;
339 } 330 }
340 if(op != NULL) 331 if (op != NULL)
341 clear_win_info(op); 332 clear_win_info (op);
342 new_draw_info(NDI_UNIQUE, 0,op,"Nr Score Who [max hp][max sp][max grace]"); 333 new_draw_info (NDI_UNIQUE, 0, op, "Nr Score Who [max hp][max sp][max grace]");
343 334
344 while(fgets(buf,MAX_BUF,fp)!=NULL) { 335 while (fgets (buf, MAX_BUF, fp) != NULL)
336 {
345 if(j>=HIGHSCORE_LENGTH||i>=(max-1)) 337 if (j >= HIGHSCORE_LENGTH || i >= (max - 1))
346 break; 338 break;
347 if((sc=get_score(buf))==NULL) 339 if ((sc = get_score (buf)) == NULL)
348 break; 340 break;
349 sc->position=++j; 341 sc->position = ++j;
350 if (match==NULL) { 342 if (match == NULL)
343 {
351 scorebuf=draw_one_high_score(sc); 344 scorebuf = draw_one_high_score (sc);
352 i++; 345 i++;
346 }
353 } else { 347 else
348 {
354 if (!strcasecmp(sc->name, match) || !strcasecmp(sc->title, match)) { 349 if (!strcasecmp (sc->name, match) || !strcasecmp (sc->title, match))
350 {
355 scorebuf=draw_one_high_score(sc); 351 scorebuf = draw_one_high_score (sc);
356 i++; 352 i++;
357 } 353 }
354 else
358 else continue; 355 continue;
359 } 356 }
360 /* Replaced what seemed to an overly complicated word wrap method 357 /* Replaced what seemed to an overly complicated word wrap method
361 * still word wraps, but assumes at most 2 lines of data. 358 * still word wraps, but assumes at most 2 lines of data.
362 * mw - 2-12-97 359 * mw - 2-12-97
363 */ 360 */
364 strncpy(buf,scorebuf,MAX_BUF); 361 assign (buf, scorebuf);
365 buf[MAX_BUF-1] = '\0'; 362
366 cp=buf; 363 cp = buf;
367 while (strlen(cp)> maxchar) { 364 while (strlen (cp) > maxchar)
365 {
368 bp = cp+maxchar-1; 366 bp = cp + maxchar - 1;
369 while (*bp != ' ' && bp>cp) bp--; 367 while (*bp != ' ' && bp > cp)
368 bp--;
370 *bp='\0'; 369 *bp = '\0';
370
371 if (op == NULL) { 371 if (op == NULL)
372 LOG(llevDebug, "%s\n", cp); 372 LOG (llevDebug, "%s\n", cp);
373 }
374 else { 373 else
375 new_draw_info(NDI_UNIQUE, 0,op,cp); 374 new_draw_info (NDI_UNIQUE, 0, op, cp);
376 } 375
377 sprintf(buf, " %s", bp+1); 376 sprintf (buf, " %s", bp + 1);
378 cp = buf; 377 cp = buf;
379 i++; 378 i++;
380 } 379 }
380
381 if(op == NULL) 381 if (op == NULL)
382 LOG(llevDebug, "%s\n", buf); 382 LOG (llevDebug, "%s\n", buf);
383 else 383 else
384 new_draw_info(NDI_UNIQUE, 0,op,buf); 384 new_draw_info (NDI_UNIQUE, 0, op, buf);
385 } 385 }
386
386 close_and_delete(fp, comp); 387 close_and_delete (fp, comp);
387} 388}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines