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.28 by root, Thu Sep 14 23:13:49 2006 UTC vs.
Revision 1.53 by root, Fri Dec 22 16:34:00 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
636 608
637 /* If we are coming from another template map, use reletive paths unless 609 /* If we are coming from another template map, use reletive paths unless
638 * indicated otherwise. 610 * indicated otherwise.
639 */ 611 */
640 if (exit_ob->map->templatemap && (resultname[0] != '/')) 612 if (exit_ob->map->templatemap && (resultname[0] != '/'))
641 {
642 new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); 613 new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname);
643 }
644 else 614 else
645 {
646 new_map_name = create_template_pathname (resultname); 615 new_map_name = create_template_pathname (resultname);
647 }
648 616
649 new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); 617 new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE);
650 if (!new_map) 618 if (!new_map)
651 { 619 {
652 memset (&rp, 0, sizeof (RMParms)); 620 memset (&rp, 0, sizeof (RMParms));
686 */ 654 */
687static void 655static void
688enter_unique_map (object *op, object *exit_ob) 656enter_unique_map (object *op, object *exit_ob)
689{ 657{
690 char apartment[HUGE_BUF]; 658 char apartment[HUGE_BUF];
691 mapstruct *newmap; 659 maptile *newmap;
692 660
693 if (EXIT_PATH (exit_ob)[0] == '/') 661 if (EXIT_PATH (exit_ob)[0] == '/')
694 { 662 {
695 sprintf (apartment, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, clean_path (EXIT_PATH (exit_ob))); 663 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); 664 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 */ 748#define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */
781 object *tmp; 749 object *tmp;
782 750
783 /* It may be nice to support other creatures moving across 751 /* It may be nice to support other creatures moving across
784 * exits, but right now a lot of the code looks at op->contr, 752 * exits, but right now a lot of the code looks at op->contr,
785 * so thta is an RFE. 753 * so that is an RFE.
786 */ 754 */
787 if (op->type != PLAYER) 755 if (op->type != PLAYER)
788 return; 756 return;
789 757
790 /* First, lets figure out what map the player is going to go to */ 758 /* First, lets figure out what map the player is going to go to */
791 if (exit_ob) 759 if (exit_ob)
792 { 760 {
793
794 /* check to see if we make a template map */ 761 /* check to see if we make a template map */
795 if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@') 762 if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@')
796 { 763 {
797 if (EXIT_PATH (exit_ob)[2] == '!') 764 if (EXIT_PATH (exit_ob)[2] == '!')
798 { 765 {
819 int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob); 786 int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob);
820 787
821 /* 'Normal' exits that do not do anything special 788 /* 'Normal' exits that do not do anything special
822 * Simple enough we don't need another routine for it. 789 * Simple enough we don't need another routine for it.
823 */ 790 */
824 mapstruct *newmap; 791 maptile *newmap;
825 792
826 if (exit_ob->map) 793 if (exit_ob->map)
827 { 794 {
828 newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0); 795 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 796 /* 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)) 864 if (tmp->type == FORCE && tmp->slaying && !strcmp (tmp->slaying, PORTAL_DESTINATION_NAME))
898 break; 865 break;
899 } 866 }
900 if (tmp) 867 if (tmp)
901 { 868 {
902 remove_ob (tmp); 869 tmp->remove ();
903 free_object (tmp); 870 tmp->destroy ();
904 } 871 }
905 872
906 strcpy (op->contr->savebed_map, path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob))); 873 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); 874 op->contr->bed_x = EXIT_X (exit_ob), op->contr->bed_y = EXIT_Y (exit_ob);
908 save_player (op, 1); 875 op->contr->save ();
909 /* LOG(llevDebug,"enter_exit: Taking damned exit %s to (%d,%d) on map %s\n", 876 /* LOG(llevDebug,"enter_exit: Taking damned exit %s to (%d,%d) on map %s\n",
910 * exit_ob->name?exit_ob->name:"(none)", exit_ob->x, exit_ob->y, 877 * exit_ob->name?exit_ob->name:"(none)", exit_ob->x, exit_ob->y,
911 * path_combine_and_normalize(exit_ob->map->path, EXIT_PATH(exit_ob))); */ 878 * path_combine_and_normalize(exit_ob->map->path, EXIT_PATH(exit_ob))); */
912 } 879 }
913 880
918 hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1); 885 hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1);
919 } 886 }
920 else 887 else
921 { 888 {
922 int flags = 0; 889 int flags = 0;
923 mapstruct *newmap; 890 maptile *newmap;
924
925 891
926 /* Hypothetically, I guess its possible that a standard map matches 892 /* Hypothetically, I guess its possible that a standard map matches
927 * the localdir, but that seems pretty unlikely - unlikely enough that 893 * the localdir, but that seems pretty unlikely - unlikely enough that
928 * I'm not going to attempt to try to deal with that possibility. 894 * 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 895 * We use the fact that when a player saves on a unique map, it prepends
950 { 916 {
951 LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n"); 917 LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n");
952 abort (); 918 abort ();
953 } 919 }
954 } 920 }
921
955 enter_map (op, newmap, op->x, op->y); 922 enter_map (op, newmap, op->x, op->y);
956 } 923 }
957} 924}
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 925
976/* process_players1 and process_players2 do all the player related stuff. 926/* 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 927 * 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 928 * 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 929 * by the various functions. process_players1() does the processing before
980 * objects have been updated, process_players2() does the processing that 930 * objects have been updated, process_players2() does the processing that
981 * is needed after the players have been updated. 931 * is needed after the players have been updated.
982 */ 932 */
983 933static void
984void 934process_players1 ()
985process_players1 (mapstruct *map)
986{ 935{
987 int flag; 936 int flag;
988 player *pl, *plnext;
989
990 /* Basically, we keep looping until all the players have done their actions. */ 937 /* Basically, we keep looping until all the players have done their actions. */
991 for (flag = 1; flag != 0;) 938 for (flag = 1; flag != 0;)
992 { 939 {
993 flag = 0; 940 flag = 0;
994 for (pl = first_player; pl != NULL; pl = plnext) 941 for (player *plnext, *pl = first_player; pl; pl = plnext)
995 { 942 {
996 plnext = pl->next; /* In case a player exits the game in handle_player() */ 943 plnext = pl->next; /* In case a player exits the game in handle_player() */
997 944
998 if (pl->ob == NULL) 945 if (!pl->ob)
999 continue;
1000
1001 if (map != NULL && pl->ob->map != map)
1002 continue; 946 continue;
1003 947
1004 if (pl->ob->speed_left > 0) 948 if (pl->ob->speed_left > 0)
1005 { 949 {
1006 if (handle_newcs_player (pl->ob)) 950 if (handle_newcs_player (pl->ob))
1018 962
1019#ifdef AUTOSAVE 963#ifdef AUTOSAVE
1020 /* check for ST_PLAYING state so that we don't try to save off when 964 /* check for ST_PLAYING state so that we don't try to save off when
1021 * the player is logging in. 965 * the player is logging in.
1022 */ 966 */
1023 if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->state == ST_PLAYING) 967 if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->ns->state == ST_PLAYING)
1024 {
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 */ 968 {
1029// if (get_map_flags(pl->ob->map, NULL, pl->ob->x, pl->ob->y, NULL, NULL) & P_NO_CLERIC) { 969 pl->ob->contr->save ();
1030// pl->last_save_tick += 100;
1031// } else {
1032 save_player (pl->ob, 1);
1033 pl->last_save_tick = pticks; 970 pl->last_save_tick = pticks;
1034// }
1035 } 971 }
1036#endif 972#endif
1037 } /* end of for loop for all the players */ 973 } /* end of for loop for all the players */
1038 } /* for flag */ 974 } /* for flag */
975
1039 for (pl = first_player; pl != NULL; pl = pl->next) 976 for (player *pl = first_player; pl; pl = pl->next)
1040 { 977 {
1041 if (map != NULL && (pl->ob == NULL || pl->ob->map != map))
1042 continue;
1043 if (settings.casting_time == TRUE) 978 if (settings.casting_time)
1044 { 979 {
1045 if (pl->ob->casting_time > 0) 980 if (pl->ob->casting_time > 0)
1046 { 981 {
1047 pl->ob->casting_time--; 982 pl->ob->casting_time--;
1048 pl->ob->start_holding = 1; 983 pl->ob->start_holding = 1;
1049 } 984 }
985
1050 /* set spell_state so we can update the range in stats field */ 986 /* set spell_state so we can update the range in stats field */
1051 if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1)) 987 if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1))
1052 {
1053 pl->ob->start_holding = 0; 988 pl->ob->start_holding = 0;
1054 } 989 }
1055 } 990
1056 do_some_living (pl->ob); 991 do_some_living (pl->ob);
1057 /* draw(pl->ob); *//* updated in socket code */
1058 } 992 }
1059} 993}
1060 994
1061void 995static void
1062process_players2 (mapstruct *map) 996process_players2 ()
1063{ 997{
1064 player *pl;
1065
1066 /* Then check if any players should use weapon-speed instead of speed */ 998 /* Then check if any players should use weapon-speed instead of speed */
1067 for (pl = first_player; pl != NULL; pl = pl->next) 999 for (player *pl = first_player; pl; pl = pl->next)
1068 { 1000 {
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 - 1001 /* The code that did weapon_sp handling here was out of place -
1080 * this isn't called until after the player has finished there 1002 * 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 1003 * actions, and is thus out of place. All we do here is bounds
1082 * checking. 1004 * checking.
1083 */ 1005 */
1089 /* This needs to be here - if the player is running, we need to 1011 /* 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 1012 * clear this each tick, but new commands are not being received
1091 * so execute_newserver_command() is never called 1013 * so execute_newserver_command() is never called
1092 */ 1014 */
1093 pl->has_hit = 0; 1015 pl->has_hit = 0;
1094
1095 } 1016 }
1096 else if (pl->ob->speed_left > pl->ob->speed) 1017 else if (pl->ob->speed_left > pl->ob->speed)
1097 pl->ob->speed_left = pl->ob->speed; 1018 pl->ob->speed_left = pl->ob->speed;
1098 } 1019 }
1099} 1020}
1100 1021
1101void 1022void
1102process_events (mapstruct *map) 1023process_events ()
1103{ 1024{
1104 object *op; 1025 object *op;
1105 1026
1106 static object *marker; 1027 static object *marker;
1028
1107 if (!marker) 1029 if (!marker)
1108 marker = get_object (); 1030 marker = object::create ();
1109 1031
1110 process_players1 (map); 1032 process_players1 ();
1111 1033
1112 marker->active_next = active_objects; 1034 marker->active_next = active_objects;
1113 1035
1114 if (marker->active_next) 1036 if (marker->active_next)
1115 marker->active_next->active_prev = marker; 1037 marker->active_next->active_prev = marker;
1157 * around. 1079 * around.
1158 */ 1080 */
1159 if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY) 1081 if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY)
1160 { 1082 {
1161 LOG (llevError, "BUG: process_events(): Removed object on list\n"); 1083 LOG (llevError, "BUG: process_events(): Removed object on list\n");
1162 dump_object (op); 1084 char *dump = dump_object (op);
1163 LOG (llevError, errmsg); 1085 LOG (llevError, dump);
1164 free_object (op); 1086 free (dump);
1087 op->destroy ();
1165 continue; 1088 continue;
1166 } 1089 }
1167 1090
1168 if (!op->speed) 1091 if (!op->speed)
1169 { 1092 {
1170 LOG (llevError, "BUG: process_events(): Object %s has no speed, " "but is on active list\n", &op->arch->name); 1093 LOG (llevError, "BUG: process_events(): Object %s has no speed, "
1094 "but is on active list\n", &op->arch->name);
1171 update_ob_speed (op); 1095 update_ob_speed (op);
1172 continue; 1096 continue;
1173 } 1097 }
1174 1098
1175 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP && map == NULL) 1099 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP)
1176 { 1100 {
1177 LOG (llevError, "BUG: process_events(): Object without map or " "inventory is on active list: %s (%d)\n", &op->name, op->count); 1101 LOG (llevError, "BUG: process_events(): Object without map or "
1102 "inventory is on active list: %s (%d)\n", &op->name, op->count);
1178 op->speed = 0; 1103 op->speed = 0;
1179 update_ob_speed (op); 1104 update_ob_speed (op);
1180 continue; 1105 continue;
1181 } 1106 }
1182 1107
1183 if (map != NULL && op->map != map)
1184 continue;
1185
1186 /* Animate the object. Bug of feature that andim_speed 1108 /* Animate the object. Bug or feature that anim_speed
1187 * is based on ticks, and not the creatures speed? 1109 * is based on ticks, and not the creatures speed?
1188 */ 1110 */
1189 if (op->anim_speed && op->last_anim >= op->anim_speed) 1111 if (op->anim_speed && op->last_anim >= op->anim_speed)
1190 { 1112 {
1191 if ((op->type == PLAYER) || (op->type == MONSTER)) 1113 if ((op->type == PLAYER))
1192 animate_object (op, op->facing); 1114 animate_object (op, op->facing);
1193 else 1115 else
1194 animate_object (op, op->direction); 1116 animate_object (op, op->direction);
1195 1117
1196 op->last_anim = 1; 1118 op->last_anim = 1;
1232 if (marker->active_prev != NULL) 1154 if (marker->active_prev != NULL)
1233 marker->active_prev->active_next = NULL; 1155 marker->active_prev->active_next = NULL;
1234 else 1156 else
1235 active_objects = NULL; 1157 active_objects = NULL;
1236 1158
1237 process_players2 (map); 1159 process_players2 ();
1238} 1160}
1239 1161
1240void 1162void
1241clean_tmp_files (void) 1163clean_tmp_files (void)
1242{ 1164{
1243 mapstruct *m, *next; 1165 maptile *m, *next;
1244 1166
1245 LOG (llevInfo, "Cleaning up...\n"); 1167 LOG (llevInfo, "Cleaning up...\n");
1246 1168
1247 /* We save the maps - it may not be intuitive why, but if there are unique 1169 /* 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 1170 * 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. 1171 * just make a special function that only saves the unique items.
1250 */ 1172 */
1251 for (m = first_map; m != NULL; m = next) 1173 for (m = first_map; m; m = next)
1252 { 1174 {
1253 next = m->next; 1175 next = m->next;
1176
1254 if (m->in_memory == MAP_IN_MEMORY) 1177 if (m->in_memory == MAP_IN_MEMORY)
1255 { 1178 {
1256 /* If we want to reuse the temp maps, swap it out (note that will also 1179 /* 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 1180 * 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 */ 1181 */
1262 1182
1263 /* XXX The above comment is dead wrong */
1264 if (settings.recycle_tmp_maps == TRUE)
1265 swap_map (m); 1183 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 } 1184 }
1271 }
1272 } 1185 }
1186
1273 write_todclock (); /* lets just write the clock here */ 1187 write_todclock (); /* lets just write the clock here */
1274} 1188}
1275 1189
1276/* clean up everything before exiting */ 1190/* clean up everything before exiting */
1277void 1191void
1278cleanup (void) 1192cleanup (bool make_core)
1279{ 1193{
1280 LOG (llevDebug, "Cleanup called.\n"); 1194 LOG (llevDebug, "Cleanup called.\n");
1195
1196 if (init_done)
1197 {
1198 for (player *pl = first_player; pl; pl = pl->next)
1199 pl->save (1);
1200
1201 for (player *pl = first_player; pl; pl = pl->next)
1202 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
1203 leave_map (pl->ob);
1204
1205 clean_tmp_files ();
1281 write_book_archive (); 1206 write_book_archive ();
1282 1207
1283 INVOKE_GLOBAL (CLEANUP); 1208 INVOKE_GLOBAL (CLEANUP);
1209 }
1284 1210
1211 if (make_core)
1212 abort ();
1213 else
1285 _exit (0); 1214 _exit (0);
1286} 1215}
1287 1216
1288void 1217void
1289leave (player *pl, int draw_exit) 1218leave (player *pl, int draw_exit)
1290{ 1219{
1291 if (pl != NULL) 1220 if (pl)
1292 { 1221 {
1222 if (pl->ob->type != DEAD_OBJECT)
1223 {
1224 /* If a hidden dm dropped connection do not create
1225 * inconsistencies by showing that they have left the game
1226 */
1227 if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden)
1228 && draw_exit)
1229 {
1230 if (pl->ob->map)
1231 {
1232 INVOKE_PLAYER (LOGOUT, pl);
1233 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->ns->host);
1234 }
1235
1236 char buf[MAX_BUF];
1237
1238 sprintf (buf, "%s left the game.", &pl->ob->name);
1239 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, 0, buf);
1240 }
1241
1242 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
1243 leave_map (pl->ob);
1244
1245 pl->ob->type = DEAD_OBJECT; /* To avoid problems with inventory window */
1246 }
1247
1293 /* We do this so that the socket handling routine can do the final 1248 /* 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 1249 * cleanup. We also leave that loop to actually handle the freeing
1295 * of the data. 1250 * of the data.
1296 */ 1251 */
1297 if (pl->ob->type != DEAD_OBJECT) 1252 if (pl->ns)
1298 { 1253 pl->ns->destroy ();
1299 pl->socket.status = Ns_Dead;
1300 1254
1301 /* If a hidden dm dropped connection do not create
1302 * inconsistencies by showing that they have left the game
1303 */
1304 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))
1306 {
1307 if (pl->ob->map)
1308 {
1309 INVOKE_PLAYER (LOGOUT, pl);
1310 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->socket.host);
1311 }
1312
1313 char buf[MAX_BUF];
1314
1315 sprintf (buf, "%s left the game.", &pl->ob->name);
1316 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, buf);
1317 }
1318
1319 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
1320 leave_map (pl->ob);
1321
1322 pl->ob->type = DEAD_OBJECT; /* To avoid problems with inventory window */
1323 }
1324 } 1255 }
1325} 1256}
1326 1257
1327int 1258int
1328forbid_play (void) 1259forbid_play (void)
1391extern unsigned long todtick; 1322extern unsigned long todtick;
1392 1323
1393void 1324void
1394do_specials (void) 1325do_specials (void)
1395{ 1326{
1396
1397#ifdef WATCHDOG
1398 if (!(pticks % 503))
1399 watchdog ();
1400#endif
1401
1402 if (!(pticks % PTICKS_PER_CLOCK)) 1327 if (!(pticks % PTICKS_PER_CLOCK))
1403 tick_the_clock (); 1328 tick_the_clock ();
1404 1329
1405 if (!(pticks % 7)) 1330 if (!(pticks % 7))
1406 shstr::gc (); 1331 shstr::gc ();
1409 flush_old_maps (); /* Clears the tmp-files of maps which have reset */ 1334 flush_old_maps (); /* Clears the tmp-files of maps which have reset */
1410 1335
1411 if (!(pticks % 2503)) 1336 if (!(pticks % 2503))
1412 fix_weight (); /* Hack to fix weightproblems caused by bugs */ 1337 fix_weight (); /* Hack to fix weightproblems caused by bugs */
1413 1338
1414 if (!(pticks % 2521))
1415 metaserver_update (); /* 2500 ticks is about 5 minutes */
1416
1417 if (!(pticks % 5003)) 1339 if (!(pticks % 5003))
1418 write_book_archive (); 1340 write_book_archive ();
1419 1341
1420 if (!(pticks % 5009)) 1342 if (!(pticks % 5009))
1421 clean_friendly_list (); 1343 clean_friendly_list ();
1430void 1352void
1431server_tick () 1353server_tick ()
1432{ 1354{
1433 nroferrors = 0; 1355 nroferrors = 0;
1434 1356
1357 // first do the user visible stuff
1435 doeric_server (); 1358 doeric_server ();
1436 INVOKE_GLOBAL (CLOCK); 1359 INVOKE_GLOBAL (CLOCK);
1437 process_events (NULL); /* "do" something with objects with speed */ 1360 process_events (); /* "do" something with objects with speed */
1438 flush_sockets (); 1361 flush_sockets ();
1362
1363 // then do some bookkeeping, should not really be here
1439 check_active_maps (); /* Removes unused maps after a certain timeout */ 1364 check_active_maps (); /* Removes unused maps after a certain timeout */
1440 do_specials (); /* Routines called from time to time. */ 1365 do_specials (); /* Routines called from time to time. */
1441 object::free_mortals (); 1366 object::free_mortals ();
1442 1367
1443 ++pticks; 1368 ++pticks;
1447main (int argc, char **argv) 1372main (int argc, char **argv)
1448{ 1373{
1449 settings.argc = argc; 1374 settings.argc = argc;
1450 settings.argv = argv; 1375 settings.argv = argv;
1451 1376
1452 cfperl_init ();
1453
1454 init (argc, argv); 1377 init (argc, argv);
1455 1378
1456 initPlugins (); 1379 initPlugins ();
1457 1380
1458 for (;;) 1381 for (;;)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines