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