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.76 by root, Wed Jan 3 20:08:04 2007 UTC vs.
Revision 1.80 by pippijn, Sat Jan 6 14:42:30 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
3 3
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team 5 Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 Copyright (C) 1992 Frank Tore Johansen
6 7
7 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
147 new_draw_info (NDI_UNIQUE, 0, this, "The exit is closed"); 148 new_draw_info (NDI_UNIQUE, 0, this, "The exit is closed");
148 return; 149 return;
149 } 150 }
150 } 151 }
151 152
152 if (map && map != newmap) 153 if (contr && map != newmap && map)
153 if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr))) 154 if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr)))
154 return; 155 return;
155 156
156 /* If it is a player login, he has yet to be inserted anyplace. 157 /* If it is a player login, he has yet to be inserted anyplace.
157 * otherwise, we need to deal with removing the player here. 158 * otherwise, we need to deal with removing the player here.
185 else 186 else
186 /* not much we can do in this case. */ 187 /* not much we can do in this case. */
187 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); 188 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);
188 } 189 }
189 190
190 if (map != newmap && contr) 191 if (contr && map != newmap)
191 { 192 {
192 if (INVOKE_PLAYER (MAP_CHANGE, contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y))) 193 if (INVOKE_PLAYER (MAP_CHANGE, contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y)))
193 return; 194 return;
194 195
195 if (INVOKE_MAP (ENTER, newmap, ARG_PLAYER (contr), ARG_INT (x), ARG_INT (y))) 196 if (INVOKE_MAP (ENTER, newmap, ARG_PLAYER (contr), ARG_INT (x), ARG_INT (y)))
489{ 490{
490 LOG (llevDebug, "emergency save begin.\n"); 491 LOG (llevDebug, "emergency save begin.\n");
491 492
492 LOG (llevDebug, "saving players.\n"); 493 LOG (llevDebug, "saving players.\n");
493 for_all_players (pl) 494 for_all_players (pl)
494 if (pl->enable_save) 495 if (pl->enable_save && pl->ob && pl->ns)
495 { 496 {
496 pl->save (true); 497 pl->save (true);
497 pl->enable_save = true; 498 pl->enable_save = true;
498 } 499 }
499 500
508 write_book_archive (); 509 write_book_archive ();
509 510
510 LOG (llevDebug, "emergency save done.\n"); 511 LOG (llevDebug, "emergency save done.\n");
511} 512}
512 513
514// send all clients some informational text
515static void
516cleanup_inform (const char *cause, bool make_core)
517{
518 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 0, 0, "The server will now shutdown.\n");
519 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 0, 0, "Cause for this shtudown: %s\n", cause);
520
521 if (make_core)
522 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 0, 0, "This is considered a crash.\n");
523 else
524 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 0, 0, "This is considered to be a clean shutdown.\n");
525
526 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 0, 0, "%s\n", CLEANUP_MESSAGE);
527
528 flush_sockets ();
529}
530
513/* clean up everything before exiting */ 531/* clean up everything before exiting */
514void 532void
515cleanup (bool make_core) 533cleanup (const char *cause, bool make_core)
516{ 534{
535 LOG (llevError, "cleanup cause: %s\n", cause);
536
537 if (!make_core)
538 cleanup_inform (cause, make_core);
539
517 LOG (llevDebug, "cleanup begin.\n"); 540 LOG (llevDebug, "cleanup begin.\n");
518 541
519 if (init_done && !in_cleanup) 542 if (init_done && !in_cleanup)
520 { 543 {
521 in_cleanup = true; 544 in_cleanup = true;
528 INVOKE_GLOBAL (CLEANUP); 551 INVOKE_GLOBAL (CLEANUP);
529 552
530 LOG (llevDebug, "cleanup done.\n"); 553 LOG (llevDebug, "cleanup done.\n");
531 554
532 if (make_core) 555 if (make_core)
556 {
557 cleanup_inform (cause, make_core);
533 abort (); 558 abort ();
559 }
534 else 560 else
535 _exit (0); 561 _exit (0);
536} 562}
537 563
538int 564int
652 678
653 initPlugins (); 679 initPlugins ();
654 680
655 for (;;) 681 for (;;)
656 cfperl_main (); 682 cfperl_main ();
657
658 cleanup (true);
659} 683}
660 684

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines