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.27 by root, Thu Sep 14 22:34:04 2006 UTC vs.
Revision 1.55 by root, Sat Dec 23 13:56:25 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
106 new_draw_info (NDI_UNIQUE, 0, op, "Images and art:"); 101 new_draw_info (NDI_UNIQUE, 0, op, "Images and art:");
107 new_draw_info (NDI_UNIQUE, 0, op, "Peter Gardner"); 102 new_draw_info (NDI_UNIQUE, 0, op, "Peter Gardner");
108 new_draw_info (NDI_UNIQUE, 0, op, "David Gervais [david_eg@mail.com]"); 103 new_draw_info (NDI_UNIQUE, 0, op, "David Gervais [david_eg@mail.com]");
109 new_draw_info (NDI_UNIQUE, 0, op, "Mitsuhiro Itakura [ita@gold.koma.jaeri.go.jp]"); 104 new_draw_info (NDI_UNIQUE, 0, op, "Mitsuhiro Itakura [ita@gold.koma.jaeri.go.jp]");
110 new_draw_info (NDI_UNIQUE, 0, op, "Hansjoerg Malthaner [hansjoerg.malthaner@danet.de]"); 105 new_draw_info (NDI_UNIQUE, 0, op, "Hansjoerg Malthaner [hansjoerg.malthaner@danet.de]");
111 new_draw_info (NDI_UNIQUE, 0, op, "Mårten Woxberg [maxmc@telia.com]"); 106 new_draw_info (NDI_UNIQUE, 0, op, "MÃ¥rten Woxberg [maxmc@telia.com]");
112 new_draw_info (NDI_UNIQUE, 0, op, "And many more!"); 107 new_draw_info (NDI_UNIQUE, 0, op, "And many more!");
113} 108}
114 109
115void 110void
116info_keys (object *op) 111info_keys (object *op)
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
191 * goes someplace. 148 * goes someplace.
192 */ 149 */
193void 150void
194enter_player_savebed (object *op) 151enter_player_savebed (object *op)
195{ 152{
196 mapstruct *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 mapstruct *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--;
197
239 if (oldmap->players <= 0) 198 if (oldmap->players <= 0)
240 { /* can be less than zero due to errors in tracking this */ 199 /* can be less than zero due to errors in tracking this */
241 set_map_timeout (oldmap); 200 set_map_timeout (oldmap);
242 }
243 } 201 }
244} 202}
245 203
246/* 204/*
247 * enter_map(): Moves the player and pets from current map (if any) to 205 * enter_map(): Moves the player and pets from current map (if any) to
249 * player to - it could be the map he just came from if the load failed for 207 * player to - it could be the map he just came from if the load failed for
250 * whatever reason. If default map coordinates are to be used, then 208 * whatever reason. If default map coordinates are to be used, then
251 * the function that calls this should figure them out. 209 * the function that calls this should figure them out.
252 */ 210 */
253static void 211static void
254enter_map (object *op, mapstruct *newmap, int x, int y) 212enter_map (object *op, maptile *newmap, int x, int y)
255{ 213{
256 mapstruct *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 = MAP_ENTER_X (newmap);
266 newmap->path, x, y, MAP_WIDTH (newmap), MAP_HEIGHT (newmap)); 224 newmap->path, x, y, MAP_WIDTH (newmap), MAP_HEIGHT (newmap));
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 }
229
271 /* try to find a spot for the player */ 230 /* try to find a spot for the player */
272 if (ob_blocked (op, newmap, x, y)) 231 if (ob_blocked (op, newmap, x, y))
273 { /* First choice blocked */ 232 { /* First choice blocked */
274 /* We try to find a spot for the player, starting closest in. 233 /* We try to find a spot for the player, starting closest in.
275 * We could use find_first_free_spot, but that doesn't randomize it at all, 234 * We could use find_first_free_spot, but that doesn't randomize it at all,
284 { 243 {
285 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE2 + 1); 244 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE2 + 1);
286 if (i == -1) 245 if (i == -1)
287 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE); 246 i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE);
288 } 247 }
248
289 if (i != -1) 249 if (i != -1)
290 { 250 {
291 x += freearr_x[i]; 251 x += freearr_x[i];
292 y += freearr_y[i]; 252 y += freearr_y[i];
293 } 253 }
296 /* not much we can do in this case. */ 256 /* not much we can do in this case. */
297 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);
298 } 258 }
299 } /* end if looking for free spot */ 259 } /* end if looking for free spot */
300 260
301 if (op->map != NULL) 261 if (op->map)
302 {
303 INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (op->map), ARG_MAP (newmap));
304 INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr)); 262 if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr)))
305 } 263 return;
264
265 if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y)))
266 return;
267
268 if (INVOKE_MAP (ENTER, newmap, ARG_PLAYER (op->contr), ARG_INT (x), ARG_INT (y)))
269 return;
306 270
307 /* 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.
308 * otherwise, we need to deal with removing the player here. 272 * otherwise, we need to deal with removing the player here.
309 */ 273 */
310 if (!QUERY_FLAG (op, FLAG_REMOVED)) 274 op->remove ();
311 remove_ob (op);
312 275
313 /* 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 */
314 op->x = x; 277 op->x = x;
315 op->y = y; 278 op->y = y;
316 op->map = newmap; 279 op->map = newmap;
280
317 insert_ob_in_map (op, op->map, NULL, INS_NO_WALK_ON); 281 insert_ob_in_map (op, op->map, NULL, INS_NO_WALK_ON);
318
319 INVOKE_MAP (ENTER, op->map, ARG_PLAYER (op->contr));
320 282
321 if (!op->contr->hidden) 283 if (!op->contr->hidden)
322 newmap->players++; 284 newmap->players++;
323 285
324 newmap->timeout = 0; 286 newmap->timeout = 0;
334 if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL) 296 if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL)
335 { 297 {
336 int i = find_free_spot (op->contr->ranges[range_golem], newmap, 298 int i = find_free_spot (op->contr->ranges[range_golem], newmap,
337 x, y, 1, SIZEOFFREE); 299 x, y, 1, SIZEOFFREE);
338 300
339 remove_ob (op->contr->ranges[range_golem]); 301 op->contr->ranges[range_golem]->remove ();
302
340 if (i == -1) 303 if (i == -1)
341 { 304 {
342 remove_friendly_object (op->contr->ranges[range_golem]); 305 remove_friendly_object (op->contr->ranges[range_golem]);
343 free_object (op->contr->ranges[range_golem]); 306 op->contr->ranges[range_golem]->destroy ();
344 op->contr->ranges[range_golem] = NULL; 307 op->contr->ranges[range_golem] = 0;
345 op->contr->golem_count = 0;
346 } 308 }
347 else 309 else
348 { 310 {
349 object *tmp;
350
351 for (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)
352 { 312 {
353 tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); 313 tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x);
354 tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); 314 tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y);
355 tmp->map = newmap; 315 tmp->map = newmap;
356 } 316 }
317
357 insert_ob_in_map (op->contr->ranges[range_golem], newmap, NULL, 0); 318 insert_ob_in_map (op->contr->ranges[range_golem], newmap, NULL, 0);
358 op->contr->ranges[range_golem]->direction = 319 op->contr->ranges[range_golem]->direction =
359 find_dir_2 (op->x - op->contr->ranges[range_golem]->x, op->y - op->contr->ranges[range_golem]->y); 320 find_dir_2 (op->x - op->contr->ranges[range_golem]->x, op->y - op->contr->ranges[range_golem]->y);
360 } 321 }
361 } 322 }
323
362 op->direction = 0; 324 op->direction = 0;
363 325
364 /* since the players map is already loaded, we don't need to worry 326 /* since the players map is already loaded, we don't need to worry
365 * about pending objects. 327 * about pending objects.
366 */ 328 */
381 } 343 }
382 } 344 }
383} 345}
384 346
385void 347void
386set_map_timeout (mapstruct *oldmap) 348set_map_timeout (maptile *oldmap)
387{ 349{
388#if MAP_MAXTIMEOUT 350#if MAP_MAXTIMEOUT
389 oldmap->timeout = MAP_TIMEOUT (oldmap); 351 oldmap->timeout = MAP_TIMEOUT (oldmap);
390 /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is 352 /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is
391 * lower than the min value. 353 * lower than the min value.
392 */ 354 */
393# if MAP_MINTIMEOUT 355# if MAP_MINTIMEOUT
394 if (oldmap->timeout < MAP_MINTIMEOUT) 356 if (oldmap->timeout < MAP_MINTIMEOUT)
395 {
396 oldmap->timeout = MAP_MINTIMEOUT; 357 oldmap->timeout = MAP_MINTIMEOUT;
397 }
398# endif 358# endif
359
399 if (oldmap->timeout > MAP_MAXTIMEOUT) 360 if (oldmap->timeout > MAP_MAXTIMEOUT)
400 {
401 oldmap->timeout = MAP_MAXTIMEOUT; 361 oldmap->timeout = MAP_MAXTIMEOUT;
402 } 362
403#else 363#else
404 /* save out the map */ 364 /* save out the map */
405 swap_map (oldmap); 365 swap_map (oldmap);
406#endif /* MAP_MAXTIMEOUT */ 366#endif /* MAP_MAXTIMEOUT */
407} 367}
452 */ 412 */
453 413
454static void 414static void
455enter_random_map (object *pl, object *exit_ob) 415enter_random_map (object *pl, object *exit_ob)
456{ 416{
457 mapstruct *new_map; 417 maptile *new_map;
458 char newmap_name[HUGE_BUF], *cp; 418 char newmap_name[HUGE_BUF], *cp;
459 static int reference_number = 0; 419 static int reference_number = 0;
460 RMParms rp; 420 RMParms rp;
461 421
462 memset (&rp, 0, sizeof (RMParms)); 422 memset (&rp, 0, sizeof (RMParms));
469 rp.origin_y = exit_ob->y; 429 rp.origin_y = exit_ob->y;
470 strcpy (rp.origin_map, pl->map->path); 430 strcpy (rp.origin_map, pl->map->path);
471 431
472 /* 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
473 * as where the player is. Otherwise, use the origin map. 433 * as where the player is. Otherwise, use the origin map.
474 * Take the last component (after the last slash) to give
475 * shorter names without bogus slashes.
476 */ 434 */
477 if (rp.final_map[0]) 435 sprintf (newmap_name, "/random%s+%04d",
478 { 436 *rp.final_map ? rp.final_map : rp.origin_map,
479 cp = strrchr (rp.final_map, '/'); 437 reference_number++);
480 if (!cp)
481 cp = rp.final_map;
482 }
483 else
484 {
485 char buf[HUGE_BUF];
486
487 cp = strrchr (rp.origin_map, '/');
488 if (!cp)
489 cp = rp.origin_map;
490 /* Need to strip of any trailing digits, if it has them */
491 strcpy (buf, cp);
492 while (isdigit (buf[strlen (buf) - 1]))
493 buf[strlen (buf) - 1] = 0;
494 cp = buf;
495 }
496
497 sprintf (newmap_name, "/random/%s%04d", cp + 1, reference_number++);
498 438
499 /* now to generate the actual map. */ 439 /* now to generate the actual map. */
500 new_map = generate_random_map (newmap_name, &rp); 440 new_map = generate_random_map (newmap_name, &rp);
501 441
502 /* 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
522 */ 462 */
523 463
524static void 464static void
525enter_fixed_template_map (object *pl, object *exit_ob) 465enter_fixed_template_map (object *pl, object *exit_ob)
526{ 466{
527 mapstruct *new_map; 467 maptile *new_map;
528 char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap; 468 char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap;
529 const char *new_map_name; 469 const char *new_map_name;
530 470
531 /* Split the exit path string into two parts, one 471 /* Split the exit path string into two parts, one
532 * for where to store the map, and one for were 472 * for where to store the map, and one for were
541 */ 481 */
542 LOG (llevError, "enter_fixed_template_map: Exit %s (%d,%d) on map %s has no source template.\n", 482 LOG (llevError, "enter_fixed_template_map: Exit %s (%d,%d) on map %s has no source template.\n",
543 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); 483 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path);
544 return; 484 return;
545 } 485 }
486
546 *sourcemap++ = '\0'; 487 *sourcemap++ = '\0';
547 488
548 /* If we are not coming from a template map, we can use relative directories 489 /* If we are not coming from a template map, we can use relative directories
549 * for the map to generate from. 490 * for the map to generate from.
550 */ 491 */
551 if (!exit_ob->map->templatemap) 492 if (!exit_ob->map->templatemap)
552 {
553 sourcemap = path_combine_and_normalize (exit_ob->map->path, sourcemap); 493 sourcemap = path_combine_and_normalize (exit_ob->map->path, sourcemap);
554 }
555 494
556 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord 495 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord
557 * of the exit, and the name of the map the exit is on, respectively. 496 * of the exit, and the name of the map the exit is on, respectively.
558 */ 497 */
559 sprintf (tmpnum, "%d", exit_ob->x); 498 sprintf (tmpnum, "%d", exit_ob->x);
568 507
569 /* If we are coming from another template map, use reletive paths unless 508 /* If we are coming from another template map, use reletive paths unless
570 * indicated otherwise. 509 * indicated otherwise.
571 */ 510 */
572 if (exit_ob->map->templatemap && (resultname[0] != '/')) 511 if (exit_ob->map->templatemap && (resultname[0] != '/'))
573 {
574 new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); 512 new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname);
575 }
576 else 513 else
577 {
578 new_map_name = create_template_pathname (resultname); 514 new_map_name = create_template_pathname (resultname);
579 }
580 515
581 /* Attempt to load the map, if unable to, then 516 /* Attempt to load the map, if unable to, then
582 * create the map from the template. 517 * create the map from the template.
583 */ 518 */
584 new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); 519 new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE);
606 LOG (llevDebug, "enter_fixed_template_map: Exit %s (%d,%d) on map %s leads no where.\n", 541 LOG (llevDebug, "enter_fixed_template_map: Exit %s (%d,%d) on map %s leads no where.\n",
607 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); 542 &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path);
608 } 543 }
609} 544}
610 545
611
612/* The player is trying to enter a randomly generated template map. In this 546/* The player is trying to enter a randomly generated template map. In this
613 * case, generate the map as needed. 547 * case, generate the map as needed.
614 */ 548 */
615 549
616static void 550static void
617enter_random_template_map (object *pl, object *exit_ob) 551enter_random_template_map (object *pl, object *exit_ob)
618{ 552{
619 mapstruct *new_map; 553 maptile *new_map;
620 char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF]; 554 char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF];
621 const char *new_map_name; 555 const char *new_map_name;
622 RMParms rp; 556 RMParms rp;
623 557
624 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord 558 /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord
636 570
637 /* 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
638 * indicated otherwise. 572 * indicated otherwise.
639 */ 573 */
640 if (exit_ob->map->templatemap && (resultname[0] != '/')) 574 if (exit_ob->map->templatemap && (resultname[0] != '/'))
641 {
642 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);
643 }
644 else 576 else
645 {
646 new_map_name = create_template_pathname (resultname); 577 new_map_name = create_template_pathname (resultname);
647 }
648 578
649 new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); 579 new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE);
650 if (!new_map) 580 if (!new_map)
651 { 581 {
652 memset (&rp, 0, sizeof (RMParms)); 582 memset (&rp, 0, sizeof (RMParms));
686 */ 616 */
687static void 617static void
688enter_unique_map (object *op, object *exit_ob) 618enter_unique_map (object *op, object *exit_ob)
689{ 619{
690 char apartment[HUGE_BUF]; 620 char apartment[HUGE_BUF];
691 mapstruct *newmap; 621 maptile *newmap;
692 622
693 if (EXIT_PATH (exit_ob)[0] == '/') 623 if (EXIT_PATH (exit_ob)[0] == '/')
694 { 624 {
695 sprintf (apartment, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, clean_path (EXIT_PATH (exit_ob))); 625 sprintf (apartment, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, clean_path (EXIT_PATH (exit_ob)));
696 newmap = ready_map_name (apartment, MAP_PLAYER_UNIQUE); 626 newmap = ready_map_name (apartment, MAP_PLAYER_UNIQUE);
780#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 */
781 object *tmp; 711 object *tmp;
782 712
783 /* It may be nice to support other creatures moving across 713 /* It may be nice to support other creatures moving across
784 * 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,
785 * so thta is an RFE. 715 * so that is an RFE.
786 */ 716 */
787 if (op->type != PLAYER) 717 if (op->type != PLAYER)
788 return; 718 return;
789 719
790 /* 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 */
791 if (exit_ob) 721 if (exit_ob)
792 { 722 {
793
794 /* check to see if we make a template map */ 723 /* check to see if we make a template map */
795 if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@') 724 if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@')
796 { 725 {
797 if (EXIT_PATH (exit_ob)[2] == '!') 726 if (EXIT_PATH (exit_ob)[2] == '!')
798 { 727 {
819 int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob); 748 int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob);
820 749
821 /* 'Normal' exits that do not do anything special 750 /* 'Normal' exits that do not do anything special
822 * Simple enough we don't need another routine for it. 751 * Simple enough we don't need another routine for it.
823 */ 752 */
824 mapstruct *newmap; 753 maptile *newmap;
825 754
826 if (exit_ob->map) 755 if (exit_ob->map)
827 { 756 {
828 newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0); 757 newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0);
829 /* Random map was previously generated, but is no longer about. Lets generate a new 758 /* Random map was previously generated, but is no longer about. Lets generate a new
897 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))
898 break; 827 break;
899 } 828 }
900 if (tmp) 829 if (tmp)
901 { 830 {
902 remove_ob (tmp); 831 tmp->remove ();
903 free_object (tmp); 832 tmp->destroy ();
904 } 833 }
905 834
906 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)));
907 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);
908 save_player (op, 1); 837 op->contr->save ();
909 /* 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",
910 * 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,
911 * 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))); */
912 } 841 }
913 842
918 hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1); 847 hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1);
919 } 848 }
920 else 849 else
921 { 850 {
922 int flags = 0; 851 int flags = 0;
923 mapstruct *newmap; 852 maptile *newmap;
924
925 853
926 /* Hypothetically, I guess its possible that a standard map matches 854 /* Hypothetically, I guess its possible that a standard map matches
927 * the localdir, but that seems pretty unlikely - unlikely enough that 855 * the localdir, but that seems pretty unlikely - unlikely enough that
928 * I'm not going to attempt to try to deal with that possibility. 856 * I'm not going to attempt to try to deal with that possibility.
929 * We use the fact that when a player saves on a unique map, it prepends 857 * We use the fact that when a player saves on a unique map, it prepends
950 { 878 {
951 LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n"); 879 LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n");
952 abort (); 880 abort ();
953 } 881 }
954 } 882 }
883
955 enter_map (op, newmap, op->x, op->y); 884 enter_map (op, newmap, op->x, op->y);
956 } 885 }
957} 886}
958
959/*
960 * process_active_maps(): Works like process_events(), but it only
961 * processes maps which a player is on.
962 *
963 */
964
965#if 0 // dead code, schmorp
966void
967process_active_maps ()
968{
969 for (mapstruct *map = first_map; map != NULL; map = map->next)
970 if (map->in_memory == MAP_IN_MEMORY)
971 if (players_on_map (map, TRUE))
972 process_events (map);
973}
974#endif
975 887
976/* process_players1 and process_players2 do all the player related stuff. 888/* process_players1 and process_players2 do all the player related stuff.
977 * 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
978 * 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
979 * by the various functions. process_players1() does the processing before 891 * by the various functions. process_players1() does the processing before
980 * objects have been updated, process_players2() does the processing that 892 * objects have been updated, process_players2() does the processing that
981 * is needed after the players have been updated. 893 * is needed after the players have been updated.
982 */ 894 */
983 895static void
984void 896process_players1 ()
985process_players1 (mapstruct *map)
986{ 897{
987 int flag; 898 int flag;
988 player *pl, *plnext;
989 899
990 /* 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. */
991 for (flag = 1; flag != 0;) 901 for (flag = 1; flag != 0;)
992 { 902 {
993 flag = 0; 903 flag = 0;
994 for (pl = first_player; pl != NULL; pl = plnext) 904 for (player *plnext, *pl = first_player; pl; pl = plnext)
995 { 905 {
996 plnext = pl->next; /* In case a player exits the game in handle_player() */ 906 plnext = pl->next; /* In case a player exits the game in handle_player() */
997 907
998 if (pl->ob == NULL) 908 if (!pl->ob)
999 continue;
1000
1001 if (map != NULL && pl->ob->map != map)
1002 continue; 909 continue;
1003 910
1004 if (pl->ob->speed_left > 0) 911 if (pl->ob->speed_left > 0)
1005 { 912 {
1006 if (handle_newcs_player (pl->ob)) 913 if (handle_newcs_player (pl->ob))
1018 925
1019#ifdef AUTOSAVE 926#ifdef AUTOSAVE
1020 /* check for ST_PLAYING state so that we don't try to save off when 927 /* check for ST_PLAYING state so that we don't try to save off when
1021 * the player is logging in. 928 * the player is logging in.
1022 */ 929 */
1023 if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->state == ST_PLAYING) 930 if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->ns->state == ST_PLAYING)
1024 {
1025 /* Don't save the player on unholy ground. Instead, increase the
1026 * tick time so it will be about 10 seconds before we try and save
1027 * again.
1028 */ 931 {
1029// if (get_map_flags(pl->ob->map, NULL, pl->ob->x, pl->ob->y, NULL, NULL) & P_NO_CLERIC) { 932 pl->ob->contr->save ();
1030// pl->last_save_tick += 100;
1031// } else {
1032 save_player (pl->ob, 1);
1033 pl->last_save_tick = pticks; 933 pl->last_save_tick = pticks;
1034// }
1035 } 934 }
1036#endif 935#endif
1037 } /* end of for loop for all the players */ 936 } /* end of for loop for all the players */
1038 } /* for flag */ 937 } /* for flag */
1039 for (pl = first_player; pl != NULL; pl = pl->next) 938
939 for_all_players (pl)
1040 { 940 {
1041 if (map != NULL && (pl->ob == NULL || pl->ob->map != map))
1042 continue;
1043 if (settings.casting_time == TRUE) 941 if (settings.casting_time)
1044 { 942 {
1045 if (pl->ob->casting_time > 0) 943 if (pl->ob->casting_time > 0)
1046 { 944 {
1047 pl->ob->casting_time--; 945 pl->ob->casting_time--;
1048 pl->ob->start_holding = 1; 946 pl->ob->start_holding = 1;
1049 } 947 }
948
1050 /* set spell_state so we can update the range in stats field */ 949 /* set spell_state so we can update the range in stats field */
1051 if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1)) 950 if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1))
1052 {
1053 pl->ob->start_holding = 0; 951 pl->ob->start_holding = 0;
1054 } 952 }
1055 } 953
1056 do_some_living (pl->ob); 954 do_some_living (pl->ob);
1057 /* draw(pl->ob); *//* updated in socket code */
1058 } 955 }
1059} 956}
1060 957
1061void 958static void
1062process_players2 (mapstruct *map) 959process_players2 ()
1063{ 960{
1064 player *pl;
1065
1066 /* Then check if any players should use weapon-speed instead of speed */ 961 /* Then check if any players should use weapon-speed instead of speed */
1067 for (pl = first_player; pl != NULL; pl = pl->next) 962 for_all_players (pl)
1068 { 963 {
1069 if (map != NULL)
1070 {
1071 if (pl->ob == NULL || QUERY_FLAG (pl->ob, FLAG_REMOVED))
1072 continue;
1073 else if (pl->loading != NULL) /* Player is blocked */
1074 pl->ob->speed_left -= pl->ob->speed;
1075 if (pl->ob->map != map)
1076 continue;
1077 }
1078
1079 /* The code that did weapon_sp handling here was out of place - 964 /* The code that did weapon_sp handling here was out of place -
1080 * this isn't called until after the player has finished there 965 * this isn't called until after the player has finished there
1081 * actions, and is thus out of place. All we do here is bounds 966 * actions, and is thus out of place. All we do here is bounds
1082 * checking. 967 * checking.
1083 */ 968 */
1089 /* This needs to be here - if the player is running, we need to 974 /* This needs to be here - if the player is running, we need to
1090 * clear this each tick, but new commands are not being received 975 * clear this each tick, but new commands are not being received
1091 * so execute_newserver_command() is never called 976 * so execute_newserver_command() is never called
1092 */ 977 */
1093 pl->has_hit = 0; 978 pl->has_hit = 0;
1094
1095 } 979 }
1096 else if (pl->ob->speed_left > pl->ob->speed) 980 else if (pl->ob->speed_left > pl->ob->speed)
1097 pl->ob->speed_left = pl->ob->speed; 981 pl->ob->speed_left = pl->ob->speed;
1098 } 982 }
1099} 983}
1100 984
1101void 985void
1102process_events (mapstruct *map) 986process_events ()
1103{ 987{
1104 object *op; 988 object *op;
1105 tag_t tag;
1106 989
1107 static object *marker; 990 static object *marker;
1108 991
1109 if (!marker) 992 if (!marker)
1110 marker = get_object (); 993 marker = object::create ();
1111 994
1112 process_players1 (map); 995 process_players1 ();
1113 996
1114 marker->active_next = active_objects; 997 marker->active_next = active_objects;
1115 998
1116 if (marker->active_next) 999 if (marker->active_next)
1117 marker->active_next->active_prev = marker; 1000 marker->active_next->active_prev = marker;
1120 active_objects = marker; 1003 active_objects = marker;
1121 1004
1122 while (marker->active_next) 1005 while (marker->active_next)
1123 { 1006 {
1124 op = marker->active_next; 1007 op = marker->active_next;
1125 tag = op->count;
1126 1008
1127 /* Move marker forward - swap op and marker */ 1009 /* Move marker forward - swap op and marker */
1128 op->active_prev = marker->active_prev; 1010 op->active_prev = marker->active_prev;
1129 1011
1130 if (op->active_prev) 1012 if (op->active_prev)
1160 * around. 1042 * around.
1161 */ 1043 */
1162 if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY) 1044 if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY)
1163 { 1045 {
1164 LOG (llevError, "BUG: process_events(): Removed object on list\n"); 1046 LOG (llevError, "BUG: process_events(): Removed object on list\n");
1165 dump_object (op); 1047 char *dump = dump_object (op);
1166 LOG (llevError, errmsg); 1048 LOG (llevError, dump);
1167 free_object (op); 1049 free (dump);
1050 op->destroy ();
1168 continue; 1051 continue;
1169 } 1052 }
1170 1053
1171 if (!op->speed) 1054 if (!op->speed)
1172 { 1055 {
1173 LOG (llevError, "BUG: process_events(): Object %s has no speed, " "but is on active list\n", &op->arch->name); 1056 LOG (llevError, "BUG: process_events(): Object %s has no speed, "
1057 "but is on active list\n", &op->arch->name);
1174 update_ob_speed (op); 1058 update_ob_speed (op);
1175 continue; 1059 continue;
1176 } 1060 }
1177 1061
1178 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP && map == NULL) 1062 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP)
1179 { 1063 {
1180 LOG (llevError, "BUG: process_events(): Object without map or " "inventory is on active list: %s (%d)\n", &op->name, op->count); 1064 LOG (llevError, "BUG: process_events(): Object without map or "
1065 "inventory is on active list: %s (%d)\n", &op->name, op->count);
1181 op->speed = 0; 1066 op->speed = 0;
1182 update_ob_speed (op); 1067 update_ob_speed (op);
1183 continue; 1068 continue;
1184 } 1069 }
1185 1070
1186 if (map != NULL && op->map != map)
1187 continue;
1188
1189 /* Animate the object. Bug of feature that andim_speed 1071 /* Animate the object. Bug or feature that anim_speed
1190 * is based on ticks, and not the creatures speed? 1072 * is based on ticks, and not the creatures speed?
1191 */ 1073 */
1192 if (op->anim_speed && op->last_anim >= op->anim_speed) 1074 if (op->anim_speed && op->last_anim >= op->anim_speed)
1193 { 1075 {
1194 if ((op->type == PLAYER) || (op->type == MONSTER)) 1076 if ((op->type == PLAYER))
1195 animate_object (op, op->facing); 1077 animate_object (op, op->facing);
1196 else 1078 else
1197 animate_object (op, op->direction); 1079 animate_object (op, op->direction);
1198 1080
1199 op->last_anim = 1; 1081 op->last_anim = 1;
1217 LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null"); 1099 LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null");
1218 } 1100 }
1219#endif 1101#endif
1220 --op->speed_left; 1102 --op->speed_left;
1221 process_object (op); 1103 process_object (op);
1104
1222 if (was_destroyed (op, tag)) 1105 if (op->destroyed ())
1223 continue; 1106 continue;
1224 } 1107 }
1108
1225 if (settings.casting_time == TRUE && op->casting_time > 0) 1109 if (settings.casting_time == TRUE && op->casting_time > 0)
1226 op->casting_time--; 1110 op->casting_time--;
1111
1227 if (op->speed_left <= 0) 1112 if (op->speed_left <= 0)
1228 op->speed_left += FABS (op->speed); 1113 op->speed_left += FABS (op->speed);
1229 } 1114 }
1230 1115
1231 /* Remove marker object from active list */ 1116 /* Remove marker object from active list */
1232 if (marker->active_prev != NULL) 1117 if (marker->active_prev != NULL)
1233 marker->active_prev->active_next = NULL; 1118 marker->active_prev->active_next = NULL;
1234 else 1119 else
1235 active_objects = NULL; 1120 active_objects = NULL;
1236 1121
1237 process_players2 (map); 1122 process_players2 ();
1238} 1123}
1239 1124
1240void 1125void
1241clean_tmp_files (void) 1126clean_tmp_files (void)
1242{ 1127{
1243 mapstruct *m, *next; 1128 maptile *m, *next;
1244 1129
1245 LOG (llevInfo, "Cleaning up...\n"); 1130 LOG (llevInfo, "Cleaning up...\n");
1246 1131
1247 /* We save the maps - it may not be intuitive why, but if there are unique 1132 /* We save the maps - it may not be intuitive why, but if there are unique
1248 * items, we need to save the map so they get saved off. Perhaps we should 1133 * items, we need to save the map so they get saved off. Perhaps we should
1249 * just make a special function that only saves the unique items. 1134 * just make a special function that only saves the unique items.
1250 */ 1135 */
1251 for (m = first_map; m != NULL; m = next) 1136 for (m = first_map; m; m = next)
1252 { 1137 {
1253 next = m->next; 1138 next = m->next;
1139
1254 if (m->in_memory == MAP_IN_MEMORY) 1140 if (m->in_memory == MAP_IN_MEMORY)
1255 { 1141 {
1256 /* If we want to reuse the temp maps, swap it out (note that will also 1142 /* If we want to reuse the temp maps, swap it out (note that will also
1257 * update the log file. Otherwise, save the map (mostly for unique item 1143 * update the log file.
1258 * stuff). Note that the clean_tmp_map is called after the end of
1259 * the for loop but is in the #else bracket. IF we are recycling the maps,
1260 * we certainly don't want the temp maps removed.
1261 */ 1144 */
1262 1145
1263 /* XXX The above comment is dead wrong */
1264 if (settings.recycle_tmp_maps == TRUE)
1265 swap_map (m); 1146 swap_map (m);
1266 else
1267 {
1268 new_save_map (m, 0); /* note we save here into a overlay map */
1269 clean_tmp_map (m);
1270 } 1147 }
1271 }
1272 } 1148 }
1149
1273 write_todclock (); /* lets just write the clock here */ 1150 write_todclock (); /* lets just write the clock here */
1274} 1151}
1275 1152
1276/* clean up everything before exiting */ 1153/* clean up everything before exiting */
1277void 1154void
1278cleanup (void) 1155cleanup (bool make_core)
1279{ 1156{
1280 LOG (llevDebug, "Cleanup called.\n"); 1157 LOG (llevDebug, "Cleanup called.\n");
1158
1159 if (init_done)
1160 {
1161 for_all_players (pl)
1162 pl->save (1);
1163
1164 for_all_players (pl)
1165 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
1166 leave_map (pl->ob);
1167
1168 clean_tmp_files ();
1281 write_book_archive (); 1169 write_book_archive ();
1282 1170
1283 INVOKE_GLOBAL (CLEANUP); 1171 INVOKE_GLOBAL (CLEANUP);
1172 }
1284 1173
1174 if (make_core)
1175 abort ();
1176 else
1285 _exit (0); 1177 _exit (0);
1286} 1178}
1287 1179
1288void 1180void
1289leave (player *pl, int draw_exit) 1181leave (player *pl, int draw_exit)
1290{ 1182{
1291 if (pl != NULL) 1183 if (pl)
1292 { 1184 {
1185 if (pl->ob->type != DEAD_OBJECT)
1186 {
1187 /* If a hidden dm dropped connection do not create
1188 * inconsistencies by showing that they have left the game
1189 */
1190 if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden)
1191 && draw_exit)
1192 {
1193 if (pl->ob->map)
1194 {
1195 INVOKE_PLAYER (LOGOUT, pl);
1196 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->ns->host);
1197 }
1198
1199 char buf[MAX_BUF];
1200
1201 sprintf (buf, "%s left the game.", &pl->ob->name);
1202 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, 0, buf);
1203 }
1204
1205 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
1206 leave_map (pl->ob);
1207
1208 pl->ob->type = DEAD_OBJECT; /* To avoid problems with inventory window */
1209 }
1210
1293 /* We do this so that the socket handling routine can do the final 1211 /* We do this so that the socket handling routine can do the final
1294 * cleanup. We also leave that loop to actually handle the freeing 1212 * cleanup. We also leave that loop to actually handle the freeing
1295 * of the data. 1213 * of the data.
1296 */ 1214 */
1297 if (pl->ob->type != DEAD_OBJECT) 1215 if (pl->ns)
1298 { 1216 pl->ns->destroy ();
1299 pl->socket.status = Ns_Dead;
1300 1217
1301 /* If a hidden dm dropped connection do not create
1302 * inconsistencies by showing that they have left the game
1303 */
1304 if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden)
1305 && draw_exit && (pl->state != ST_GET_NAME && pl->state != ST_GET_PASSWORD && pl->state != ST_CONFIRM_PASSWORD))
1306 {
1307 if (pl->ob->map)
1308 {
1309 INVOKE_PLAYER (LOGOUT, pl);
1310 LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->socket.host);
1311 }
1312
1313 char buf[MAX_BUF];
1314
1315 sprintf (buf, "%s left the game.", &pl->ob->name);
1316 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, buf);
1317 }
1318
1319 if (!QUERY_FLAG (pl->ob, FLAG_REMOVED))
1320 leave_map (pl->ob);
1321
1322 pl->ob->type = DEAD_OBJECT; /* To avoid problems with inventory window */
1323 }
1324 } 1218 }
1325} 1219}
1326 1220
1327int 1221int
1328forbid_play (void) 1222forbid_play (void)
1391extern unsigned long todtick; 1285extern unsigned long todtick;
1392 1286
1393void 1287void
1394do_specials (void) 1288do_specials (void)
1395{ 1289{
1396
1397#ifdef WATCHDOG
1398 if (!(pticks % 503))
1399 watchdog ();
1400#endif
1401
1402 if (!(pticks % PTICKS_PER_CLOCK)) 1290 if (!(pticks % PTICKS_PER_CLOCK))
1403 tick_the_clock (); 1291 tick_the_clock ();
1404 1292
1405 if (!(pticks % 7)) 1293 if (!(pticks % 7))
1406 shstr::gc (); 1294 shstr::gc ();
1409 flush_old_maps (); /* Clears the tmp-files of maps which have reset */ 1297 flush_old_maps (); /* Clears the tmp-files of maps which have reset */
1410 1298
1411 if (!(pticks % 2503)) 1299 if (!(pticks % 2503))
1412 fix_weight (); /* Hack to fix weightproblems caused by bugs */ 1300 fix_weight (); /* Hack to fix weightproblems caused by bugs */
1413 1301
1414 if (!(pticks % 2521))
1415 metaserver_update (); /* 2500 ticks is about 5 minutes */
1416
1417 if (!(pticks % 5003)) 1302 if (!(pticks % 5003))
1418 write_book_archive (); 1303 write_book_archive ();
1419 1304
1420 if (!(pticks % 5009)) 1305 if (!(pticks % 5009))
1421 clean_friendly_list (); 1306 clean_friendly_list ();
1430void 1315void
1431server_tick () 1316server_tick ()
1432{ 1317{
1433 nroferrors = 0; 1318 nroferrors = 0;
1434 1319
1320 // first do the user visible stuff
1435 doeric_server (); 1321 doeric_server ();
1436 INVOKE_GLOBAL (CLOCK); 1322 INVOKE_GLOBAL (CLOCK);
1437 process_events (NULL); /* "do" something with objects with speed */ 1323 process_events (); /* "do" something with objects with speed */
1438 flush_sockets (); 1324 flush_sockets ();
1325
1326 // then do some bookkeeping, should not really be here
1439 check_active_maps (); /* Removes unused maps after a certain timeout */ 1327 check_active_maps (); /* Removes unused maps after a certain timeout */
1440 do_specials (); /* Routines called from time to time. */ 1328 do_specials (); /* Routines called from time to time. */
1441 object::free_mortals (); 1329 object::free_mortals ();
1442 1330
1443 ++pticks; 1331 ++pticks;
1447main (int argc, char **argv) 1335main (int argc, char **argv)
1448{ 1336{
1449 settings.argc = argc; 1337 settings.argc = argc;
1450 settings.argv = argv; 1338 settings.argv = argv;
1451 1339
1452 cfperl_init ();
1453
1454 init (argc, argv); 1340 init (argc, argv);
1455 1341
1456 initPlugins (); 1342 initPlugins ();
1457 1343
1458 for (;;) 1344 for (;;)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines