-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
72 lines (61 loc) · 2.61 KB
/
main.py
File metadata and controls
72 lines (61 loc) · 2.61 KB
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
"""
A lot of this has been taken directly from https://zxq.co/ripple/pep.py/src/branch/master/pep.py
and modified to fit the project.
I dont see the reason to reinvent the structure if this is suppost to work alongside the original project.
"""
import redis
import sys
import os
from helpers import consoleHelper, configHelper
from common.constants import bcolors
from objects import glob
import redis_subscriber
import time
if __name__ == "__main__":
try:
# Server start
consoleHelper.printServerStartHeader(True)
# Read config.ini
consoleHelper.printNoNl("> Loading config file...")
glob.conf = configHelper.config("config.ini")
if glob.conf.default:
# We have generated a default config.ini, quit server
consoleHelper.printWarning()
consoleHelper.printColored("[!] config.ini not found. A default one has been generated.", bcolors.YELLOW)
consoleHelper.printColored("[!] Please edit your config.ini and run the server again.", bcolors.YELLOW)
sys.exit()
# If we haven't generated a default config.ini, check if it's valid
if not glob.conf.checkConfig():
consoleHelper.printError()
consoleHelper.printColored("[!] Invalid config.ini. Please configure it properly.", bcolors.RED)
consoleHelper.printColored("[!] Delete your config.ini to generate a default one.", bcolors.RED)
sys.exit()
else:
consoleHelper.printDone()
if not os.path.isdir(glob.conf.config["paths"]["lets"]):
consoleHelper.printError()
consoleHelper.printColored("[!] Invalid path for lets", bcolors.RED)
consoleHelper.printColored("[!] Please edit your config.ini and run the server again.", bcolors.RED)
sys.exit()
# Connect to redis
try:
consoleHelper.printNoNl("> Connecting to redis... ")
glob.redis = redis.Redis(glob.conf.config["redis"]["host"], glob.conf.config["redis"]["port"], glob.conf.config["redis"]["database"], glob.conf.config["redis"]["password"])
glob.redis.ping()
consoleHelper.printNoNl(" ")
consoleHelper.printDone()
except:
# Exception while connecting to db
consoleHelper.printError()
consoleHelper.printColored("[!] Error while connection to redis. Please check your config.ini and run the server again", bcolors.RED)
raise
# Subscribe to redis events
consoleHelper.printColored("> Subscribing to redis events... ", bcolors.YELLOW)
redis_subscriber.subscribe()
consoleHelper.printDone()
while True: # Makeshift (PLEASE CHANGE)
time.sleep(1)
finally:
print("> Disposing server... ")
# glob.fileBuffers.flushAll() #Maybe I will need something like this? I am not using any files on disk atm.
consoleHelper.printColored("Goodbye!", bcolors.GREEN)