forked from Lekuruu/snowflake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
47 lines (36 loc) · 1.17 KB
/
main.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
from twisted.internet import reactor
from app.protocols import SocketPolicyServer
from app.server import SnowflakeWorld
from app.logging import Console
import traceback
import logging
import signal
import config
logging.basicConfig(
handlers=[Console],
level=logging.DEBUG if config.ENABLE_DEBUG_LOGGING else logging.INFO
)
def on_shutdown(*args):
"""Kick all players from the server, before the reactor stops"""
world_server.logger.warning("Shutting down...")
world_server.shutting_down = True
for player in world_server.players:
player.send_to_room()
reactor.callLater(0.1, reactor.stop)
signal.signal(signal.SIGINT, on_shutdown)
if __name__ == "__main__":
global world_server, policy_server
try:
world_server = SnowflakeWorld()
world_server.listen(config.PORT)
if config.ENABLE_POLICY_SERVER:
policy_server = SocketPolicyServer(
config.POLICY_DOMAIN,
config.POLICY_PORT
)
policy_server.listen(843)
reactor.run()
except Exception as e:
traceback.print_exc()
logging.fatal(f'Failed to start server: {e}')
exit(1)