ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/main.C
Revision: 1.82
Committed: Tue Jan 9 01:28:32 2007 UTC (17 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.81: +3 -8 lines
Log Message:
- fix This exit is cloed on login because the maplevel of
  players not on any map was not saved.

File Contents

# User Rev Content
1 elmex 1.1 /*
2     CrossFire, A Multiplayer game for X-windows
3    
4 pippijn 1.80 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 elmex 1.1 Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team
6     Copyright (C) 1992 Frank Tore Johansen
7    
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12    
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     GNU General Public License for more details.
17    
18     You should have received a copy of the GNU General Public License
19     along with this program; if not, write to the Free Software
20     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21    
22 root 1.27 The authors can be reached via e-mail at <crossfire@schmorp.de>
23 elmex 1.1 */
24    
25     #include <global.h>
26     #include <object.h>
27     #include <tod.h>
28    
29     #ifdef HAVE_DES_H
30 root 1.23 # include <des.h>
31 elmex 1.1 #else
32 root 1.23 # ifdef HAVE_CRYPT_H
33 elmex 1.1 # include <crypt.h>
34 root 1.23 # endif
35 elmex 1.1 #endif
36    
37 root 1.47 #include <sproto.h>
38     #include <time.h>
39 elmex 1.1
40     #include <../random_maps/random_map.h>
41     #include <../random_maps/rproto.h>
42     #include "path.h"
43    
44     static char days[7][4] = {
45 root 1.20 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
46     };
47 elmex 1.1
48 root 1.20 void
49 root 1.23 version (object *op)
50 root 1.20 {
51 root 1.71 if (op)
52 root 1.20 clear_win_info (op);
53 elmex 1.1
54 root 1.71 new_draw_info_format (NDI_UNIQUE, 0, op, "This is Crossfire+ v%s", VERSION);
55 root 1.63
56 root 1.20 new_draw_info (NDI_UNIQUE, 0, op, "Authors and contributors to this program:");
57 root 1.63 new_draw_info (NDI_UNIQUE, 0, op, "Marc A. Lehmann <pcg@goof.com>");
58     new_draw_info (NDI_UNIQUE, 0, op, "Robin Redeker <elmex@x-paste.de>");
59     new_draw_info (NDI_UNIQUE, 0, op, "Pippijn van Steenhoven <pip88nl@gmail.com>");
60     new_draw_info (NDI_UNIQUE, 0, op, "Mark Wedel <mwedel@sonic.net>");
61     new_draw_info (NDI_UNIQUE, 0, op, "Frank Tore Johansen <frankj@ifi.uio.no>");
62     new_draw_info (NDI_UNIQUE, 0, op, "Kjetil Torgrim Homme <kjetilho@ifi.uio.no>");
63     new_draw_info (NDI_UNIQUE, 0, op, "Tyler Van Gorder <tvangod@ecst.csuchico.edu>");
64     new_draw_info (NDI_UNIQUE, 0, op, "Tony Elmroth <elmroth@cd.chalmers.se>");
65     new_draw_info (NDI_UNIQUE, 0, op, "Dougal Scott <dougal.scott@fcit.monasu.edu.au>");
66     new_draw_info (NDI_UNIQUE, 0, op, "William <wchuang@athena.mit.edu>");
67     new_draw_info (NDI_UNIQUE, 0, op, "Geoff Bailey <ftww@cs.su.oz.au>");
68 root 1.71 new_draw_info (NDI_UNIQUE, 0, op, "Kjetil Wiekhorst Jørgensen <jorgens@flipper.pvv.unit.no>");
69 root 1.63 new_draw_info (NDI_UNIQUE, 0, op, "Cameron Blackwood <c.blackwood@rdt.monash.edu.au>");
70     new_draw_info (NDI_UNIQUE, 0, op, "Joseph L. Traub <jtraub+@cmu.edu>");
71     new_draw_info (NDI_UNIQUE, 0, op, "Rupert G. Goldie <rgg@aaii.oz.au>");
72     new_draw_info (NDI_UNIQUE, 0, op, "Eric A. Anderson <eanders+@cmu.edu>");
73     new_draw_info (NDI_UNIQUE, 0, op, "Rickard Eneqvist <eneq@Prag.DoCS.UU.SE>");
74     new_draw_info (NDI_UNIQUE, 0, op, "Jarkko Sonninen <Jarkko.Sonninen@lut.fi>");
75     new_draw_info (NDI_UNIQUE, 0, op, "Karl Holland <kholland@sunlab.cit.cornell.du>");
76     new_draw_info (NDI_UNIQUE, 0, op, "Mikael Lundgren <vick@bern.docs.uu.se>");
77     new_draw_info (NDI_UNIQUE, 0, op, "Mikael Olsson <mol@meryl.csd.uu.se>");
78     new_draw_info (NDI_UNIQUE, 0, op, "Tero Haatanen <Tero.Haatanen@lut.fi>");
79     new_draw_info (NDI_UNIQUE, 0, op, "Lasse Ylitalo <ylitalo@student.docs.uu.se>");
80     new_draw_info (NDI_UNIQUE, 0, op, "Niilo Neuvo <anipa@guru.magic.fi>");
81     new_draw_info (NDI_UNIQUE, 0, op, "Markku J{rvinen <mta@modeemi.cs.tut.fi>");
82     new_draw_info (NDI_UNIQUE, 0, op, "Sylvain Meunier <meunier@inf.enst.fr>");
83     new_draw_info (NDI_UNIQUE, 0, op, "Jason Fosback <jfosback@darmok.uoregon.edu>");
84     new_draw_info (NDI_UNIQUE, 0, op, "Carl Edman <cedman@capitalist.princeton.edu>");
85     new_draw_info (NDI_UNIQUE, 0, op, "Charles Henrich <henrich@crh.cl.msu.edu>");
86     new_draw_info (NDI_UNIQUE, 0, op, "Gregor Schmid <schmid@fb3-s7.math.tu-berlin.de>");
87     new_draw_info (NDI_UNIQUE, 0, op, "Raphael Quinet <quinet@montefiore.ulg.ac.be>");
88     new_draw_info (NDI_UNIQUE, 0, op, "Jari Vanhala <jam@modeemi.cs.tut.fi>");
89     new_draw_info (NDI_UNIQUE, 0, op, "Tero Kivinen <kivinen@joker.cs.hut.fi>");
90     new_draw_info (NDI_UNIQUE, 0, op, "Peter Mardahl <peterm@soda.berkeley.edu>");
91     new_draw_info (NDI_UNIQUE, 0, op, "Matthew Zeher <matt@cs.odu.edu>");
92     new_draw_info (NDI_UNIQUE, 0, op, "Scott R. Turner <srt@sun-dimas.aero.org>");
93     new_draw_info (NDI_UNIQUE, 0, op, "Ben Fennema <huma@netcom.com>");
94     new_draw_info (NDI_UNIQUE, 0, op, "Nick Williams <njw@cs.city.ac.uk>");
95     new_draw_info (NDI_UNIQUE, 0, op, "Laurent Wacrenier <Wacren@Gin.ObsPM.Fr>");
96     new_draw_info (NDI_UNIQUE, 0, op, "Brian Thomas <thomas@astro.psu.edu>");
97     new_draw_info (NDI_UNIQUE, 0, op, "John Steven Moerk <jsm@axon.ksc.nasa.gov>");
98     new_draw_info (NDI_UNIQUE, 0, op, "Delbecq David <david.delbecq@mailandnews.com>");
99     new_draw_info (NDI_UNIQUE, 0, op, "Chachkoff Yann <yann.chachkoff@mailandnews.com>\n");
100    
101 root 1.20 new_draw_info (NDI_UNIQUE, 0, op, "Images and art:");
102     new_draw_info (NDI_UNIQUE, 0, op, "Peter Gardner");
103 root 1.63 new_draw_info (NDI_UNIQUE, 0, op, "David Gervais <david_eg@mail.com>");
104     new_draw_info (NDI_UNIQUE, 0, op, "Mitsuhiro Itakura <ita@gold.koma.jaeri.go.jp>");
105     new_draw_info (NDI_UNIQUE, 0, op, "Hansjoerg Malthaner <hansjoerg.malthaner@danet.de>");
106     new_draw_info (NDI_UNIQUE, 0, op, "Mårten Woxberg <maxmc@telia.com>");
107 root 1.20 new_draw_info (NDI_UNIQUE, 0, op, "And many more!");
108     }
109    
110 elmex 1.1 /* This is a basic little function to put the player back to his
111     * savebed. We do some error checking - its possible that the
112     * savebed map may no longer exist, so we make sure the player
113     * goes someplace.
114     */
115 root 1.20 void
116 root 1.23 enter_player_savebed (object *op)
117 elmex 1.1 {
118 root 1.63 object *tmp = object::create ();
119 root 1.20 EXIT_PATH (tmp) = op->contr->savebed_map;
120     EXIT_X (tmp) = op->contr->bed_x;
121     EXIT_Y (tmp) = op->contr->bed_y;
122 root 1.62 op->enter_exit (tmp);
123 root 1.41 tmp->destroy ();
124 elmex 1.1 }
125    
126     /*
127 root 1.62 * enter_map(): Moves the player and pets from current map (if any) to
128 elmex 1.1 * new map. map, x, y must be set. map is the map we are moving the
129     * player to - it could be the map he just came from if the load failed for
130     * whatever reason. If default map coordinates are to be used, then
131     * the function that calls this should figure them out.
132     */
133 root 1.62 void
134     object::enter_map (maptile *newmap, int x, int y)
135 root 1.20 {
136 root 1.72 if (destroyed () || !newmap || newmap->in_memory != MAP_IN_MEMORY)
137 root 1.69 return;
138    
139 root 1.20 if (out_of_map (newmap, x, y))
140     {
141 root 1.62 LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", &newmap->path, x, y);
142 root 1.58 x = newmap->enter_x;
143     y = newmap->enter_y;
144 root 1.20 if (out_of_map (newmap, x, y))
145     {
146     LOG (llevError, "enter_map: map %s provides invalid default enter location (%d, %d) > (%d, %d)\n",
147 root 1.62 &newmap->path, x, y, newmap->width, newmap->height);
148     new_draw_info (NDI_UNIQUE, 0, this, "The exit is closed");
149 root 1.20 return;
150     }
151     }
152 root 1.31
153 root 1.78 if (contr && map != newmap && map)
154 root 1.65 if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr)))
155     return;
156    
157 root 1.82 // remove, so stupid ob_locked does not trigger a failure
158 root 1.65 remove ();
159    
160 root 1.20 /* try to find a spot for the player */
161 root 1.62 if (ob_blocked (this, newmap, x, y))
162 root 1.20 { /* First choice blocked */
163     /* We try to find a spot for the player, starting closest in.
164     * We could use find_first_free_spot, but that doesn't randomize it at all,
165     * So for example, if the north space is free, you would always end up there even
166     * if other spaces around are available.
167     * Note that for the second and third calls, we could start at a position other
168     * than one, but then we could end up on the other side of walls and so forth.
169     */
170 root 1.62 int i = find_free_spot (this, newmap, x, y, 1, SIZEOFFREE1 + 1);
171 root 1.23
172 root 1.20 if (i == -1)
173     {
174 root 1.62 i = find_free_spot (this, newmap, x, y, 1, SIZEOFFREE2 + 1);
175 root 1.20 if (i == -1)
176 root 1.62 i = find_free_spot (this, newmap, x, y, 1, SIZEOFFREE);
177 root 1.20 }
178 root 1.31
179 root 1.20 if (i != -1)
180     {
181     x += freearr_x[i];
182     y += freearr_y[i];
183     }
184     else
185 root 1.62 /* not much we can do in this case. */
186     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);
187     }
188 elmex 1.1
189 root 1.78 if (contr && map != newmap)
190 root 1.69 {
191     if (INVOKE_PLAYER (MAP_CHANGE, contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y)))
192     return;
193 root 1.31
194 root 1.69 if (INVOKE_MAP (ENTER, newmap, ARG_PLAYER (contr), ARG_INT (x), ARG_INT (y)))
195     return;
196     }
197 root 1.20
198 root 1.62 this->x = x;
199     this->y = y;
200     map = newmap;
201 root 1.20
202 root 1.62 insert_ob_in_map (this, map, 0, INS_NO_WALK_ON);
203 root 1.20
204 root 1.82 enemy = 0;
205 root 1.20
206 root 1.62 if (contr)
207 root 1.20 {
208 root 1.70 contr->maplevel = newmap->path;
209 root 1.62 contr->count = 0;
210 root 1.20 }
211    
212     /* Update any golems */
213 root 1.62 if (type == PLAYER && contr->ranges[range_golem])
214 root 1.20 {
215 root 1.62 int i = find_free_spot (contr->ranges[range_golem], newmap,
216 root 1.20 x, y, 1, SIZEOFFREE);
217 root 1.23
218 root 1.20 if (i == -1)
219     {
220 root 1.62 contr->ranges[range_golem]->destroy ();
221     contr->ranges[range_golem] = 0;
222 root 1.20 }
223     else
224     {
225 root 1.82 for (object *tmp = contr->ranges[range_golem]; tmp; tmp = tmp->more)
226 root 1.20 {
227 root 1.76 tmp->x = x + freearr_x[i] + (tmp->arch ? 0 : tmp->arch->clone.x);
228     tmp->y = y + freearr_y[i] + (tmp->arch ? 0 : tmp->arch->clone.y);
229 root 1.20 tmp->map = newmap;
230 root 1.14 }
231 root 1.31
232 root 1.62 insert_ob_in_map (contr->ranges[range_golem], newmap, NULL, 0);
233     contr->ranges[range_golem]->direction =
234     find_dir_2 (x - contr->ranges[range_golem]->x, y - contr->ranges[range_golem]->y);
235 root 1.14 }
236 elmex 1.1 }
237 root 1.31
238 root 1.20 /* since the players map is already loaded, we don't need to worry
239     * about pending objects.
240     */
241     remove_all_pets (newmap);
242 elmex 1.1 }
243    
244     /* process_players1 and process_players2 do all the player related stuff.
245     * I moved it out of process events and process_map. This was to some
246     * extent for debugging as well as to get a better idea of the time used
247     * by the various functions. process_players1() does the processing before
248     * objects have been updated, process_players2() does the processing that
249     * is needed after the players have been updated.
250     */
251 root 1.46 static void
252     process_players1 ()
253 elmex 1.1 {
254 root 1.20 int flag;
255 root 1.55
256 root 1.20 /* Basically, we keep looping until all the players have done their actions. */
257     for (flag = 1; flag != 0;)
258     {
259     flag = 0;
260 root 1.56 for_all_players (pl)
261 root 1.20 {
262 root 1.56 pl->refcnt_chk ();
263 elmex 1.1
264 root 1.81 if (!pl->ob || !pl->ns || !pl->ob->active)
265 root 1.20 continue;
266    
267     if (pl->ob->speed_left > 0)
268 root 1.56 if (handle_newcs_player (pl->ob))
269     flag = 1;
270 root 1.20
271     /* If the player is not actively playing, don't make a
272     * backup save - nothing to save anyway. Plus, the
273     * map may not longer be valid. This can happen when the
274     * player quits - they exist for purposes of tracking on the map,
275     * but don't actually reside on any actual map.
276     */
277     if (QUERY_FLAG (pl->ob, FLAG_REMOVED))
278     continue;
279     } /* end of for loop for all the players */
280     } /* for flag */
281 root 1.46
282 root 1.55 for_all_players (pl)
283 root 1.20 {
284 root 1.81 if (!pl->ob || !pl->ns || !pl->ob->active)
285 root 1.56 continue;
286    
287 root 1.46 if (settings.casting_time)
288 root 1.20 {
289     if (pl->ob->casting_time > 0)
290     {
291     pl->ob->casting_time--;
292     pl->ob->start_holding = 1;
293 root 1.14 }
294 root 1.46
295 root 1.20 /* set spell_state so we can update the range in stats field */
296     if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1))
297 root 1.46 pl->ob->start_holding = 0;
298 root 1.14 }
299 root 1.46
300 root 1.20 do_some_living (pl->ob);
301 elmex 1.1 }
302     }
303    
304 root 1.46 static void
305     process_players2 ()
306 elmex 1.1 {
307 root 1.20 /* Then check if any players should use weapon-speed instead of speed */
308 root 1.55 for_all_players (pl)
309 root 1.20 {
310     /* The code that did weapon_sp handling here was out of place -
311     * this isn't called until after the player has finished there
312     * actions, and is thus out of place. All we do here is bounds
313     * checking.
314     */
315     if (pl->has_hit)
316     {
317     if (pl->ob->speed_left > pl->weapon_sp)
318     pl->ob->speed_left = pl->weapon_sp;
319 root 1.14
320 root 1.20 /* This needs to be here - if the player is running, we need to
321     * clear this each tick, but new commands are not being received
322     * so execute_newserver_command() is never called
323     */
324     pl->has_hit = 0;
325     }
326     else if (pl->ob->speed_left > pl->ob->speed)
327     pl->ob->speed_left = pl->ob->speed;
328 elmex 1.1 }
329     }
330    
331 root 1.20 void
332 root 1.46 process_events ()
333 root 1.20 {
334 root 1.46 process_players1 ();
335 elmex 1.1
336 root 1.81 for_all_actives (op)
337 root 1.20 {
338     /* Now process op */
339     if (QUERY_FLAG (op, FLAG_FREED))
340     {
341     LOG (llevError, "BUG: process_events(): Free object on list\n");
342 root 1.59 op->set_speed (0);
343 root 1.20 continue;
344     }
345    
346     /* I've seen occasional crashes due to this - the object is removed,
347     * and thus the map it points to (last map it was on) may be bogus
348     * The real bug is to try to find out the cause of this - someone
349     * is probably calling remove_ob without either an insert_ob or
350     * free_object afterwards, leaving an object dangling. But I'd
351     * rather log this and continue on instead of crashing.
352     * Don't remove players - when a player quits, the object is in
353     * sort of a limbo, of removed, but something we want to keep
354     * around.
355     */
356     if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY)
357     {
358     LOG (llevError, "BUG: process_events(): Removed object on list\n");
359 root 1.36 char *dump = dump_object (op);
360     LOG (llevError, dump);
361     free (dump);
362 root 1.41 op->destroy ();
363 root 1.20 continue;
364 root 1.14 }
365    
366 elmex 1.66 if (!op->has_active_speed ())
367 root 1.20 {
368 elmex 1.66 LOG (llevError, "BUG: process_events(): Object %s has no speed (%f), "
369     "but is on active list\n", op->debug_desc (), op->speed);
370 root 1.59 op->set_speed (0);
371 root 1.20 continue;
372 root 1.14 }
373    
374 root 1.46 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP)
375 root 1.20 {
376 root 1.46 LOG (llevError, "BUG: process_events(): Object without map or "
377     "inventory is on active list: %s (%d)\n", &op->name, op->count);
378 root 1.59 op->set_speed (0);
379 root 1.20 continue;
380 root 1.14 }
381    
382 root 1.46 /* Animate the object. Bug or feature that anim_speed
383 root 1.20 * is based on ticks, and not the creatures speed?
384     */
385     if (op->anim_speed && op->last_anim >= op->anim_speed)
386     {
387 elmex 1.50 if ((op->type == PLAYER))
388 root 1.20 animate_object (op, op->facing);
389     else
390     animate_object (op, op->direction);
391 root 1.14
392 root 1.20 op->last_anim = 1;
393     }
394     else
395     op->last_anim++;
396 elmex 1.1
397 root 1.20 if (op->speed_left > 0)
398     {
399 elmex 1.1 #if 0
400 root 1.20 /* I've seen occasional crashes in move_symptom() with it
401     * crashing because op is removed - add some debugging to
402     * track if it is removed at this point.
403     * This unfortunately is a bit too verbose it seems - not sure
404     * why - I think what happens is a map is freed or something and
405     * some objects get 'lost' - removed never to be reclaimed.
406     * removed objects generally shouldn't exist.
407     */
408     if (QUERY_FLAG (op, FLAG_REMOVED))
409     {
410     LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null");
411 root 1.14 }
412 elmex 1.1 #endif
413 root 1.20 --op->speed_left;
414     process_object (op);
415 root 1.28
416     if (op->destroyed ())
417 root 1.20 continue;
418 root 1.14 }
419 root 1.28
420 root 1.20 if (settings.casting_time == TRUE && op->casting_time > 0)
421     op->casting_time--;
422 root 1.28
423 root 1.20 if (op->speed_left <= 0)
424     op->speed_left += FABS (op->speed);
425 elmex 1.1 }
426    
427 root 1.46 process_players2 ();
428 elmex 1.1 }
429    
430 root 1.62 /* clean up everything before exiting */
431 root 1.20 void
432 root 1.62 emergency_save ()
433 root 1.20 {
434 root 1.62 LOG (llevDebug, "emergency save begin.\n");
435 elmex 1.1
436 root 1.62 maptile::emergency_save ();
437    
438     LOG (llevDebug, "saving book archive.\n");
439     write_book_archive ();
440 root 1.47
441 root 1.62 LOG (llevDebug, "emergency save done.\n");
442 elmex 1.1 }
443    
444 root 1.79 // send all clients some informational text
445     static void
446     cleanup_inform (const char *cause, bool make_core)
447     {
448     new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 0, 0, "The server will now shutdown.\n");
449     new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 0, 0, "Cause for this shtudown: %s\n", cause);
450    
451     if (make_core)
452     new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 0, 0, "This is considered a crash.\n");
453     else
454     new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 0, 0, "This is considered to be a clean shutdown.\n");
455    
456     new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 0, 0, "%s\n", CLEANUP_MESSAGE);
457    
458     flush_sockets ();
459     }
460    
461 elmex 1.1 /* clean up everything before exiting */
462 root 1.20 void
463 root 1.79 cleanup (const char *cause, bool make_core)
464 elmex 1.1 {
465 root 1.79 LOG (llevError, "cleanup cause: %s\n", cause);
466    
467     if (!make_core)
468     cleanup_inform (cause, make_core);
469    
470 root 1.62 LOG (llevDebug, "cleanup begin.\n");
471    
472 root 1.65 if (init_done && !in_cleanup)
473 root 1.67 {
474     in_cleanup = true;
475     emergency_save ();
476     }
477     else
478     in_cleanup = true;
479 root 1.29
480 root 1.62 LOG (llevDebug, "running cleanup handlers.\n");
481     INVOKE_GLOBAL (CLEANUP);
482 root 1.23
483 root 1.62 LOG (llevDebug, "cleanup done.\n");
484 root 1.25
485 root 1.49 if (make_core)
486 root 1.79 {
487     cleanup_inform (cause, make_core);
488     abort ();
489     }
490 root 1.49 else
491     _exit (0);
492 elmex 1.1 }
493    
494 root 1.20 int
495     forbid_play (void)
496 elmex 1.1 {
497     #if !defined(_IBMR2) && !defined(___IBMR2) && defined(PERM_FILE)
498 root 1.20 char buf[MAX_BUF], day[MAX_BUF];
499     FILE *fp;
500     time_t clock;
501     struct tm *tm;
502     int i, start, stop, forbit = 0, comp;
503    
504     clock = time (NULL);
505     tm = (struct tm *) localtime (&clock);
506 root 1.14
507 root 1.20 sprintf (buf, "%s/%s", settings.confdir, PERM_FILE);
508     if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
509     return 0;
510    
511     while (fgets (buf, MAX_BUF, fp))
512     {
513     if (buf[0] == '#')
514     continue;
515 root 1.73
516 root 1.20 if (!strncmp (buf, "msg", 3))
517     {
518     if (forbit)
519     while (fgets (buf, MAX_BUF, fp)) /* print message */
520     fputs (buf, logfile);
521     break;
522     }
523     else if (sscanf (buf, "%s %d%*c%d\n", day, &start, &stop) != 3)
524     {
525     LOG (llevDebug, "Warning: Incomplete line in permission file ignored.\n");
526     continue;
527 root 1.14 }
528    
529 root 1.20 for (i = 0; i < 7; i++)
530     {
531     if (!strncmp (buf, days[i], 3) && (tm->tm_wday == i) && (tm->tm_hour >= start) && (tm->tm_hour < stop))
532     forbit = 1;
533 root 1.14 }
534 elmex 1.1 }
535    
536 root 1.20 close_and_delete (fp, comp);
537 elmex 1.1
538 root 1.20 return forbit;
539 elmex 1.1 #else
540 root 1.20 return 0;
541 elmex 1.1 #endif
542     }
543    
544     /*
545 root 1.73 * do_specials() is a collection of functions to call from time to time.
546 elmex 1.1 * Modified 2000-1-14 MSW to use the global pticks count to determine how
547     * often to do things. This will allow us to spred them out more often.
548     * I use prime numbers for the factor count - in that way, it is less likely
549     * these actions will fall on the same tick (compared to say using 500/2500/15000
550     * which would mean on that 15,000 tick count a whole bunch of stuff gets
551     * done). Of course, there can still be times where multiple specials are
552     * done on the same tick, but that will happen very infrequently
553     *
554     * I also think this code makes it easier to see how often we really are
555     * doing the various things.
556     */
557    
558     extern unsigned long todtick;
559    
560 root 1.20 void
561     do_specials (void)
562     {
563     if (!(pticks % PTICKS_PER_CLOCK))
564     tick_the_clock ();
565 elmex 1.1
566 root 1.20 if (!(pticks % 7))
567     shstr::gc ();
568 root 1.18
569 root 1.20 if (!(pticks % 2503))
570     fix_weight (); /* Hack to fix weightproblems caused by bugs */
571 elmex 1.1
572 root 1.20 if (!(pticks % 5003))
573     write_book_archive ();
574 elmex 1.1
575 root 1.20 if (!(pticks % 5009))
576     clean_friendly_list ();
577 elmex 1.1
578 root 1.20 if (!(pticks % 5011))
579     obsolete_parties ();
580 elmex 1.1
581 root 1.20 if (!(pticks % 12503))
582     fix_luck ();
583 elmex 1.1 }
584    
585 root 1.20 void
586     server_tick ()
587 root 1.2 {
588 root 1.44 // first do the user visible stuff
589 root 1.20 doeric_server ();
590 root 1.12 INVOKE_GLOBAL (CLOCK);
591 root 1.46 process_events (); /* "do" something with objects with speed */
592 root 1.20 flush_sockets ();
593 root 1.44
594     // then do some bookkeeping, should not really be here
595 root 1.20 do_specials (); /* Routines called from time to time. */
596 root 1.56 attachable::check_mortals ();
597 root 1.5
598     ++pticks;
599 root 1.2 }
600    
601 root 1.20 int
602     main (int argc, char **argv)
603 elmex 1.1 {
604 root 1.6 settings.argc = argc;
605     settings.argv = argv;
606    
607     init (argc, argv);
608    
609 root 1.10 initPlugins ();
610 elmex 1.1
611 root 1.6 for (;;)
612     cfperl_main ();
613 root 1.64 }
614 root 1.4