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.47 by root, Mon Dec 18 02:35:01 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));
522 */ 520 */
523 521
524static void 522static void
525enter_fixed_template_map (object *pl, object *exit_ob) 523enter_fixed_template_map (object *pl, object *exit_ob)
526{ 524{
527 mapstruct *new_map; 525 maptile *new_map;
528 char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap; 526 char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap;
529 const char *new_map_name; 527 const char *new_map_name;
530 528
531 /* Split the exit path string into two parts, one 529 /* Split the exit path string into two parts, one
532 * for where to store the map, and one for were 530 * for where to store the map, and one for were
541 */ 539 */
542 LOG (llevError, "enter_fixed_template_map: Exit %s (%d,%d) on map %s has no source template.\n", 540 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); 541 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path);
544 return; 542 return;
545 } 543 }
544
546 *sourcemap++ = '\0'; 545 *sourcemap++ = '\0';
547 546
548 /* If we are not coming from a template map, we can use relative directories 547 /* If we are not coming from a template map, we can use relative directories
549 * for the map to generate from. 548 * for the map to generate from.
550 */ 549 */
551 if (!exit_ob->map->templatemap) 550 if (!exit_ob->map->templatemap)
552 {
553 sourcemap = path_combine_and_normalize (exit_ob->map->path, sourcemap); 551 sourcemap = path_combine_and_normalize (exit_ob->map->path, sourcemap);
554 }
555 552
556 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord 553 /* 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. 554 * of the exit, and the name of the map the exit is on, respectively.
558 */ 555 */
559 sprintf (tmpnum, "%d", exit_ob->x); 556 sprintf (tmpnum, "%d", exit_ob->x);
568 565
569 /* If we are coming from another template map, use reletive paths unless 566 /* If we are coming from another template map, use reletive paths unless
570 * indicated otherwise. 567 * indicated otherwise.
571 */ 568 */
572 if (exit_ob->map->templatemap && (resultname[0] != '/')) 569 if (exit_ob->map->templatemap && (resultname[0] != '/'))
573 {
574 new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); 570 new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname);
575 }
576 else 571 else
577 {
578 new_map_name = create_template_pathname (resultname); 572 new_map_name = create_template_pathname (resultname);
579 }
580 573
581 /* Attempt to load the map, if unable to, then 574 /* Attempt to load the map, if unable to, then
582 * create the map from the template. 575 * create the map from the template.
583 */ 576 */
584 new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); 577 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", 599 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); 600 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path);
608 } 601 }
609} 602}
610 603
611
612/* The player is trying to enter a randomly generated template map. In this 604/* The player is trying to enter a randomly generated template map. In this
613 * case, generate the map as needed. 605 * case, generate the map as needed.
614 */ 606 */
615 607
616static void 608static void
617enter_random_template_map (object *pl, object *exit_ob) 609enter_random_template_map (object *pl, object *exit_ob)
618{ 610{
619 mapstruct *new_map; 611 maptile *new_map;
620 char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF]; 612 char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF];
621 const char *new_map_name; 613 const char *new_map_name;
622 RMParms rp; 614 RMParms rp;
623 615
624 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord 616 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord
686 */ 678 */
687static void 679static void
688enter_unique_map (object *op, object *exit_ob) 680enter_unique_map (object *op, object *exit_ob)
689{ 681{
690 char apartment[HUGE_BUF]; 682 char apartment[HUGE_BUF];
691 mapstruct *newmap; 683 maptile *newmap;
692 684
693 if (EXIT_PATH (exit_ob)[0] == '/') 685 if (EXIT_PATH (exit_ob)[0] == '/')
694 { 686 {
695 sprintf (apartment, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, clean_path (EXIT_PATH (exit_ob))); 687 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); 688 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 */ 772#define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */
781 object *tmp; 773 object *tmp;
782 774
783 /* It may be nice to support other creatures moving across 775 /* It may be nice to support other creatures moving across
784 * exits, but right now a lot of the code looks at op->contr, 776 * exits, but right now a lot of the code looks at op->contr,
785 * so thta is an RFE. 777 * so that is an RFE.
786 */ 778 */
787 if (op->type != PLAYER) 779 if (op->type != PLAYER)
788 return; 780 return;
789 781
790 /* First, lets figure out what map the player is going to go to */ 782 /* First, lets figure out what map the player is going to go to */
791 if (exit_ob) 783 if (exit_ob)
792 { 784 {
793
794 /* check to see if we make a template map */ 785 /* check to see if we make a template map */
795 if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@') 786 if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@')
796 { 787 {
797 if (EXIT_PATH (exit_ob)[2] == '!') 788 if (EXIT_PATH (exit_ob)[2] == '!')
798 { 789 {
819 int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob); 810 int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob);
820 811
821 /* 'Normal' exits that do not do anything special 812 /* 'Normal' exits that do not do anything special
822 * Simple enough we don't need another routine for it. 813 * Simple enough we don't need another routine for it.
823 */ 814 */
824 mapstruct *newmap; 815 maptile *newmap;
825 816
826 if (exit_ob->map) 817 if (exit_ob->map)
827 { 818 {
828 newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0); 819 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 820 /* 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)) 888 if (tmp->type == FORCE && tmp->slaying && !strcmp (tmp->slaying, PORTAL_DESTINATION_NAME))
898 break; 889 break;
899 } 890 }
900 if (tmp) 891 if (tmp)
901 { 892 {
902 remove_ob (tmp); 893 tmp->remove ();
903 free_object (tmp); 894 tmp->destroy ();
904 } 895 }
905 896
906 strcpy (op->contr->savebed_map, path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob))); 897 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); 898 op->contr->bed_x = EXIT_X (exit_ob), op->contr->bed_y = EXIT_Y (exit_ob);
908 save_player (op, 1); 899 save_player (op, 1);
918 hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1); 909 hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1);
919 } 910 }
920 else 911 else
921 { 912 {
922 int flags = 0; 913 int flags = 0;
923 mapstruct *newmap; 914 maptile *newmap;
924
925 915
926 /* Hypothetically, I guess its possible that a standard map matches 916 /* Hypothetically, I guess its possible that a standard map matches
927 * the localdir, but that seems pretty unlikely - unlikely enough that 917 * the localdir, but that seems pretty unlikely - unlikely enough that
928 * I'm not going to attempt to try to deal with that possibility. 918 * 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 919 * We use the fact that when a player saves on a unique map, it prepends
950 { 940 {
951 LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n"); 941 LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n");
952 abort (); 942 abort ();
953 } 943 }
954 } 944 }
945
955 enter_map (op, newmap, op->x, op->y); 946 enter_map (op, newmap, op->x, op->y);
956 } 947 }
957} 948}
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 949
976/* process_players1 and process_players2 do all the player related stuff. 950/* 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 951 * 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 952 * 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 953 * by the various functions. process_players1() does the processing before
980 * objects have been updated, process_players2() does the processing that 954 * objects have been updated, process_players2() does the processing that
981 * is needed after the players have been updated. 955 * is needed after the players have been updated.
982 */ 956 */
983 957static void
984void 958process_players1 ()
985process_players1 (mapstruct *map)
986{ 959{
987 int flag; 960 int flag;
988 player *pl, *plnext;
989
990 /* Basically, we keep looping until all the players have done their actions. */ 961 /* Basically, we keep looping until all the players have done their actions. */
991 for (flag = 1; flag != 0;) 962 for (flag = 1; flag != 0;)
992 { 963 {
993 flag = 0; 964 flag = 0;
994 for (pl = first_player; pl != NULL; pl = plnext) 965 for (player *plnext, *pl = first_player; pl; pl = plnext)
995 { 966 {
996 plnext = pl->next; /* In case a player exits the game in handle_player() */ 967 plnext = pl->next; /* In case a player exits the game in handle_player() */
997 968
998 if (pl->ob == NULL) 969 if (!pl->ob)
999 continue;
1000
1001 if (map != NULL && pl->ob->map != map)
1002 continue; 970 continue;
1003 971
1004 if (pl->ob->speed_left > 0) 972 if (pl->ob->speed_left > 0)
1005 { 973 {
1006 if (handle_newcs_player (pl->ob)) 974 if (handle_newcs_player (pl->ob))
1020 /* check for ST_PLAYING state so that we don't try to save off when 988 /* check for ST_PLAYING state so that we don't try to save off when
1021 * the player is logging in. 989 * the player is logging in.
1022 */ 990 */
1023 if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->state == ST_PLAYING) 991 if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->state == ST_PLAYING)
1024 { 992 {
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); 993 save_player (pl->ob, 1);
1033 pl->last_save_tick = pticks; 994 pl->last_save_tick = pticks;
1034// }
1035 } 995 }
1036#endif 996#endif
1037 } /* end of for loop for all the players */ 997 } /* end of for loop for all the players */
1038 } /* for flag */ 998 } /* for flag */
999
1039 for (pl = first_player; pl != NULL; pl = pl->next) 1000 for (player *pl = first_player; pl; pl = pl->next)
1040 { 1001 {
1041 if (map != NULL && (pl->ob == NULL || pl->ob->map != map))
1042 continue;
1043 if (settings.casting_time == TRUE) 1002 if (settings.casting_time)
1044 { 1003 {
1045 if (pl->ob->casting_time > 0) 1004 if (pl->ob->casting_time > 0)
1046 { 1005 {
1047 pl->ob->casting_time--; 1006 pl->ob->casting_time--;
1048 pl->ob->start_holding = 1; 1007 pl->ob->start_holding = 1;
1049 } 1008 }
1009
1050 /* set spell_state so we can update the range in stats field */ 1010 /* set spell_state so we can update the range in stats field */
1051 if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1)) 1011 if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1))
1052 {
1053 pl->ob->start_holding = 0; 1012 pl->ob->start_holding = 0;
1054 } 1013 }
1055 } 1014
1056 do_some_living (pl->ob); 1015 do_some_living (pl->ob);
1057 /* draw(pl->ob); *//* updated in socket code */
1058 } 1016 }
1059} 1017}
1060 1018
1061void 1019static void
1062process_players2 (mapstruct *map) 1020process_players2 ()
1063{ 1021{
1064 player *pl;
1065
1066 /* Then check if any players should use weapon-speed instead of speed */ 1022 /* Then check if any players should use weapon-speed instead of speed */
1067 for (pl = first_player; pl != NULL; pl = pl->next) 1023 for (player *pl = first_player; pl; pl = pl->next)
1068 { 1024 {
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 - 1025 /* The code that did weapon_sp handling here was out of place -
1080 * this isn't called until after the player has finished there 1026 * 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 1027 * actions, and is thus out of place. All we do here is bounds
1082 * checking. 1028 * checking.
1083 */ 1029 */
1089 /* This needs to be here - if the player is running, we need to 1035 /* 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 1036 * clear this each tick, but new commands are not being received
1091 * so execute_newserver_command() is never called 1037 * so execute_newserver_command() is never called
1092 */ 1038 */
1093 pl->has_hit = 0; 1039 pl->has_hit = 0;
1094
1095 } 1040 }
1096 else if (pl->ob->speed_left > pl->ob->speed) 1041 else if (pl->ob->speed_left > pl->ob->speed)
1097 pl->ob->speed_left = pl->ob->speed; 1042 pl->ob->speed_left = pl->ob->speed;
1098 } 1043 }
1099} 1044}
1100 1045
1101void 1046void
1102process_events (mapstruct *map) 1047process_events ()
1103{ 1048{
1104 object *op; 1049 object *op;
1105 tag_t tag;
1106 1050
1107 static object *marker; 1051 static object *marker;
1108 1052
1109 if (!marker) 1053 if (!marker)
1110 marker = get_object (); 1054 marker = object::create ();
1111 1055
1112 process_players1 (map); 1056 process_players1 ();
1113 1057
1114 marker->active_next = active_objects; 1058 marker->active_next = active_objects;
1115 1059
1116 if (marker->active_next) 1060 if (marker->active_next)
1117 marker->active_next->active_prev = marker; 1061 marker->active_next->active_prev = marker;
1120 active_objects = marker; 1064 active_objects = marker;
1121 1065
1122 while (marker->active_next) 1066 while (marker->active_next)
1123 { 1067 {
1124 op = marker->active_next; 1068 op = marker->active_next;
1125 tag = op->count;
1126 1069
1127 /* Move marker forward - swap op and marker */ 1070 /* Move marker forward - swap op and marker */
1128 op->active_prev = marker->active_prev; 1071 op->active_prev = marker->active_prev;
1129 1072
1130 if (op->active_prev) 1073 if (op->active_prev)
1160 * around. 1103 * around.
1161 */ 1104 */
1162 if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY) 1105 if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY)
1163 { 1106 {
1164 LOG (llevError, "BUG: process_events(): Removed object on list\n"); 1107 LOG (llevError, "BUG: process_events(): Removed object on list\n");
1165 dump_object (op); 1108 char *dump = dump_object (op);
1166 LOG (llevError, errmsg); 1109 LOG (llevError, dump);
1167 free_object (op); 1110 free (dump);
1111 op->destroy ();
1168 continue; 1112 continue;
1169 } 1113 }
1170 1114
1171 if (!op->speed) 1115 if (!op->speed)
1172 { 1116 {
1173 LOG (llevError, "BUG: process_events(): Object %s has no speed, " "but is on active list\n", &op->arch->name); 1117 LOG (llevError, "BUG: process_events(): Object %s has no speed, "
1118 "but is on active list\n", &op->arch->name);
1174 update_ob_speed (op); 1119 update_ob_speed (op);
1175 continue; 1120 continue;
1176 } 1121 }
1177 1122
1178 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP && map == NULL) 1123 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP)
1179 { 1124 {
1180 LOG (llevError, "BUG: process_events(): Object without map or " "inventory is on active list: %s (%d)\n", &op->name, op->count); 1125 LOG (llevError, "BUG: process_events(): Object without map or "
1126 "inventory is on active list: %s (%d)\n", &op->name, op->count);
1181 op->speed = 0; 1127 op->speed = 0;
1182 update_ob_speed (op); 1128 update_ob_speed (op);
1183 continue; 1129 continue;
1184 } 1130 }
1185 1131
1186 if (map != NULL && op->map != map)
1187 continue;
1188
1189 /* Animate the object. Bug of feature that andim_speed 1132 /* Animate the object. Bug or feature that anim_speed
1190 * is based on ticks, and not the creatures speed? 1133 * is based on ticks, and not the creatures speed?
1191 */ 1134 */
1192 if (op->anim_speed && op->last_anim >= op->anim_speed) 1135 if (op->anim_speed && op->last_anim >= op->anim_speed)
1193 { 1136 {
1194 if ((op->type == PLAYER) || (op->type == MONSTER)) 1137 if ((op->type == PLAYER) || (op->type == MONSTER))
1217 LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null"); 1160 LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null");
1218 } 1161 }
1219#endif 1162#endif
1220 --op->speed_left; 1163 --op->speed_left;
1221 process_object (op); 1164 process_object (op);
1165
1222 if (was_destroyed (op, tag)) 1166 if (op->destroyed ())
1223 continue; 1167 continue;
1224 } 1168 }
1169
1225 if (settings.casting_time == TRUE && op->casting_time > 0) 1170 if (settings.casting_time == TRUE && op->casting_time > 0)
1226 op->casting_time--; 1171 op->casting_time--;
1172
1227 if (op->speed_left <= 0) 1173 if (op->speed_left <= 0)
1228 op->speed_left += FABS (op->speed); 1174 op->speed_left += FABS (op->speed);
1229 } 1175 }
1230 1176
1231 /* Remove marker object from active list */ 1177 /* Remove marker object from active list */
1232 if (marker->active_prev != NULL) 1178 if (marker->active_prev != NULL)
1233 marker->active_prev->active_next = NULL; 1179 marker->active_prev->active_next = NULL;
1234 else 1180 else
1235 active_objects = NULL; 1181 active_objects = NULL;
1236 1182
1237 process_players2 (map); 1183 process_players2 ();
1238} 1184}
1239 1185
1240void 1186void
1241clean_tmp_files (void) 1187clean_tmp_files (void)
1242{ 1188{
1243 mapstruct *m, *next; 1189 maptile *m, *next;
1244 1190
1245 LOG (llevInfo, "Cleaning up...\n"); 1191 LOG (llevInfo, "Cleaning up...\n");
1246 1192
1247 /* We save the maps - it may not be intuitive why, but if there are unique 1193 /* 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 1194 * 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. 1195 * just make a special function that only saves the unique items.
1250 */ 1196 */
1251 for (m = first_map; m != NULL; m = next) 1197 for (m = first_map; m; m = next)
1252 { 1198 {
1253 next = m->next; 1199 next = m->next;
1200
1254 if (m->in_memory == MAP_IN_MEMORY) 1201 if (m->in_memory == MAP_IN_MEMORY)
1255 { 1202 {
1256 /* If we want to reuse the temp maps, swap it out (note that will also 1203 /* 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 1204 * 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 */ 1205 */
1262 1206
1263 /* XXX The above comment is dead wrong */
1264 if (settings.recycle_tmp_maps == TRUE)
1265 swap_map (m); 1207 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 } 1208 }
1271 }
1272 } 1209 }
1210
1273 write_todclock (); /* lets just write the clock here */ 1211 write_todclock (); /* lets just write the clock here */
1274} 1212}
1275 1213
1276/* clean up everything before exiting */ 1214/* clean up everything before exiting */
1277void 1215void
1278cleanup (void) 1216cleanup (void)
1279{ 1217{
1280 LOG (llevDebug, "Cleanup called.\n"); 1218 LOG (llevDebug, "Cleanup called.\n");
1219
1220 for (player *pl = first_player; pl != NULL; pl = pl->next)
1221 save_player (pl->ob, 0);
1222
1223 for (player *pl = first_player; pl != NULL; pl = pl->next)
1224 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
1225 leave_map (pl->ob);
1226
1227 clean_tmp_files ();
1281 write_book_archive (); 1228 write_book_archive ();
1282 1229
1283 INVOKE_GLOBAL (CLEANUP); 1230 INVOKE_GLOBAL (CLEANUP);
1284 1231
1285 _exit (0); 1232 _exit (0);
1294 * cleanup. We also leave that loop to actually handle the freeing 1241 * cleanup. We also leave that loop to actually handle the freeing
1295 * of the data. 1242 * of the data.
1296 */ 1243 */
1297 if (pl->ob->type != DEAD_OBJECT) 1244 if (pl->ob->type != DEAD_OBJECT)
1298 { 1245 {
1299 pl->socket.status = Ns_Dead; 1246 pl->socket->status = Ns_Dead;
1300 1247
1301 /* If a hidden dm dropped connection do not create 1248 /* If a hidden dm dropped connection do not create
1302 * inconsistencies by showing that they have left the game 1249 * inconsistencies by showing that they have left the game
1303 */ 1250 */
1304 if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden) 1251 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)) 1252 && draw_exit && (pl->state != ST_GET_NAME && pl->state != ST_GET_PASSWORD && pl->state != ST_CONFIRM_PASSWORD))
1306 { 1253 {
1307 if (pl->ob->map) 1254 if (pl->ob->map)
1308 { 1255 {
1309 INVOKE_PLAYER (LOGOUT, pl); 1256 INVOKE_PLAYER (LOGOUT, pl);
1310 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->socket.host); 1257 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->socket->host);
1311 } 1258 }
1312 1259
1313 char buf[MAX_BUF]; 1260 char buf[MAX_BUF];
1314 1261
1315 sprintf (buf, "%s left the game.", &pl->ob->name); 1262 sprintf (buf, "%s left the game.", &pl->ob->name);
1391extern unsigned long todtick; 1338extern unsigned long todtick;
1392 1339
1393void 1340void
1394do_specials (void) 1341do_specials (void)
1395{ 1342{
1396
1397#ifdef WATCHDOG
1398 if (!(pticks % 503))
1399 watchdog ();
1400#endif
1401
1402 if (!(pticks % PTICKS_PER_CLOCK)) 1343 if (!(pticks % PTICKS_PER_CLOCK))
1403 tick_the_clock (); 1344 tick_the_clock ();
1404 1345
1405 if (!(pticks % 7)) 1346 if (!(pticks % 7))
1406 shstr::gc (); 1347 shstr::gc ();
1409 flush_old_maps (); /* Clears the tmp-files of maps which have reset */ 1350 flush_old_maps (); /* Clears the tmp-files of maps which have reset */
1410 1351
1411 if (!(pticks % 2503)) 1352 if (!(pticks % 2503))
1412 fix_weight (); /* Hack to fix weightproblems caused by bugs */ 1353 fix_weight (); /* Hack to fix weightproblems caused by bugs */
1413 1354
1414 if (!(pticks % 2521))
1415 metaserver_update (); /* 2500 ticks is about 5 minutes */
1416
1417 if (!(pticks % 5003)) 1355 if (!(pticks % 5003))
1418 write_book_archive (); 1356 write_book_archive ();
1419 1357
1420 if (!(pticks % 5009)) 1358 if (!(pticks % 5009))
1421 clean_friendly_list (); 1359 clean_friendly_list ();
1430void 1368void
1431server_tick () 1369server_tick ()
1432{ 1370{
1433 nroferrors = 0; 1371 nroferrors = 0;
1434 1372
1373 // first do the user visible stuff
1435 doeric_server (); 1374 doeric_server ();
1436 INVOKE_GLOBAL (CLOCK); 1375 INVOKE_GLOBAL (CLOCK);
1437 process_events (NULL); /* "do" something with objects with speed */ 1376 process_events (); /* "do" something with objects with speed */
1438 flush_sockets (); 1377 flush_sockets ();
1378
1379 // then do some bookkeeping, should not really be here
1439 check_active_maps (); /* Removes unused maps after a certain timeout */ 1380 check_active_maps (); /* Removes unused maps after a certain timeout */
1440 do_specials (); /* Routines called from time to time. */ 1381 do_specials (); /* Routines called from time to time. */
1441 object::free_mortals (); 1382 object::free_mortals ();
1442 1383
1443 ++pticks; 1384 ++pticks;
1447main (int argc, char **argv) 1388main (int argc, char **argv)
1448{ 1389{
1449 settings.argc = argc; 1390 settings.argc = argc;
1450 settings.argv = argv; 1391 settings.argv = argv;
1451 1392
1452 cfperl_init ();
1453
1454 init (argc, argv); 1393 init (argc, argv);
1455 1394
1456 initPlugins (); 1395 initPlugins ();
1457 1396
1458 for (;;) 1397 for (;;)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines