7a5d5b20aabfddc1c636ad90722787fea03c94ac
[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         "argv",
13         "create_pidfile",
14         "daemonize",
15         "log",
16         "on_pulse",
17         "reload_data",
18         "remove_pidfile",
19         "universe"
20         ]
21 for item in importlist: exec("from mudpy import " + item)
22
23 # log an initial message
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_flag or universe.userlist:
35
36         # the world was flagged for a reload of all code/data
37         if universe.reload_flag:
38
39                 # reload the mudpy module
40                 reload(mudpy)
41                 for item in importlist: exec("from mudpy import " + item)
42
43         # do what needs to be done on each pulse
44         on_pulse()
45
46 # the loop has terminated, so save persistent data
47 universe.save()
48
49 # log a final message
50 log("Shutting down now.")
51
52 # get rid of the pidfile
53 remove_pidfile(universe)
54