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.61 by root, Wed Dec 27 18:09:49 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
133 new_draw_info (NDI_UNIQUE, 0, op, "Ctrl-R = refresh Ctrl-C = clear"); 128 new_draw_info (NDI_UNIQUE, 0, op, "Ctrl-R = refresh Ctrl-C = clear");
134 new_draw_info (NDI_UNIQUE, 0, op, "You can type a number before most commands."); 129 new_draw_info (NDI_UNIQUE, 0, op, "You can type a number before most commands.");
135 new_draw_info (NDI_UNIQUE, 0, op, "(For instance 3d drops 3 items.)"); 130 new_draw_info (NDI_UNIQUE, 0, op, "(For instance 3d drops 3 items.)");
136} 131}
137 132
138void
139start_info (object *op)
140{
141 char buf[MAX_BUF];
142
143 sprintf (buf, "Welcome to Crossfire, v%s!", VERSION);
144 new_draw_info (NDI_UNIQUE, 0, op, buf);
145 new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help");
146 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);
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}
187
188/* This is a basic little function to put the player back to his 133/* This is a basic little function to put the player back to his
189 * savebed. We do some error checking - its possible that the 134 * savebed. We do some error checking - its possible that the
190 * savebed map may no longer exist, so we make sure the player 135 * savebed map may no longer exist, so we make sure the player
191 * goes someplace. 136 * goes someplace.
192 */ 137 */
194enter_player_savebed (object *op) 139enter_player_savebed (object *op)
195{ 140{
196 maptile *oldmap = op->map; 141 maptile *oldmap = op->map;
197 object *tmp; 142 object *tmp;
198 143
199 tmp = get_object (); 144 tmp = object::create ();
200 145
201 EXIT_PATH (tmp) = op->contr->savebed_map; 146 EXIT_PATH (tmp) = op->contr->savebed_map;
202 EXIT_X (tmp) = op->contr->bed_x; 147 EXIT_X (tmp) = op->contr->bed_x;
203 EXIT_Y (tmp) = op->contr->bed_y; 148 EXIT_Y (tmp) = op->contr->bed_y;
204 enter_exit (op, tmp); 149 enter_exit (op, tmp);
217 EXIT_PATH (tmp) = op->contr->savebed_map; 162 EXIT_PATH (tmp) = op->contr->savebed_map;
218 EXIT_X (tmp) = op->contr->bed_x; 163 EXIT_X (tmp) = op->contr->bed_x;
219 EXIT_Y (tmp) = op->contr->bed_y; 164 EXIT_Y (tmp) = op->contr->bed_y;
220 enter_exit (op, tmp); 165 enter_exit (op, tmp);
221 } 166 }
222 free_object (tmp); 167
168 tmp->destroy ();
223} 169}
224 170
225/* All this really is is a glorified remove_object that also updates 171/* All this really is is a glorified remove_object that also updates
226 * the counts on the map if needed. 172 * the counts on the map if needed.
227 */ 173 */
228void 174void
229leave_map (object *op) 175leave_map (object *op)
230{ 176{
231 maptile *oldmap = op->map; 177 maptile *oldmap = op->map;
232 178
233 remove_ob (op); 179 op->remove ();
234 180
235 if (oldmap) 181 if (oldmap)
236 { 182 {
237 if (!op->contr->hidden) 183 if (!op->contr->hidden)
238 oldmap->players--; 184 oldmap->players--;
256 maptile *oldmap = op->map; 202 maptile *oldmap = op->map;
257 203
258 if (out_of_map (newmap, x, y)) 204 if (out_of_map (newmap, x, y))
259 { 205 {
260 LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", newmap->path, x, y); 206 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); 207 x = newmap->enter_x;
262 y = MAP_ENTER_Y (newmap); 208 y = newmap->enter_y;
263 if (out_of_map (newmap, x, y)) 209 if (out_of_map (newmap, x, y))
264 { 210 {
265 LOG (llevError, "enter_map: map %s provides invalid default enter location (%d, %d) > (%d, %d)\n", 211 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)); 212 newmap->path, x, y, newmap->width, newmap->height);
267 new_draw_info (NDI_UNIQUE, 0, op, "The exit is closed"); 213 new_draw_info (NDI_UNIQUE, 0, op, "The exit is closed");
268 return; 214 return;
269 } 215 }
270 } 216 }
271 217
298 /* not much we can do in this case. */ 244 /* 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); 245 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 } 246 }
301 } /* end if looking for free spot */ 247 } /* end if looking for free spot */
302 248
303 if (op->map != NULL) 249 if (op->map)
304 if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr))) 250 if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr)))
305 return; 251 return;
306 252
307 if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y))) 253 if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y)))
308 return; 254 return;
311 return; 257 return;
312 258
313 /* If it is a player login, he has yet to be inserted anyplace. 259 /* If it is a player login, he has yet to be inserted anyplace.
314 * otherwise, we need to deal with removing the player here. 260 * otherwise, we need to deal with removing the player here.
315 */ 261 */
316 remove_ob (op); 262 op->remove ();
317 263
318 /* remove_ob clears these so they must be reset after the remove_ob call */ 264 /* remove_ob clears these so they must be reset after the remove_ob call */
319 op->x = x; 265 op->x = x;
320 op->y = y; 266 op->y = y;
321 op->map = newmap; 267 op->map = newmap;
338 if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL) 284 if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL)
339 { 285 {
340 int i = find_free_spot (op->contr->ranges[range_golem], newmap, 286 int i = find_free_spot (op->contr->ranges[range_golem], newmap,
341 x, y, 1, SIZEOFFREE); 287 x, y, 1, SIZEOFFREE);
342 288
343 remove_ob (op->contr->ranges[range_golem]); 289 op->contr->ranges[range_golem]->remove ();
344 290
345 if (i == -1) 291 if (i == -1)
346 { 292 {
347 remove_friendly_object (op->contr->ranges[range_golem]); 293 remove_friendly_object (op->contr->ranges[range_golem]);
348 free_object (op->contr->ranges[range_golem]); 294 op->contr->ranges[range_golem]->destroy ();
349 op->contr->ranges[range_golem] = NULL; 295 op->contr->ranges[range_golem] = 0;
350 op->contr->golem_count = 0;
351 } 296 }
352 else 297 else
353 { 298 {
354 for (object *tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more) 299 for (object *tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more)
355 { 300 {
389 334
390void 335void
391set_map_timeout (maptile *oldmap) 336set_map_timeout (maptile *oldmap)
392{ 337{
393#if MAP_MAXTIMEOUT 338#if MAP_MAXTIMEOUT
394 oldmap->timeout = MAP_TIMEOUT (oldmap); 339 oldmap->timeout = oldmap->timeout;
395 /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is 340 /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is
396 * lower than the min value. 341 * lower than the min value.
397 */ 342 */
398# if MAP_MINTIMEOUT 343# if MAP_MINTIMEOUT
399 if (oldmap->timeout < MAP_MINTIMEOUT) 344 if (oldmap->timeout < MAP_MINTIMEOUT)
472 rp.origin_y = exit_ob->y; 417 rp.origin_y = exit_ob->y;
473 strcpy (rp.origin_map, pl->map->path); 418 strcpy (rp.origin_map, pl->map->path);
474 419
475 /* If we have a final_map, use it as a base name to give some clue 420 /* 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. 421 * 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 */ 422 */
480 if (rp.final_map[0]) 423 sprintf (newmap_name, "/random%s+%04d",
481 { 424 *rp.final_map ? rp.final_map : rp.origin_map,
482 cp = strrchr (rp.final_map, '/'); 425 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 426
502 /* now to generate the actual map. */ 427 /* now to generate the actual map. */
503 new_map = generate_random_map (newmap_name, &rp); 428 new_map = generate_random_map (newmap_name, &rp);
504 429
505 /* Update the exit_ob so it now points directly at the newly created 430 /* Update the exit_ob so it now points directly at the newly created
510 */ 435 */
511 if (new_map) 436 if (new_map)
512 { 437 {
513 int x, y; 438 int x, y;
514 439
515 x = EXIT_X (exit_ob) = MAP_ENTER_X (new_map); 440 x = EXIT_X (exit_ob) = new_map->enter_x;
516 y = EXIT_Y (exit_ob) = MAP_ENTER_Y (new_map); 441 y = EXIT_Y (exit_ob) = new_map->enter_y;
517 EXIT_PATH (exit_ob) = newmap_name; 442 EXIT_PATH (exit_ob) = newmap_name;
518 strcpy (new_map->path, newmap_name); 443 strcpy (new_map->path, newmap_name);
519 enter_map (pl, new_map, x, y); 444 enter_map (pl, new_map, x, y);
520 } 445 }
521} 446}
633 558
634 /* If we are coming from another template map, use reletive paths unless 559 /* If we are coming from another template map, use reletive paths unless
635 * indicated otherwise. 560 * indicated otherwise.
636 */ 561 */
637 if (exit_ob->map->templatemap && (resultname[0] != '/')) 562 if (exit_ob->map->templatemap && (resultname[0] != '/'))
638 {
639 new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); 563 new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname);
640 }
641 else 564 else
642 {
643 new_map_name = create_template_pathname (resultname); 565 new_map_name = create_template_pathname (resultname);
644 }
645 566
646 new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); 567 new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE);
647 if (!new_map) 568 if (!new_map)
648 { 569 {
649 memset (&rp, 0, sizeof (RMParms)); 570 memset (&rp, 0, sizeof (RMParms));
669 */ 590 */
670 if (new_map) 591 if (new_map)
671 { 592 {
672 int x, y; 593 int x, y;
673 594
674 x = EXIT_X (exit_ob) = MAP_ENTER_X (new_map); 595 x = EXIT_X (exit_ob) = new_map->enter_x;
675 y = EXIT_Y (exit_ob) = MAP_ENTER_Y (new_map); 596 y = EXIT_Y (exit_ob) = new_map->enter_y;
676 new_map->templatemap = 1; 597 new_map->templatemap = 1;
677 enter_map (pl, new_map, x, y); 598 enter_map (pl, new_map, x, y);
678 } 599 }
679} 600}
680 601
777#define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */ 698#define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */
778 object *tmp; 699 object *tmp;
779 700
780 /* It may be nice to support other creatures moving across 701 /* It may be nice to support other creatures moving across
781 * exits, but right now a lot of the code looks at op->contr, 702 * exits, but right now a lot of the code looks at op->contr,
782 * so thta is an RFE. 703 * so that is an RFE.
783 */ 704 */
784 if (op->type != PLAYER) 705 if (op->type != PLAYER)
785 return; 706 return;
786 707
787 /* First, lets figure out what map the player is going to go to */ 708 /* 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 797 * using the new maps default coordinates, the exit ob should use
877 * something like -1, -1 so it is clear to do that. 798 * something like -1, -1 so it is clear to do that.
878 */ 799 */
879 if (x == 0 && y == 0) 800 if (x == 0 && y == 0)
880 { 801 {
881 x = MAP_ENTER_X (newmap); 802 x = newmap->enter_x;
882 y = MAP_ENTER_Y (newmap); 803 y = newmap->enter_y;
883 LOG (llevDebug, "enter_exit: Exit %s (%d,%d) on map %s is 0 destination coordinates\n", 804 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>"); 805 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map ? exit_ob->map->path : "<nil>");
885 } 806 }
886 807
887 /* mids 02/13/2002 if exit is damned, update players death & WoR home-position and delete town portal */ 808 /* 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)) 814 if (tmp->type == FORCE && tmp->slaying && !strcmp (tmp->slaying, PORTAL_DESTINATION_NAME))
894 break; 815 break;
895 } 816 }
896 if (tmp) 817 if (tmp)
897 { 818 {
898 remove_ob (tmp); 819 tmp->remove ();
899 free_object (tmp); 820 tmp->destroy ();
900 } 821 }
901 822
902 strcpy (op->contr->savebed_map, path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob))); 823 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); 824 op->contr->bed_x = EXIT_X (exit_ob), op->contr->bed_y = EXIT_Y (exit_ob);
904 save_player (op, 1); 825 op->contr->save ();
905 /* LOG(llevDebug,"enter_exit: Taking damned exit %s to (%d,%d) on map %s\n", 826 /* 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, 827 * 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))); */ 828 * path_combine_and_normalize(exit_ob->map->path, EXIT_PATH(exit_ob))); */
908 } 829 }
909 830
950 871
951 enter_map (op, newmap, op->x, op->y); 872 enter_map (op, newmap, op->x, op->y);
952 } 873 }
953} 874}
954 875
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. 876/* 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 877 * 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 878 * 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 879 * by the various functions. process_players1() does the processing before
976 * objects have been updated, process_players2() does the processing that 880 * objects have been updated, process_players2() does the processing that
977 * is needed after the players have been updated. 881 * is needed after the players have been updated.
978 */ 882 */
979 883static void
980void
981process_players1 (maptile *map) 884process_players1 ()
982{ 885{
983 int flag; 886 int flag;
984 player *pl, *plnext;
985 887
986 /* Basically, we keep looping until all the players have done their actions. */ 888 /* Basically, we keep looping until all the players have done their actions. */
987 for (flag = 1; flag != 0;) 889 for (flag = 1; flag != 0;)
988 { 890 {
989 flag = 0; 891 flag = 0;
990 for (pl = first_player; pl != NULL; pl = plnext) 892 for_all_players (pl)
991 { 893 {
992 plnext = pl->next; /* In case a player exits the game in handle_player() */ 894 pl->refcnt_chk ();
993 895
994 if (pl->ob == NULL) 896 if (!pl->ob || !pl->ns)
995 continue; 897 continue;
996 898
997 if (map != NULL && pl->ob->map != map)
998 continue;
999
1000 if (pl->ob->speed_left > 0) 899 if (pl->ob->speed_left > 0)
1001 {
1002 if (handle_newcs_player (pl->ob)) 900 if (handle_newcs_player (pl->ob))
1003 flag = 1; 901 flag = 1;
1004 } /* end if player has speed left */
1005 902
1006 /* If the player is not actively playing, don't make a 903 /* If the player is not actively playing, don't make a
1007 * backup save - nothing to save anyway. Plus, the 904 * backup save - nothing to save anyway. Plus, the
1008 * map may not longer be valid. This can happen when the 905 * map may not longer be valid. This can happen when the
1009 * player quits - they exist for purposes of tracking on the map, 906 * player quits - they exist for purposes of tracking on the map,
1014 911
1015#ifdef AUTOSAVE 912#ifdef AUTOSAVE
1016 /* check for ST_PLAYING state so that we don't try to save off when 913 /* check for ST_PLAYING state so that we don't try to save off when
1017 * the player is logging in. 914 * the player is logging in.
1018 */ 915 */
1019 if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->state == ST_PLAYING) 916 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 */ 917 {
1025// if (get_map_flags(pl->ob->map, NULL, pl->ob->x, pl->ob->y, NULL, NULL) & P_NO_CLERIC) { 918 pl->ob->contr->save ();
1026// pl->last_save_tick += 100;
1027// } else {
1028 save_player (pl->ob, 1);
1029 pl->last_save_tick = pticks; 919 pl->last_save_tick = pticks;
1030// }
1031 } 920 }
1032#endif 921#endif
1033 } /* end of for loop for all the players */ 922 } /* end of for loop for all the players */
1034 } /* for flag */ 923 } /* for flag */
1035 for (pl = first_player; pl != NULL; pl = pl->next) 924
925 for_all_players (pl)
1036 { 926 {
1037 if (map != NULL && (pl->ob == NULL || pl->ob->map != map)) 927 if (!pl->ob || !pl->ns)
1038 continue; 928 continue;
929
1039 if (settings.casting_time == TRUE) 930 if (settings.casting_time)
1040 { 931 {
1041 if (pl->ob->casting_time > 0) 932 if (pl->ob->casting_time > 0)
1042 { 933 {
1043 pl->ob->casting_time--; 934 pl->ob->casting_time--;
1044 pl->ob->start_holding = 1; 935 pl->ob->start_holding = 1;
1045 } 936 }
937
1046 /* set spell_state so we can update the range in stats field */ 938 /* set spell_state so we can update the range in stats field */
1047 if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1)) 939 if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1))
1048 {
1049 pl->ob->start_holding = 0; 940 pl->ob->start_holding = 0;
1050 } 941 }
1051 } 942
1052 do_some_living (pl->ob); 943 do_some_living (pl->ob);
1053 /* draw(pl->ob); *//* updated in socket code */
1054 } 944 }
1055} 945}
1056 946
1057void 947static void
1058process_players2 (maptile *map) 948process_players2 ()
1059{ 949{
1060 player *pl;
1061
1062 /* Then check if any players should use weapon-speed instead of speed */ 950 /* Then check if any players should use weapon-speed instead of speed */
1063 for (pl = first_player; pl != NULL; pl = pl->next) 951 for_all_players (pl)
1064 { 952 {
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 - 953 /* The code that did weapon_sp handling here was out of place -
1076 * this isn't called until after the player has finished there 954 * 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 955 * actions, and is thus out of place. All we do here is bounds
1078 * checking. 956 * checking.
1079 */ 957 */
1085 /* This needs to be here - if the player is running, we need to 963 /* 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 964 * clear this each tick, but new commands are not being received
1087 * so execute_newserver_command() is never called 965 * so execute_newserver_command() is never called
1088 */ 966 */
1089 pl->has_hit = 0; 967 pl->has_hit = 0;
1090
1091 } 968 }
1092 else if (pl->ob->speed_left > pl->ob->speed) 969 else if (pl->ob->speed_left > pl->ob->speed)
1093 pl->ob->speed_left = pl->ob->speed; 970 pl->ob->speed_left = pl->ob->speed;
1094 } 971 }
1095} 972}
1096 973
1097void 974void
1098process_events (maptile *map) 975process_events ()
1099{ 976{
1100 object *op; 977 object *op;
1101 978
1102 static object *marker; 979 static object_ptr marker_;
980
1103 if (!marker) 981 if (!marker_)
1104 marker = get_object (); 982 marker_ = object::create ();
1105 983
984 object *marker = marker_;
985
1106 process_players1 (map); 986 process_players1 ();
1107 987
1108 marker->active_next = active_objects; 988 marker->active_next = active_objects;
1109 989
1110 if (marker->active_next) 990 if (marker->active_next)
1111 marker->active_next->active_prev = marker; 991 marker->active_next->active_prev = marker;
1112 992
1113 marker->active_prev = NULL; 993 marker->active_prev = 0;
1114 active_objects = marker; 994 active_objects = marker;
1115 995
1116 while (marker->active_next) 996 while (marker->active_next)
1117 { 997 {
1118 op = marker->active_next; 998 op = marker->active_next;
1135 1015
1136 /* Now process op */ 1016 /* Now process op */
1137 if (QUERY_FLAG (op, FLAG_FREED)) 1017 if (QUERY_FLAG (op, FLAG_FREED))
1138 { 1018 {
1139 LOG (llevError, "BUG: process_events(): Free object on list\n"); 1019 LOG (llevError, "BUG: process_events(): Free object on list\n");
1140 op->speed = 0; 1020 op->set_speed (0);
1141 update_ob_speed (op);
1142 continue; 1021 continue;
1143 } 1022 }
1144 1023
1145 /* I've seen occasional crashes due to this - the object is removed, 1024 /* 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 1025 * and thus the map it points to (last map it was on) may be bogus
1153 * around. 1032 * around.
1154 */ 1033 */
1155 if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY) 1034 if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY)
1156 { 1035 {
1157 LOG (llevError, "BUG: process_events(): Removed object on list\n"); 1036 LOG (llevError, "BUG: process_events(): Removed object on list\n");
1158 dump_object (op); 1037 char *dump = dump_object (op);
1159 LOG (llevError, errmsg); 1038 LOG (llevError, dump);
1160 free_object (op); 1039 free (dump);
1040 op->destroy ();
1161 continue; 1041 continue;
1162 } 1042 }
1163 1043
1164 if (!op->speed) 1044 if (!op->speed)
1165 { 1045 {
1166 LOG (llevError, "BUG: process_events(): Object %s has no speed, " "but is on active list\n", &op->arch->name); 1046 LOG (llevError, "BUG: process_events(): Object %s has no speed, "
1167 update_ob_speed (op); 1047 "but is on active list\n", &op->arch->name);
1048 op->set_speed (0);
1168 continue; 1049 continue;
1169 } 1050 }
1170 1051
1171 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP && map == NULL) 1052 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP)
1172 { 1053 {
1173 LOG (llevError, "BUG: process_events(): Object without map or " "inventory is on active list: %s (%d)\n", &op->name, op->count); 1054 LOG (llevError, "BUG: process_events(): Object without map or "
1055 "inventory is on active list: %s (%d)\n", &op->name, op->count);
1174 op->speed = 0; 1056 op->set_speed (0);
1175 update_ob_speed (op);
1176 continue; 1057 continue;
1177 } 1058 }
1178 1059
1179 if (map != NULL && op->map != map)
1180 continue;
1181
1182 /* Animate the object. Bug of feature that andim_speed 1060 /* Animate the object. Bug or feature that anim_speed
1183 * is based on ticks, and not the creatures speed? 1061 * is based on ticks, and not the creatures speed?
1184 */ 1062 */
1185 if (op->anim_speed && op->last_anim >= op->anim_speed) 1063 if (op->anim_speed && op->last_anim >= op->anim_speed)
1186 { 1064 {
1187 if ((op->type == PLAYER) || (op->type == MONSTER)) 1065 if ((op->type == PLAYER))
1188 animate_object (op, op->facing); 1066 animate_object (op, op->facing);
1189 else 1067 else
1190 animate_object (op, op->direction); 1068 animate_object (op, op->direction);
1191 1069
1192 op->last_anim = 1; 1070 op->last_anim = 1;
1228 if (marker->active_prev != NULL) 1106 if (marker->active_prev != NULL)
1229 marker->active_prev->active_next = NULL; 1107 marker->active_prev->active_next = NULL;
1230 else 1108 else
1231 active_objects = NULL; 1109 active_objects = NULL;
1232 1110
1233 process_players2 (map); 1111 process_players2 ();
1234} 1112}
1235 1113
1236void 1114void
1237clean_tmp_files (void) 1115clean_tmp_files (void)
1238{ 1116{
1242 1120
1243 /* We save the maps - it may not be intuitive why, but if there are unique 1121 /* 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 1122 * 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. 1123 * just make a special function that only saves the unique items.
1246 */ 1124 */
1247 for (m = first_map; m != NULL; m = next) 1125 for_all_maps (m)
1248 {
1249 next = m->next;
1250 if (m->in_memory == MAP_IN_MEMORY) 1126 if (m->in_memory == MAP_IN_MEMORY)
1251 {
1252 /* If we want to reuse the temp maps, swap it out (note that will also 1127 /* 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 1128 * 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 */ 1129 */
1258
1259 /* XXX The above comment is dead wrong */
1260 if (settings.recycle_tmp_maps == TRUE)
1261 swap_map (m); 1130 swap_map (m);
1262 else 1131
1263 {
1264 new_save_map (m, 0); /* note we save here into a overlay map */
1265 clean_tmp_map (m);
1266 }
1267 }
1268 }
1269 write_todclock (); /* lets just write the clock here */ 1132 write_todclock (); /* lets just write the clock here */
1270} 1133}
1271 1134
1272/* clean up everything before exiting */ 1135/* clean up everything before exiting */
1273void 1136void
1274cleanup (void) 1137cleanup (bool make_core)
1275{ 1138{
1276 LOG (llevDebug, "Cleanup called.\n"); 1139 LOG (llevDebug, "Cleanup called.\n");
1277 1140
1278 for (player *pl = first_player; pl != NULL; pl = pl->next) 1141 if (init_done)
1279 save_player (pl->ob, 0); 1142 {
1143 for_all_players (pl)
1144 pl->save (1);
1280 1145
1281 for (player *pl = first_player; pl != NULL; pl = pl->next) 1146 for_all_players (pl)
1282 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED)) 1147 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
1283 leave_map (pl->ob); 1148 leave_map (pl->ob);
1284 1149
1285 clean_tmp_files (); 1150 clean_tmp_files ();
1286 write_book_archive (); 1151 write_book_archive ();
1287 1152
1288 INVOKE_GLOBAL (CLEANUP); 1153 INVOKE_GLOBAL (CLEANUP);
1154 }
1289 1155
1156 if (make_core)
1157 abort ();
1158 else
1290 _exit (0); 1159 _exit (0);
1291} 1160}
1292 1161
1293void 1162void
1294leave (player *pl, int draw_exit) 1163leave (player *pl, int draw_exit)
1295{ 1164{
1296 if (pl != NULL) 1165 if (pl)
1297 { 1166 {
1167 if (pl->ob->type != DEAD_OBJECT)
1168 {
1169 /* If a hidden dm dropped connection do not create
1170 * inconsistencies by showing that they have left the game
1171 */
1172 if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden)
1173 && draw_exit)
1174 {
1175 if (pl->ob->map)
1176 {
1177 INVOKE_PLAYER (LOGOUT, pl);
1178 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->ns->host);
1179 }
1180
1181 char buf[MAX_BUF];
1182
1183 sprintf (buf, "%s left the game.", &pl->ob->name);
1184 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, 0, buf);
1185 }
1186
1187 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
1188 leave_map (pl->ob);
1189
1190 pl->ob->type = DEAD_OBJECT; /* To avoid problems with inventory window */
1191 }
1192
1298 /* We do this so that the socket handling routine can do the final 1193 /* 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 1194 * cleanup. We also leave that loop to actually handle the freeing
1300 * of the data. 1195 * of the data.
1301 */ 1196 */
1302 if (pl->ob->type != DEAD_OBJECT) 1197 if (pl->ns)
1303 { 1198 pl->ns->destroy ();
1304 pl->socket.status = Ns_Dead;
1305 1199
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 } 1200 }
1330} 1201}
1331 1202
1332int 1203int
1333forbid_play (void) 1204forbid_play (void)
1396extern unsigned long todtick; 1267extern unsigned long todtick;
1397 1268
1398void 1269void
1399do_specials (void) 1270do_specials (void)
1400{ 1271{
1401
1402#ifdef WATCHDOG
1403 if (!(pticks % 503))
1404 watchdog ();
1405#endif
1406
1407 if (!(pticks % PTICKS_PER_CLOCK)) 1272 if (!(pticks % PTICKS_PER_CLOCK))
1408 tick_the_clock (); 1273 tick_the_clock ();
1409 1274
1410 if (!(pticks % 7)) 1275 if (!(pticks % 7))
1411 shstr::gc (); 1276 shstr::gc ();
1414 flush_old_maps (); /* Clears the tmp-files of maps which have reset */ 1279 flush_old_maps (); /* Clears the tmp-files of maps which have reset */
1415 1280
1416 if (!(pticks % 2503)) 1281 if (!(pticks % 2503))
1417 fix_weight (); /* Hack to fix weightproblems caused by bugs */ 1282 fix_weight (); /* Hack to fix weightproblems caused by bugs */
1418 1283
1419 if (!(pticks % 2521))
1420 metaserver_update (); /* 2500 ticks is about 5 minutes */
1421
1422 if (!(pticks % 5003)) 1284 if (!(pticks % 5003))
1423 write_book_archive (); 1285 write_book_archive ();
1424 1286
1425 if (!(pticks % 5009)) 1287 if (!(pticks % 5009))
1426 clean_friendly_list (); 1288 clean_friendly_list ();
1435void 1297void
1436server_tick () 1298server_tick ()
1437{ 1299{
1438 nroferrors = 0; 1300 nroferrors = 0;
1439 1301
1302 // first do the user visible stuff
1440 doeric_server (); 1303 doeric_server ();
1441 INVOKE_GLOBAL (CLOCK); 1304 INVOKE_GLOBAL (CLOCK);
1442 process_events (NULL); /* "do" something with objects with speed */ 1305 process_events (); /* "do" something with objects with speed */
1443 flush_sockets (); 1306 flush_sockets ();
1307
1308 // then do some bookkeeping, should not really be here
1444 check_active_maps (); /* Removes unused maps after a certain timeout */ 1309 check_active_maps (); /* Removes unused maps after a certain timeout */
1445 do_specials (); /* Routines called from time to time. */ 1310 do_specials (); /* Routines called from time to time. */
1446 object::free_mortals (); 1311 attachable::check_mortals ();
1447 1312
1448 ++pticks; 1313 ++pticks;
1449} 1314}
1450 1315
1451int 1316int

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines