… | |
… | |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <object.h> |
26 | #include <object.h> |
27 | #include <tod.h> |
27 | #include <tod.h> |
28 | |
|
|
29 | #ifdef HAVE_DES_H |
|
|
30 | # include <des.h> |
|
|
31 | #else |
|
|
32 | # ifdef HAVE_CRYPT_H |
|
|
33 | # include <crypt.h> |
|
|
34 | # endif |
|
|
35 | #endif |
|
|
36 | |
28 | |
37 | #include <sproto.h> |
29 | #include <sproto.h> |
38 | #include <time.h> |
30 | #include <time.h> |
39 | |
31 | |
40 | #include <../random_maps/random_map.h> |
32 | #include <../random_maps/random_map.h> |
… | |
… | |
213 | } |
205 | } |
214 | |
206 | |
215 | /* Update any golems */ |
207 | /* Update any golems */ |
216 | if (type == PLAYER && contr->ranges[range_golem]) |
208 | if (type == PLAYER && contr->ranges[range_golem]) |
217 | { |
209 | { |
218 | int i = find_free_spot (contr->ranges[range_golem], newmap, |
210 | int i = find_free_spot (contr->ranges[range_golem], newmap, x, y, 1, SIZEOFFREE); |
219 | x, y, 1, SIZEOFFREE); |
|
|
220 | |
211 | |
221 | if (i == -1) |
212 | if (i < 0) |
222 | { |
213 | { |
223 | contr->ranges[range_golem]->destroy (); |
214 | contr->ranges[range_golem]->destroy (); |
224 | contr->ranges[range_golem] = 0; |
215 | contr->ranges[range_golem] = 0; |
225 | } |
216 | } |
226 | else |
217 | else |
227 | { |
218 | { |
228 | for (object *tmp = contr->ranges[range_golem]; tmp; tmp = tmp->more) |
219 | newmap->insert (contr->ranges[range_golem], x + freearr_x[i], y + freearr_y[i]); |
229 | { |
|
|
230 | tmp->x = x + freearr_x[i] + (tmp->arch ? 0 : tmp->arch->clone.x); |
|
|
231 | tmp->y = y + freearr_y[i] + (tmp->arch ? 0 : tmp->arch->clone.y); |
|
|
232 | tmp->map = newmap; |
|
|
233 | } |
|
|
234 | |
220 | |
235 | insert_ob_in_map (contr->ranges[range_golem], newmap, NULL, 0); |
|
|
236 | contr->ranges[range_golem]->direction = |
221 | contr->ranges[range_golem]->direction = |
237 | find_dir_2 (x - contr->ranges[range_golem]->x, y - contr->ranges[range_golem]->y); |
222 | find_dir_2 (x - contr->ranges[range_golem]->x, y - contr->ranges[range_golem]->y); |
238 | } |
223 | } |
239 | } |
224 | } |
240 | |
225 | |
… | |
… | |
449 | cleanup_inform (const char *cause, bool make_core) |
434 | cleanup_inform (const char *cause, bool make_core) |
450 | { |
435 | { |
451 | int flags = NDI_UNIQUE | NDI_ALL | (make_core ? NDI_RED : NDI_GREEN); |
436 | int flags = NDI_UNIQUE | NDI_ALL | (make_core ? NDI_RED : NDI_GREEN); |
452 | |
437 | |
453 | new_draw_info_format (flags, 0, 0, "The server will now shutdown.\n"); |
438 | new_draw_info_format (flags, 0, 0, "The server will now shutdown.\n"); |
454 | new_draw_info_format (flags, 0, 0, "Cause for this shtudown: %s\n", cause); |
439 | new_draw_info_format (flags, 0, 0, "Cause for this shutdown: %s\n", cause); |
455 | |
440 | |
456 | if (make_core) |
441 | if (make_core) |
457 | new_draw_info_format (flags, 0, 0, "This is considered a crash.\n"); |
442 | new_draw_info_format (flags, 0, 0, "This is considered a crash, but all maps and players have been saved.\n"); |
458 | else |
443 | else |
459 | new_draw_info_format (flags, 0, 0, "This is considered to be a clean shutdown.\n"); |
444 | new_draw_info_format (flags, 0, 0, "This is considered to be a clean shutdown, and all maps and players have been saved.\n"); |
460 | |
445 | |
461 | new_draw_info_format (flags, 0, 0, "%s\n", CLEANUP_MESSAGE); |
446 | new_draw_info_format (flags, 0, 0, "%s\n", CLEANUP_MESSAGE); |
462 | |
447 | |
463 | flush_sockets (); |
448 | flush_sockets (); |
464 | } |
449 | } |
… | |
… | |
466 | /* clean up everything before exiting */ |
451 | /* clean up everything before exiting */ |
467 | void |
452 | void |
468 | cleanup (const char *cause, bool make_core) |
453 | cleanup (const char *cause, bool make_core) |
469 | { |
454 | { |
470 | if (make_core) |
455 | if (make_core) |
471 | if (!fork ()) |
456 | fork_abort (cause); |
472 | abort (); |
|
|
473 | |
457 | |
474 | LOG (llevError, "cleanup cause: %s\n", cause); |
458 | LOG (llevError, "cleanup cause: %s\n", cause); |
475 | |
459 | |
476 | if (!make_core) |
460 | if (!make_core) |
477 | cleanup_inform (cause, make_core); |
461 | cleanup_inform (cause, make_core); |
… | |
… | |
605 | attachable::check_mortals (); |
589 | attachable::check_mortals (); |
606 | |
590 | |
607 | ++pticks; |
591 | ++pticks; |
608 | } |
592 | } |
609 | |
593 | |
|
|
594 | #if 0 |
|
|
595 | // used fro benchmarking (x86/amd64-specific) |
|
|
596 | typedef unsigned long tval; |
|
|
597 | typedef unsigned long long stamp64; |
|
|
598 | |
|
|
599 | extern inline tval |
|
|
600 | stamp (void) |
|
|
601 | { |
|
|
602 | tval tsc; |
|
|
603 | asm volatile ("rdtsc":"=a" (tsc)::"edx"); |
|
|
604 | |
|
|
605 | return tsc; |
|
|
606 | } |
|
|
607 | |
|
|
608 | extern inline tval |
|
|
609 | measure (tval t) |
|
|
610 | { |
|
|
611 | tval tsc; |
|
|
612 | asm volatile ("rdtsc":"=a" (tsc)::"edx"); |
|
|
613 | |
|
|
614 | if (tsc > t) |
|
|
615 | return tsc - t; |
|
|
616 | else |
|
|
617 | return t - tsc; |
|
|
618 | } |
|
|
619 | |
610 | int |
620 | int |
611 | main (int argc, char **argv) |
621 | main (int argc, char **argv) |
612 | { |
622 | { |
|
|
623 | rand_gen rg(0); |
|
|
624 | tval fastest = 0x7fffffff; |
|
|
625 | for (int loop = 10000; loop--; ) |
|
|
626 | { |
|
|
627 | tval s = stamp (); |
|
|
628 | volatile int i = rg.get_int(25); |
|
|
629 | fastest = min (fastest, measure (s)); |
|
|
630 | } |
|
|
631 | |
|
|
632 | //printf ("fastest %d\n", fastest); |
|
|
633 | for (int i = 0; i < 1024*1024*3; ++i) |
|
|
634 | { |
|
|
635 | char c = rg.get_int (256); |
|
|
636 | write (2, &c, 1); |
|
|
637 | } |
|
|
638 | } |
|
|
639 | |
|
|
640 | #else |
|
|
641 | |
|
|
642 | // normal main |
|
|
643 | int |
|
|
644 | main (int argc, char **argv) |
|
|
645 | { |
613 | settings.argc = argc; |
646 | settings.argc = argc; |
614 | settings.argv = argv; |
647 | settings.argv = argv; |
615 | |
648 | |
616 | init (argc, argv); |
649 | init (argc, argv); |
617 | |
650 | |
618 | initPlugins (); |
651 | initPlugins (); |
619 | |
652 | |
620 | for (;;) |
653 | for (;;) |
621 | cfperl_main (); |
654 | cfperl_main (); |
622 | } |
655 | } |
|
|
656 | #endif |
623 | |
657 | |