Imported from archive.
[mudpy.git] / mudpy
1 #!/usr/bin/python
2 """Skeletal executable for the mudpy engine."""
3
4 # Copyright (c) 2004-2008 Jeremy Stanley <fungi@yuggoth.org>. Permission
5 # to use, copy, modify, and distribute this software is granted under
6 # terms provided in the LICENSE file distributed with this software.
7
8 # core objects for the mudpy engine
9 import mudpy
10
11 # a consistent list so we can reimport these on reload
12 importlist = [
13         "argv",
14         "create_pidfile",
15         "daemonize",
16         "log",
17         "on_pulse",
18         "reload_data",
19         "remove_pidfile",
20         "universe"
21         ]
22 for item in importlist: exec("from mudpy import " + item)
23
24 # log an initial message
25 log("Started mudpy with command line: " + " ".join(argv))
26
27 # fork and disassociate
28 daemonize()
29
30 # make the pidfile
31 create_pidfile(universe)
32
33 # loop indefinitely while the world is not flagged for termination or
34 # there are connected users
35 while not universe.terminate_flag or universe.userlist:
36
37         # the world was flagged for a reload of all code/data
38         if universe.reload_flag:
39
40                 # reload the mudpy module
41                 reload(mudpy)
42                 for item in importlist: exec("from mudpy import " + item)
43
44         # do what needs to be done on each pulse
45         on_pulse()
46
47 # the loop has terminated, so save persistent data
48 universe.save()
49
50 # log a final message
51 log("Shutting down now.")
52
53 # get rid of the pidfile
54 remove_pidfile(universe)
55