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.34 by root, Sat Sep 30 23:48:57 2006 UTC vs.
Revision 1.59 by root, Tue Dec 26 08:55:00 2006 UTC

31# ifdef HAVE_CRYPT_H 31# ifdef HAVE_CRYPT_H
32# include <crypt.h> 32# include <crypt.h>
33# endif 33# endif
34#endif 34#endif
35 35
36#ifndef __CEXTRACT__
37# include <sproto.h> 36#include <sproto.h>
38#endif
39
40#ifdef HAVE_TIME_H
41# include <time.h> 37#include <time.h>
42#endif
43 38
44#include <../random_maps/random_map.h> 39#include <../random_maps/random_map.h>
45#include <../random_maps/rproto.h> 40#include <../random_maps/rproto.h>
46#include "path.h" 41#include "path.h"
47 42
138void 133void
139start_info (object *op) 134start_info (object *op)
140{ 135{
141 char buf[MAX_BUF]; 136 char buf[MAX_BUF];
142 137
143 sprintf (buf, "Welcome to Crossfire, v%s!", VERSION); 138 sprintf (buf, "Welcome to Crossfire v%s!", VERSION);
144 new_draw_info (NDI_UNIQUE, 0, op, buf); 139 new_draw_info (NDI_UNIQUE, 0, op, buf);
145 new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help"); 140 new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help");
146 new_draw_info (NDI_UNIQUE, 0, op, " "); 141 new_draw_info (NDI_UNIQUE, 0, op, " ");
147 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, op, "%s entered the game.", &op->name); 142 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, op, "%s entered the game.", &op->name);
148 if (!op->contr->name_changed)
149 {
150 new_draw_info (NDI_UNIQUE, 0, op, "Note that you must set your name with the name");
151 new_draw_info (NDI_UNIQUE, 0, op, "command to enter the highscore list.");
152 new_draw_info (NDI_UNIQUE, 0, op, "(You can also use the crossfire.name X-resource.)");
153 }
154}
155
156/* Really, there is no reason to crypt the passwords any system. But easier
157 * to just leave this enabled for backward compatibility. Put the
158 * simple case at top - no encryption - makes it easier to read.
159 */
160char *
161crypt_string (char *str, char *salt)
162{
163#if defined(WIN32) || (defined(__FreeBSD__) && !defined(HAVE_LIBDES))
164 return (str);
165#else
166 static char *c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
167 char s[2];
168
169 if (salt == NULL)
170 s[0] = c[RANDOM () % (int) strlen (c)], s[1] = c[RANDOM () % (int) strlen (c)];
171 else
172 s[0] = salt[0], s[1] = salt[1];
173
174# ifdef HAVE_LIBDES
175 return (char *) des_crypt (str, s);
176# endif
177 /* Default case - just use crypt */
178 return (char *) crypt (str, s);
179#endif
180}
181
182int
183check_password (char *typed, char *crypted)
184{
185 return !strcmp (crypt_string (typed, crypted), crypted);
186} 143}
187 144
188/* This is a basic little function to put the player back to his 145/* This is a basic little function to put the player back to his
189 * savebed. We do some error checking - its possible that the 146 * savebed. We do some error checking - its possible that the
190 * savebed map may no longer exist, so we make sure the player 147 * savebed map may no longer exist, so we make sure the player
194enter_player_savebed (object *op) 151enter_player_savebed (object *op)
195{ 152{
196 maptile *oldmap = op->map; 153 maptile *oldmap = op->map;
197 object *tmp; 154 object *tmp;
198 155
199 tmp = get_object (); 156 tmp = object::create ();
200 157
201 EXIT_PATH (tmp) = op->contr->savebed_map; 158 EXIT_PATH (tmp) = op->contr->savebed_map;
202 EXIT_X (tmp) = op->contr->bed_x; 159 EXIT_X (tmp) = op->contr->bed_x;
203 EXIT_Y (tmp) = op->contr->bed_y; 160 EXIT_Y (tmp) = op->contr->bed_y;
204 enter_exit (op, tmp); 161 enter_exit (op, tmp);
217 EXIT_PATH (tmp) = op->contr->savebed_map; 174 EXIT_PATH (tmp) = op->contr->savebed_map;
218 EXIT_X (tmp) = op->contr->bed_x; 175 EXIT_X (tmp) = op->contr->bed_x;
219 EXIT_Y (tmp) = op->contr->bed_y; 176 EXIT_Y (tmp) = op->contr->bed_y;
220 enter_exit (op, tmp); 177 enter_exit (op, tmp);
221 } 178 }
222 free_object (tmp); 179
180 tmp->destroy ();
223} 181}
224 182
225/* All this really is is a glorified remove_object that also updates 183/* All this really is is a glorified remove_object that also updates
226 * the counts on the map if needed. 184 * the counts on the map if needed.
227 */ 185 */
228void 186void
229leave_map (object *op) 187leave_map (object *op)
230{ 188{
231 maptile *oldmap = op->map; 189 maptile *oldmap = op->map;
232 190
233 remove_ob (op); 191 op->remove ();
234 192
235 if (oldmap) 193 if (oldmap)
236 { 194 {
237 if (!op->contr->hidden) 195 if (!op->contr->hidden)
238 oldmap->players--; 196 oldmap->players--;
256 maptile *oldmap = op->map; 214 maptile *oldmap = op->map;
257 215
258 if (out_of_map (newmap, x, y)) 216 if (out_of_map (newmap, x, y))
259 { 217 {
260 LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", newmap->path, x, y); 218 LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", newmap->path, x, y);
261 x = MAP_ENTER_X (newmap); 219 x = newmap->enter_x;
262 y = MAP_ENTER_Y (newmap); 220 y = newmap->enter_y;
263 if (out_of_map (newmap, x, y)) 221 if (out_of_map (newmap, x, y))
264 { 222 {
265 LOG (llevError, "enter_map: map %s provides invalid default enter location (%d, %d) > (%d, %d)\n", 223 LOG (llevError, "enter_map: map %s provides invalid default enter location (%d, %d) > (%d, %d)\n",
266 newmap->path, x, y, MAP_WIDTH (newmap), MAP_HEIGHT (newmap)); 224 newmap->path, x, y, newmap->width, newmap->height);
267 new_draw_info (NDI_UNIQUE, 0, op, "The exit is closed"); 225 new_draw_info (NDI_UNIQUE, 0, op, "The exit is closed");
268 return; 226 return;
269 } 227 }
270 } 228 }
271 229
298 /* not much we can do in this case. */ 256 /* not much we can do in this case. */
299 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); 257 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);
300 } 258 }
301 } /* end if looking for free spot */ 259 } /* end if looking for free spot */
302 260
303 if (op->map != NULL) 261 if (op->map)
304 if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr))) 262 if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr)))
305 return; 263 return;
306 264
307 if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y))) 265 if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y)))
308 return; 266 return;
311 return; 269 return;
312 270
313 /* If it is a player login, he has yet to be inserted anyplace. 271 /* If it is a player login, he has yet to be inserted anyplace.
314 * otherwise, we need to deal with removing the player here. 272 * otherwise, we need to deal with removing the player here.
315 */ 273 */
316 remove_ob (op); 274 op->remove ();
317 275
318 /* remove_ob clears these so they must be reset after the remove_ob call */ 276 /* remove_ob clears these so they must be reset after the remove_ob call */
319 op->x = x; 277 op->x = x;
320 op->y = y; 278 op->y = y;
321 op->map = newmap; 279 op->map = newmap;
338 if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL) 296 if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL)
339 { 297 {
340 int i = find_free_spot (op->contr->ranges[range_golem], newmap, 298 int i = find_free_spot (op->contr->ranges[range_golem], newmap,
341 x, y, 1, SIZEOFFREE); 299 x, y, 1, SIZEOFFREE);
342 300
343 remove_ob (op->contr->ranges[range_golem]); 301 op->contr->ranges[range_golem]->remove ();
344 302
345 if (i == -1) 303 if (i == -1)
346 { 304 {
347 remove_friendly_object (op->contr->ranges[range_golem]); 305 remove_friendly_object (op->contr->ranges[range_golem]);
348 free_object (op->contr->ranges[range_golem]); 306 op->contr->ranges[range_golem]->destroy ();
349 op->contr->ranges[range_golem] = NULL; 307 op->contr->ranges[range_golem] = 0;
350 op->contr->golem_count = 0;
351 } 308 }
352 else 309 else
353 { 310 {
354 for (object *tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more) 311 for (object *tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more)
355 { 312 {
389 346
390void 347void
391set_map_timeout (maptile *oldmap) 348set_map_timeout (maptile *oldmap)
392{ 349{
393#if MAP_MAXTIMEOUT 350#if MAP_MAXTIMEOUT
394 oldmap->timeout = MAP_TIMEOUT (oldmap); 351 oldmap->timeout = oldmap->timeout;
395 /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is 352 /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is
396 * lower than the min value. 353 * lower than the min value.
397 */ 354 */
398# if MAP_MINTIMEOUT 355# if MAP_MINTIMEOUT
399 if (oldmap->timeout < MAP_MINTIMEOUT) 356 if (oldmap->timeout < MAP_MINTIMEOUT)
472 rp.origin_y = exit_ob->y; 429 rp.origin_y = exit_ob->y;
473 strcpy (rp.origin_map, pl->map->path); 430 strcpy (rp.origin_map, pl->map->path);
474 431
475 /* If we have a final_map, use it as a base name to give some clue 432 /* If we have a final_map, use it as a base name to give some clue
476 * as where the player is. Otherwise, use the origin map. 433 * as where the player is. Otherwise, use the origin map.
477 * Take the last component (after the last slash) to give
478 * shorter names without bogus slashes.
479 */ 434 */
480 if (rp.final_map[0]) 435 sprintf (newmap_name, "/random%s+%04d",
481 { 436 *rp.final_map ? rp.final_map : rp.origin_map,
482 cp = strrchr (rp.final_map, '/'); 437 reference_number++);
483 if (!cp)
484 cp = rp.final_map;
485 }
486 else
487 {
488 char buf[HUGE_BUF];
489
490 cp = strrchr (rp.origin_map, '/');
491 if (!cp)
492 cp = rp.origin_map;
493 /* Need to strip of any trailing digits, if it has them */
494 strcpy (buf, cp);
495 while (isdigit (buf[strlen (buf) - 1]))
496 buf[strlen (buf) - 1] = 0;
497 cp = buf;
498 }
499
500 sprintf (newmap_name, "/random/%s%04d", cp + 1, reference_number++);
501 438
502 /* now to generate the actual map. */ 439 /* now to generate the actual map. */
503 new_map = generate_random_map (newmap_name, &rp); 440 new_map = generate_random_map (newmap_name, &rp);
504 441
505 /* Update the exit_ob so it now points directly at the newly created 442 /* Update the exit_ob so it now points directly at the newly created
510 */ 447 */
511 if (new_map) 448 if (new_map)
512 { 449 {
513 int x, y; 450 int x, y;
514 451
515 x = EXIT_X (exit_ob) = MAP_ENTER_X (new_map); 452 x = EXIT_X (exit_ob) = new_map->enter_x;
516 y = EXIT_Y (exit_ob) = MAP_ENTER_Y (new_map); 453 y = EXIT_Y (exit_ob) = new_map->enter_y;
517 EXIT_PATH (exit_ob) = newmap_name; 454 EXIT_PATH (exit_ob) = newmap_name;
518 strcpy (new_map->path, newmap_name); 455 strcpy (new_map->path, newmap_name);
519 enter_map (pl, new_map, x, y); 456 enter_map (pl, new_map, x, y);
520 } 457 }
521} 458}
633 570
634 /* If we are coming from another template map, use reletive paths unless 571 /* If we are coming from another template map, use reletive paths unless
635 * indicated otherwise. 572 * indicated otherwise.
636 */ 573 */
637 if (exit_ob->map->templatemap && (resultname[0] != '/')) 574 if (exit_ob->map->templatemap && (resultname[0] != '/'))
638 {
639 new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); 575 new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname);
640 }
641 else 576 else
642 {
643 new_map_name = create_template_pathname (resultname); 577 new_map_name = create_template_pathname (resultname);
644 }
645 578
646 new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); 579 new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE);
647 if (!new_map) 580 if (!new_map)
648 { 581 {
649 memset (&rp, 0, sizeof (RMParms)); 582 memset (&rp, 0, sizeof (RMParms));
669 */ 602 */
670 if (new_map) 603 if (new_map)
671 { 604 {
672 int x, y; 605 int x, y;
673 606
674 x = EXIT_X (exit_ob) = MAP_ENTER_X (new_map); 607 x = EXIT_X (exit_ob) = new_map->enter_x;
675 y = EXIT_Y (exit_ob) = MAP_ENTER_Y (new_map); 608 y = EXIT_Y (exit_ob) = new_map->enter_y;
676 new_map->templatemap = 1; 609 new_map->templatemap = 1;
677 enter_map (pl, new_map, x, y); 610 enter_map (pl, new_map, x, y);
678 } 611 }
679} 612}
680 613
777#define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */ 710#define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */
778 object *tmp; 711 object *tmp;
779 712
780 /* It may be nice to support other creatures moving across 713 /* It may be nice to support other creatures moving across
781 * exits, but right now a lot of the code looks at op->contr, 714 * exits, but right now a lot of the code looks at op->contr,
782 * so thta is an RFE. 715 * so that is an RFE.
783 */ 716 */
784 if (op->type != PLAYER) 717 if (op->type != PLAYER)
785 return; 718 return;
786 719
787 /* First, lets figure out what map the player is going to go to */ 720 /* First, lets figure out what map the player is going to go to */
876 * using the new maps default coordinates, the exit ob should use 809 * using the new maps default coordinates, the exit ob should use
877 * something like -1, -1 so it is clear to do that. 810 * something like -1, -1 so it is clear to do that.
878 */ 811 */
879 if (x == 0 && y == 0) 812 if (x == 0 && y == 0)
880 { 813 {
881 x = MAP_ENTER_X (newmap); 814 x = newmap->enter_x;
882 y = MAP_ENTER_Y (newmap); 815 y = newmap->enter_y;
883 LOG (llevDebug, "enter_exit: Exit %s (%d,%d) on map %s is 0 destination coordinates\n", 816 LOG (llevDebug, "enter_exit: Exit %s (%d,%d) on map %s is 0 destination coordinates\n",
884 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map ? exit_ob->map->path : "<nil>"); 817 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map ? exit_ob->map->path : "<nil>");
885 } 818 }
886 819
887 /* mids 02/13/2002 if exit is damned, update players death & WoR home-position and delete town portal */ 820 /* mids 02/13/2002 if exit is damned, update players death & WoR home-position and delete town portal */
893 if (tmp->type == FORCE && tmp->slaying && !strcmp (tmp->slaying, PORTAL_DESTINATION_NAME)) 826 if (tmp->type == FORCE && tmp->slaying && !strcmp (tmp->slaying, PORTAL_DESTINATION_NAME))
894 break; 827 break;
895 } 828 }
896 if (tmp) 829 if (tmp)
897 { 830 {
898 remove_ob (tmp); 831 tmp->remove ();
899 free_object (tmp); 832 tmp->destroy ();
900 } 833 }
901 834
902 strcpy (op->contr->savebed_map, path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob))); 835 strcpy (op->contr->savebed_map, path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)));
903 op->contr->bed_x = EXIT_X (exit_ob), op->contr->bed_y = EXIT_Y (exit_ob); 836 op->contr->bed_x = EXIT_X (exit_ob), op->contr->bed_y = EXIT_Y (exit_ob);
904 save_player (op, 1); 837 op->contr->save ();
905 /* LOG(llevDebug,"enter_exit: Taking damned exit %s to (%d,%d) on map %s\n", 838 /* LOG(llevDebug,"enter_exit: Taking damned exit %s to (%d,%d) on map %s\n",
906 * exit_ob->name?exit_ob->name:"(none)", exit_ob->x, exit_ob->y, 839 * exit_ob->name?exit_ob->name:"(none)", exit_ob->x, exit_ob->y,
907 * path_combine_and_normalize(exit_ob->map->path, EXIT_PATH(exit_ob))); */ 840 * path_combine_and_normalize(exit_ob->map->path, EXIT_PATH(exit_ob))); */
908 } 841 }
909 842
950 883
951 enter_map (op, newmap, op->x, op->y); 884 enter_map (op, newmap, op->x, op->y);
952 } 885 }
953} 886}
954 887
955/*
956 * process_active_maps(): Works like process_events(), but it only
957 * processes maps which a player is on.
958 *
959 */
960
961#if 0 // dead code, schmorp
962void
963process_active_maps ()
964{
965 for (maptile *map = first_map; map != NULL; map = map->next)
966 if (map->in_memory == MAP_IN_MEMORY)
967 if (players_on_map (map, TRUE))
968 process_events (map);
969}
970#endif
971
972/* process_players1 and process_players2 do all the player related stuff. 888/* process_players1 and process_players2 do all the player related stuff.
973 * I moved it out of process events and process_map. This was to some 889 * I moved it out of process events and process_map. This was to some
974 * extent for debugging as well as to get a better idea of the time used 890 * extent for debugging as well as to get a better idea of the time used
975 * by the various functions. process_players1() does the processing before 891 * by the various functions. process_players1() does the processing before
976 * objects have been updated, process_players2() does the processing that 892 * objects have been updated, process_players2() does the processing that
977 * is needed after the players have been updated. 893 * is needed after the players have been updated.
978 */ 894 */
979 895static void
980void
981process_players1 (maptile *map) 896process_players1 ()
982{ 897{
983 int flag; 898 int flag;
984 player *pl, *plnext;
985 899
986 /* Basically, we keep looping until all the players have done their actions. */ 900 /* Basically, we keep looping until all the players have done their actions. */
987 for (flag = 1; flag != 0;) 901 for (flag = 1; flag != 0;)
988 { 902 {
989 flag = 0; 903 flag = 0;
990 for (pl = first_player; pl != NULL; pl = plnext) 904 for_all_players (pl)
991 { 905 {
992 plnext = pl->next; /* In case a player exits the game in handle_player() */ 906 pl->refcnt_chk ();
993 907
994 if (pl->ob == NULL) 908 if (!pl->ob || !pl->ns)
995 continue; 909 continue;
996 910
997 if (map != NULL && pl->ob->map != map)
998 continue;
999
1000 if (pl->ob->speed_left > 0) 911 if (pl->ob->speed_left > 0)
1001 {
1002 if (handle_newcs_player (pl->ob)) 912 if (handle_newcs_player (pl->ob))
1003 flag = 1; 913 flag = 1;
1004 } /* end if player has speed left */
1005 914
1006 /* If the player is not actively playing, don't make a 915 /* If the player is not actively playing, don't make a
1007 * backup save - nothing to save anyway. Plus, the 916 * backup save - nothing to save anyway. Plus, the
1008 * map may not longer be valid. This can happen when the 917 * map may not longer be valid. This can happen when the
1009 * player quits - they exist for purposes of tracking on the map, 918 * player quits - they exist for purposes of tracking on the map,
1014 923
1015#ifdef AUTOSAVE 924#ifdef AUTOSAVE
1016 /* check for ST_PLAYING state so that we don't try to save off when 925 /* check for ST_PLAYING state so that we don't try to save off when
1017 * the player is logging in. 926 * the player is logging in.
1018 */ 927 */
1019 if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->state == ST_PLAYING) 928 if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->ns->state == ST_PLAYING)
1020 {
1021 /* Don't save the player on unholy ground. Instead, increase the
1022 * tick time so it will be about 10 seconds before we try and save
1023 * again.
1024 */ 929 {
1025// if (get_map_flags(pl->ob->map, NULL, pl->ob->x, pl->ob->y, NULL, NULL) & P_NO_CLERIC) { 930 pl->ob->contr->save ();
1026// pl->last_save_tick += 100;
1027// } else {
1028 save_player (pl->ob, 1);
1029 pl->last_save_tick = pticks; 931 pl->last_save_tick = pticks;
1030// }
1031 } 932 }
1032#endif 933#endif
1033 } /* end of for loop for all the players */ 934 } /* end of for loop for all the players */
1034 } /* for flag */ 935 } /* for flag */
1035 for (pl = first_player; pl != NULL; pl = pl->next) 936
937 for_all_players (pl)
1036 { 938 {
1037 if (map != NULL && (pl->ob == NULL || pl->ob->map != map)) 939 if (!pl->ob || !pl->ns)
1038 continue; 940 continue;
941
1039 if (settings.casting_time == TRUE) 942 if (settings.casting_time)
1040 { 943 {
1041 if (pl->ob->casting_time > 0) 944 if (pl->ob->casting_time > 0)
1042 { 945 {
1043 pl->ob->casting_time--; 946 pl->ob->casting_time--;
1044 pl->ob->start_holding = 1; 947 pl->ob->start_holding = 1;
1045 } 948 }
949
1046 /* set spell_state so we can update the range in stats field */ 950 /* set spell_state so we can update the range in stats field */
1047 if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1)) 951 if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1))
1048 {
1049 pl->ob->start_holding = 0; 952 pl->ob->start_holding = 0;
1050 } 953 }
1051 } 954
1052 do_some_living (pl->ob); 955 do_some_living (pl->ob);
1053 /* draw(pl->ob); *//* updated in socket code */
1054 } 956 }
1055} 957}
1056 958
1057void 959static void
1058process_players2 (maptile *map) 960process_players2 ()
1059{ 961{
1060 player *pl;
1061
1062 /* Then check if any players should use weapon-speed instead of speed */ 962 /* Then check if any players should use weapon-speed instead of speed */
1063 for (pl = first_player; pl != NULL; pl = pl->next) 963 for_all_players (pl)
1064 { 964 {
1065 if (map != NULL)
1066 {
1067 if (pl->ob == NULL || QUERY_FLAG (pl->ob, FLAG_REMOVED))
1068 continue;
1069 else if (pl->loading != NULL) /* Player is blocked */
1070 pl->ob->speed_left -= pl->ob->speed;
1071 if (pl->ob->map != map)
1072 continue;
1073 }
1074
1075 /* The code that did weapon_sp handling here was out of place - 965 /* The code that did weapon_sp handling here was out of place -
1076 * this isn't called until after the player has finished there 966 * this isn't called until after the player has finished there
1077 * actions, and is thus out of place. All we do here is bounds 967 * actions, and is thus out of place. All we do here is bounds
1078 * checking. 968 * checking.
1079 */ 969 */
1085 /* This needs to be here - if the player is running, we need to 975 /* This needs to be here - if the player is running, we need to
1086 * clear this each tick, but new commands are not being received 976 * clear this each tick, but new commands are not being received
1087 * so execute_newserver_command() is never called 977 * so execute_newserver_command() is never called
1088 */ 978 */
1089 pl->has_hit = 0; 979 pl->has_hit = 0;
1090
1091 } 980 }
1092 else if (pl->ob->speed_left > pl->ob->speed) 981 else if (pl->ob->speed_left > pl->ob->speed)
1093 pl->ob->speed_left = pl->ob->speed; 982 pl->ob->speed_left = pl->ob->speed;
1094 } 983 }
1095} 984}
1096 985
1097void 986void
1098process_events (maptile *map) 987process_events ()
1099{ 988{
1100 object *op; 989 object *op;
1101 990
1102 static object *marker; 991 static object_ptr marker_;
992
1103 if (!marker) 993 if (!marker_)
1104 marker = get_object (); 994 marker_ = object::create ();
1105 995
996 object *marker = marker_;
997
1106 process_players1 (map); 998 process_players1 ();
1107 999
1108 marker->active_next = active_objects; 1000 marker->active_next = active_objects;
1109 1001
1110 if (marker->active_next) 1002 if (marker->active_next)
1111 marker->active_next->active_prev = marker; 1003 marker->active_next->active_prev = marker;
1112 1004
1113 marker->active_prev = NULL; 1005 marker->active_prev = 0;
1114 active_objects = marker; 1006 active_objects = marker;
1115 1007
1116 while (marker->active_next) 1008 while (marker->active_next)
1117 { 1009 {
1118 op = marker->active_next; 1010 op = marker->active_next;
1135 1027
1136 /* Now process op */ 1028 /* Now process op */
1137 if (QUERY_FLAG (op, FLAG_FREED)) 1029 if (QUERY_FLAG (op, FLAG_FREED))
1138 { 1030 {
1139 LOG (llevError, "BUG: process_events(): Free object on list\n"); 1031 LOG (llevError, "BUG: process_events(): Free object on list\n");
1140 op->speed = 0; 1032 op->set_speed (0);
1141 update_ob_speed (op);
1142 continue; 1033 continue;
1143 } 1034 }
1144 1035
1145 /* I've seen occasional crashes due to this - the object is removed, 1036 /* I've seen occasional crashes due to this - the object is removed,
1146 * and thus the map it points to (last map it was on) may be bogus 1037 * and thus the map it points to (last map it was on) may be bogus
1153 * around. 1044 * around.
1154 */ 1045 */
1155 if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY) 1046 if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY)
1156 { 1047 {
1157 LOG (llevError, "BUG: process_events(): Removed object on list\n"); 1048 LOG (llevError, "BUG: process_events(): Removed object on list\n");
1158 dump_object (op); 1049 char *dump = dump_object (op);
1159 LOG (llevError, errmsg); 1050 LOG (llevError, dump);
1160 free_object (op); 1051 free (dump);
1052 op->destroy ();
1161 continue; 1053 continue;
1162 } 1054 }
1163 1055
1164 if (!op->speed) 1056 if (!op->speed)
1165 { 1057 {
1166 LOG (llevError, "BUG: process_events(): Object %s has no speed, " "but is on active list\n", &op->arch->name); 1058 LOG (llevError, "BUG: process_events(): Object %s has no speed, "
1167 update_ob_speed (op); 1059 "but is on active list\n", &op->arch->name);
1060 op->set_speed (0);
1168 continue; 1061 continue;
1169 } 1062 }
1170 1063
1171 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP && map == NULL) 1064 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP)
1172 { 1065 {
1173 LOG (llevError, "BUG: process_events(): Object without map or " "inventory is on active list: %s (%d)\n", &op->name, op->count); 1066 LOG (llevError, "BUG: process_events(): Object without map or "
1067 "inventory is on active list: %s (%d)\n", &op->name, op->count);
1174 op->speed = 0; 1068 op->set_speed (0);
1175 update_ob_speed (op);
1176 continue; 1069 continue;
1177 } 1070 }
1178 1071
1179 if (map != NULL && op->map != map)
1180 continue;
1181
1182 /* Animate the object. Bug of feature that andim_speed 1072 /* Animate the object. Bug or feature that anim_speed
1183 * is based on ticks, and not the creatures speed? 1073 * is based on ticks, and not the creatures speed?
1184 */ 1074 */
1185 if (op->anim_speed && op->last_anim >= op->anim_speed) 1075 if (op->anim_speed && op->last_anim >= op->anim_speed)
1186 { 1076 {
1187 if ((op->type == PLAYER) || (op->type == MONSTER)) 1077 if ((op->type == PLAYER))
1188 animate_object (op, op->facing); 1078 animate_object (op, op->facing);
1189 else 1079 else
1190 animate_object (op, op->direction); 1080 animate_object (op, op->direction);
1191 1081
1192 op->last_anim = 1; 1082 op->last_anim = 1;
1228 if (marker->active_prev != NULL) 1118 if (marker->active_prev != NULL)
1229 marker->active_prev->active_next = NULL; 1119 marker->active_prev->active_next = NULL;
1230 else 1120 else
1231 active_objects = NULL; 1121 active_objects = NULL;
1232 1122
1233 process_players2 (map); 1123 process_players2 ();
1234} 1124}
1235 1125
1236void 1126void
1237clean_tmp_files (void) 1127clean_tmp_files (void)
1238{ 1128{
1242 1132
1243 /* We save the maps - it may not be intuitive why, but if there are unique 1133 /* We save the maps - it may not be intuitive why, but if there are unique
1244 * items, we need to save the map so they get saved off. Perhaps we should 1134 * items, we need to save the map so they get saved off. Perhaps we should
1245 * just make a special function that only saves the unique items. 1135 * just make a special function that only saves the unique items.
1246 */ 1136 */
1247 for (m = first_map; m != NULL; m = next) 1137 for (m = first_map; m; m = next)
1248 { 1138 {
1249 next = m->next; 1139 next = m->next;
1140
1250 if (m->in_memory == MAP_IN_MEMORY) 1141 if (m->in_memory == MAP_IN_MEMORY)
1251 { 1142 {
1252 /* If we want to reuse the temp maps, swap it out (note that will also 1143 /* If we want to reuse the temp maps, swap it out (note that will also
1253 * update the log file. Otherwise, save the map (mostly for unique item 1144 * update the log file.
1254 * stuff). Note that the clean_tmp_map is called after the end of
1255 * the for loop but is in the #else bracket. IF we are recycling the maps,
1256 * we certainly don't want the temp maps removed.
1257 */ 1145 */
1258 1146
1259 /* XXX The above comment is dead wrong */
1260 if (settings.recycle_tmp_maps == TRUE)
1261 swap_map (m); 1147 swap_map (m);
1262 else
1263 {
1264 new_save_map (m, 0); /* note we save here into a overlay map */
1265 clean_tmp_map (m);
1266 } 1148 }
1267 }
1268 } 1149 }
1150
1269 write_todclock (); /* lets just write the clock here */ 1151 write_todclock (); /* lets just write the clock here */
1270} 1152}
1271 1153
1272/* clean up everything before exiting */ 1154/* clean up everything before exiting */
1273void 1155void
1274cleanup (void) 1156cleanup (bool make_core)
1275{ 1157{
1276 LOG (llevDebug, "Cleanup called.\n"); 1158 LOG (llevDebug, "Cleanup called.\n");
1277 1159
1278 for (player *pl = first_player; pl != NULL; pl = pl->next) 1160 if (init_done)
1279 save_player (pl->ob, 0); 1161 {
1162 for_all_players (pl)
1163 pl->save (1);
1280 1164
1281 for (player *pl = first_player; pl != NULL; pl = pl->next) 1165 for_all_players (pl)
1282 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED)) 1166 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
1283 leave_map (pl->ob); 1167 leave_map (pl->ob);
1284 1168
1285 clean_tmp_files (); 1169 clean_tmp_files ();
1286 write_book_archive (); 1170 write_book_archive ();
1287 1171
1288 INVOKE_GLOBAL (CLEANUP); 1172 INVOKE_GLOBAL (CLEANUP);
1173 }
1289 1174
1175 if (make_core)
1176 abort ();
1177 else
1290 _exit (0); 1178 _exit (0);
1291} 1179}
1292 1180
1293void 1181void
1294leave (player *pl, int draw_exit) 1182leave (player *pl, int draw_exit)
1295{ 1183{
1296 if (pl != NULL) 1184 if (pl)
1297 { 1185 {
1186 if (pl->ob->type != DEAD_OBJECT)
1187 {
1188 /* If a hidden dm dropped connection do not create
1189 * inconsistencies by showing that they have left the game
1190 */
1191 if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden)
1192 && draw_exit)
1193 {
1194 if (pl->ob->map)
1195 {
1196 INVOKE_PLAYER (LOGOUT, pl);
1197 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->ns->host);
1198 }
1199
1200 char buf[MAX_BUF];
1201
1202 sprintf (buf, "%s left the game.", &pl->ob->name);
1203 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, 0, buf);
1204 }
1205
1206 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
1207 leave_map (pl->ob);
1208
1209 pl->ob->type = DEAD_OBJECT; /* To avoid problems with inventory window */
1210 }
1211
1298 /* We do this so that the socket handling routine can do the final 1212 /* We do this so that the socket handling routine can do the final
1299 * cleanup. We also leave that loop to actually handle the freeing 1213 * cleanup. We also leave that loop to actually handle the freeing
1300 * of the data. 1214 * of the data.
1301 */ 1215 */
1302 if (pl->ob->type != DEAD_OBJECT) 1216 if (pl->ns)
1303 { 1217 pl->ns->destroy ();
1304 pl->socket.status = Ns_Dead;
1305 1218
1306 /* If a hidden dm dropped connection do not create
1307 * inconsistencies by showing that they have left the game
1308 */
1309 if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden)
1310 && draw_exit && (pl->state != ST_GET_NAME && pl->state != ST_GET_PASSWORD && pl->state != ST_CONFIRM_PASSWORD))
1311 {
1312 if (pl->ob->map)
1313 {
1314 INVOKE_PLAYER (LOGOUT, pl);
1315 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->socket.host);
1316 }
1317
1318 char buf[MAX_BUF];
1319
1320 sprintf (buf, "%s left the game.", &pl->ob->name);
1321 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, buf);
1322 }
1323
1324 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
1325 leave_map (pl->ob);
1326
1327 pl->ob->type = DEAD_OBJECT; /* To avoid problems with inventory window */
1328 }
1329 } 1219 }
1330} 1220}
1331 1221
1332int 1222int
1333forbid_play (void) 1223forbid_play (void)
1396extern unsigned long todtick; 1286extern unsigned long todtick;
1397 1287
1398void 1288void
1399do_specials (void) 1289do_specials (void)
1400{ 1290{
1401
1402#ifdef WATCHDOG
1403 if (!(pticks % 503))
1404 watchdog ();
1405#endif
1406
1407 if (!(pticks % PTICKS_PER_CLOCK)) 1291 if (!(pticks % PTICKS_PER_CLOCK))
1408 tick_the_clock (); 1292 tick_the_clock ();
1409 1293
1410 if (!(pticks % 7)) 1294 if (!(pticks % 7))
1411 shstr::gc (); 1295 shstr::gc ();
1414 flush_old_maps (); /* Clears the tmp-files of maps which have reset */ 1298 flush_old_maps (); /* Clears the tmp-files of maps which have reset */
1415 1299
1416 if (!(pticks % 2503)) 1300 if (!(pticks % 2503))
1417 fix_weight (); /* Hack to fix weightproblems caused by bugs */ 1301 fix_weight (); /* Hack to fix weightproblems caused by bugs */
1418 1302
1419 if (!(pticks % 2521))
1420 metaserver_update (); /* 2500 ticks is about 5 minutes */
1421
1422 if (!(pticks % 5003)) 1303 if (!(pticks % 5003))
1423 write_book_archive (); 1304 write_book_archive ();
1424 1305
1425 if (!(pticks % 5009)) 1306 if (!(pticks % 5009))
1426 clean_friendly_list (); 1307 clean_friendly_list ();
1435void 1316void
1436server_tick () 1317server_tick ()
1437{ 1318{
1438 nroferrors = 0; 1319 nroferrors = 0;
1439 1320
1321 // first do the user visible stuff
1440 doeric_server (); 1322 doeric_server ();
1441 INVOKE_GLOBAL (CLOCK); 1323 INVOKE_GLOBAL (CLOCK);
1442 process_events (NULL); /* "do" something with objects with speed */ 1324 process_events (); /* "do" something with objects with speed */
1443 flush_sockets (); 1325 flush_sockets ();
1326
1327 // then do some bookkeeping, should not really be here
1444 check_active_maps (); /* Removes unused maps after a certain timeout */ 1328 check_active_maps (); /* Removes unused maps after a certain timeout */
1445 do_specials (); /* Routines called from time to time. */ 1329 do_specials (); /* Routines called from time to time. */
1446 object::free_mortals (); 1330 attachable::check_mortals ();
1447 1331
1448 ++pticks; 1332 ++pticks;
1449} 1333}
1450 1334
1451int 1335int

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines