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.71 by root, Mon Jan 1 15:32:40 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
130 * the function that calls this should figure them out. 131 * the function that calls this should figure them out.
131 */ 132 */
132void 133void
133object::enter_map (maptile *newmap, int x, int y) 134object::enter_map (maptile *newmap, int x, int y)
134{ 135{
135 if (destroyed () || !newmap) 136 if (destroyed () || !newmap || newmap->in_memory != MAP_IN_MEMORY)
136 return; 137 return;
137 138
138 if (out_of_map (newmap, x, y)) 139 if (out_of_map (newmap, x, y))
139 { 140 {
140 LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", &newmap->path, x, y); 141 LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", &newmap->path, x, y);
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)
495 if (pl->enable_save && pl->ob && pl->ns)
496 {
496 pl->save (1); 497 pl->save (true);
498 pl->enable_save = true;
499 }
497 500
498// for_all_players (pl) 501// for_all_players (pl)
499// if (pl->ob) 502// if (pl->ob)
500// pl->ob->remove (); 503// pl->ob->remove ();
501 504
506 write_book_archive (); 509 write_book_archive ();
507 510
508 LOG (llevDebug, "emergency save done.\n"); 511 LOG (llevDebug, "emergency save done.\n");
509} 512}
510 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
511/* clean up everything before exiting */ 531/* clean up everything before exiting */
512void 532void
513cleanup (bool make_core) 533cleanup (const char *cause, bool make_core)
514{ 534{
535 LOG (llevError, "cleanup cause: %s\n", cause);
536
537 if (!make_core)
538 cleanup_inform (cause, make_core);
539
515 LOG (llevDebug, "cleanup begin.\n"); 540 LOG (llevDebug, "cleanup begin.\n");
516 541
517 if (init_done && !in_cleanup) 542 if (init_done && !in_cleanup)
518 { 543 {
519 in_cleanup = true; 544 in_cleanup = true;
526 INVOKE_GLOBAL (CLEANUP); 551 INVOKE_GLOBAL (CLEANUP);
527 552
528 LOG (llevDebug, "cleanup done.\n"); 553 LOG (llevDebug, "cleanup done.\n");
529 554
530 if (make_core) 555 if (make_core)
556 {
557 cleanup_inform (cause, make_core);
531 abort (); 558 abort ();
559 }
532 else 560 else
533 _exit (0); 561 _exit (0);
534}
535
536void
537leave (player *pl, int draw_exit)
538{
539 if (pl)
540 {
541 if (pl->ob->type != DEAD_OBJECT)
542 {
543 /* If a hidden dm dropped connection do not create
544 * inconsistencies by showing that they have left the game
545 */
546 if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden)
547 && draw_exit)
548 {
549 if (pl->ob->map)
550 {
551 INVOKE_PLAYER (LOGOUT, pl);
552 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->ns->host);
553 }
554
555 char buf[MAX_BUF];
556
557 sprintf (buf, "%s left the game.", &pl->ob->name);
558 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, 0, buf);
559 }
560
561 pl->ob->remove ();
562 pl->ob->type = DEAD_OBJECT; /* To avoid problems with inventory window */
563 }
564
565 /* We do this so that the socket handling routine can do the final
566 * cleanup. We also leave that loop to actually handle the freeing
567 * of the data.
568 */
569 if (pl->ns)
570 pl->ns->destroy ();
571
572 }
573} 562}
574 563
575int 564int
576forbid_play (void) 565forbid_play (void)
577{ 566{
591 580
592 while (fgets (buf, MAX_BUF, fp)) 581 while (fgets (buf, MAX_BUF, fp))
593 { 582 {
594 if (buf[0] == '#') 583 if (buf[0] == '#')
595 continue; 584 continue;
585
596 if (!strncmp (buf, "msg", 3)) 586 if (!strncmp (buf, "msg", 3))
597 { 587 {
598 if (forbit) 588 if (forbit)
599 while (fgets (buf, MAX_BUF, fp)) /* print message */ 589 while (fgets (buf, MAX_BUF, fp)) /* print message */
600 fputs (buf, logfile); 590 fputs (buf, logfile);
601 break; 591 break;
602
603 } 592 }
604 else if (sscanf (buf, "%s %d%*c%d\n", day, &start, &stop) != 3) 593 else if (sscanf (buf, "%s %d%*c%d\n", day, &start, &stop) != 3)
605 { 594 {
606 LOG (llevDebug, "Warning: Incomplete line in permission file ignored.\n"); 595 LOG (llevDebug, "Warning: Incomplete line in permission file ignored.\n");
607 continue; 596 continue;
621 return 0; 610 return 0;
622#endif 611#endif
623} 612}
624 613
625/* 614/*
626 * do_specials() is a collection of functions to call from time to time. 615 * do_specials() is a collection of functions to call from time to time.
627 * Modified 2000-1-14 MSW to use the global pticks count to determine how 616 * Modified 2000-1-14 MSW to use the global pticks count to determine how
628 * often to do things. This will allow us to spred them out more often. 617 * often to do things. This will allow us to spred them out more often.
629 * I use prime numbers for the factor count - in that way, it is less likely 618 * I use prime numbers for the factor count - in that way, it is less likely
630 * these actions will fall on the same tick (compared to say using 500/2500/15000 619 * these actions will fall on the same tick (compared to say using 500/2500/15000
631 * which would mean on that 15,000 tick count a whole bunch of stuff gets 620 * which would mean on that 15,000 tick count a whole bunch of stuff gets
689 678
690 initPlugins (); 679 initPlugins ();
691 680
692 for (;;) 681 for (;;)
693 cfperl_main (); 682 cfperl_main ();
694
695 cleanup (true);
696} 683}
697 684

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines