ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/main.C
Revision: 1.81
Committed: Sun Jan 7 02:39:14 2007 UTC (17 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.80: +3 -68 lines
Log Message:
""

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     /* If it is a player login, he has yet to be inserted anyplace.
158     * otherwise, we need to deal with removing the player here.
159     */
160     remove ();
161    
162 root 1.20 /* try to find a spot for the player */
163 root 1.62 if (ob_blocked (this, newmap, x, y))
164 root 1.20 { /* First choice blocked */
165     /* We try to find a spot for the player, starting closest in.
166     * We could use find_first_free_spot, but that doesn't randomize it at all,
167     * So for example, if the north space is free, you would always end up there even
168     * if other spaces around are available.
169     * Note that for the second and third calls, we could start at a position other
170     * than one, but then we could end up on the other side of walls and so forth.
171     */
172 root 1.62 int i = find_free_spot (this, newmap, x, y, 1, SIZEOFFREE1 + 1);
173 root 1.23
174 root 1.20 if (i == -1)
175     {
176 root 1.62 i = find_free_spot (this, newmap, x, y, 1, SIZEOFFREE2 + 1);
177 root 1.20 if (i == -1)
178 root 1.62 i = find_free_spot (this, newmap, x, y, 1, SIZEOFFREE);
179 root 1.20 }
180 root 1.31
181 root 1.20 if (i != -1)
182     {
183     x += freearr_x[i];
184     y += freearr_y[i];
185     }
186     else
187 root 1.62 /* not much we can do in this case. */
188     LOG (llevInfo, "enter_map: Could not find free spot for player - will dump on top of object (%s: %d, %d)\n", &newmap->path, x, y);
189     }
190 elmex 1.1
191 root 1.78 if (contr && map != newmap)
192 root 1.69 {
193     if (INVOKE_PLAYER (MAP_CHANGE, contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y)))
194     return;
195 root 1.31
196 root 1.69 if (INVOKE_MAP (ENTER, newmap, ARG_PLAYER (contr), ARG_INT (x), ARG_INT (y)))
197     return;
198     }
199 root 1.20
200 root 1.62 this->x = x;
201     this->y = y;
202     map = newmap;
203 root 1.20
204 root 1.62 insert_ob_in_map (this, map, 0, INS_NO_WALK_ON);
205 root 1.20
206 root 1.62 enemy = NULL;
207 root 1.20
208 root 1.62 if (contr)
209 root 1.20 {
210 root 1.70 contr->maplevel = newmap->path;
211 root 1.62 contr->count = 0;
212 root 1.20 }
213    
214     /* Update any golems */
215 root 1.62 if (type == PLAYER && contr->ranges[range_golem])
216 root 1.20 {
217 root 1.62 int i = find_free_spot (contr->ranges[range_golem], newmap,
218 root 1.20 x, y, 1, SIZEOFFREE);
219 root 1.23
220 root 1.62 contr->ranges[range_golem]->remove ();
221 root 1.31
222 root 1.20 if (i == -1)
223     {
224 root 1.62 remove_friendly_object (contr->ranges[range_golem]);
225     contr->ranges[range_golem]->destroy ();
226     contr->ranges[range_golem] = 0;
227 root 1.20 }
228     else
229     {
230 root 1.62 for (object *tmp = contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more)
231 root 1.20 {
232 root 1.76 tmp->x = x + freearr_x[i] + (tmp->arch ? 0 : tmp->arch->clone.x);
233     tmp->y = y + freearr_y[i] + (tmp->arch ? 0 : tmp->arch->clone.y);
234 root 1.20 tmp->map = newmap;
235 root 1.14 }
236 root 1.31
237 root 1.62 insert_ob_in_map (contr->ranges[range_golem], newmap, NULL, 0);
238     contr->ranges[range_golem]->direction =
239     find_dir_2 (x - contr->ranges[range_golem]->x, y - contr->ranges[range_golem]->y);
240 root 1.14 }
241 elmex 1.1 }
242 root 1.31
243 root 1.20 /* since the players map is already loaded, we don't need to worry
244     * about pending objects.
245     */
246     remove_all_pets (newmap);
247 elmex 1.1 }
248    
249     /* process_players1 and process_players2 do all the player related stuff.
250     * I moved it out of process events and process_map. This was to some
251     * extent for debugging as well as to get a better idea of the time used
252     * by the various functions. process_players1() does the processing before
253     * objects have been updated, process_players2() does the processing that
254     * is needed after the players have been updated.
255     */
256 root 1.46 static void
257     process_players1 ()
258 elmex 1.1 {
259 root 1.20 int flag;
260 root 1.55
261 root 1.20 /* Basically, we keep looping until all the players have done their actions. */
262     for (flag = 1; flag != 0;)
263     {
264     flag = 0;
265 root 1.56 for_all_players (pl)
266 root 1.20 {
267 root 1.56 pl->refcnt_chk ();
268 elmex 1.1
269 root 1.81 if (!pl->ob || !pl->ns || !pl->ob->active)
270 root 1.20 continue;
271    
272     if (pl->ob->speed_left > 0)
273 root 1.56 if (handle_newcs_player (pl->ob))
274     flag = 1;
275 root 1.20
276     /* If the player is not actively playing, don't make a
277     * backup save - nothing to save anyway. Plus, the
278     * map may not longer be valid. This can happen when the
279     * player quits - they exist for purposes of tracking on the map,
280     * but don't actually reside on any actual map.
281     */
282     if (QUERY_FLAG (pl->ob, FLAG_REMOVED))
283     continue;
284     } /* end of for loop for all the players */
285     } /* for flag */
286 root 1.46
287 root 1.55 for_all_players (pl)
288 root 1.20 {
289 root 1.81 if (!pl->ob || !pl->ns || !pl->ob->active)
290 root 1.56 continue;
291    
292 root 1.46 if (settings.casting_time)
293 root 1.20 {
294     if (pl->ob->casting_time > 0)
295     {
296     pl->ob->casting_time--;
297     pl->ob->start_holding = 1;
298 root 1.14 }
299 root 1.46
300 root 1.20 /* set spell_state so we can update the range in stats field */
301     if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1))
302 root 1.46 pl->ob->start_holding = 0;
303 root 1.14 }
304 root 1.46
305 root 1.20 do_some_living (pl->ob);
306 elmex 1.1 }
307     }
308    
309 root 1.46 static void
310     process_players2 ()
311 elmex 1.1 {
312 root 1.20 /* Then check if any players should use weapon-speed instead of speed */
313 root 1.55 for_all_players (pl)
314 root 1.20 {
315     /* The code that did weapon_sp handling here was out of place -
316     * this isn't called until after the player has finished there
317     * actions, and is thus out of place. All we do here is bounds
318     * checking.
319     */
320     if (pl->has_hit)
321     {
322     if (pl->ob->speed_left > pl->weapon_sp)
323     pl->ob->speed_left = pl->weapon_sp;
324 root 1.14
325 root 1.20 /* This needs to be here - if the player is running, we need to
326     * clear this each tick, but new commands are not being received
327     * so execute_newserver_command() is never called
328     */
329     pl->has_hit = 0;
330     }
331     else if (pl->ob->speed_left > pl->ob->speed)
332     pl->ob->speed_left = pl->ob->speed;
333 elmex 1.1 }
334     }
335    
336 root 1.20 void
337 root 1.46 process_events ()
338 root 1.20 {
339 root 1.46 process_players1 ();
340 elmex 1.1
341 root 1.81 for_all_actives (op)
342 root 1.20 {
343     /* Now process op */
344     if (QUERY_FLAG (op, FLAG_FREED))
345     {
346     LOG (llevError, "BUG: process_events(): Free object on list\n");
347 root 1.59 op->set_speed (0);
348 root 1.20 continue;
349     }
350    
351     /* I've seen occasional crashes due to this - the object is removed,
352     * and thus the map it points to (last map it was on) may be bogus
353     * The real bug is to try to find out the cause of this - someone
354     * is probably calling remove_ob without either an insert_ob or
355     * free_object afterwards, leaving an object dangling. But I'd
356     * rather log this and continue on instead of crashing.
357     * Don't remove players - when a player quits, the object is in
358     * sort of a limbo, of removed, but something we want to keep
359     * around.
360     */
361     if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY)
362     {
363     LOG (llevError, "BUG: process_events(): Removed object on list\n");
364 root 1.36 char *dump = dump_object (op);
365     LOG (llevError, dump);
366     free (dump);
367 root 1.41 op->destroy ();
368 root 1.20 continue;
369 root 1.14 }
370    
371 elmex 1.66 if (!op->has_active_speed ())
372 root 1.20 {
373 elmex 1.66 LOG (llevError, "BUG: process_events(): Object %s has no speed (%f), "
374     "but is on active list\n", op->debug_desc (), op->speed);
375 root 1.59 op->set_speed (0);
376 root 1.20 continue;
377 root 1.14 }
378    
379 root 1.46 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP)
380 root 1.20 {
381 root 1.46 LOG (llevError, "BUG: process_events(): Object without map or "
382     "inventory is on active list: %s (%d)\n", &op->name, op->count);
383 root 1.59 op->set_speed (0);
384 root 1.20 continue;
385 root 1.14 }
386    
387 root 1.46 /* Animate the object. Bug or feature that anim_speed
388 root 1.20 * is based on ticks, and not the creatures speed?
389     */
390     if (op->anim_speed && op->last_anim >= op->anim_speed)
391     {
392 elmex 1.50 if ((op->type == PLAYER))
393 root 1.20 animate_object (op, op->facing);
394     else
395     animate_object (op, op->direction);
396 root 1.14
397 root 1.20 op->last_anim = 1;
398     }
399     else
400     op->last_anim++;
401 elmex 1.1
402 root 1.20 if (op->speed_left > 0)
403     {
404 elmex 1.1 #if 0
405 root 1.20 /* I've seen occasional crashes in move_symptom() with it
406     * crashing because op is removed - add some debugging to
407     * track if it is removed at this point.
408     * This unfortunately is a bit too verbose it seems - not sure
409     * why - I think what happens is a map is freed or something and
410     * some objects get 'lost' - removed never to be reclaimed.
411     * removed objects generally shouldn't exist.
412     */
413     if (QUERY_FLAG (op, FLAG_REMOVED))
414     {
415     LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null");
416 root 1.14 }
417 elmex 1.1 #endif
418 root 1.20 --op->speed_left;
419     process_object (op);
420 root 1.28
421     if (op->destroyed ())
422 root 1.20 continue;
423 root 1.14 }
424 root 1.28
425 root 1.20 if (settings.casting_time == TRUE && op->casting_time > 0)
426     op->casting_time--;
427 root 1.28
428 root 1.20 if (op->speed_left <= 0)
429     op->speed_left += FABS (op->speed);
430 elmex 1.1 }
431    
432 root 1.46 process_players2 ();
433 elmex 1.1 }
434    
435 root 1.62 /* clean up everything before exiting */
436 root 1.20 void
437 root 1.62 emergency_save ()
438 root 1.20 {
439 root 1.62 LOG (llevDebug, "emergency save begin.\n");
440 elmex 1.1
441 root 1.62 maptile::emergency_save ();
442    
443     LOG (llevDebug, "saving book archive.\n");
444     write_book_archive ();
445 root 1.47
446 root 1.62 LOG (llevDebug, "emergency save done.\n");
447 elmex 1.1 }
448    
449 root 1.79 // send all clients some informational text
450     static void
451     cleanup_inform (const char *cause, bool make_core)
452     {
453     new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 0, 0, "The server will now shutdown.\n");
454     new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 0, 0, "Cause for this shtudown: %s\n", cause);
455    
456     if (make_core)
457     new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 0, 0, "This is considered a crash.\n");
458     else
459     new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 0, 0, "This is considered to be a clean shutdown.\n");
460    
461     new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_RED, 0, 0, "%s\n", CLEANUP_MESSAGE);
462    
463     flush_sockets ();
464     }
465    
466 elmex 1.1 /* clean up everything before exiting */
467 root 1.20 void
468 root 1.79 cleanup (const char *cause, bool make_core)
469 elmex 1.1 {
470 root 1.79 LOG (llevError, "cleanup cause: %s\n", cause);
471    
472     if (!make_core)
473     cleanup_inform (cause, make_core);
474    
475 root 1.62 LOG (llevDebug, "cleanup begin.\n");
476    
477 root 1.65 if (init_done && !in_cleanup)
478 root 1.67 {
479     in_cleanup = true;
480     emergency_save ();
481     }
482     else
483     in_cleanup = true;
484 root 1.29
485 root 1.62 LOG (llevDebug, "running cleanup handlers.\n");
486     INVOKE_GLOBAL (CLEANUP);
487 root 1.23
488 root 1.62 LOG (llevDebug, "cleanup done.\n");
489 root 1.25
490 root 1.49 if (make_core)
491 root 1.79 {
492     cleanup_inform (cause, make_core);
493     abort ();
494     }
495 root 1.49 else
496     _exit (0);
497 elmex 1.1 }
498    
499 root 1.20 int
500     forbid_play (void)
501 elmex 1.1 {
502     #if !defined(_IBMR2) && !defined(___IBMR2) && defined(PERM_FILE)
503 root 1.20 char buf[MAX_BUF], day[MAX_BUF];
504     FILE *fp;
505     time_t clock;
506     struct tm *tm;
507     int i, start, stop, forbit = 0, comp;
508    
509     clock = time (NULL);
510     tm = (struct tm *) localtime (&clock);
511 root 1.14
512 root 1.20 sprintf (buf, "%s/%s", settings.confdir, PERM_FILE);
513     if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
514     return 0;
515    
516     while (fgets (buf, MAX_BUF, fp))
517     {
518     if (buf[0] == '#')
519     continue;
520 root 1.73
521 root 1.20 if (!strncmp (buf, "msg", 3))
522     {
523     if (forbit)
524     while (fgets (buf, MAX_BUF, fp)) /* print message */
525     fputs (buf, logfile);
526     break;
527     }
528     else if (sscanf (buf, "%s %d%*c%d\n", day, &start, &stop) != 3)
529     {
530     LOG (llevDebug, "Warning: Incomplete line in permission file ignored.\n");
531     continue;
532 root 1.14 }
533    
534 root 1.20 for (i = 0; i < 7; i++)
535     {
536     if (!strncmp (buf, days[i], 3) && (tm->tm_wday == i) && (tm->tm_hour >= start) && (tm->tm_hour < stop))
537     forbit = 1;
538 root 1.14 }
539 elmex 1.1 }
540    
541 root 1.20 close_and_delete (fp, comp);
542 elmex 1.1
543 root 1.20 return forbit;
544 elmex 1.1 #else
545 root 1.20 return 0;
546 elmex 1.1 #endif
547     }
548    
549     /*
550 root 1.73 * do_specials() is a collection of functions to call from time to time.
551 elmex 1.1 * Modified 2000-1-14 MSW to use the global pticks count to determine how
552     * often to do things. This will allow us to spred them out more often.
553     * I use prime numbers for the factor count - in that way, it is less likely
554     * these actions will fall on the same tick (compared to say using 500/2500/15000
555     * which would mean on that 15,000 tick count a whole bunch of stuff gets
556     * done). Of course, there can still be times where multiple specials are
557     * done on the same tick, but that will happen very infrequently
558     *
559     * I also think this code makes it easier to see how often we really are
560     * doing the various things.
561     */
562    
563     extern unsigned long todtick;
564    
565 root 1.20 void
566     do_specials (void)
567     {
568     if (!(pticks % PTICKS_PER_CLOCK))
569     tick_the_clock ();
570 elmex 1.1
571 root 1.20 if (!(pticks % 7))
572     shstr::gc ();
573 root 1.18
574 root 1.20 if (!(pticks % 2503))
575     fix_weight (); /* Hack to fix weightproblems caused by bugs */
576 elmex 1.1
577 root 1.20 if (!(pticks % 5003))
578     write_book_archive ();
579 elmex 1.1
580 root 1.20 if (!(pticks % 5009))
581     clean_friendly_list ();
582 elmex 1.1
583 root 1.20 if (!(pticks % 5011))
584     obsolete_parties ();
585 elmex 1.1
586 root 1.20 if (!(pticks % 12503))
587     fix_luck ();
588 elmex 1.1 }
589    
590 root 1.20 void
591     server_tick ()
592 root 1.2 {
593 root 1.44 // first do the user visible stuff
594 root 1.20 doeric_server ();
595 root 1.12 INVOKE_GLOBAL (CLOCK);
596 root 1.46 process_events (); /* "do" something with objects with speed */
597 root 1.20 flush_sockets ();
598 root 1.44
599     // then do some bookkeeping, should not really be here
600 root 1.20 do_specials (); /* Routines called from time to time. */
601 root 1.56 attachable::check_mortals ();
602 root 1.5
603     ++pticks;
604 root 1.2 }
605    
606 root 1.20 int
607     main (int argc, char **argv)
608 elmex 1.1 {
609 root 1.6 settings.argc = argc;
610     settings.argv = argv;
611    
612     init (argc, argv);
613    
614 root 1.10 initPlugins ();
615 elmex 1.1
616 root 1.6 for (;;)
617     cfperl_main ();
618 root 1.64 }
619 root 1.4