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.3 by root, Sun Sep 3 00:18:39 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.3 2006/09/03 00:18:39 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; 261 animations=NULL;
264 animations_allocated=0; 262 animations_allocated=0;
265 init_defaults(); 263 init_defaults();
310 308
311 309
312void init_dynamic (void) { 310void init_dynamic (void) {
313 archetype *at = first_archetype; 311 archetype *at = first_archetype;
314 while (at) { 312 while (at) {
315 if (at->clone.type == MAP) { 313 if (at->clone.type == MAP) {
316 if (at->clone.race) { 314 if (at->clone.race) {
317 strcpy (first_map_ext_path, at->clone.race); 315 strcpy (first_map_ext_path, at->clone.race);
318 } 316 }
319 if (EXIT_PATH (&at->clone)) { 317 if (EXIT_PATH (&at->clone)) {
320 strcpy (first_map_path, EXIT_PATH (&at->clone)); 318 strcpy (first_map_path, EXIT_PATH (&at->clone));
321 return; 319 return;
322 } 320 }
323 } 321 }
324 at = at->next; 322 at = at->next;
325 } 323 }
326 LOG(llevDebug,"You Need a archetype called 'map' and it have to contain start map\n"); 324 LOG(llevDebug,"You Need a archetype called 'map' and it have to contain start map\n");
327 exit (-1); 325 exit (-1);
328} 326}
329 327
339 char filename[MAX_BUF]; 337 char filename[MAX_BUF];
340 FILE *fp; 338 FILE *fp;
341 339
342 sprintf(filename, "%s/clockdata", settings.localdir); 340 sprintf(filename, "%s/clockdata", settings.localdir);
343 if ((fp = fopen(filename, "w")) == NULL) { 341 if ((fp = fopen(filename, "w")) == NULL) {
344 LOG(llevError, "Cannot open %s for writing\n", filename); 342 LOG(llevError, "Cannot open %s for writing\n", filename);
345 return; 343 return;
346 } 344 }
347 fprintf(fp, "%lu", todtick); 345 fprintf(fp, "%lu", todtick);
348 fclose(fp); 346 fclose(fp);
349} 347}
350 348
366 364
367 sprintf(filename, "%s/clockdata", settings.localdir); 365 sprintf(filename, "%s/clockdata", settings.localdir);
368 LOG(llevDebug, "Reading clockdata from %s...", filename); 366 LOG(llevDebug, "Reading clockdata from %s...", filename);
369 if ((fp = fopen(filename, "r")) == NULL) { 367 if ((fp = fopen(filename, "r")) == NULL) {
370 LOG(llevError, "Can't open %s.\n", filename); 368 LOG(llevError, "Can't open %s.\n", filename);
371 todtick = 0; 369 todtick = 0;
372 write_todclock(); 370 write_todclock();
373 return; 371 return;
374 } 372 }
375 fscanf(fp, "%lu", &todtick); 373 fscanf(fp, "%lu", &todtick);
376 LOG(llevDebug, "todtick=%lu\n", todtick); 374 LOG(llevDebug, "todtick=%lu\n", todtick);
377 fclose(fp); 375 fclose(fp);
378} 376}
400 398
401 sprintf(filename, "%s/attackmess", settings.datadir); 399 sprintf(filename, "%s/attackmess", settings.datadir);
402 LOG(llevDebug, "Reading attack messages from %s...", filename); 400 LOG(llevDebug, "Reading attack messages from %s...", filename);
403 if ((fp = open_and_uncompress(filename, 0, &comp)) == NULL) { 401 if ((fp = open_and_uncompress(filename, 0, &comp)) == NULL) {
404 LOG(llevError, "Can't open %s.\n", filename); 402 LOG(llevError, "Can't open %s.\n", filename);
405 return; 403 return;
406 } 404 }
407 405
408 level = 0; 406 level = 0;
409 while (fgets(buf, MAX_BUF, fp)!=NULL) { 407 while (fgets(buf, MAX_BUF, fp)!=NULL) {
410 if (*buf=='#') continue; 408 if (*buf=='#') continue;
411 if((cp=strchr(buf,'\n'))!=NULL) 409 if((cp=strchr(buf,'\n'))!=NULL)
412 *cp='\0'; 410 *cp='\0';
413 cp=buf; 411 cp=buf;
414 while(*cp==' ') /* Skip blanks */ 412 while(*cp==' ') /* Skip blanks */
415 cp++; 413 cp++;
416 414
417 if (strncmp(cp, "TYPE:", 5)==0) { 415 if (strncmp(cp, "TYPE:", 5)==0) {
418 p = strtok(buf, ":"); 416 p = strtok(buf, ":");
419 p = strtok(NULL, ":"); 417 p = strtok(NULL, ":");
420 if (mode == 1) { 418 if (mode == 1) {
421 attack_mess[mess][level].level = -1; 419 attack_mess[mess][level].level = -1;
422 attack_mess[mess][level].buf1 = NULL; 420 attack_mess[mess][level].buf1 = NULL;
423 attack_mess[mess][level].buf2 = NULL; 421 attack_mess[mess][level].buf2 = NULL;
424 attack_mess[mess][level].buf3 = NULL; 422 attack_mess[mess][level].buf3 = NULL;
425 } 423 }
426 level = 0; 424 level = 0;
427 mess = atoi(p); 425 mess = atoi(p);
428 mode = 1; 426 mode = 1;
429 continue; 427 continue;
430 } 428 }
431 if (mode==1) { 429 if (mode==1) {
432 p = strtok(buf, "="); 430 p = strtok(buf, "=");
433 attack_mess[mess][level].level = atoi(buf); 431 attack_mess[mess][level].level = atoi(buf);
434 p = strtok(NULL, "="); 432 p = strtok(NULL, "=");
435 if (p != NULL) 433 if (p != NULL)
436 attack_mess[mess][level].buf1 = strdup_local(p); 434 attack_mess[mess][level].buf1 = strdup_local(p);
437 else 435 else
438 attack_mess[mess][level].buf1 = strdup_local(""); 436 attack_mess[mess][level].buf1 = strdup_local("");
439 mode = 2; 437 mode = 2;
440 continue; 438 continue;
441 } else if (mode==2) { 439 } else if (mode==2) {
442 p = strtok(buf, "="); 440 p = strtok(buf, "=");
443 attack_mess[mess][level].level = atoi(buf); 441 attack_mess[mess][level].level = atoi(buf);
444 p = strtok(NULL, "="); 442 p = strtok(NULL, "=");
445 if (p != NULL) 443 if (p != NULL)
446 attack_mess[mess][level].buf2 = strdup_local(p); 444 attack_mess[mess][level].buf2 = strdup_local(p);
447 else 445 else
448 attack_mess[mess][level].buf2 = strdup_local(""); 446 attack_mess[mess][level].buf2 = strdup_local("");
449 mode = 3; 447 mode = 3;
450 continue; 448 continue;
451 } else if (mode==3) { 449 } else if (mode==3) {
452 p = strtok(buf, "="); 450 p = strtok(buf, "=");
453 attack_mess[mess][level].level = atoi(buf); 451 attack_mess[mess][level].level = atoi(buf);
454 p = strtok(NULL, "="); 452 p = strtok(NULL, "=");
455 if (p != NULL) 453 if (p != NULL)
456 attack_mess[mess][level].buf3 = strdup_local(p); 454 attack_mess[mess][level].buf3 = strdup_local(p);
457 else 455 else
458 attack_mess[mess][level].buf3 = strdup_local(""); 456 attack_mess[mess][level].buf3 = strdup_local("");
459 mode = 1; 457 mode = 1;
460 level++; 458 level++;
461 total++; 459 total++;
462 continue; 460 continue;
463 } 461 }
464 } 462 }
465 LOG(llevDebug, "got %d messages in %d categories.\n", total, mess+1); 463 LOG(llevDebug, "got %d messages in %d categories.\n", total, mess+1);
466 close_and_delete(fp, comp); 464 close_and_delete(fp, comp);
467} 465}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines