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.5 by root, Sun Sep 10 15:59:57 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines