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.75 by root, Tue Jan 2 19:47:59 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)))
226 } 227 }
227 else 228 else
228 { 229 {
229 for (object *tmp = contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more) 230 for (object *tmp = contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more)
230 { 231 {
231 tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); 232 tmp->x = x + freearr_x[i] + (tmp->arch ? 0 : tmp->arch->clone.x);
232 tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); 233 tmp->y = y + freearr_y[i] + (tmp->arch ? 0 : tmp->arch->clone.y);
233 tmp->map = newmap; 234 tmp->map = newmap;
234 } 235 }
235 236
236 insert_ob_in_map (contr->ranges[range_golem], newmap, NULL, 0); 237 insert_ob_in_map (contr->ranges[range_golem], newmap, NULL, 0);
237 contr->ranges[range_golem]->direction = 238 contr->ranges[range_golem]->direction =
238 find_dir_2 (x - contr->ranges[range_golem]->x, y - contr->ranges[range_golem]->y); 239 find_dir_2 (x - contr->ranges[range_golem]->x, y - contr->ranges[range_golem]->y);
239 } 240 }
240 } 241 }
241
242 direction = 0;
243 242
244 /* since the players map is already loaded, we don't need to worry 243 /* since the players map is already loaded, we don't need to worry
245 * about pending objects. 244 * about pending objects.
246 */ 245 */
247 remove_all_pets (newmap); 246 remove_all_pets (newmap);
491{ 490{
492 LOG (llevDebug, "emergency save begin.\n"); 491 LOG (llevDebug, "emergency save begin.\n");
493 492
494 LOG (llevDebug, "saving players.\n"); 493 LOG (llevDebug, "saving players.\n");
495 for_all_players (pl) 494 for_all_players (pl)
496 if (pl->enable_save) 495 if (pl->enable_save && pl->ob && pl->ns)
497 { 496 {
498 pl->save (true); 497 pl->save (true);
499 pl->enable_save = true; 498 pl->enable_save = true;
500 } 499 }
501 500
510 write_book_archive (); 509 write_book_archive ();
511 510
512 LOG (llevDebug, "emergency save done.\n"); 511 LOG (llevDebug, "emergency save done.\n");
513} 512}
514 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
515/* clean up everything before exiting */ 531/* clean up everything before exiting */
516void 532void
517cleanup (bool make_core) 533cleanup (const char *cause, bool make_core)
518{ 534{
535 LOG (llevError, "cleanup cause: %s\n", cause);
536
537 if (!make_core)
538 cleanup_inform (cause, make_core);
539
519 LOG (llevDebug, "cleanup begin.\n"); 540 LOG (llevDebug, "cleanup begin.\n");
520 541
521 if (init_done && !in_cleanup) 542 if (init_done && !in_cleanup)
522 { 543 {
523 in_cleanup = true; 544 in_cleanup = true;
530 INVOKE_GLOBAL (CLEANUP); 551 INVOKE_GLOBAL (CLEANUP);
531 552
532 LOG (llevDebug, "cleanup done.\n"); 553 LOG (llevDebug, "cleanup done.\n");
533 554
534 if (make_core) 555 if (make_core)
556 {
557 cleanup_inform (cause, make_core);
535 abort (); 558 abort ();
559 }
536 else 560 else
537 _exit (0); 561 _exit (0);
538} 562}
539 563
540int 564int
654 678
655 initPlugins (); 679 initPlugins ();
656 680
657 for (;;) 681 for (;;)
658 cfperl_main (); 682 cfperl_main ();
659
660 cleanup (true);
661} 683}
662 684

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines