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.23 by root, Sun Sep 10 15:59:57 2006 UTC vs.
Revision 1.43 by root, Thu Dec 14 04:30:32 2006 UTC

1
2/*
3 * static char *rcsid_main_c =
4 * "$Id: main.C,v 1.23 2006/09/10 15:59:57 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30#include <global.h> 24#include <global.h>
31#include <object.h> 25#include <object.h>
32#include <tod.h> 26#include <tod.h>
112 new_draw_info (NDI_UNIQUE, 0, op, "Images and art:"); 106 new_draw_info (NDI_UNIQUE, 0, op, "Images and art:");
113 new_draw_info (NDI_UNIQUE, 0, op, "Peter Gardner"); 107 new_draw_info (NDI_UNIQUE, 0, op, "Peter Gardner");
114 new_draw_info (NDI_UNIQUE, 0, op, "David Gervais [david_eg@mail.com]"); 108 new_draw_info (NDI_UNIQUE, 0, op, "David Gervais [david_eg@mail.com]");
115 new_draw_info (NDI_UNIQUE, 0, op, "Mitsuhiro Itakura [ita@gold.koma.jaeri.go.jp]"); 109 new_draw_info (NDI_UNIQUE, 0, op, "Mitsuhiro Itakura [ita@gold.koma.jaeri.go.jp]");
116 new_draw_info (NDI_UNIQUE, 0, op, "Hansjoerg Malthaner [hansjoerg.malthaner@danet.de]"); 110 new_draw_info (NDI_UNIQUE, 0, op, "Hansjoerg Malthaner [hansjoerg.malthaner@danet.de]");
117 new_draw_info (NDI_UNIQUE, 0, op, "Mårten Woxberg [maxmc@telia.com]"); 111 new_draw_info (NDI_UNIQUE, 0, op, "MÃ¥rten Woxberg [maxmc@telia.com]");
118 new_draw_info (NDI_UNIQUE, 0, op, "And many more!"); 112 new_draw_info (NDI_UNIQUE, 0, op, "And many more!");
119} 113}
120 114
121void 115void
122info_keys (object *op) 116info_keys (object *op)
164 * simple case at top - no encryption - makes it easier to read. 158 * simple case at top - no encryption - makes it easier to read.
165 */ 159 */
166char * 160char *
167crypt_string (char *str, char *salt) 161crypt_string (char *str, char *salt)
168{ 162{
169#if defined(WIN32) || (defined(__FreeBSD__) && !defined(HAVE_LIBDES)) 163#if (defined(__FreeBSD__) && !defined(HAVE_LIBDES))
170 return (str); 164 return (str);
171#else 165#else
172 static char *c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; 166 static char *c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
173 char s[2]; 167 char s[2];
174 168
197 * goes someplace. 191 * goes someplace.
198 */ 192 */
199void 193void
200enter_player_savebed (object *op) 194enter_player_savebed (object *op)
201{ 195{
202 mapstruct *oldmap = op->map; 196 maptile *oldmap = op->map;
203 object *tmp; 197 object *tmp;
204 198
205 tmp = get_object (); 199 tmp = object::create ();
206 200
207 EXIT_PATH (tmp) = op->contr->savebed_map; 201 EXIT_PATH (tmp) = op->contr->savebed_map;
208 EXIT_X (tmp) = op->contr->bed_x; 202 EXIT_X (tmp) = op->contr->bed_x;
209 EXIT_Y (tmp) = op->contr->bed_y; 203 EXIT_Y (tmp) = op->contr->bed_y;
210 enter_exit (op, tmp); 204 enter_exit (op, tmp);
223 EXIT_PATH (tmp) = op->contr->savebed_map; 217 EXIT_PATH (tmp) = op->contr->savebed_map;
224 EXIT_X (tmp) = op->contr->bed_x; 218 EXIT_X (tmp) = op->contr->bed_x;
225 EXIT_Y (tmp) = op->contr->bed_y; 219 EXIT_Y (tmp) = op->contr->bed_y;
226 enter_exit (op, tmp); 220 enter_exit (op, tmp);
227 } 221 }
228 free_object (tmp); 222
223 tmp->destroy ();
229} 224}
230 225
231/* All this really is is a glorified remove_object that also updates 226/* All this really is is a glorified remove_object that also updates
232 * the counts on the map if needed. 227 * the counts on the map if needed.
233 */ 228 */
234void 229void
235leave_map (object *op) 230leave_map (object *op)
236{ 231{
237 mapstruct *oldmap = op->map; 232 maptile *oldmap = op->map;
238 233
239 remove_ob (op); 234 op->remove ();
240 235
241 if (oldmap) 236 if (oldmap)
242 { 237 {
243 if (!op->contr->hidden) 238 if (!op->contr->hidden)
244 oldmap->players--; 239 oldmap->players--;
240
245 if (oldmap->players <= 0) 241 if (oldmap->players <= 0)
246 { /* can be less than zero due to errors in tracking this */ 242 /* can be less than zero due to errors in tracking this */
247 set_map_timeout (oldmap); 243 set_map_timeout (oldmap);
248 }
249 } 244 }
250} 245}
251 246
252/* 247/*
253 * enter_map(): Moves the player and pets from current map (if any) to 248 * enter_map(): Moves the player and pets from current map (if any) to
255 * player to - it could be the map he just came from if the load failed for 250 * player to - it could be the map he just came from if the load failed for
256 * whatever reason. If default map coordinates are to be used, then 251 * whatever reason. If default map coordinates are to be used, then
257 * the function that calls this should figure them out. 252 * the function that calls this should figure them out.
258 */ 253 */
259static void 254static void
260enter_map (object *op, mapstruct *newmap, int x, int y) 255enter_map (object *op, maptile *newmap, int x, int y)
261{ 256{
262 mapstruct *oldmap = op->map; 257 maptile *oldmap = op->map;
263 258
264 if (out_of_map (newmap, x, y)) 259 if (out_of_map (newmap, x, y))
265 { 260 {
266 LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", newmap->path, x, y); 261 LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", newmap->path, x, y);
267 x = MAP_ENTER_X (newmap); 262 x = MAP_ENTER_X (newmap);
272 newmap->path, x, y, MAP_WIDTH (newmap), MAP_HEIGHT (newmap)); 267 newmap->path, x, y, MAP_WIDTH (newmap), MAP_HEIGHT (newmap));
273 new_draw_info (NDI_UNIQUE, 0, op, "The exit is closed"); 268 new_draw_info (NDI_UNIQUE, 0, op, "The exit is closed");
274 return; 269 return;
275 } 270 }
276 } 271 }
272
277 /* try to find a spot for the player */ 273 /* try to find a spot for the player */
278 if (ob_blocked (op, newmap, x, y)) 274 if (ob_blocked (op, newmap, x, y))
279 { /* First choice blocked */ 275 { /* First choice blocked */
280 /* We try to find a spot for the player, starting closest in. 276 /* We try to find a spot for the player, starting closest in.
281 * We could use find_first_free_spot, but that doesn't randomize it at all, 277 * We could use find_first_free_spot, but that doesn't randomize it at all,
290 { 286 {
291 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE2 + 1); 287 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE2 + 1);
292 if (i == -1) 288 if (i == -1)
293 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE); 289 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE);
294 } 290 }
291
295 if (i != -1) 292 if (i != -1)
296 { 293 {
297 x += freearr_x[i]; 294 x += freearr_x[i];
298 y += freearr_y[i]; 295 y += freearr_y[i];
299 } 296 }
302 /* not much we can do in this case. */ 299 /* not much we can do in this case. */
303 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); 300 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);
304 } 301 }
305 } /* end if looking for free spot */ 302 } /* end if looking for free spot */
306 303
307 if (op->map != NULL) 304 if (op->map)
308 {
309 INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (op->map), ARG_MAP (newmap));
310 INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr)); 305 if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr)))
311 } 306 return;
307
308 if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y)))
309 return;
310
311 if (INVOKE_MAP (ENTER, newmap, ARG_PLAYER (op->contr), ARG_INT (x), ARG_INT (y)))
312 return;
312 313
313 /* If it is a player login, he has yet to be inserted anyplace. 314 /* If it is a player login, he has yet to be inserted anyplace.
314 * otherwise, we need to deal with removing the player here. 315 * otherwise, we need to deal with removing the player here.
315 */ 316 */
316 if (!QUERY_FLAG (op, FLAG_REMOVED)) 317 op->remove ();
317 remove_ob (op);
318 318
319 /* remove_ob clears these so they must be reset after the remove_ob call */ 319 /* remove_ob clears these so they must be reset after the remove_ob call */
320 op->x = x; 320 op->x = x;
321 op->y = y; 321 op->y = y;
322 op->map = newmap; 322 op->map = newmap;
323
323 insert_ob_in_map (op, op->map, NULL, INS_NO_WALK_ON); 324 insert_ob_in_map (op, op->map, NULL, INS_NO_WALK_ON);
324
325 INVOKE_MAP (ENTER, op->map, ARG_PLAYER (op->contr));
326 325
327 if (!op->contr->hidden) 326 if (!op->contr->hidden)
328 newmap->players++; 327 newmap->players++;
329 328
330 newmap->timeout = 0; 329 newmap->timeout = 0;
340 if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL) 339 if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL)
341 { 340 {
342 int i = find_free_spot (op->contr->ranges[range_golem], newmap, 341 int i = find_free_spot (op->contr->ranges[range_golem], newmap,
343 x, y, 1, SIZEOFFREE); 342 x, y, 1, SIZEOFFREE);
344 343
345 remove_ob (op->contr->ranges[range_golem]); 344 op->contr->ranges[range_golem]->remove ();
345
346 if (i == -1) 346 if (i == -1)
347 { 347 {
348 remove_friendly_object (op->contr->ranges[range_golem]); 348 remove_friendly_object (op->contr->ranges[range_golem]);
349 free_object (op->contr->ranges[range_golem]); 349 op->contr->ranges[range_golem]->destroy ();
350 op->contr->ranges[range_golem] = NULL; 350 op->contr->ranges[range_golem] = 0;
351 op->contr->golem_count = 0;
352 } 351 }
353 else 352 else
354 { 353 {
355 object *tmp;
356
357 for (tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more) 354 for (object *tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more)
358 { 355 {
359 tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); 356 tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x);
360 tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); 357 tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y);
361 tmp->map = newmap; 358 tmp->map = newmap;
362 } 359 }
360
363 insert_ob_in_map (op->contr->ranges[range_golem], newmap, NULL, 0); 361 insert_ob_in_map (op->contr->ranges[range_golem], newmap, NULL, 0);
364 op->contr->ranges[range_golem]->direction = 362 op->contr->ranges[range_golem]->direction =
365 find_dir_2 (op->x - op->contr->ranges[range_golem]->x, op->y - op->contr->ranges[range_golem]->y); 363 find_dir_2 (op->x - op->contr->ranges[range_golem]->x, op->y - op->contr->ranges[range_golem]->y);
366 } 364 }
367 } 365 }
366
368 op->direction = 0; 367 op->direction = 0;
369 368
370 /* since the players map is already loaded, we don't need to worry 369 /* since the players map is already loaded, we don't need to worry
371 * about pending objects. 370 * about pending objects.
372 */ 371 */
387 } 386 }
388 } 387 }
389} 388}
390 389
391void 390void
392set_map_timeout (mapstruct *oldmap) 391set_map_timeout (maptile *oldmap)
393{ 392{
394#if MAP_MAXTIMEOUT 393#if MAP_MAXTIMEOUT
395 oldmap->timeout = MAP_TIMEOUT (oldmap); 394 oldmap->timeout = MAP_TIMEOUT (oldmap);
396 /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is 395 /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is
397 * lower than the min value. 396 * lower than the min value.
398 */ 397 */
399# if MAP_MINTIMEOUT 398# if MAP_MINTIMEOUT
400 if (oldmap->timeout < MAP_MINTIMEOUT) 399 if (oldmap->timeout < MAP_MINTIMEOUT)
401 {
402 oldmap->timeout = MAP_MINTIMEOUT; 400 oldmap->timeout = MAP_MINTIMEOUT;
403 }
404# endif 401# endif
402
405 if (oldmap->timeout > MAP_MAXTIMEOUT) 403 if (oldmap->timeout > MAP_MAXTIMEOUT)
406 {
407 oldmap->timeout = MAP_MAXTIMEOUT; 404 oldmap->timeout = MAP_MAXTIMEOUT;
408 } 405
409#else 406#else
410 /* save out the map */ 407 /* save out the map */
411 swap_map (oldmap); 408 swap_map (oldmap);
412#endif /* MAP_MAXTIMEOUT */ 409#endif /* MAP_MAXTIMEOUT */
413} 410}
418 */ 415 */
419char * 416char *
420clean_path (const char *file) 417clean_path (const char *file)
421{ 418{
422 static char newpath[MAX_BUF], *cp; 419 static char newpath[MAX_BUF], *cp;
420 assign (newpath, file);
423 421
424 strncpy (newpath, file, MAX_BUF - 1);
425 newpath[MAX_BUF - 1] = '\0';
426 for (cp = newpath; *cp != '\0'; cp++) 422 for (cp = newpath; *cp != '\0'; cp++)
427 {
428 if (*cp == '/') 423 if (*cp == '/')
429 *cp = '_'; 424 *cp = '_';
430 } 425
431 return newpath; 426 return newpath;
432} 427}
433 428
434 429
435/* unclean_path takes a path and replaces all _ with / 430/* unclean_path takes a path and replaces all _ with /
443unclean_path (const char *src) 438unclean_path (const char *src)
444{ 439{
445 static char newpath[MAX_BUF], *cp; 440 static char newpath[MAX_BUF], *cp;
446 441
447 cp = strrchr (src, '/'); 442 cp = strrchr (src, '/');
448 if (cp) 443 assign (newpath, cp ? cp + 1 : src);
449 strncpy (newpath, cp + 1, MAX_BUF - 1);
450 else
451 strncpy (newpath, src, MAX_BUF - 1);
452 newpath[MAX_BUF - 1] = '\0';
453 444
454 for (cp = newpath; *cp != '\0'; cp++) 445 for (cp = newpath; *cp != '\0'; cp++)
455 {
456 if (*cp == '_') 446 if (*cp == '_')
457 *cp = '/'; 447 *cp = '/';
458 } 448
459 return newpath; 449 return newpath;
460} 450}
461 451
462 452
463/* The player is trying to enter a randomly generated map. In this case, generate the 453/* The player is trying to enter a randomly generated map. In this case, generate the
465 */ 455 */
466 456
467static void 457static void
468enter_random_map (object *pl, object *exit_ob) 458enter_random_map (object *pl, object *exit_ob)
469{ 459{
470 mapstruct *new_map; 460 maptile *new_map;
471 char newmap_name[HUGE_BUF], *cp; 461 char newmap_name[HUGE_BUF], *cp;
472 static int reference_number = 0; 462 static int reference_number = 0;
473 RMParms rp; 463 RMParms rp;
474 464
475 memset (&rp, 0, sizeof (RMParms)); 465 memset (&rp, 0, sizeof (RMParms));
535 */ 525 */
536 526
537static void 527static void
538enter_fixed_template_map (object *pl, object *exit_ob) 528enter_fixed_template_map (object *pl, object *exit_ob)
539{ 529{
540 mapstruct *new_map; 530 maptile *new_map;
541 char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap; 531 char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap;
542 const char *new_map_name; 532 const char *new_map_name;
543 533
544 /* Split the exit path string into two parts, one 534 /* Split the exit path string into two parts, one
545 * for where to store the map, and one for were 535 * for where to store the map, and one for were
554 */ 544 */
555 LOG (llevError, "enter_fixed_template_map: Exit %s (%d,%d) on map %s has no source template.\n", 545 LOG (llevError, "enter_fixed_template_map: Exit %s (%d,%d) on map %s has no source template.\n",
556 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); 546 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path);
557 return; 547 return;
558 } 548 }
549
559 *sourcemap++ = '\0'; 550 *sourcemap++ = '\0';
560 551
561 /* If we are not coming from a template map, we can use relative directories 552 /* If we are not coming from a template map, we can use relative directories
562 * for the map to generate from. 553 * for the map to generate from.
563 */ 554 */
564 if (!exit_ob->map->templatemap) 555 if (!exit_ob->map->templatemap)
565 {
566 sourcemap = path_combine_and_normalize (exit_ob->map->path, sourcemap); 556 sourcemap = path_combine_and_normalize (exit_ob->map->path, sourcemap);
567 }
568 557
569 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord 558 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord
570 * of the exit, and the name of the map the exit is on, respectively. 559 * of the exit, and the name of the map the exit is on, respectively.
571 */ 560 */
572 sprintf (tmpnum, "%d", exit_ob->x); 561 sprintf (tmpnum, "%d", exit_ob->x);
581 570
582 /* If we are coming from another template map, use reletive paths unless 571 /* If we are coming from another template map, use reletive paths unless
583 * indicated otherwise. 572 * indicated otherwise.
584 */ 573 */
585 if (exit_ob->map->templatemap && (resultname[0] != '/')) 574 if (exit_ob->map->templatemap && (resultname[0] != '/'))
586 {
587 new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); 575 new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname);
588 }
589 else 576 else
590 {
591 new_map_name = create_template_pathname (resultname); 577 new_map_name = create_template_pathname (resultname);
592 }
593 578
594 /* Attempt to load the map, if unable to, then 579 /* Attempt to load the map, if unable to, then
595 * create the map from the template. 580 * create the map from the template.
596 */ 581 */
597 new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); 582 new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE);
619 LOG (llevDebug, "enter_fixed_template_map: Exit %s (%d,%d) on map %s leads no where.\n", 604 LOG (llevDebug, "enter_fixed_template_map: Exit %s (%d,%d) on map %s leads no where.\n",
620 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); 605 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path);
621 } 606 }
622} 607}
623 608
624
625/* The player is trying to enter a randomly generated template map. In this 609/* The player is trying to enter a randomly generated template map. In this
626 * case, generate the map as needed. 610 * case, generate the map as needed.
627 */ 611 */
628 612
629static void 613static void
630enter_random_template_map (object *pl, object *exit_ob) 614enter_random_template_map (object *pl, object *exit_ob)
631{ 615{
632 mapstruct *new_map; 616 maptile *new_map;
633 char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF]; 617 char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF];
634 const char *new_map_name; 618 const char *new_map_name;
635 RMParms rp; 619 RMParms rp;
636 620
637 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord 621 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord
699 */ 683 */
700static void 684static void
701enter_unique_map (object *op, object *exit_ob) 685enter_unique_map (object *op, object *exit_ob)
702{ 686{
703 char apartment[HUGE_BUF]; 687 char apartment[HUGE_BUF];
704 mapstruct *newmap; 688 maptile *newmap;
705 689
706 if (EXIT_PATH (exit_ob)[0] == '/') 690 if (EXIT_PATH (exit_ob)[0] == '/')
707 { 691 {
708 sprintf (apartment, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, clean_path (EXIT_PATH (exit_ob))); 692 sprintf (apartment, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, clean_path (EXIT_PATH (exit_ob)));
709 newmap = ready_map_name (apartment, MAP_PLAYER_UNIQUE); 693 newmap = ready_map_name (apartment, MAP_PLAYER_UNIQUE);
793#define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */ 777#define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */
794 object *tmp; 778 object *tmp;
795 779
796 /* It may be nice to support other creatures moving across 780 /* It may be nice to support other creatures moving across
797 * exits, but right now a lot of the code looks at op->contr, 781 * exits, but right now a lot of the code looks at op->contr,
798 * so thta is an RFE. 782 * so that is an RFE.
799 */ 783 */
800 if (op->type != PLAYER) 784 if (op->type != PLAYER)
801 return; 785 return;
802 786
803 /* First, lets figure out what map the player is going to go to */ 787 /* First, lets figure out what map the player is going to go to */
804 if (exit_ob) 788 if (exit_ob)
805 { 789 {
806
807 /* check to see if we make a template map */ 790 /* check to see if we make a template map */
808 if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@') 791 if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@')
809 { 792 {
810 if (EXIT_PATH (exit_ob)[2] == '!') 793 if (EXIT_PATH (exit_ob)[2] == '!')
811 { 794 {
832 int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob); 815 int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob);
833 816
834 /* 'Normal' exits that do not do anything special 817 /* 'Normal' exits that do not do anything special
835 * Simple enough we don't need another routine for it. 818 * Simple enough we don't need another routine for it.
836 */ 819 */
837 mapstruct *newmap; 820 maptile *newmap;
838 821
839 if (exit_ob->map) 822 if (exit_ob->map)
840 { 823 {
841 newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0); 824 newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0);
842 /* Random map was previously generated, but is no longer about. Lets generate a new 825 /* Random map was previously generated, but is no longer about. Lets generate a new
910 if (tmp->type == FORCE && tmp->slaying && !strcmp (tmp->slaying, PORTAL_DESTINATION_NAME)) 893 if (tmp->type == FORCE && tmp->slaying && !strcmp (tmp->slaying, PORTAL_DESTINATION_NAME))
911 break; 894 break;
912 } 895 }
913 if (tmp) 896 if (tmp)
914 { 897 {
915 remove_ob (tmp); 898 tmp->remove ();
916 free_object (tmp); 899 tmp->destroy ();
917 } 900 }
918 901
919 strcpy (op->contr->savebed_map, path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob))); 902 strcpy (op->contr->savebed_map, path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)));
920 op->contr->bed_x = EXIT_X (exit_ob), op->contr->bed_y = EXIT_Y (exit_ob); 903 op->contr->bed_x = EXIT_X (exit_ob), op->contr->bed_y = EXIT_Y (exit_ob);
921 save_player (op, 1); 904 save_player (op, 1);
931 hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1); 914 hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1);
932 } 915 }
933 else 916 else
934 { 917 {
935 int flags = 0; 918 int flags = 0;
936 mapstruct *newmap; 919 maptile *newmap;
937
938 920
939 /* Hypothetically, I guess its possible that a standard map matches 921 /* Hypothetically, I guess its possible that a standard map matches
940 * the localdir, but that seems pretty unlikely - unlikely enough that 922 * the localdir, but that seems pretty unlikely - unlikely enough that
941 * I'm not going to attempt to try to deal with that possibility. 923 * I'm not going to attempt to try to deal with that possibility.
942 * We use the fact that when a player saves on a unique map, it prepends 924 * We use the fact that when a player saves on a unique map, it prepends
963 { 945 {
964 LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n"); 946 LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n");
965 abort (); 947 abort ();
966 } 948 }
967 } 949 }
950
968 enter_map (op, newmap, op->x, op->y); 951 enter_map (op, newmap, op->x, op->y);
969 } 952 }
970} 953}
971 954
972/* 955/*
977 960
978#if 0 // dead code, schmorp 961#if 0 // dead code, schmorp
979void 962void
980process_active_maps () 963process_active_maps ()
981{ 964{
982 for (mapstruct *map = first_map; map != NULL; map = map->next) 965 for (maptile *map = first_map; map != NULL; map = map->next)
983 if (map->in_memory == MAP_IN_MEMORY) 966 if (map->in_memory == MAP_IN_MEMORY)
984 if (players_on_map (map, TRUE)) 967 if (players_on_map (map, TRUE))
985 process_events (map); 968 process_events (map);
986} 969}
987#endif 970#endif
993 * objects have been updated, process_players2() does the processing that 976 * objects have been updated, process_players2() does the processing that
994 * is needed after the players have been updated. 977 * is needed after the players have been updated.
995 */ 978 */
996 979
997void 980void
998process_players1 (mapstruct *map) 981process_players1 (maptile *map)
999{ 982{
1000 int flag; 983 int flag;
1001 player *pl, *plnext; 984 player *pl, *plnext;
1002 985
1003 /* Basically, we keep looping until all the players have done their actions. */ 986 /* Basically, we keep looping until all the players have done their actions. */
1070 /* draw(pl->ob); *//* updated in socket code */ 1053 /* draw(pl->ob); *//* updated in socket code */
1071 } 1054 }
1072} 1055}
1073 1056
1074void 1057void
1075process_players2 (mapstruct *map) 1058process_players2 (maptile *map)
1076{ 1059{
1077 player *pl; 1060 player *pl;
1078 1061
1079 /* Then check if any players should use weapon-speed instead of speed */ 1062 /* Then check if any players should use weapon-speed instead of speed */
1080 for (pl = first_player; pl != NULL; pl = pl->next) 1063 for (pl = first_player; pl != NULL; pl = pl->next)
1110 pl->ob->speed_left = pl->ob->speed; 1093 pl->ob->speed_left = pl->ob->speed;
1111 } 1094 }
1112} 1095}
1113 1096
1114void 1097void
1115process_events (mapstruct *map) 1098process_events (maptile *map)
1116{ 1099{
1117 object *op; 1100 object *op;
1118 object *marker = get_object (); 1101
1119 tag_t tag; 1102 static object *marker;
1103
1104 if (!marker)
1105 marker = object::create ();
1120 1106
1121 process_players1 (map); 1107 process_players1 (map);
1122 1108
1123 marker->active_next = active_objects; 1109 marker->active_next = active_objects;
1124 1110
1129 active_objects = marker; 1115 active_objects = marker;
1130 1116
1131 while (marker->active_next) 1117 while (marker->active_next)
1132 { 1118 {
1133 op = marker->active_next; 1119 op = marker->active_next;
1134 tag = op->count;
1135 1120
1136 /* Move marker forward - swap op and marker */ 1121 /* Move marker forward - swap op and marker */
1137 op->active_prev = marker->active_prev; 1122 op->active_prev = marker->active_prev;
1138 1123
1139 if (op->active_prev) 1124 if (op->active_prev)
1169 * around. 1154 * around.
1170 */ 1155 */
1171 if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY) 1156 if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY)
1172 { 1157 {
1173 LOG (llevError, "BUG: process_events(): Removed object on list\n"); 1158 LOG (llevError, "BUG: process_events(): Removed object on list\n");
1174 dump_object (op); 1159 char *dump = dump_object (op);
1175 LOG (llevError, errmsg); 1160 LOG (llevError, dump);
1176 free_object (op); 1161 free (dump);
1162 op->destroy ();
1177 continue; 1163 continue;
1178 } 1164 }
1179 1165
1180 if (!op->speed) 1166 if (!op->speed)
1181 { 1167 {
1226 LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null"); 1212 LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null");
1227 } 1213 }
1228#endif 1214#endif
1229 --op->speed_left; 1215 --op->speed_left;
1230 process_object (op); 1216 process_object (op);
1217
1231 if (was_destroyed (op, tag)) 1218 if (op->destroyed ())
1232 continue; 1219 continue;
1233 } 1220 }
1221
1234 if (settings.casting_time == TRUE && op->casting_time > 0) 1222 if (settings.casting_time == TRUE && op->casting_time > 0)
1235 op->casting_time--; 1223 op->casting_time--;
1224
1236 if (op->speed_left <= 0) 1225 if (op->speed_left <= 0)
1237 op->speed_left += FABS (op->speed); 1226 op->speed_left += FABS (op->speed);
1238 } 1227 }
1239 1228
1240 /* Remove marker object from active list */ 1229 /* Remove marker object from active list */
1242 marker->active_prev->active_next = NULL; 1231 marker->active_prev->active_next = NULL;
1243 else 1232 else
1244 active_objects = NULL; 1233 active_objects = NULL;
1245 1234
1246 process_players2 (map); 1235 process_players2 (map);
1247
1248 free_object (marker);
1249} 1236}
1250 1237
1251void 1238void
1252clean_tmp_files (void) 1239clean_tmp_files (void)
1253{ 1240{
1254 mapstruct *m, *next; 1241 maptile *m, *next;
1255 1242
1256 LOG (llevInfo, "Cleaning up...\n"); 1243 LOG (llevInfo, "Cleaning up...\n");
1257 1244
1258 /* We save the maps - it may not be intuitive why, but if there are unique 1245 /* We save the maps - it may not be intuitive why, but if there are unique
1259 * items, we need to save the map so they get saved off. Perhaps we should 1246 * items, we need to save the map so they get saved off. Perhaps we should
1286 1273
1287/* clean up everything before exiting */ 1274/* clean up everything before exiting */
1288void 1275void
1289cleanup (void) 1276cleanup (void)
1290{ 1277{
1291 LOG (llevDebug, "Cleanup called. freeing data.\n"); 1278 LOG (llevDebug, "Cleanup called.\n");
1279
1280 for (player *pl = first_player; pl != NULL; pl = pl->next)
1281 save_player (pl->ob, 0);
1282
1283 for (player *pl = first_player; pl != NULL; pl = pl->next)
1284 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
1285 leave_map (pl->ob);
1286
1292 clean_tmp_files (); 1287 clean_tmp_files ();
1293 write_book_archive (); 1288 write_book_archive ();
1294#ifdef MEMORY_DEBUG
1295 free_all_maps ();
1296 free_style_maps ();
1297 free_all_object_data ();
1298 free_all_archs ();
1299 free_all_treasures ();
1300 free_all_images ();
1301 free_all_newserver ();
1302 free_all_recipes ();
1303 free_all_readable ();
1304 free_all_god ();
1305 free_all_anim ();
1306 /* See what the string data that is out there that hasn't been freed. */
1307 1289
1308/* LOG(llevDebug, ss_dump_table(0xff));*/ 1290 INVOKE_GLOBAL (CLEANUP);
1309#endif 1291
1310 exit (0); 1292 _exit (0);
1311} 1293}
1312 1294
1313void 1295void
1314leave (player *pl, int draw_exit) 1296leave (player *pl, int draw_exit)
1315{ 1297{
1319 * cleanup. We also leave that loop to actually handle the freeing 1301 * cleanup. We also leave that loop to actually handle the freeing
1320 * of the data. 1302 * of the data.
1321 */ 1303 */
1322 if (pl->ob->type != DEAD_OBJECT) 1304 if (pl->ob->type != DEAD_OBJECT)
1323 { 1305 {
1324 pl->socket.status = Ns_Dead; 1306 pl->socket->status = Ns_Dead;
1325 1307
1326 /* If a hidden dm dropped connection do not create 1308 /* If a hidden dm dropped connection do not create
1327 * inconsistencies by showing that they have left the game 1309 * inconsistencies by showing that they have left the game
1328 */ 1310 */
1329 if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden) 1311 if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden)
1330 && draw_exit && (pl->state != ST_GET_NAME && pl->state != ST_GET_PASSWORD && pl->state != ST_CONFIRM_PASSWORD)) 1312 && draw_exit && (pl->state != ST_GET_NAME && pl->state != ST_GET_PASSWORD && pl->state != ST_CONFIRM_PASSWORD))
1331 { 1313 {
1332 if (pl->ob->map) 1314 if (pl->ob->map)
1333 { 1315 {
1334 INVOKE_PLAYER (LOGOUT, pl); 1316 INVOKE_PLAYER (LOGOUT, pl);
1335 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->socket.host); 1317 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->socket->host);
1336 } 1318 }
1337 1319
1338 char buf[MAX_BUF]; 1320 char buf[MAX_BUF];
1339 1321
1340 sprintf (buf, "%s left the game.", &pl->ob->name); 1322 sprintf (buf, "%s left the game.", &pl->ob->name);
1434 flush_old_maps (); /* Clears the tmp-files of maps which have reset */ 1416 flush_old_maps (); /* Clears the tmp-files of maps which have reset */
1435 1417
1436 if (!(pticks % 2503)) 1418 if (!(pticks % 2503))
1437 fix_weight (); /* Hack to fix weightproblems caused by bugs */ 1419 fix_weight (); /* Hack to fix weightproblems caused by bugs */
1438 1420
1439 if (!(pticks % 2521))
1440 metaserver_update (); /* 2500 ticks is about 5 minutes */
1441
1442 if (!(pticks % 5003)) 1421 if (!(pticks % 5003))
1443 write_book_archive (); 1422 write_book_archive ();
1444 1423
1445 if (!(pticks % 5009)) 1424 if (!(pticks % 5009))
1446 clean_friendly_list (); 1425 clean_friendly_list ();
1472main (int argc, char **argv) 1451main (int argc, char **argv)
1473{ 1452{
1474 settings.argc = argc; 1453 settings.argc = argc;
1475 settings.argv = argv; 1454 settings.argv = argv;
1476 1455
1477 cfperl_init ();
1478
1479 init (argc, argv); 1456 init (argc, argv);
1480 1457
1481 initPlugins (); 1458 initPlugins ();
1482 1459
1483 for (;;) 1460 for (;;)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines