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

Comparing deliantra/server/common/init.C (file contents):
Revision 1.1 by elmex, Sun Aug 13 17:16:00 2006 UTC vs.
Revision 1.4 by root, Sun Sep 3 07:57:54 2006 UTC

1/* 1/*
2 * static char *rcsid_init_c = 2 * static char *rcsid_init_c =
3 * "$Id: init.C,v 1.1 2006/08/13 17:16:00 elmex Exp $"; 3 * "$Id: init.C,v 1.4 2006/09/03 07:57:54 root Exp $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
141 int online=0; 141 int online=0;
142 142
143 /* If this file doesn't exist, not a big deal */ 143 /* If this file doesn't exist, not a big deal */
144 sprintf(filename,"%s/%s/.emergency",settings.datadir, settings.mapdir); 144 sprintf(filename,"%s/%s/.emergency",settings.datadir, settings.mapdir);
145 if ((fp = fopen(filename, "r"))!=NULL) { 145 if ((fp = fopen(filename, "r"))!=NULL) {
146 while (fgets(tmpbuf, MAX_BUF-1, fp)) { 146 while (fgets(tmpbuf, MAX_BUF-1, fp)) {
147 if (tmpbuf[0] == '#') continue; /* ignore comments */ 147 if (tmpbuf[0] == '#') continue; /* ignore comments */
148 148
149 if (online == 0) { 149 if (online == 0) {
150 tmpbuf[strlen(tmpbuf)-1] = 0; /* kill newline */ 150 tmpbuf[strlen(tmpbuf)-1] = 0; /* kill newline */
151 settings.emergency_mapname = strdup_local(tmpbuf); 151 settings.emergency_mapname = strdup_local(tmpbuf);
152 } 152 }
153 else if (online == 1) { 153 else if (online == 1) {
154 settings.emergency_x = atoi(tmpbuf); 154 settings.emergency_x = atoi(tmpbuf);
155 } 155 }
156 156
157 else if (online == 2) { 157 else if (online == 2) {
158 settings.emergency_y = atoi(tmpbuf); 158 settings.emergency_y = atoi(tmpbuf);
159 } 159 }
160 online++; 160 online++;
161 if (online>2) break; 161 if (online>2) break;
162 } 162 }
163 fclose(fp); 163 fclose(fp);
164 if (online<=2) 164 if (online<=2)
165 LOG(llevError,"Online read partial data from %s\n", filename); 165 LOG(llevError,"Online read partial data from %s\n", filename);
166 LOG(llevDebug,"Emergency mappath reset to %s (%d, %d)\n", settings.emergency_mapname, 166 LOG(llevDebug,"Emergency mappath reset to %s (%d, %d)\n", settings.emergency_mapname,
167 settings.emergency_x, settings.emergency_y); 167 settings.emergency_x, settings.emergency_y);
168 } 168 }
169} 169}
170 170
171 171
172/* 172/*
179 */ 179 */
180 180
181void init_library(void) { 181void init_library(void) {
182 init_environ(); 182 init_environ();
183 init_globals(); 183 init_globals();
184 init_hash_table();
185 init_objects(); 184 init_objects();
186 init_vars(); 185 init_vars();
187 init_block(); 186 init_block();
188 ReadBmapNames (); 187 ReadBmapNames ();
189 ReadSmooth(); 188 ReadSmooth();
230 * Might use environment-variables as default for some of them. 229 * Might use environment-variables as default for some of them.
231 */ 230 */
232 231
233void init_globals(void) { 232void init_globals(void) {
234 if (settings.logfilename[0] == 0) { 233 if (settings.logfilename[0] == 0) {
235 logfile = stderr; 234 logfile = stderr;
236 } 235 }
237 else if ((logfile=fopen(settings.logfilename, "a"))==NULL) { 236 else if ((logfile=fopen(settings.logfilename, "a"))==NULL) {
238 fprintf(stderr,"Unable to open %s as the logfile - will use stderr instead\n", 237 fprintf(stderr,"Unable to open %s as the logfile - will use stderr instead\n",
239 settings.logfilename); 238 settings.logfilename);
240 logfile = stderr; 239 logfile = stderr;
241 } 240 }
242 else { 241 else {
243 setvbuf(logfile, NULL, _IOLBF, 0); 242 setvbuf(logfile, NULL, _IOLBF, 0);
244 } 243 }
245 exiting = 0; 244 exiting = 0;
246 first_player=NULL; 245 first_player=NULL;
247 first_friendly_object=NULL; 246 first_friendly_object=NULL;
248 first_map=NULL; 247 first_map=NULL;
255 nrofartifacts = 0; 254 nrofartifacts = 0;
256 nrofallowedstr=0; 255 nrofallowedstr=0;
257 ring_arch = NULL; 256 ring_arch = NULL;
258 amulet_arch = NULL; 257 amulet_arch = NULL;
259 staff_arch = NULL; 258 staff_arch = NULL;
260 undead_name = add_string("undead");
261 trying_emergency_save = 0; 259 trying_emergency_save = 0;
262 num_animations=0; 260 num_animations=0;
263 animations=NULL;
264 animations_allocated=0; 261 animations_allocated=0;
265 init_defaults(); 262 init_defaults();
266} 263}
267 264
268/* 265/*
310 307
311 308
312void init_dynamic (void) { 309void init_dynamic (void) {
313 archetype *at = first_archetype; 310 archetype *at = first_archetype;
314 while (at) { 311 while (at) {
315 if (at->clone.type == MAP) { 312 if (at->clone.type == MAP) {
316 if (at->clone.race) { 313 if (at->clone.race) {
317 strcpy (first_map_ext_path, at->clone.race); 314 strcpy (first_map_ext_path, at->clone.race);
318 } 315 }
319 if (EXIT_PATH (&at->clone)) { 316 if (EXIT_PATH (&at->clone)) {
320 strcpy (first_map_path, EXIT_PATH (&at->clone)); 317 strcpy (first_map_path, EXIT_PATH (&at->clone));
321 return; 318 return;
322 } 319 }
323 } 320 }
324 at = at->next; 321 at = at->next;
325 } 322 }
326 LOG(llevDebug,"You Need a archetype called 'map' and it have to contain start map\n"); 323 LOG(llevDebug,"You Need a archetype called 'map' and it have to contain start map\n");
327 exit (-1); 324 exit (-1);
328} 325}
329 326
339 char filename[MAX_BUF]; 336 char filename[MAX_BUF];
340 FILE *fp; 337 FILE *fp;
341 338
342 sprintf(filename, "%s/clockdata", settings.localdir); 339 sprintf(filename, "%s/clockdata", settings.localdir);
343 if ((fp = fopen(filename, "w")) == NULL) { 340 if ((fp = fopen(filename, "w")) == NULL) {
344 LOG(llevError, "Cannot open %s for writing\n", filename); 341 LOG(llevError, "Cannot open %s for writing\n", filename);
345 return; 342 return;
346 } 343 }
347 fprintf(fp, "%lu", todtick); 344 fprintf(fp, "%lu", todtick);
348 fclose(fp); 345 fclose(fp);
349} 346}
350 347
366 363
367 sprintf(filename, "%s/clockdata", settings.localdir); 364 sprintf(filename, "%s/clockdata", settings.localdir);
368 LOG(llevDebug, "Reading clockdata from %s...", filename); 365 LOG(llevDebug, "Reading clockdata from %s...", filename);
369 if ((fp = fopen(filename, "r")) == NULL) { 366 if ((fp = fopen(filename, "r")) == NULL) {
370 LOG(llevError, "Can't open %s.\n", filename); 367 LOG(llevError, "Can't open %s.\n", filename);
371 todtick = 0; 368 todtick = 0;
372 write_todclock(); 369 write_todclock();
373 return; 370 return;
374 } 371 }
375 fscanf(fp, "%lu", &todtick); 372 fscanf(fp, "%lu", &todtick);
376 LOG(llevDebug, "todtick=%lu\n", todtick); 373 LOG(llevDebug, "todtick=%lu\n", todtick);
377 fclose(fp); 374 fclose(fp);
378} 375}
400 397
401 sprintf(filename, "%s/attackmess", settings.datadir); 398 sprintf(filename, "%s/attackmess", settings.datadir);
402 LOG(llevDebug, "Reading attack messages from %s...", filename); 399 LOG(llevDebug, "Reading attack messages from %s...", filename);
403 if ((fp = open_and_uncompress(filename, 0, &comp)) == NULL) { 400 if ((fp = open_and_uncompress(filename, 0, &comp)) == NULL) {
404 LOG(llevError, "Can't open %s.\n", filename); 401 LOG(llevError, "Can't open %s.\n", filename);
405 return; 402 return;
406 } 403 }
407 404
408 level = 0; 405 level = 0;
409 while (fgets(buf, MAX_BUF, fp)!=NULL) { 406 while (fgets(buf, MAX_BUF, fp)!=NULL) {
410 if (*buf=='#') continue; 407 if (*buf=='#') continue;
411 if((cp=strchr(buf,'\n'))!=NULL) 408 if((cp=strchr(buf,'\n'))!=NULL)
412 *cp='\0'; 409 *cp='\0';
413 cp=buf; 410 cp=buf;
414 while(*cp==' ') /* Skip blanks */ 411 while(*cp==' ') /* Skip blanks */
415 cp++; 412 cp++;
416 413
417 if (strncmp(cp, "TYPE:", 5)==0) { 414 if (strncmp(cp, "TYPE:", 5)==0) {
418 p = strtok(buf, ":"); 415 p = strtok(buf, ":");
419 p = strtok(NULL, ":"); 416 p = strtok(NULL, ":");
420 if (mode == 1) { 417 if (mode == 1) {
421 attack_mess[mess][level].level = -1; 418 attack_mess[mess][level].level = -1;
422 attack_mess[mess][level].buf1 = NULL; 419 attack_mess[mess][level].buf1 = NULL;
423 attack_mess[mess][level].buf2 = NULL; 420 attack_mess[mess][level].buf2 = NULL;
424 attack_mess[mess][level].buf3 = NULL; 421 attack_mess[mess][level].buf3 = NULL;
425 } 422 }
426 level = 0; 423 level = 0;
427 mess = atoi(p); 424 mess = atoi(p);
428 mode = 1; 425 mode = 1;
429 continue; 426 continue;
430 } 427 }
431 if (mode==1) { 428 if (mode==1) {
432 p = strtok(buf, "="); 429 p = strtok(buf, "=");
433 attack_mess[mess][level].level = atoi(buf); 430 attack_mess[mess][level].level = atoi(buf);
434 p = strtok(NULL, "="); 431 p = strtok(NULL, "=");
435 if (p != NULL) 432 if (p != NULL)
436 attack_mess[mess][level].buf1 = strdup_local(p); 433 attack_mess[mess][level].buf1 = strdup_local(p);
437 else 434 else
438 attack_mess[mess][level].buf1 = strdup_local(""); 435 attack_mess[mess][level].buf1 = strdup_local("");
439 mode = 2; 436 mode = 2;
440 continue; 437 continue;
441 } else if (mode==2) { 438 } else if (mode==2) {
442 p = strtok(buf, "="); 439 p = strtok(buf, "=");
443 attack_mess[mess][level].level = atoi(buf); 440 attack_mess[mess][level].level = atoi(buf);
444 p = strtok(NULL, "="); 441 p = strtok(NULL, "=");
445 if (p != NULL) 442 if (p != NULL)
446 attack_mess[mess][level].buf2 = strdup_local(p); 443 attack_mess[mess][level].buf2 = strdup_local(p);
447 else 444 else
448 attack_mess[mess][level].buf2 = strdup_local(""); 445 attack_mess[mess][level].buf2 = strdup_local("");
449 mode = 3; 446 mode = 3;
450 continue; 447 continue;
451 } else if (mode==3) { 448 } else if (mode==3) {
452 p = strtok(buf, "="); 449 p = strtok(buf, "=");
453 attack_mess[mess][level].level = atoi(buf); 450 attack_mess[mess][level].level = atoi(buf);
454 p = strtok(NULL, "="); 451 p = strtok(NULL, "=");
455 if (p != NULL) 452 if (p != NULL)
456 attack_mess[mess][level].buf3 = strdup_local(p); 453 attack_mess[mess][level].buf3 = strdup_local(p);
457 else 454 else
458 attack_mess[mess][level].buf3 = strdup_local(""); 455 attack_mess[mess][level].buf3 = strdup_local("");
459 mode = 1; 456 mode = 1;
460 level++; 457 level++;
461 total++; 458 total++;
462 continue; 459 continue;
463 } 460 }
464 } 461 }
465 LOG(llevDebug, "got %d messages in %d categories.\n", total, mess+1); 462 LOG(llevDebug, "got %d messages in %d categories.\n", total, mess+1);
466 close_and_delete(fp, comp); 463 close_and_delete(fp, comp);
467} 464}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines