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.85 by root, Mon Jan 15 02:39:41 2007 UTC vs.
Revision 1.92 by root, Tue Mar 6 03:06:00 2007 UTC

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
265 pl->refcnt_chk (); 250 pl->refcnt_chk ();
266 251
267 if (!pl->ob || !pl->ns || !pl->ob->active) 252 if (!pl->ob || !pl->ns || !pl->ob->active)
268 continue; 253 continue;
269 254
270 if (pl->ob->speed_left > 0) 255 if (pl->ob->speed_left > 0 && pl->ns)
271 if (handle_newcs_player (pl->ob)) 256 if (handle_newcs_player (pl->ob))
272 flag = 1; 257 flag = 1;
273 258
274 /* If the player is not actively playing, don't make a 259 /* If the player is not actively playing, don't make a
275 * backup save - nothing to save anyway. Plus, the 260 * backup save - nothing to save anyway. Plus, the
385 /* Animate the object. Bug or feature that anim_speed 370 /* Animate the object. Bug or feature that anim_speed
386 * is based on ticks, and not the creatures speed? 371 * is based on ticks, and not the creatures speed?
387 */ 372 */
388 if (op->anim_speed && op->last_anim >= op->anim_speed) 373 if (op->anim_speed && op->last_anim >= op->anim_speed)
389 { 374 {
390 if ((op->type == PLAYER)) 375 animate_object (op, op->type == PLAYER ? op->facing : op->direction);
391 animate_object (op, op->facing);
392 else
393 animate_object (op, op->direction);
394 376
395 op->last_anim = 1; 377 op->last_anim = 1;
396 } 378 }
397 else 379 else
398 op->last_anim++; 380 op->last_anim++;
449cleanup_inform (const char *cause, bool make_core) 431cleanup_inform (const char *cause, bool make_core)
450{ 432{
451 int flags = NDI_UNIQUE | NDI_ALL | (make_core ? NDI_RED : NDI_GREEN); 433 int flags = NDI_UNIQUE | NDI_ALL | (make_core ? NDI_RED : NDI_GREEN);
452 434
453 new_draw_info_format (flags, 0, 0, "The server will now shutdown.\n"); 435 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); 436 new_draw_info_format (flags, 0, 0, "Cause for this shutdown: %s\n", cause);
455 437
456 if (make_core) 438 if (make_core)
457 new_draw_info_format (flags, 0, 0, "This is considered a crash.\n"); 439 new_draw_info_format (flags, 0, 0, "This is considered a crash, but all maps and players have been saved.\n");
458 else 440 else
459 new_draw_info_format (flags, 0, 0, "This is considered to be a clean shutdown.\n"); 441 new_draw_info_format (flags, 0, 0, "This is considered to be a clean shutdown, and all maps and players will be saved now.\n");
460 442
461 new_draw_info_format (flags, 0, 0, "%s\n", CLEANUP_MESSAGE); 443 new_draw_info_format (flags, 0, 0, "%s\n", CLEANUP_MESSAGE);
462 444
463 flush_sockets (); 445 flush_sockets ();
464} 446}
491 LOG (llevDebug, "cleanup done.\n"); 473 LOG (llevDebug, "cleanup done.\n");
492 474
493 if (make_core) 475 if (make_core)
494 { 476 {
495 cleanup_inform (cause, make_core); 477 cleanup_inform (cause, make_core);
478 cfperl_cleanup (make_core);
496 _exit (1); 479 _exit (1);
497 } 480 }
498 else 481 else
482 {
483 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_GREEN, 0, 0, "Maps and players successfully saved, exiting.\n");
484 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_GREEN, 0, 0, "And again: " CLEANUP_MESSAGE "\n");
485 flush_sockets ();
486 cfperl_cleanup (make_core);
499 _exit (0); 487 _exit (0);
488 }
500} 489}
501 490
502int 491int
503forbid_play (void) 492forbid_play (void)
504{ 493{
604 attachable::check_mortals (); 593 attachable::check_mortals ();
605 594
606 ++pticks; 595 ++pticks;
607} 596}
608 597
598#if 0
599// used fro benchmarking (x86/amd64-specific)
600typedef unsigned long tval;
601typedef unsigned long long stamp64;
602
603extern inline tval
604stamp (void)
605{
606 tval tsc;
607 asm volatile ("rdtsc":"=a" (tsc)::"edx");
608
609 return tsc;
610}
611
612extern inline tval
613measure (tval t)
614{
615 tval tsc;
616 asm volatile ("rdtsc":"=a" (tsc)::"edx");
617
618 if (tsc > t)
619 return tsc - t;
620 else
621 return t - tsc;
622}
623
609int 624int
610main (int argc, char **argv) 625main (int argc, char **argv)
611{ 626{
627 rand_gen rg(0);
628 tval fastest = 0x7fffffff;
629 for (int loop = 10000; loop--; )
630 {
631 tval s = stamp ();
632 volatile int i = rg.get_int(25);
633 fastest = min (fastest, measure (s));
634 }
635
636 //printf ("fastest %d\n", fastest);
637 for (int i = 0; i < 1024*1024*3; ++i)
638 {
639 char c = rg.get_int (256);
640 write (2, &c, 1);
641 }
642}
643
644#else
645
646// normal main
647int
648main (int argc, char **argv)
649{
612 settings.argc = argc; 650 settings.argc = argc;
613 settings.argv = argv; 651 settings.argv = argv;
614 652
615 init (argc, argv); 653 init (argc, argv);
654 init_environ ();
616 655
617 initPlugins (); 656 initPlugins ();
618 657
619 for (;;) 658 for (;;)
620 cfperl_main (); 659 cfperl_main ();
621} 660}
661#endif
622 662

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines