-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathMain.py
61 lines (46 loc) · 2.26 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from Core.Networking.Server import Server
import json # meh
from Utils.Updater import Updater
class Main:
def __init__(self):
self.crashCount: int = 0
self.configuration = json.loads(open("config.json", "r").read())
self.useUpdater = self.configuration.get("UpgradesEnabled", False)
self.main()
self.updater: Updater = None
def main(self):
if self.useUpdater: self.updater = Updater() # Execute deadly weapons
if not self.updater.updateInstalled and self.crashCount >= 2:
print("No fixes are available for the crashes. Shutting down server...")
exit()
try:
print(r"""
________ _ ____ __
/ ____/ /___ ___________(_)____ / __ )_________ __ __/ /
/ / / / __ `/ ___/ ___/ / ___/ / __ / ___/ __ `/ | /| / / /
/ /___/ / /_/ (__ |__ ) / /__ / /_/ / / / /_/ /| |/ |/ / /
\____/_/\__,_/____/____/_/\___/ /_____/_/ \__,_/ |__/|__/_/
""")
Server("0.0.0.0", 9339).start()
except ImportError:
print("Some modules are missing, please run pip install -r requirements.txt on your terminal to install them.")
except Exception as e:
if self.useUpdater:
self.crashCount += 1
if self.crashCount >= 2:
# TODO: Close all connections so that the server gets a bit faster on fixing stuff
req = "yes" in input("The server has crashed 2+ times."
" Would you like to check for updates in case there's a fix? ").lower()
if req: self.main()
updaterRollbackRequest: bool = "yes" in input(
f"The Updater has detected that the server is in a crashed state (error: {e}).\n"
"Would you like to roll-back the update? ").lower()
if updaterRollbackRequest:
self.updater.performRollback()
print("The roll-back has been completed successfully!")
self.crashCount = 0
else:
print("Request declined. Restarting server...\n")
self.main()
if __name__ == '__main__':
Main()