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

Comparing deliantra/server/server/main.C (file contents):
Revision 1.27 by root, Thu Sep 14 22:34:04 2006 UTC vs.
Revision 1.51 by root, Thu Dec 21 06:12:37 2006 UTC

31# ifdef HAVE_CRYPT_H 31# ifdef HAVE_CRYPT_H
32# include <crypt.h> 32# include <crypt.h>
33# endif 33# endif
34#endif 34#endif
35 35
36#ifndef __CEXTRACT__
37# include <sproto.h> 36#include <sproto.h>
38#endif
39
40#ifdef HAVE_TIME_H
41# include <time.h> 37#include <time.h>
42#endif
43 38
44#include <../random_maps/random_map.h> 39#include <../random_maps/random_map.h>
45#include <../random_maps/rproto.h> 40#include <../random_maps/rproto.h>
46#include "path.h" 41#include "path.h"
47 42
106 new_draw_info (NDI_UNIQUE, 0, op, "Images and art:"); 101 new_draw_info (NDI_UNIQUE, 0, op, "Images and art:");
107 new_draw_info (NDI_UNIQUE, 0, op, "Peter Gardner"); 102 new_draw_info (NDI_UNIQUE, 0, op, "Peter Gardner");
108 new_draw_info (NDI_UNIQUE, 0, op, "David Gervais [david_eg@mail.com]"); 103 new_draw_info (NDI_UNIQUE, 0, op, "David Gervais [david_eg@mail.com]");
109 new_draw_info (NDI_UNIQUE, 0, op, "Mitsuhiro Itakura [ita@gold.koma.jaeri.go.jp]"); 104 new_draw_info (NDI_UNIQUE, 0, op, "Mitsuhiro Itakura [ita@gold.koma.jaeri.go.jp]");
110 new_draw_info (NDI_UNIQUE, 0, op, "Hansjoerg Malthaner [hansjoerg.malthaner@danet.de]"); 105 new_draw_info (NDI_UNIQUE, 0, op, "Hansjoerg Malthaner [hansjoerg.malthaner@danet.de]");
111 new_draw_info (NDI_UNIQUE, 0, op, "Mårten Woxberg [maxmc@telia.com]"); 106 new_draw_info (NDI_UNIQUE, 0, op, "MÃ¥rten Woxberg [maxmc@telia.com]");
112 new_draw_info (NDI_UNIQUE, 0, op, "And many more!"); 107 new_draw_info (NDI_UNIQUE, 0, op, "And many more!");
113} 108}
114 109
115void 110void
116info_keys (object *op) 111info_keys (object *op)
158 * simple case at top - no encryption - makes it easier to read. 153 * simple case at top - no encryption - makes it easier to read.
159 */ 154 */
160char * 155char *
161crypt_string (char *str, char *salt) 156crypt_string (char *str, char *salt)
162{ 157{
163#if defined(WIN32) || (defined(__FreeBSD__) && !defined(HAVE_LIBDES)) 158#if (defined(__FreeBSD__) && !defined(HAVE_LIBDES))
164 return (str); 159 return (str);
165#else 160#else
166 static char *c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; 161 static char *c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
167 char s[2]; 162 char s[2];
168 163
191 * goes someplace. 186 * goes someplace.
192 */ 187 */
193void 188void
194enter_player_savebed (object *op) 189enter_player_savebed (object *op)
195{ 190{
196 mapstruct *oldmap = op->map; 191 maptile *oldmap = op->map;
197 object *tmp; 192 object *tmp;
198 193
199 tmp = get_object (); 194 tmp = object::create ();
200 195
201 EXIT_PATH (tmp) = op->contr->savebed_map; 196 EXIT_PATH (tmp) = op->contr->savebed_map;
202 EXIT_X (tmp) = op->contr->bed_x; 197 EXIT_X (tmp) = op->contr->bed_x;
203 EXIT_Y (tmp) = op->contr->bed_y; 198 EXIT_Y (tmp) = op->contr->bed_y;
204 enter_exit (op, tmp); 199 enter_exit (op, tmp);
217 EXIT_PATH (tmp) = op->contr->savebed_map; 212 EXIT_PATH (tmp) = op->contr->savebed_map;
218 EXIT_X (tmp) = op->contr->bed_x; 213 EXIT_X (tmp) = op->contr->bed_x;
219 EXIT_Y (tmp) = op->contr->bed_y; 214 EXIT_Y (tmp) = op->contr->bed_y;
220 enter_exit (op, tmp); 215 enter_exit (op, tmp);
221 } 216 }
222 free_object (tmp); 217
218 tmp->destroy ();
223} 219}
224 220
225/* All this really is is a glorified remove_object that also updates 221/* All this really is is a glorified remove_object that also updates
226 * the counts on the map if needed. 222 * the counts on the map if needed.
227 */ 223 */
228void 224void
229leave_map (object *op) 225leave_map (object *op)
230{ 226{
231 mapstruct *oldmap = op->map; 227 maptile *oldmap = op->map;
232 228
233 remove_ob (op); 229 op->remove ();
234 230
235 if (oldmap) 231 if (oldmap)
236 { 232 {
237 if (!op->contr->hidden) 233 if (!op->contr->hidden)
238 oldmap->players--; 234 oldmap->players--;
235
239 if (oldmap->players <= 0) 236 if (oldmap->players <= 0)
240 { /* can be less than zero due to errors in tracking this */ 237 /* can be less than zero due to errors in tracking this */
241 set_map_timeout (oldmap); 238 set_map_timeout (oldmap);
242 }
243 } 239 }
244} 240}
245 241
246/* 242/*
247 * enter_map(): Moves the player and pets from current map (if any) to 243 * enter_map(): Moves the player and pets from current map (if any) to
249 * player to - it could be the map he just came from if the load failed for 245 * player to - it could be the map he just came from if the load failed for
250 * whatever reason. If default map coordinates are to be used, then 246 * whatever reason. If default map coordinates are to be used, then
251 * the function that calls this should figure them out. 247 * the function that calls this should figure them out.
252 */ 248 */
253static void 249static void
254enter_map (object *op, mapstruct *newmap, int x, int y) 250enter_map (object *op, maptile *newmap, int x, int y)
255{ 251{
256 mapstruct *oldmap = op->map; 252 maptile *oldmap = op->map;
257 253
258 if (out_of_map (newmap, x, y)) 254 if (out_of_map (newmap, x, y))
259 { 255 {
260 LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", newmap->path, x, y); 256 LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", newmap->path, x, y);
261 x = MAP_ENTER_X (newmap); 257 x = MAP_ENTER_X (newmap);
266 newmap->path, x, y, MAP_WIDTH (newmap), MAP_HEIGHT (newmap)); 262 newmap->path, x, y, MAP_WIDTH (newmap), MAP_HEIGHT (newmap));
267 new_draw_info (NDI_UNIQUE, 0, op, "The exit is closed"); 263 new_draw_info (NDI_UNIQUE, 0, op, "The exit is closed");
268 return; 264 return;
269 } 265 }
270 } 266 }
267
271 /* try to find a spot for the player */ 268 /* try to find a spot for the player */
272 if (ob_blocked (op, newmap, x, y)) 269 if (ob_blocked (op, newmap, x, y))
273 { /* First choice blocked */ 270 { /* First choice blocked */
274 /* We try to find a spot for the player, starting closest in. 271 /* We try to find a spot for the player, starting closest in.
275 * We could use find_first_free_spot, but that doesn't randomize it at all, 272 * We could use find_first_free_spot, but that doesn't randomize it at all,
284 { 281 {
285 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE2 + 1); 282 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE2 + 1);
286 if (i == -1) 283 if (i == -1)
287 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE); 284 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE);
288 } 285 }
286
289 if (i != -1) 287 if (i != -1)
290 { 288 {
291 x += freearr_x[i]; 289 x += freearr_x[i];
292 y += freearr_y[i]; 290 y += freearr_y[i];
293 } 291 }
296 /* not much we can do in this case. */ 294 /* not much we can do in this case. */
297 LOG (llevInfo, "enter_map: Could not find free spot for player - will dump on top of object (%s: %d, %d)\n", newmap->path, x, y); 295 LOG (llevInfo, "enter_map: Could not find free spot for player - will dump on top of object (%s: %d, %d)\n", newmap->path, x, y);
298 } 296 }
299 } /* end if looking for free spot */ 297 } /* end if looking for free spot */
300 298
301 if (op->map != NULL) 299 if (op->map)
302 {
303 INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (op->map), ARG_MAP (newmap));
304 INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr)); 300 if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr)))
305 } 301 return;
302
303 if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y)))
304 return;
305
306 if (INVOKE_MAP (ENTER, newmap, ARG_PLAYER (op->contr), ARG_INT (x), ARG_INT (y)))
307 return;
306 308
307 /* If it is a player login, he has yet to be inserted anyplace. 309 /* If it is a player login, he has yet to be inserted anyplace.
308 * otherwise, we need to deal with removing the player here. 310 * otherwise, we need to deal with removing the player here.
309 */ 311 */
310 if (!QUERY_FLAG (op, FLAG_REMOVED)) 312 op->remove ();
311 remove_ob (op);
312 313
313 /* remove_ob clears these so they must be reset after the remove_ob call */ 314 /* remove_ob clears these so they must be reset after the remove_ob call */
314 op->x = x; 315 op->x = x;
315 op->y = y; 316 op->y = y;
316 op->map = newmap; 317 op->map = newmap;
318
317 insert_ob_in_map (op, op->map, NULL, INS_NO_WALK_ON); 319 insert_ob_in_map (op, op->map, NULL, INS_NO_WALK_ON);
318
319 INVOKE_MAP (ENTER, op->map, ARG_PLAYER (op->contr));
320 320
321 if (!op->contr->hidden) 321 if (!op->contr->hidden)
322 newmap->players++; 322 newmap->players++;
323 323
324 newmap->timeout = 0; 324 newmap->timeout = 0;
334 if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL) 334 if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL)
335 { 335 {
336 int i = find_free_spot (op->contr->ranges[range_golem], newmap, 336 int i = find_free_spot (op->contr->ranges[range_golem], newmap,
337 x, y, 1, SIZEOFFREE); 337 x, y, 1, SIZEOFFREE);
338 338
339 remove_ob (op->contr->ranges[range_golem]); 339 op->contr->ranges[range_golem]->remove ();
340
340 if (i == -1) 341 if (i == -1)
341 { 342 {
342 remove_friendly_object (op->contr->ranges[range_golem]); 343 remove_friendly_object (op->contr->ranges[range_golem]);
343 free_object (op->contr->ranges[range_golem]); 344 op->contr->ranges[range_golem]->destroy ();
344 op->contr->ranges[range_golem] = NULL; 345 op->contr->ranges[range_golem] = 0;
345 op->contr->golem_count = 0;
346 } 346 }
347 else 347 else
348 { 348 {
349 object *tmp;
350
351 for (tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more) 349 for (object *tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more)
352 { 350 {
353 tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); 351 tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x);
354 tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); 352 tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y);
355 tmp->map = newmap; 353 tmp->map = newmap;
356 } 354 }
355
357 insert_ob_in_map (op->contr->ranges[range_golem], newmap, NULL, 0); 356 insert_ob_in_map (op->contr->ranges[range_golem], newmap, NULL, 0);
358 op->contr->ranges[range_golem]->direction = 357 op->contr->ranges[range_golem]->direction =
359 find_dir_2 (op->x - op->contr->ranges[range_golem]->x, op->y - op->contr->ranges[range_golem]->y); 358 find_dir_2 (op->x - op->contr->ranges[range_golem]->x, op->y - op->contr->ranges[range_golem]->y);
360 } 359 }
361 } 360 }
361
362 op->direction = 0; 362 op->direction = 0;
363 363
364 /* since the players map is already loaded, we don't need to worry 364 /* since the players map is already loaded, we don't need to worry
365 * about pending objects. 365 * about pending objects.
366 */ 366 */
381 } 381 }
382 } 382 }
383} 383}
384 384
385void 385void
386set_map_timeout (mapstruct *oldmap) 386set_map_timeout (maptile *oldmap)
387{ 387{
388#if MAP_MAXTIMEOUT 388#if MAP_MAXTIMEOUT
389 oldmap->timeout = MAP_TIMEOUT (oldmap); 389 oldmap->timeout = MAP_TIMEOUT (oldmap);
390 /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is 390 /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is
391 * lower than the min value. 391 * lower than the min value.
392 */ 392 */
393# if MAP_MINTIMEOUT 393# if MAP_MINTIMEOUT
394 if (oldmap->timeout < MAP_MINTIMEOUT) 394 if (oldmap->timeout < MAP_MINTIMEOUT)
395 {
396 oldmap->timeout = MAP_MINTIMEOUT; 395 oldmap->timeout = MAP_MINTIMEOUT;
397 }
398# endif 396# endif
397
399 if (oldmap->timeout > MAP_MAXTIMEOUT) 398 if (oldmap->timeout > MAP_MAXTIMEOUT)
400 {
401 oldmap->timeout = MAP_MAXTIMEOUT; 399 oldmap->timeout = MAP_MAXTIMEOUT;
402 } 400
403#else 401#else
404 /* save out the map */ 402 /* save out the map */
405 swap_map (oldmap); 403 swap_map (oldmap);
406#endif /* MAP_MAXTIMEOUT */ 404#endif /* MAP_MAXTIMEOUT */
407} 405}
452 */ 450 */
453 451
454static void 452static void
455enter_random_map (object *pl, object *exit_ob) 453enter_random_map (object *pl, object *exit_ob)
456{ 454{
457 mapstruct *new_map; 455 maptile *new_map;
458 char newmap_name[HUGE_BUF], *cp; 456 char newmap_name[HUGE_BUF], *cp;
459 static int reference_number = 0; 457 static int reference_number = 0;
460 RMParms rp; 458 RMParms rp;
461 459
462 memset (&rp, 0, sizeof (RMParms)); 460 memset (&rp, 0, sizeof (RMParms));
469 rp.origin_y = exit_ob->y; 467 rp.origin_y = exit_ob->y;
470 strcpy (rp.origin_map, pl->map->path); 468 strcpy (rp.origin_map, pl->map->path);
471 469
472 /* If we have a final_map, use it as a base name to give some clue 470 /* If we have a final_map, use it as a base name to give some clue
473 * as where the player is. Otherwise, use the origin map. 471 * as where the player is. Otherwise, use the origin map.
474 * Take the last component (after the last slash) to give
475 * shorter names without bogus slashes.
476 */ 472 */
477 if (rp.final_map[0]) 473 sprintf (newmap_name, "/random%s+%04d",
478 { 474 *rp.final_map ? rp.final_map : rp.origin_map,
479 cp = strrchr (rp.final_map, '/'); 475 reference_number++);
480 if (!cp)
481 cp = rp.final_map;
482 }
483 else
484 {
485 char buf[HUGE_BUF];
486
487 cp = strrchr (rp.origin_map, '/');
488 if (!cp)
489 cp = rp.origin_map;
490 /* Need to strip of any trailing digits, if it has them */
491 strcpy (buf, cp);
492 while (isdigit (buf[strlen (buf) - 1]))
493 buf[strlen (buf) - 1] = 0;
494 cp = buf;
495 }
496
497 sprintf (newmap_name, "/random/%s%04d", cp + 1, reference_number++);
498 476
499 /* now to generate the actual map. */ 477 /* now to generate the actual map. */
500 new_map = generate_random_map (newmap_name, &rp); 478 new_map = generate_random_map (newmap_name, &rp);
501 479
502 /* Update the exit_ob so it now points directly at the newly created 480 /* Update the exit_ob so it now points directly at the newly created
522 */ 500 */
523 501
524static void 502static void
525enter_fixed_template_map (object *pl, object *exit_ob) 503enter_fixed_template_map (object *pl, object *exit_ob)
526{ 504{
527 mapstruct *new_map; 505 maptile *new_map;
528 char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap; 506 char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap;
529 const char *new_map_name; 507 const char *new_map_name;
530 508
531 /* Split the exit path string into two parts, one 509 /* Split the exit path string into two parts, one
532 * for where to store the map, and one for were 510 * for where to store the map, and one for were
541 */ 519 */
542 LOG (llevError, "enter_fixed_template_map: Exit %s (%d,%d) on map %s has no source template.\n", 520 LOG (llevError, "enter_fixed_template_map: Exit %s (%d,%d) on map %s has no source template.\n",
543 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); 521 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path);
544 return; 522 return;
545 } 523 }
524
546 *sourcemap++ = '\0'; 525 *sourcemap++ = '\0';
547 526
548 /* If we are not coming from a template map, we can use relative directories 527 /* If we are not coming from a template map, we can use relative directories
549 * for the map to generate from. 528 * for the map to generate from.
550 */ 529 */
551 if (!exit_ob->map->templatemap) 530 if (!exit_ob->map->templatemap)
552 {
553 sourcemap = path_combine_and_normalize (exit_ob->map->path, sourcemap); 531 sourcemap = path_combine_and_normalize (exit_ob->map->path, sourcemap);
554 }
555 532
556 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord 533 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord
557 * of the exit, and the name of the map the exit is on, respectively. 534 * of the exit, and the name of the map the exit is on, respectively.
558 */ 535 */
559 sprintf (tmpnum, "%d", exit_ob->x); 536 sprintf (tmpnum, "%d", exit_ob->x);
568 545
569 /* If we are coming from another template map, use reletive paths unless 546 /* If we are coming from another template map, use reletive paths unless
570 * indicated otherwise. 547 * indicated otherwise.
571 */ 548 */
572 if (exit_ob->map->templatemap && (resultname[0] != '/')) 549 if (exit_ob->map->templatemap && (resultname[0] != '/'))
573 {
574 new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); 550 new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname);
575 }
576 else 551 else
577 {
578 new_map_name = create_template_pathname (resultname); 552 new_map_name = create_template_pathname (resultname);
579 }
580 553
581 /* Attempt to load the map, if unable to, then 554 /* Attempt to load the map, if unable to, then
582 * create the map from the template. 555 * create the map from the template.
583 */ 556 */
584 new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); 557 new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE);
606 LOG (llevDebug, "enter_fixed_template_map: Exit %s (%d,%d) on map %s leads no where.\n", 579 LOG (llevDebug, "enter_fixed_template_map: Exit %s (%d,%d) on map %s leads no where.\n",
607 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); 580 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path);
608 } 581 }
609} 582}
610 583
611
612/* The player is trying to enter a randomly generated template map. In this 584/* The player is trying to enter a randomly generated template map. In this
613 * case, generate the map as needed. 585 * case, generate the map as needed.
614 */ 586 */
615 587
616static void 588static void
617enter_random_template_map (object *pl, object *exit_ob) 589enter_random_template_map (object *pl, object *exit_ob)
618{ 590{
619 mapstruct *new_map; 591 maptile *new_map;
620 char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF]; 592 char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF];
621 const char *new_map_name; 593 const char *new_map_name;
622 RMParms rp; 594 RMParms rp;
623 595
624 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord 596 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord
686 */ 658 */
687static void 659static void
688enter_unique_map (object *op, object *exit_ob) 660enter_unique_map (object *op, object *exit_ob)
689{ 661{
690 char apartment[HUGE_BUF]; 662 char apartment[HUGE_BUF];
691 mapstruct *newmap; 663 maptile *newmap;
692 664
693 if (EXIT_PATH (exit_ob)[0] == '/') 665 if (EXIT_PATH (exit_ob)[0] == '/')
694 { 666 {
695 sprintf (apartment, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, clean_path (EXIT_PATH (exit_ob))); 667 sprintf (apartment, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, clean_path (EXIT_PATH (exit_ob)));
696 newmap = ready_map_name (apartment, MAP_PLAYER_UNIQUE); 668 newmap = ready_map_name (apartment, MAP_PLAYER_UNIQUE);
780#define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */ 752#define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */
781 object *tmp; 753 object *tmp;
782 754
783 /* It may be nice to support other creatures moving across 755 /* It may be nice to support other creatures moving across
784 * exits, but right now a lot of the code looks at op->contr, 756 * exits, but right now a lot of the code looks at op->contr,
785 * so thta is an RFE. 757 * so that is an RFE.
786 */ 758 */
787 if (op->type != PLAYER) 759 if (op->type != PLAYER)
788 return; 760 return;
789 761
790 /* First, lets figure out what map the player is going to go to */ 762 /* First, lets figure out what map the player is going to go to */
791 if (exit_ob) 763 if (exit_ob)
792 { 764 {
793
794 /* check to see if we make a template map */ 765 /* check to see if we make a template map */
795 if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@') 766 if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@')
796 { 767 {
797 if (EXIT_PATH (exit_ob)[2] == '!') 768 if (EXIT_PATH (exit_ob)[2] == '!')
798 { 769 {
819 int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob); 790 int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob);
820 791
821 /* 'Normal' exits that do not do anything special 792 /* 'Normal' exits that do not do anything special
822 * Simple enough we don't need another routine for it. 793 * Simple enough we don't need another routine for it.
823 */ 794 */
824 mapstruct *newmap; 795 maptile *newmap;
825 796
826 if (exit_ob->map) 797 if (exit_ob->map)
827 { 798 {
828 newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0); 799 newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0);
829 /* Random map was previously generated, but is no longer about. Lets generate a new 800 /* Random map was previously generated, but is no longer about. Lets generate a new
897 if (tmp->type == FORCE && tmp->slaying && !strcmp (tmp->slaying, PORTAL_DESTINATION_NAME)) 868 if (tmp->type == FORCE && tmp->slaying && !strcmp (tmp->slaying, PORTAL_DESTINATION_NAME))
898 break; 869 break;
899 } 870 }
900 if (tmp) 871 if (tmp)
901 { 872 {
902 remove_ob (tmp); 873 tmp->remove ();
903 free_object (tmp); 874 tmp->destroy ();
904 } 875 }
905 876
906 strcpy (op->contr->savebed_map, path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob))); 877 strcpy (op->contr->savebed_map, path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)));
907 op->contr->bed_x = EXIT_X (exit_ob), op->contr->bed_y = EXIT_Y (exit_ob); 878 op->contr->bed_x = EXIT_X (exit_ob), op->contr->bed_y = EXIT_Y (exit_ob);
908 save_player (op, 1); 879 save_player (op, 1);
918 hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1); 889 hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1);
919 } 890 }
920 else 891 else
921 { 892 {
922 int flags = 0; 893 int flags = 0;
923 mapstruct *newmap; 894 maptile *newmap;
924
925 895
926 /* Hypothetically, I guess its possible that a standard map matches 896 /* Hypothetically, I guess its possible that a standard map matches
927 * the localdir, but that seems pretty unlikely - unlikely enough that 897 * the localdir, but that seems pretty unlikely - unlikely enough that
928 * I'm not going to attempt to try to deal with that possibility. 898 * I'm not going to attempt to try to deal with that possibility.
929 * We use the fact that when a player saves on a unique map, it prepends 899 * We use the fact that when a player saves on a unique map, it prepends
950 { 920 {
951 LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n"); 921 LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n");
952 abort (); 922 abort ();
953 } 923 }
954 } 924 }
925
955 enter_map (op, newmap, op->x, op->y); 926 enter_map (op, newmap, op->x, op->y);
956 } 927 }
957} 928}
958
959/*
960 * process_active_maps(): Works like process_events(), but it only
961 * processes maps which a player is on.
962 *
963 */
964
965#if 0 // dead code, schmorp
966void
967process_active_maps ()
968{
969 for (mapstruct *map = first_map; map != NULL; map = map->next)
970 if (map->in_memory == MAP_IN_MEMORY)
971 if (players_on_map (map, TRUE))
972 process_events (map);
973}
974#endif
975 929
976/* process_players1 and process_players2 do all the player related stuff. 930/* process_players1 and process_players2 do all the player related stuff.
977 * I moved it out of process events and process_map. This was to some 931 * I moved it out of process events and process_map. This was to some
978 * extent for debugging as well as to get a better idea of the time used 932 * extent for debugging as well as to get a better idea of the time used
979 * by the various functions. process_players1() does the processing before 933 * by the various functions. process_players1() does the processing before
980 * objects have been updated, process_players2() does the processing that 934 * objects have been updated, process_players2() does the processing that
981 * is needed after the players have been updated. 935 * is needed after the players have been updated.
982 */ 936 */
983 937static void
984void 938process_players1 ()
985process_players1 (mapstruct *map)
986{ 939{
987 int flag; 940 int flag;
988 player *pl, *plnext;
989
990 /* Basically, we keep looping until all the players have done their actions. */ 941 /* Basically, we keep looping until all the players have done their actions. */
991 for (flag = 1; flag != 0;) 942 for (flag = 1; flag != 0;)
992 { 943 {
993 flag = 0; 944 flag = 0;
994 for (pl = first_player; pl != NULL; pl = plnext) 945 for (player *plnext, *pl = first_player; pl; pl = plnext)
995 { 946 {
996 plnext = pl->next; /* In case a player exits the game in handle_player() */ 947 plnext = pl->next; /* In case a player exits the game in handle_player() */
997 948
998 if (pl->ob == NULL) 949 if (!pl->ob)
999 continue;
1000
1001 if (map != NULL && pl->ob->map != map)
1002 continue; 950 continue;
1003 951
1004 if (pl->ob->speed_left > 0) 952 if (pl->ob->speed_left > 0)
1005 { 953 {
1006 if (handle_newcs_player (pl->ob)) 954 if (handle_newcs_player (pl->ob))
1020 /* check for ST_PLAYING state so that we don't try to save off when 968 /* check for ST_PLAYING state so that we don't try to save off when
1021 * the player is logging in. 969 * the player is logging in.
1022 */ 970 */
1023 if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->state == ST_PLAYING) 971 if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->state == ST_PLAYING)
1024 { 972 {
1025 /* Don't save the player on unholy ground. Instead, increase the
1026 * tick time so it will be about 10 seconds before we try and save
1027 * again.
1028 */
1029// if (get_map_flags(pl->ob->map, NULL, pl->ob->x, pl->ob->y, NULL, NULL) & P_NO_CLERIC) {
1030// pl->last_save_tick += 100;
1031// } else {
1032 save_player (pl->ob, 1); 973 save_player (pl->ob, 1);
1033 pl->last_save_tick = pticks; 974 pl->last_save_tick = pticks;
1034// }
1035 } 975 }
1036#endif 976#endif
1037 } /* end of for loop for all the players */ 977 } /* end of for loop for all the players */
1038 } /* for flag */ 978 } /* for flag */
979
1039 for (pl = first_player; pl != NULL; pl = pl->next) 980 for (player *pl = first_player; pl; pl = pl->next)
1040 { 981 {
1041 if (map != NULL && (pl->ob == NULL || pl->ob->map != map))
1042 continue;
1043 if (settings.casting_time == TRUE) 982 if (settings.casting_time)
1044 { 983 {
1045 if (pl->ob->casting_time > 0) 984 if (pl->ob->casting_time > 0)
1046 { 985 {
1047 pl->ob->casting_time--; 986 pl->ob->casting_time--;
1048 pl->ob->start_holding = 1; 987 pl->ob->start_holding = 1;
1049 } 988 }
989
1050 /* set spell_state so we can update the range in stats field */ 990 /* set spell_state so we can update the range in stats field */
1051 if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1)) 991 if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1))
1052 {
1053 pl->ob->start_holding = 0; 992 pl->ob->start_holding = 0;
1054 } 993 }
1055 } 994
1056 do_some_living (pl->ob); 995 do_some_living (pl->ob);
1057 /* draw(pl->ob); *//* updated in socket code */
1058 } 996 }
1059} 997}
1060 998
1061void 999static void
1062process_players2 (mapstruct *map) 1000process_players2 ()
1063{ 1001{
1064 player *pl;
1065
1066 /* Then check if any players should use weapon-speed instead of speed */ 1002 /* Then check if any players should use weapon-speed instead of speed */
1067 for (pl = first_player; pl != NULL; pl = pl->next) 1003 for (player *pl = first_player; pl; pl = pl->next)
1068 { 1004 {
1069 if (map != NULL)
1070 {
1071 if (pl->ob == NULL || QUERY_FLAG (pl->ob, FLAG_REMOVED))
1072 continue;
1073 else if (pl->loading != NULL) /* Player is blocked */
1074 pl->ob->speed_left -= pl->ob->speed;
1075 if (pl->ob->map != map)
1076 continue;
1077 }
1078
1079 /* The code that did weapon_sp handling here was out of place - 1005 /* The code that did weapon_sp handling here was out of place -
1080 * this isn't called until after the player has finished there 1006 * this isn't called until after the player has finished there
1081 * actions, and is thus out of place. All we do here is bounds 1007 * actions, and is thus out of place. All we do here is bounds
1082 * checking. 1008 * checking.
1083 */ 1009 */
1089 /* This needs to be here - if the player is running, we need to 1015 /* This needs to be here - if the player is running, we need to
1090 * clear this each tick, but new commands are not being received 1016 * clear this each tick, but new commands are not being received
1091 * so execute_newserver_command() is never called 1017 * so execute_newserver_command() is never called
1092 */ 1018 */
1093 pl->has_hit = 0; 1019 pl->has_hit = 0;
1094
1095 } 1020 }
1096 else if (pl->ob->speed_left > pl->ob->speed) 1021 else if (pl->ob->speed_left > pl->ob->speed)
1097 pl->ob->speed_left = pl->ob->speed; 1022 pl->ob->speed_left = pl->ob->speed;
1098 } 1023 }
1099} 1024}
1100 1025
1101void 1026void
1102process_events (mapstruct *map) 1027process_events ()
1103{ 1028{
1104 object *op; 1029 object *op;
1105 tag_t tag;
1106 1030
1107 static object *marker; 1031 static object *marker;
1108 1032
1109 if (!marker) 1033 if (!marker)
1110 marker = get_object (); 1034 marker = object::create ();
1111 1035
1112 process_players1 (map); 1036 process_players1 ();
1113 1037
1114 marker->active_next = active_objects; 1038 marker->active_next = active_objects;
1115 1039
1116 if (marker->active_next) 1040 if (marker->active_next)
1117 marker->active_next->active_prev = marker; 1041 marker->active_next->active_prev = marker;
1120 active_objects = marker; 1044 active_objects = marker;
1121 1045
1122 while (marker->active_next) 1046 while (marker->active_next)
1123 { 1047 {
1124 op = marker->active_next; 1048 op = marker->active_next;
1125 tag = op->count;
1126 1049
1127 /* Move marker forward - swap op and marker */ 1050 /* Move marker forward - swap op and marker */
1128 op->active_prev = marker->active_prev; 1051 op->active_prev = marker->active_prev;
1129 1052
1130 if (op->active_prev) 1053 if (op->active_prev)
1160 * around. 1083 * around.
1161 */ 1084 */
1162 if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY) 1085 if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY)
1163 { 1086 {
1164 LOG (llevError, "BUG: process_events(): Removed object on list\n"); 1087 LOG (llevError, "BUG: process_events(): Removed object on list\n");
1165 dump_object (op); 1088 char *dump = dump_object (op);
1166 LOG (llevError, errmsg); 1089 LOG (llevError, dump);
1167 free_object (op); 1090 free (dump);
1091 op->destroy ();
1168 continue; 1092 continue;
1169 } 1093 }
1170 1094
1171 if (!op->speed) 1095 if (!op->speed)
1172 { 1096 {
1173 LOG (llevError, "BUG: process_events(): Object %s has no speed, " "but is on active list\n", &op->arch->name); 1097 LOG (llevError, "BUG: process_events(): Object %s has no speed, "
1098 "but is on active list\n", &op->arch->name);
1174 update_ob_speed (op); 1099 update_ob_speed (op);
1175 continue; 1100 continue;
1176 } 1101 }
1177 1102
1178 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP && map == NULL) 1103 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP)
1179 { 1104 {
1180 LOG (llevError, "BUG: process_events(): Object without map or " "inventory is on active list: %s (%d)\n", &op->name, op->count); 1105 LOG (llevError, "BUG: process_events(): Object without map or "
1106 "inventory is on active list: %s (%d)\n", &op->name, op->count);
1181 op->speed = 0; 1107 op->speed = 0;
1182 update_ob_speed (op); 1108 update_ob_speed (op);
1183 continue; 1109 continue;
1184 } 1110 }
1185 1111
1186 if (map != NULL && op->map != map)
1187 continue;
1188
1189 /* Animate the object. Bug of feature that andim_speed 1112 /* Animate the object. Bug or feature that anim_speed
1190 * is based on ticks, and not the creatures speed? 1113 * is based on ticks, and not the creatures speed?
1191 */ 1114 */
1192 if (op->anim_speed && op->last_anim >= op->anim_speed) 1115 if (op->anim_speed && op->last_anim >= op->anim_speed)
1193 { 1116 {
1194 if ((op->type == PLAYER) || (op->type == MONSTER)) 1117 if ((op->type == PLAYER))
1195 animate_object (op, op->facing); 1118 animate_object (op, op->facing);
1196 else 1119 else
1197 animate_object (op, op->direction); 1120 animate_object (op, op->direction);
1198 1121
1199 op->last_anim = 1; 1122 op->last_anim = 1;
1217 LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null"); 1140 LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null");
1218 } 1141 }
1219#endif 1142#endif
1220 --op->speed_left; 1143 --op->speed_left;
1221 process_object (op); 1144 process_object (op);
1145
1222 if (was_destroyed (op, tag)) 1146 if (op->destroyed ())
1223 continue; 1147 continue;
1224 } 1148 }
1149
1225 if (settings.casting_time == TRUE && op->casting_time > 0) 1150 if (settings.casting_time == TRUE && op->casting_time > 0)
1226 op->casting_time--; 1151 op->casting_time--;
1152
1227 if (op->speed_left <= 0) 1153 if (op->speed_left <= 0)
1228 op->speed_left += FABS (op->speed); 1154 op->speed_left += FABS (op->speed);
1229 } 1155 }
1230 1156
1231 /* Remove marker object from active list */ 1157 /* Remove marker object from active list */
1232 if (marker->active_prev != NULL) 1158 if (marker->active_prev != NULL)
1233 marker->active_prev->active_next = NULL; 1159 marker->active_prev->active_next = NULL;
1234 else 1160 else
1235 active_objects = NULL; 1161 active_objects = NULL;
1236 1162
1237 process_players2 (map); 1163 process_players2 ();
1238} 1164}
1239 1165
1240void 1166void
1241clean_tmp_files (void) 1167clean_tmp_files (void)
1242{ 1168{
1243 mapstruct *m, *next; 1169 maptile *m, *next;
1244 1170
1245 LOG (llevInfo, "Cleaning up...\n"); 1171 LOG (llevInfo, "Cleaning up...\n");
1246 1172
1247 /* We save the maps - it may not be intuitive why, but if there are unique 1173 /* We save the maps - it may not be intuitive why, but if there are unique
1248 * items, we need to save the map so they get saved off. Perhaps we should 1174 * items, we need to save the map so they get saved off. Perhaps we should
1249 * just make a special function that only saves the unique items. 1175 * just make a special function that only saves the unique items.
1250 */ 1176 */
1251 for (m = first_map; m != NULL; m = next) 1177 for (m = first_map; m; m = next)
1252 { 1178 {
1253 next = m->next; 1179 next = m->next;
1180
1254 if (m->in_memory == MAP_IN_MEMORY) 1181 if (m->in_memory == MAP_IN_MEMORY)
1255 { 1182 {
1256 /* If we want to reuse the temp maps, swap it out (note that will also 1183 /* If we want to reuse the temp maps, swap it out (note that will also
1257 * update the log file. Otherwise, save the map (mostly for unique item 1184 * update the log file.
1258 * stuff). Note that the clean_tmp_map is called after the end of
1259 * the for loop but is in the #else bracket. IF we are recycling the maps,
1260 * we certainly don't want the temp maps removed.
1261 */ 1185 */
1262 1186
1263 /* XXX The above comment is dead wrong */
1264 if (settings.recycle_tmp_maps == TRUE)
1265 swap_map (m); 1187 swap_map (m);
1266 else
1267 {
1268 new_save_map (m, 0); /* note we save here into a overlay map */
1269 clean_tmp_map (m);
1270 } 1188 }
1271 }
1272 } 1189 }
1190
1273 write_todclock (); /* lets just write the clock here */ 1191 write_todclock (); /* lets just write the clock here */
1274} 1192}
1275 1193
1276/* clean up everything before exiting */ 1194/* clean up everything before exiting */
1277void 1195void
1278cleanup (void) 1196cleanup (bool make_core)
1279{ 1197{
1280 LOG (llevDebug, "Cleanup called.\n"); 1198 LOG (llevDebug, "Cleanup called.\n");
1199
1200 if (init_done)
1201 {
1202 for (player *pl = first_player; pl != NULL; pl = pl->next)
1203 save_player (pl->ob, 0);
1204
1205 for (player *pl = first_player; pl != NULL; pl = pl->next)
1206 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
1207 leave_map (pl->ob);
1208
1209 clean_tmp_files ();
1281 write_book_archive (); 1210 write_book_archive ();
1282 1211
1283 INVOKE_GLOBAL (CLEANUP); 1212 INVOKE_GLOBAL (CLEANUP);
1213 }
1284 1214
1215 if (make_core)
1216 abort ();
1217 else
1285 _exit (0); 1218 _exit (0);
1286} 1219}
1287 1220
1288void 1221void
1289leave (player *pl, int draw_exit) 1222leave (player *pl, int draw_exit)
1290{ 1223{
1291 if (pl != NULL) 1224 if (pl)
1292 { 1225 {
1293 /* We do this so that the socket handling routine can do the final 1226 /* We do this so that the socket handling routine can do the final
1294 * cleanup. We also leave that loop to actually handle the freeing 1227 * cleanup. We also leave that loop to actually handle the freeing
1295 * of the data. 1228 * of the data.
1296 */ 1229 */
1230 if (pl->socket)
1231 pl->socket->destroy ();
1232
1297 if (pl->ob->type != DEAD_OBJECT) 1233 if (pl->ob->type != DEAD_OBJECT)
1298 { 1234 {
1299 pl->socket.status = Ns_Dead;
1300
1301 /* If a hidden dm dropped connection do not create 1235 /* If a hidden dm dropped connection do not create
1302 * inconsistencies by showing that they have left the game 1236 * inconsistencies by showing that they have left the game
1303 */ 1237 */
1304 if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden) 1238 if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden)
1305 && draw_exit && (pl->state != ST_GET_NAME && pl->state != ST_GET_PASSWORD && pl->state != ST_CONFIRM_PASSWORD)) 1239 && draw_exit && (pl->state != ST_GET_NAME && pl->state != ST_GET_PASSWORD && pl->state != ST_CONFIRM_PASSWORD))
1306 { 1240 {
1307 if (pl->ob->map) 1241 if (pl->ob->map)
1308 { 1242 {
1309 INVOKE_PLAYER (LOGOUT, pl); 1243 INVOKE_PLAYER (LOGOUT, pl);
1310 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->socket.host); 1244 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->socket->host);
1311 } 1245 }
1312 1246
1313 char buf[MAX_BUF]; 1247 char buf[MAX_BUF];
1314 1248
1315 sprintf (buf, "%s left the game.", &pl->ob->name); 1249 sprintf (buf, "%s left the game.", &pl->ob->name);
1391extern unsigned long todtick; 1325extern unsigned long todtick;
1392 1326
1393void 1327void
1394do_specials (void) 1328do_specials (void)
1395{ 1329{
1396
1397#ifdef WATCHDOG
1398 if (!(pticks % 503))
1399 watchdog ();
1400#endif
1401
1402 if (!(pticks % PTICKS_PER_CLOCK)) 1330 if (!(pticks % PTICKS_PER_CLOCK))
1403 tick_the_clock (); 1331 tick_the_clock ();
1404 1332
1405 if (!(pticks % 7)) 1333 if (!(pticks % 7))
1406 shstr::gc (); 1334 shstr::gc ();
1409 flush_old_maps (); /* Clears the tmp-files of maps which have reset */ 1337 flush_old_maps (); /* Clears the tmp-files of maps which have reset */
1410 1338
1411 if (!(pticks % 2503)) 1339 if (!(pticks % 2503))
1412 fix_weight (); /* Hack to fix weightproblems caused by bugs */ 1340 fix_weight (); /* Hack to fix weightproblems caused by bugs */
1413 1341
1414 if (!(pticks % 2521))
1415 metaserver_update (); /* 2500 ticks is about 5 minutes */
1416
1417 if (!(pticks % 5003)) 1342 if (!(pticks % 5003))
1418 write_book_archive (); 1343 write_book_archive ();
1419 1344
1420 if (!(pticks % 5009)) 1345 if (!(pticks % 5009))
1421 clean_friendly_list (); 1346 clean_friendly_list ();
1430void 1355void
1431server_tick () 1356server_tick ()
1432{ 1357{
1433 nroferrors = 0; 1358 nroferrors = 0;
1434 1359
1360 // first do the user visible stuff
1435 doeric_server (); 1361 doeric_server ();
1436 INVOKE_GLOBAL (CLOCK); 1362 INVOKE_GLOBAL (CLOCK);
1437 process_events (NULL); /* "do" something with objects with speed */ 1363 process_events (); /* "do" something with objects with speed */
1438 flush_sockets (); 1364 flush_sockets ();
1365
1366 // then do some bookkeeping, should not really be here
1439 check_active_maps (); /* Removes unused maps after a certain timeout */ 1367 check_active_maps (); /* Removes unused maps after a certain timeout */
1440 do_specials (); /* Routines called from time to time. */ 1368 do_specials (); /* Routines called from time to time. */
1441 object::free_mortals (); 1369 object::free_mortals ();
1442 1370
1443 ++pticks; 1371 ++pticks;
1447main (int argc, char **argv) 1375main (int argc, char **argv)
1448{ 1376{
1449 settings.argc = argc; 1377 settings.argc = argc;
1450 settings.argv = argv; 1378 settings.argv = argv;
1451 1379
1452 cfperl_init ();
1453
1454 init (argc, argv); 1380 init (argc, argv);
1455 1381
1456 initPlugins (); 1382 initPlugins ();
1457 1383
1458 for (;;) 1384 for (;;)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines