-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
82 lines (73 loc) · 2.7 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/python
# The Nexus software is licensed under the BSD 2-Clause license.
#
# You should have recieved a copy of this license with the software.
# If you did not, you can find one at the following link.
#
# http://opensource.org/licenses/bsd-license.php
import os, sys, datetime, logging, shutil
from reqs.twisted.internet import reactor
from reqs.twisted.internet.error import CannotListenError
from logging.handlers import SMTPHandler
from core.constants import *
from core.globals import *
from core.server import CoreFactory
from core.controller import ControllerFactory
from ConfigParser import RawConfigParser as ConfigParser
makefile("logs/")
makefile("logs/console/")
makefile("logs/console/console.log")
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=("--debug" in sys.argv) and logging.DEBUG or logging.INFO,
datefmt="%m/%d/%Y %H:%M:%S",
)
rotate = logging.handlers.TimedRotatingFileHandler(
filename="logs/console/console.log", when="H",
interval=6, backupCount=14,
)
rotate.setFormatter( logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s", "%m/%d/%Y %H:%M:%S") )
logging.root.addHandler(rotate)
logger = logging.getLogger("iCraft")
logger.info("Now starting up iCraft+ 1G version %s..." % VERSION)
makefile("core/archives/")
makefile("logs/chat.log")
makefile("logs/server.log")
makefile("logs/staff.log")
makefile("logs/whisper.log")
makefile("logs/world.log")
makefile("config/data/")
makedatfile("config/data/balances.dat")
makedatfile("config/data/inbox.dat")
makedatfile("config/data/jail.dat")
makedatfile("config/data/titles.dat")
factory = CoreFactory()
try:
reactor.listenTCP(factory.config.getint("network", "port"), factory)
reactor.listenTCP(30000, factory)
except CannotListenError:
logger.critical("Something is already running on port %s" % (factory.config.getint("network", "port")))
sys.exit(1)
controller = ControllerFactory(factory)
try:
reactor.listenTCP(factory.config.getint("network", "controller_port"), controller)
except CannotListenError:
logger.warning("Controller cannot listen on port %s. Disabled." % factory.config.getint("network", "port"))
del controller
money_logger = logging.getLogger('TransactionLogger')
fh = logging.FileHandler('logs/server.log')
formatter = logging.Formatter("%(asctime)s: %(message)s")
fh.setFormatter(formatter)
money_logger.addHandler(fh)
try:
reactor.run()
finally:
logger.info("Saving server metas...")
factory.saveMeta()
logger.info("Flushing worlds to disk...")
for world in factory.worlds.values():
logger.info("Saving: %s" % world.basename)
world.stop()
world.save_meta()
logger.info("Done flushing...")
sys.exit(1)