Check-in Lasker-2.2.3 tar ball from samba.org
[capablanca.git] / lasker-2.2.3 / src / playerdb_old.c
1 /*
2    Copyright (c) 1993 Richard V. Nash.
3    Copyright (c) 2000 Dan Papasian
4    Copyright (C) Andrew Tridgell 2002
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22
23 /*
24   support for reading the old player formats
25   thank goodness I don't need to update this any more! It sure was a complex format.
26 */
27
28
29 /* return 0 if corrupt */
30
31 static int ReadV1PlayerFmt(int p,struct player *pp, FILE * fp, const char *file, int version)
32 {
33
34  int i,size_cens, size_noplay, size_not, size_gnot, size_chan, len;
35  int bs,ss,ws,ls,bugs;
36  int bell, pgn, notifiedby, pin, gin, avail, private, jprivate;
37  int open, ropen, rated, tell, kib, shout, cshout, automail, mailmess;
38  int numAlias = 0;
39
40  char* tmp;
41  char tmp2[MAX_STRING_LENGTH];
42
43  fgets(tmp2, MAX_STRING_LENGTH, fp);
44  if (strcmp(tmp2,"NONE\n")) {
45    tmp2[strlen(tmp2)-1] = '\0';
46    pp->name = strdup (tmp2);
47  } else
48    pp->name = NULL;
49  fgets(tmp2, MAX_STRING_LENGTH, fp);
50  if (strcmp(tmp2,"NONE\n")) {
51    tmp2[strlen(tmp2)-1] = '\0';
52    pp->fullName = strdup (tmp2);
53  } else
54    pp->fullName = NULL;
55  fgets(tmp2, MAX_STRING_LENGTH, fp);
56  if (strcmp(tmp2,"NONE\n")) {
57    tmp2[strlen(tmp2)-1] = '\0';
58    pp->passwd = strdup (tmp2);
59  } else
60    pp->passwd = NULL;
61  fgets(tmp2, MAX_STRING_LENGTH, fp);
62  if (strcmp(tmp2,"NONE\n")) {
63    tmp2[strlen(tmp2)-1] = '\0';
64    pp->emailAddress = strdup (tmp2);
65  } else
66    pp->emailAddress = NULL;
67  if (fscanf(fp, "%u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %d\n",
68
69  &pp->s_stats.num, &pp->s_stats.win, &pp->s_stats.los,
70  &pp->s_stats.dra, &pp->s_stats.rating, &ss,
71  &pp->s_stats.ltime, &pp->s_stats.best, &pp->s_stats.whenbest,
72
73  &pp->b_stats.num, &pp->b_stats.win, &pp->b_stats.los,
74  &pp->b_stats.dra, &pp->b_stats.rating, &bs,
75  &pp->b_stats.ltime, &pp->b_stats.best, &pp->b_stats.whenbest,
76
77  &pp->w_stats.num, &pp->w_stats.win, &pp->w_stats.los,
78  &pp->w_stats.dra, &pp->w_stats.rating, &ws,
79  &pp->w_stats.ltime, &pp->w_stats.best, &pp->w_stats.whenbest,
80
81  &pp->l_stats.num, &pp->l_stats.win, &pp->l_stats.los,
82  &pp->l_stats.dra, &pp->l_stats.rating, &ls,
83  &pp->l_stats.ltime, &pp->l_stats.best, &pp->l_stats.whenbest,
84
85  &pp->bug_stats.num, &pp->bug_stats.win, &pp->bug_stats.los,
86  &pp->bug_stats.dra, &pp->bug_stats.rating, &bugs,
87  &pp->bug_stats.ltime, &pp->bug_stats.best, &pp->bug_stats.whenbest,
88  &pp->lastHost.s_addr) != 46) {
89   d_printf("Player %s is corrupt\n",player_globals.parray[p].name);
90     free(pp->fullName);
91     free(pp->passwd);
92     free(pp->emailAddress);
93     pp->fullName = NULL;
94     pp->passwd = NULL;
95     pp->emailAddress = NULL;
96   return 0; 
97  }
98
99  pp->b_stats.sterr = bs / 10.0;
100  pp->s_stats.sterr = ss / 10.0;
101  pp->w_stats.sterr = ws / 10.0;
102  pp->l_stats.sterr = ls / 10.0;
103  pp->bug_stats.sterr = bugs / 10.0;
104
105  fgets (tmp2, MAX_STRING_LENGTH, fp);
106    tmp2[strlen(tmp2)-1] = '\0';
107    pp->prompt = strdup(tmp2);
108  if (version == 1) {
109    if (fscanf (fp, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
110    &open, &rated, &ropen, &pp->timeOfReg,
111    &pp->totalTime, &bell, &pgn, &notifiedby,
112    &pin, &gin, &shout, &cshout,
113    &tell, &kib, &private, &jprivate,
114    &automail, &mailmess, &pp->style, &pp->d_time,
115    &pp->d_inc, &pp->d_height, &pp->d_width, &pp->language,
116    &pp->adminLevel, &pp->num_white, &pp->num_black, &pp->highlight,
117    &pp->num_comments,
118    &pp->num_plan, &pp->num_formula,&size_cens,
119    &size_not, &size_noplay,
120    &size_gnot, &numAlias, &size_chan) != 37) {
121     d_printf("Player %s is corrupt.\n",player_globals.parray[p].name);
122     free(pp->prompt);
123     pp->prompt = config_get("DEFAULT_PROMPT");
124     free(pp->fullName);
125     free(pp->passwd);
126     free(pp->emailAddress);
127     pp->fullName = NULL;
128     pp->passwd = NULL;
129     pp->emailAddress = NULL;
130     pp->num_plan = 0;
131     pp->num_formula = 0;
132     pp->adminLevel = 0;
133     return 0;
134    }
135  } else if (version == 2) {
136    if (fscanf (fp, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
137    &open, &rated, &ropen, &pp->timeOfReg,
138    &pp->totalTime, &bell, &pgn, &notifiedby,
139    &pin, &gin, &avail, &shout, &cshout,
140    &tell, &kib, &private, &jprivate,
141    &automail, &mailmess, &pp->style, &pp->d_time,
142    &pp->d_inc, &pp->d_height, &pp->d_width, &pp->language,
143    &pp->adminLevel, &pp->num_white, &pp->num_black, &pp->highlight,
144    &pp->num_comments,
145    &pp->num_plan, &pp->num_formula,&size_cens,
146    &size_not, &size_noplay,
147    &size_gnot, &numAlias, &size_chan) != 38) {
148     d_printf("Player %s is corrupt.\n",player_globals.parray[p].name);
149     free(pp->prompt);
150     pp->prompt = config_get("DEFAULT_PROMPT");
151     free(pp->fullName);
152     free(pp->passwd);
153     free(pp->emailAddress);
154     pp->fullName = NULL;
155     pp->passwd = NULL;
156     pp->emailAddress = NULL;
157     pp->num_plan = 0;
158     pp->num_formula = 0;
159     pp->adminLevel = 0;
160     return 0;
161    }
162  } else if (version > 2) {
163    if (fscanf (fp, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
164    &open, &rated, &ropen, &pp->timeOfReg,
165    &pp->totalTime, &bell, &pgn, &notifiedby,
166    &pin, &gin, &avail, &shout, &cshout,
167    &tell, &kib, &private, &jprivate,
168    &automail, &mailmess, &pp->style, &pp->d_time,
169    &pp->d_inc, &pp->d_height, &pp->d_width, &pp->language,
170    &pp->adminLevel, &pp->num_white, &pp->num_black, &pp->highlight,
171    &pp->num_comments,
172    &pp->num_plan, &pp->num_formula,&size_cens,
173    &size_not, &size_noplay,
174    &size_gnot, &numAlias, &size_chan, &pp->availmin, &pp->availmax) != 40) {
175     d_printf("Player %s is corrupt.\n",player_globals.parray[p].name);
176     free(pp->prompt);
177     pp->prompt = config_get("DEFAULT_PROMPT");
178     free(pp->fullName);
179     free(pp->passwd);
180     free(pp->emailAddress);
181     pp->fullName = NULL;
182     pp->passwd = NULL;
183     pp->emailAddress = NULL;
184     pp->num_plan = 0;
185     pp->num_formula = 0;
186     pp->adminLevel = 0;
187     return 0;
188    }
189  }
190  SetFlag(pp->Flags, PFLAG_OPEN, open);
191  SetFlag(pp->Flags, PFLAG_ROPEN, ropen);
192  SetFlag(pp->Flags, PFLAG_RATED, rated);
193  SetFlag(pp->Flags, PFLAG_BELL, bell);
194  SetFlag(pp->Flags, PFLAG_PGN, pgn);
195  SetFlag(pp->Flags, PFLAG_NOTIFYBY, notifiedby);
196  SetFlag(pp->Flags, PFLAG_PIN, pin);
197  SetFlag(pp->Flags, PFLAG_GIN, gin);
198  SetFlag(pp->Flags, PFLAG_AVAIL, avail);
199  SetFlag(pp->Flags, PFLAG_PRIVATE, private);
200  SetFlag(pp->Flags, PFLAG_JPRIVATE, jprivate);
201  SetFlag(pp->Flags, PFLAG_SHOUT, shout);
202  SetFlag(pp->Flags, PFLAG_CSHOUT, cshout);
203  SetFlag(pp->Flags, PFLAG_TELL, tell);
204  SetFlag(pp->Flags, PFLAG_KIBITZ, kib);
205  SetFlag(pp->Flags, PFLAG_AUTOMAIL, automail);
206  SetFlag(pp->Flags, PFLAG_MAILMESS, mailmess);
207
208  if (version > 3)
209    getc (fp); /* skip a dot */
210
211    if (pp->num_plan > 0) {
212      for (i = 0; i < pp->num_plan; i++) {
213        fgets(tmp2, MAX_LINE_SIZE, fp);
214        if (!(len = strlen(tmp2))) {
215          d_printf( "CHESSD: Error bad plan in file %s\n", file);
216          i--;
217          pp->num_plan--; 
218        } else {
219          tmp2[len - 1] = '\0';  /* Get rid of '\n' */
220          pp->planLines[i] = (len > 1) ? strdup(tmp2) : NULL;
221        }
222      }
223    }
224    if (pp->num_formula > 0) {
225      for (i = 0; i < pp->num_formula; i++) {
226        fgets(tmp2, MAX_LINE_SIZE, fp);
227        if (!(len = strlen(tmp2))) {
228          d_printf( "CHESSD: Error bad formula in file %s\n", file);
229          i--;
230          pp->num_formula--;
231        } else {
232          tmp2[len - 1] = '\0';  /* Get rid of '\n' */
233          pp->formulaLines[i] = (len > 1) ? strdup(tmp2) : NULL;
234        }
235      }
236    }
237   fgets(tmp2, MAX_LINE_SIZE, fp);
238   tmp2[strlen(tmp2) - 1] = '\0';
239   if (!strcmp (tmp2,"NONE"))
240     pp->formula = NULL;
241   else
242     pp->formula = strdup(tmp2);
243
244   if (numAlias > 0) {
245     for (i = 0; i < numAlias; i++) {
246       fgets(tmp2, MAX_LINE_SIZE, fp);
247       if (!(len = strlen(tmp2))) {
248         d_printf( "CHESSD: Error bad alias in file %s\n", file);
249         i--;
250       } else {
251         tmp2[len - 1] = '\0';  /* Get rid of '\n' */
252         tmp = tmp2;
253         tmp = eatword(tmp2);
254         *tmp = '\0';
255         tmp++;
256         tmp = eatwhite(tmp);
257         alias_add(p, tmp2, tmp);
258       }
259     }
260   }
261
262     while (size_cens--) {
263       fscanf(fp,"%s",tmp2);
264       list_add(p, L_CENSOR, tmp2);
265       }
266
267     while(size_not--) {
268       fscanf(fp,"%s",tmp2);
269       list_add(p, L_NOTIFY, tmp2);
270       }
271
272     while(size_noplay--) {
273       fscanf(fp,"%s",tmp2);
274       list_add(p, L_NOPLAY, tmp2);
275       }
276
277     while(size_gnot--) {
278       fscanf(fp,"%s",tmp2);
279       list_add(p, L_GNOTIFY, tmp2);
280       }
281
282     while(size_chan--) {
283       fscanf(fp,"%s",tmp2);
284       list_add(p, L_CHANNEL, tmp2);
285       }
286   return 1;
287 }
288
289 static int got_attr_value_player(int p, char *attr, char *value, FILE * fp, const char *file)
290 {
291   int i, len;
292   char tmp[MAX_LINE_SIZE], *tmp1;
293   int numAlias = 0;
294
295   if (!strcmp(attr, "name:")) {
296     player_globals.parray[p].name = strdup(value);
297   } else if (!strcmp(attr, "password:")) {
298     player_globals.parray[p].passwd = strdup(value);
299   } else if (!strcmp(attr, "fullname:")) {
300     player_globals.parray[p].fullName = strdup(value);
301   } else if (!strcmp(attr, "email:")) {
302     player_globals.parray[p].emailAddress = strdup(value);
303   } else if (!strcmp(attr, "prompt:")) {
304     player_globals.parray[p].prompt = strdup(value);
305   } else if (!strcmp(attr, "s_num:")) {
306     player_globals.parray[p].s_stats.num = atoi(value);
307   } else if (!strcmp(attr, "s_win:")) {
308     player_globals.parray[p].s_stats.win = atoi(value);
309   } else if (!strcmp(attr, "s_loss:")) {
310     player_globals.parray[p].s_stats.los = atoi(value);
311   } else if (!strcmp(attr, "s_draw:")) {
312     player_globals.parray[p].s_stats.dra = atoi(value);
313   } else if (!strcmp(attr, "s_rating:")) {
314     player_globals.parray[p].s_stats.rating = atoi(value);
315   } else if (!strcmp(attr, "s_sterr:")) {
316     player_globals.parray[p].s_stats.sterr = (atoi(value) / 10.0);
317   } else if (!strcmp(attr, "s_ltime:")) {
318     player_globals.parray[p].s_stats.ltime = atoi(value);
319   } else if (!strcmp(attr, "s_best:")) {
320     player_globals.parray[p].s_stats.best = atoi(value);
321   } else if (!strcmp(attr, "s_wbest:")) {
322     player_globals.parray[p].s_stats.whenbest = atoi(value);
323   } else if (!strcmp(attr, "b_num:")) {
324     player_globals.parray[p].b_stats.num = atoi(value);
325   } else if (!strcmp(attr, "b_win:")) {
326     player_globals.parray[p].b_stats.win = atoi(value);
327   } else if (!strcmp(attr, "b_loss:")) {
328     player_globals.parray[p].b_stats.los = atoi(value);
329   } else if (!strcmp(attr, "b_draw:")) {
330     player_globals.parray[p].b_stats.dra = atoi(value);
331   } else if (!strcmp(attr, "b_rating:")) {
332     player_globals.parray[p].b_stats.rating = atoi(value);
333   } else if (!strcmp(attr, "b_sterr:")) {
334     player_globals.parray[p].b_stats.sterr = (atoi(value) / 10.0);
335   } else if (!strcmp(attr, "b_ltime:")) {
336     player_globals.parray[p].b_stats.ltime = atoi(value);
337   } else if (!strcmp(attr, "b_best:")) {
338     player_globals.parray[p].b_stats.best = atoi(value);
339   } else if (!strcmp(attr, "b_wbest:")) {
340     player_globals.parray[p].b_stats.whenbest = atoi(value);
341   } else if (!strcmp(attr, "w_num:")) {
342     player_globals.parray[p].w_stats.num = atoi(value);
343   } else if (!strcmp(attr, "w_win:")) {
344     player_globals.parray[p].w_stats.win = atoi(value);
345   } else if (!strcmp(attr, "w_loss:")) {
346     player_globals.parray[p].w_stats.los = atoi(value);
347   } else if (!strcmp(attr, "w_draw:")) {
348     player_globals.parray[p].w_stats.dra = atoi(value);
349   } else if (!strcmp(attr, "w_rating:")) {
350     player_globals.parray[p].w_stats.rating = atoi(value);
351   } else if (!strcmp(attr, "w_sterr:")) {
352     player_globals.parray[p].w_stats.sterr = (atoi(value) / 10.0);
353   } else if (!strcmp(attr, "w_ltime:")) {
354     player_globals.parray[p].w_stats.ltime = atoi(value);
355   } else if (!strcmp(attr, "w_best:")) {
356     player_globals.parray[p].w_stats.best = atoi(value);
357   } else if (!strcmp(attr, "w_wbest:")) {
358     player_globals.parray[p].w_stats.whenbest = atoi(value);
359   } else if (!strcmp(attr, "open:")) {
360     SetPFlag(p, PFLAG_OPEN, atoi(value));
361   } else if (!strcmp(attr, "rated:")) {
362     SetPFlag(p, PFLAG_RATED, atoi(value));
363   } else if (!strcmp(attr, "ropen:")) {
364     SetPFlag(p, PFLAG_ROPEN, atoi(value));
365   } else if (!strcmp(attr, "bell:")) {
366     SetPFlag(p, PFLAG_BELL, atoi(value));
367   } else if (!strcmp(attr, "pgn:")) {
368     SetPFlag(p, PFLAG_PGN, atoi(value));
369   } else if (!strcmp(attr, "timeofreg:")) {
370     player_globals.parray[p].timeOfReg = atoi(value);
371   } else if (!strcmp(attr, "totaltime:")) {
372     player_globals.parray[p].totalTime = atoi(value);
373   } else if (!strcmp(attr, "notifiedby:")) {
374     SetPFlag(p, PFLAG_NOTIFYBY, atoi(value));
375   } else if (!strcmp(attr, "i_login:")) {
376     SetPFlag(p, PFLAG_PIN, atoi(value));
377   } else if (!strcmp(attr, "i_game:")) {
378     SetPFlag(p, PFLAG_GIN, atoi(value));
379   } else if (!strcmp(attr, "i_shout:")) {
380     SetPFlag(p, PFLAG_SHOUT, atoi(value));
381   } else if (!strcmp(attr, "i_cshout:")) {
382     SetPFlag(p, PFLAG_CSHOUT, atoi(value));
383   } else if (!strcmp(attr, "i_tell:")) {
384     SetPFlag(p, PFLAG_TELL, atoi(value));
385   } else if (!strcmp(attr, "i_kibitz:")) {
386     SetPFlag(p, PFLAG_KIBITZ, atoi(value));
387   } else if (!strcmp(attr, "kiblevel:")) {
388     player_globals.parray[p].kiblevel = atoi(value);
389   } else if (!strcmp(attr, "private:")) {
390     SetPFlag(p, PFLAG_PRIVATE, atoi(value));
391   } else if (!strcmp(attr, "jprivate:")) {
392     SetPFlag(p, PFLAG_JPRIVATE, atoi(value));
393   } else if (!strcmp(attr, "automail:")) {
394     SetPFlag(p, PFLAG_AUTOMAIL, atoi(value));
395   } else if (!strcmp(attr, "i_mailmess:")) {
396     SetPFlag(p, PFLAG_MAILMESS, atoi(value));
397   } else if (!strcmp(attr, "style:")) {
398     player_globals.parray[p].style = atoi(value);
399   } else if (!strcmp(attr, "d_time:")) {
400     player_globals.parray[p].d_time = atoi(value);
401   } else if (!strcmp(attr, "d_inc:")) {
402     player_globals.parray[p].d_inc = atoi(value);
403   } else if (!strcmp(attr, "d_height:")) {
404     player_globals.parray[p].d_height = atoi(value);
405   } else if (!strcmp(attr, "d_width:")) {
406     player_globals.parray[p].d_width = atoi(value);
407   } else if (!strcmp(attr, "language:")) {
408     player_globals.parray[p].language = atoi(value);
409   } else if (!strcmp(attr, "admin_level:")) {
410     player_globals.parray[p].adminLevel = atoi(value);
411     if (player_globals.parray[p].adminLevel >= ADMIN_ADMIN)
412       PFlagON(p, PFLAG_ADMINLIGHT);
413   } else if (!strcmp(attr, "i_admin:")) {
414 /*    player_globals.parray[p].i_admin = atoi(value);  */
415   } else if (!strcmp(attr, "computer:")) {
416 /*    player_globals.parray[p].computer = atoi(value); */
417   } else if (!strcmp(attr, "black_games:")) {
418     player_globals.parray[p].num_black = atoi(value);
419   } else if (!strcmp(attr, "white_games:")) {
420     player_globals.parray[p].num_white = atoi(value);
421   } else if (!strcmp(attr, "uscf:")) {
422 /*    player_globals.parray[p].uscfRating = atoi(value); */
423   } else if (!strcmp(attr, "muzzled:")) {       /* ignore these: obsolete */
424   } else if (!strcmp(attr, "cmuzzled:")) {      /* ignore these: obsolete */
425   } else if (!strcmp(attr, "highlight:")) {
426     player_globals.parray[p].highlight = atoi(value);
427   } else if (!strcmp(attr, "network:")) {
428 /*    player_globals.parray[p].network_player = atoi(value); */
429   } else if (!strcmp(attr, "lasthost:")) {
430     player_globals.parray[p].lastHost.s_addr = atoi(value);
431   } else if (!strcmp(attr, "channel:")) {
432     list_addsub(p,"channel",value, 1);
433   } else if (!strcmp(attr, "num_comments:")) {
434     player_globals.parray[p].num_comments = atoi(value);
435   } else if (!strcmp(attr, "num_plan:")) {
436     player_globals.parray[p].num_plan = atoi(value);
437     if (player_globals.parray[p].num_plan > 0) {
438       for (i = 0; i < player_globals.parray[p].num_plan; i++) {
439         fgets(tmp, MAX_LINE_SIZE, fp);
440         if (!(len = strlen(tmp))) {
441           d_printf( "CHESSD: Error bad plan in file %s\n", file);
442           i--;
443           player_globals.parray[p].num_plan--;
444         } else {
445           tmp[len - 1] = '\0';  /* Get rid of '\n' */
446           player_globals.parray[p].planLines[i] = (len > 1) ? strdup(tmp) : NULL;
447         }
448       }
449     }
450   } else if (!strcmp(attr, "num_formula:")) {
451     player_globals.parray[p].num_formula = atoi(value);
452     if (player_globals.parray[p].num_formula > 0) {
453       for (i = 0; i < player_globals.parray[p].num_formula; i++) {
454         fgets(tmp, MAX_LINE_SIZE, fp);
455         if (!(len = strlen(tmp))) {
456           d_printf( "CHESSD: Error bad formula in file %s\n", file);
457           i--;
458           player_globals.parray[p].num_formula--;
459         } else {
460           tmp[len - 1] = '\0';  /* Get rid of '\n' */
461           player_globals.parray[p].formulaLines[i] = (len > 1) ? strdup(tmp) : NULL;
462         }
463       }
464     }
465   } else if (!strcmp(attr, "formula:")) {
466     player_globals.parray[p].formula = strdup(value);
467   } else if (!strcmp(attr, "num_alias:")) {
468     numAlias = atoi(value);
469     if (numAlias > 0) {
470       for (i = 0; i < numAlias; i++) {
471         fgets(tmp, MAX_LINE_SIZE, fp);
472         if (!(len = strlen(tmp))) {
473           d_printf( "CHESSD: Error bad alias in file %s\n", file);
474           i--;
475         } else {
476           tmp[len - 1] = '\0';  /* Get rid of '\n' */
477           tmp1 = tmp;
478           tmp1 = eatword(tmp1);
479           *tmp1 = '\0';
480           tmp1++;
481           tmp1 = eatwhite(tmp1);
482           alias_add(p, tmp, tmp1);
483         }
484       }
485       player_globals.parray[p].alias_list[i].comm_name = NULL;
486     }
487   } else if (!strcmp(attr, "num_censor:")) {
488     i = atoi(value);
489     while (i--) {
490       fgets(tmp, MAX_LINE_SIZE, fp);
491       if ((!(len = strlen(tmp))) || (len == 1)) { /* blank lines do occur!! */
492         d_printf( "CHESSD: Error bad censor in file %s\n", file);
493       } else {
494         tmp[len - 1] = '\0';    /* Get rid of '\n' */
495         list_add(p, L_CENSOR, tmp);
496       }
497     }
498   } else if (!strcmp(attr, "num_notify:")) {
499     i = atoi(value);
500     while(i--) {
501       fgets(tmp, MAX_LINE_SIZE, fp);
502       if ((!(len = strlen(tmp))) || (len == 1)) { /* blank lines do occur!! */
503         d_printf( "CHESSD: Error bad notify in file %s\n", file);
504       } else {
505         tmp[len - 1] = '\0';    /* Get rid of '\n' */
506         list_add(p, L_NOTIFY, tmp);
507       }
508     }
509   } else if (!strcmp(attr, "num_noplay:")) {
510     i = atoi(value);
511     while(i--) {
512       fgets(tmp, MAX_LINE_SIZE, fp);
513       if ((!(len = strlen(tmp))) || (len == 1)) { /* blank lines do occur!! */
514         d_printf( "CHESSD: Error bad noplay in file %s\n", file);
515       } else {
516         tmp[len - 1] = '\0';    /* Get rid of '\n' */
517         list_add(p, L_NOPLAY, tmp);
518       }
519     }
520   } else if (!strcmp(attr, "num_gnotify:")) {
521     i = atoi(value);
522     while(i--) {
523       fgets(tmp, MAX_LINE_SIZE, fp);
524       if ((!(len = strlen(tmp)))  || (len == 1)) { /* blank lines do occur!! */
525         d_printf( "CHESSD: Error bad gnotify in file %s\n", file);
526       } else {
527         tmp[len - 1] = '\0';    /* Get rid of '\n' */
528         list_add(p, L_GNOTIFY, tmp);
529       }
530     }
531   } else if (!strcmp(attr, "num_follow:")) {
532     i = atoi(value);
533     while(i--) {
534       fgets(tmp, MAX_LINE_SIZE, fp);
535       if ((!(len = strlen(tmp)))  || (len == 1)) { /* blank lines do occur!! */
536         d_printf( "CHESSD: Error bad follow in file %s\n", file);
537       } else {
538         tmp[len - 1] = '\0';    /* Get rid of '\n' */
539         list_add(p, L_FOLLOW, tmp);
540       }
541     }
542   } else {
543     d_printf( "CHESSD: Error bad attribute >%s< from file %s\n", attr, file);
544   }
545   return 0;
546 }
547
548
549
550
551 int player_read_old(int p, FILE *fp, const char *pname, const char *fname, int version)
552 {
553         char line[MAX_LINE_SIZE];
554         char *attr, *value;
555         int len;
556
557         if (version > 4) { /* eg if two version of code running at diff sites */
558                 pprintf(p, "Your account's version number is newer than that of the version running.\n"); 
559                 pprintf(p, "Please see an admin.\n");
560                 d_printf("Player %s's version number is incorrect for this version.\n",player_globals.parray[p].name);
561                 PFlagOFF(p, PFLAG_REG);
562                 player_globals.parray[p].name = strdup(pname);
563                 return -1;
564         }
565         if (version > 0) {
566                 if (!ReadV1PlayerFmt(p,&player_globals.parray[p], fp, fname, version)) {/* Quick method */
567                         /* error in reading; make unreg */
568                         PFlagOFF(p, PFLAG_REG);
569                         PFlagOFF(p, PFLAG_RATED);
570                         pprintf(p, "\n*** WARNING: Your Data file is corrupt. Please tell an admin ***\n");
571                         return -1; /* other data has already been freed */
572                 }
573         } else {
574                 /* do it the old SLOW way */
575                 do {
576                         if (feof(fp))
577                                 break;
578                         if ((len = strlen(line)) <= 1)
579                                 continue;
580                         line[len - 1] = '\0';
581                         attr = eatwhite(line);
582                         if (attr[0] == '#')
583                                 continue;                       /* Comment */
584                         value = eatword(attr);
585                         if (!*value) {
586                                 d_printf( "CHESSD: Error reading file %s\n", fname);
587                                 continue;
588                         }
589                         *value = '\0';
590                         value++;
591                         value = eatwhite(value);
592                         stolower(attr);
593                         got_attr_value_player(p, attr, value, fp, fname);
594                         fgets(line, MAX_LINE_SIZE, fp);
595                 } while (!feof(fp));
596         }
597         
598         if (!player_globals.parray[p].name) {
599                 player_globals.parray[p].name = strdup(pname);
600                 pprintf(p, "\n*** WARNING: Your Data file is corrupt. Please tell an admin ***\n");
601         }
602         
603         return 0;
604 }
605
606
607 #if 0
608 /* the old and tedious way of writing the player data */
609 static void WritePlayerFile_old(FILE* fp, int p)
610 {
611  int i;
612  struct player *pp = &player_globals.parray[p];
613
614  fprintf (fp, "v %d\n", 4);
615  if (pp->name == NULL) /* This should never happen! */
616    fprintf (fp,"NONE\n");
617  else
618    fprintf(fp, "%s\n", pp->name);
619  if (pp->fullName == NULL)
620    fprintf (fp,"NONE\n");
621  else
622    fprintf(fp, "%s\n", pp->fullName);
623  if (pp->passwd == NULL)
624    fprintf (fp,"NONE\n");
625  else
626    fprintf(fp, "%s\n", pp->passwd);
627  if (pp->emailAddress == NULL)
628    fprintf (fp,"NONE\n");
629  else
630    fprintf(fp, "%s\n", pp->emailAddress); 
631  fprintf(fp, "%u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %d\n",
632
633  pp->s_stats.num, pp->s_stats.win, pp->s_stats.los, 
634  pp->s_stats.dra, pp->s_stats.rating, (int) (pp->s_stats.sterr * 10.0),
635  pp->s_stats.ltime, pp->s_stats.best, pp->s_stats.whenbest,
636
637  pp->b_stats.num, pp->b_stats.win, pp->b_stats.los,
638  pp->b_stats.dra, pp->b_stats.rating, (int) (pp->b_stats.sterr * 10.0),
639  pp->b_stats.ltime, pp->b_stats.best, pp->b_stats.whenbest,
640
641  pp->w_stats.num, pp->w_stats.win, pp->w_stats.los,
642  pp->w_stats.dra, pp->w_stats.rating, (int) (pp->w_stats.sterr * 10.0),
643  pp->w_stats.ltime, pp->w_stats.best, pp->w_stats.whenbest,
644
645  pp->l_stats.num, pp->l_stats.win, pp->l_stats.los,
646  pp->l_stats.dra, pp->l_stats.rating, (int) (pp->l_stats.sterr * 10.0),
647  pp->l_stats.ltime, pp->l_stats.best, pp->l_stats.whenbest,
648
649  pp->bug_stats.num, pp->bug_stats.win, pp->bug_stats.los,
650  pp->bug_stats.dra, pp->bug_stats.rating, (int) (pp->bug_stats.sterr * 10.0),
651  pp->bug_stats.ltime, pp->bug_stats.best, pp->bug_stats.whenbest,
652  pp->lastHost);
653
654  fprintf (fp, "%s\n", pp->prompt);
655  fprintf (fp, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
656  BoolCheckPFlag(p, PFLAG_OPEN), BoolCheckPFlag(p, PFLAG_RATED), 
657  BoolCheckPFlag(p, PFLAG_ROPEN), pp->timeOfReg,
658  pp->totalTime, BoolCheckPFlag(p, PFLAG_BELL),
659  BoolCheckPFlag(p, PFLAG_PGN), BoolCheckPFlag(p, PFLAG_NOTIFYBY),
660  BoolCheckPFlag(p, PFLAG_PIN), BoolCheckPFlag(p, PFLAG_GIN),
661  BoolCheckPFlag(p, PFLAG_AVAIL), BoolCheckPFlag(p, PFLAG_SHOUT),
662  BoolCheckPFlag(p, PFLAG_CSHOUT), BoolCheckPFlag(p, PFLAG_TELL),
663  BoolCheckPFlag(p, PFLAG_KIBITZ), BoolCheckPFlag(p, PFLAG_PRIVATE),
664  BoolCheckPFlag(p, PFLAG_JPRIVATE), BoolCheckPFlag(p, PFLAG_AUTOMAIL),
665  BoolCheckPFlag(p, PFLAG_MAILMESS), pp->style,
666  pp->d_time, pp->d_inc, pp->d_height, pp->d_width, pp->language,
667  pp->adminLevel, pp->num_white, pp->num_black, pp->highlight,
668  pp->num_comments,
669  pp->num_plan, pp->num_formula,list_size(p, L_CENSOR),
670  list_size(p, L_NOTIFY), list_size(p, L_NOPLAY),
671  list_size(p, L_GNOTIFY), pp->numAlias, list_size(p, L_CHANNEL ), pp->availmin, pp->availmax);
672
673   fprintf (fp,"."); /* Dot before plan - stop ill affects of scanf */
674
675   for (i = 0; i < pp->num_plan; i++)
676     fprintf(fp, "%s\n", (pp->planLines[i] ? pp->planLines[i] : ""));
677   for (i = 0; i < pp->num_formula; i++)
678     fprintf(fp, "%s\n", (pp->formulaLines[i] ? pp->formulaLines[i] : ""));
679   if (player_globals.parray[p].formula != NULL)
680     fprintf(fp, "%s\n", pp->formula);
681   else
682     fprintf(fp, "NONE\n");
683   for (i = 0; i < pp->numAlias; i++)
684     fprintf(fp, "%s %s\n", pp->alias_list[i].comm_name,
685             pp->alias_list[i].alias);
686
687   list_print(fp, p, L_CENSOR);
688   list_print(fp, p, L_NOTIFY);
689   list_print(fp, p, L_NOPLAY);
690   list_print(fp, p, L_GNOTIFY);
691   list_print(fp, p, L_CHANNEL);
692 }
693 #endif
694