This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.py
103 lines (79 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""The script to run PoiManager-Core.
Use ` python3 run.py` to run this.
"""
import os
import signal
import sys
from flask import Flask
from auth.Token import TokenManager
from core.bds import BdsCore
from core.core import ManagerCore
from database import BdsLogger
from database.ConfigHelper import get_config, printConfig
from loader.PropertiesLoader import PropertiesLoader
# noinspection PyUnusedLocal
from utils.init import init_db
from utils.ws_utils import WebSocketCollector
def CtrlC(*args):
print('>stopped<')
BdsLogger.put_log('manager', 'stop_done')
while True:
sys.exit()
# noinspection PyTypeChecker
signal.signal(signal.SIGINT, CtrlC)
# noinspection PyTypeChecker
signal.signal(signal.SIGTERM, CtrlC)
if __name__ == '__main__':
print('>PoiManager-Core starting...')
abs_dir = os.path.dirname(os.path.abspath(__file__))
if os.path.isfile('db.sqlite3') is not True:
print('Database is missing, creating...')
init_db()
argv = sys.argv
debug = False
debug_no_bds = False
if len(argv) > 1:
if argv[1] == 'debug':
debug = True
elif argv[1] == 'debug-no-bds':
debug = True
debug_no_bds = True
if debug:
print('>Manager Debug')
tokenManager = TokenManager(debug=debug)
ws_collector = WebSocketCollector()
prop_loader = PropertiesLoader(no_bds=debug_no_bds)
bdsCore = BdsCore(no_bds=debug_no_bds, ws_collector=ws_collector)
print('====================')
print('>Manager Configs are:')
printConfig()
print('--------------------')
print('>Bedrock Server Configs are:')
print('\n'.join([f'{v}={prop_loader.prop[v]}' for v in prop_loader.prop]))
print('====================')
BdsLogger.put_log('manager', 'start')
BdsLogger.put_log('manager', '%s:%s' % (
get_config('web_listening_address'),
get_config('web_listening_port')
))
print('>Listening at %s:%s' % (
get_config('web_listening_address'),
get_config('web_listening_port')
))
print('>Manager Token: %s' % tokenManager.token)
app = Flask(
__name__,
static_url_path='/',
static_folder=os.path.join(abs_dir, 'static'),
template_folder=os.path.join(abs_dir, 'template')
)
if get_config('clear_log_on_start') == 'true':
BdsLogger.clear_log()
managerCore = ManagerCore(token_manager=tokenManager,
bds=bdsCore,
prop_loader=prop_loader,
ws_collector=ws_collector,
name=__name__,
app=app,
debug=debug)
managerCore.run()