forked from Map-A-Droid/MAD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configmode.py
74 lines (60 loc) · 2.57 KB
/
configmode.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
import os
import sys
from threading import Thread
from db.dbWrapperBase import DbWrapperBase
from db.DbFactory import DbFactory
from utils.MappingManager import MappingManagerManager, MappingManager
from utils.logging import initLogging, logger
from utils.version import MADVersion
from utils.walkerArgs import parseArgs
from websocket.WebsocketServer import WebsocketServer
args = parseArgs()
os.environ['LANGUAGE'] = args.language
initLogging(args)
def generate_mappingjson():
import json
newfile = {}
newfile['areas'] = []
newfile['auth'] = []
newfile['devices'] = []
newfile['walker'] = []
newfile['devicesettings'] = []
with open(args.mappings, 'w') as outfile:
json.dump(newfile, outfile, indent=4, sort_keys=True)
def start_madmin(args, db_wrapper: DbWrapperBase, ws_server, mapping_manager: MappingManager):
from madmin.madmin import madmin_start
madmin_start(args, db_wrapper, ws_server, mapping_manager)
if __name__ == "__main__":
logger.info('Start MAD configmode - pls wait')
filename = os.path.join('configs', 'config.ini')
if not os.path.exists(filename):
logger.error(
'config.ini file not found - check configs folder and copy .example')
sys.exit(1)
filename = args.mappings
if not os.path.exists(filename):
generate_mappingjson()
db_wrapper, db_wrapper_manager = DbFactory.get_wrapper(args)
db_wrapper.create_hash_database_if_not_exists()
db_wrapper.check_and_create_spawn_tables()
db_wrapper.create_quest_database_if_not_exists()
db_wrapper.create_status_database_if_not_exists()
db_wrapper.create_usage_database_if_not_exists()
db_wrapper.create_statistics_databases_if_not_exists()
version = MADVersion(args, db_wrapper)
version.get_version()
MappingManagerManager.register('MappingManager', MappingManager)
mapping_manager_manager = MappingManagerManager()
mapping_manager_manager.start()
mapping_manager_stop_event = mapping_manager_manager.Event()
mapping_manager: MappingManager = mapping_manager_manager.MappingManager(db_wrapper, args, True)
ws_server = WebsocketServer(args, None, db_wrapper, mapping_manager, None, True)
t_ws = Thread(name='scanner', target=ws_server.start_server)
t_ws.daemon = False
t_ws.start()
logger.success(
'Starting MADmin on port {} - open browser and click "Mapping Editor"', int(args.madmin_port))
t_flask = Thread(name='madmin', target=start_madmin,
args=(args, db_wrapper, ws_server, mapping_manager))
t_flask.daemon = False
t_flask.start()