Reworked config structure

This commit is contained in:
Sunpy 2018-10-09 10:54:35 +02:00
parent 5111b6b05f
commit 848dacf621
8 changed files with 54 additions and 30 deletions

View File

@ -1,18 +0,0 @@
{
"support-email": "support@ripple.moe",
"faq":
{
"rules": "Please make sure to check (Ripple's rules)[http://ripple.moe/?p=23].",
"swearing": "Please don't abuse swearing",
"spam": "Please don't spam",
"offend": "Please don't offend other players",
"github": "(Ripple's Github page!)[https://github.com/osuripple/ripple]",
"discord": "(Join Ripple's Discord!)[https://discord.gg/0rJcZruIsA6rXuIx]",
"blog": "You can find the latest Ripple news on the (blog)[https://ripple.moe/blog/]!",
"changelog": "Check the (changelog)[https://ripple.moe/index.php?p=17] !",
"status": "Check the server status (here!)[https://ripple.moe/index.php?p=27]",
"english": "Please keep this channel in english.",
"topic": "Can you please drop the topic and talk about something else?",
"lines": "Please try to keep your sentences on a single line to avoid getting silenced."
}
}

View File

@ -51,9 +51,9 @@ def instantRestart(fro, chan, message):
def faq(fro, chan, message):
key = message[0].lower()
if key not in glob.conf.extra["faq"]:
if key not in glob.conf.extra["pep.py"]["faq"]:
return False
return glob.conf.extra["faq"][key]
return glob.conf.extra["pep.py"]["faq"][key]
def roll(fro, chan, message):
maxPoints = 100

View File

@ -16,12 +16,12 @@ def forceUpdate():
def loginBanned():
packets = packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.SINT32]])
packets += notification("You are banned. You can appeal after one month since your ban by sending an email to {} from the email address you've used to sign up.".format(glob.conf.extra["support-email"]))
packets += notification("You are banned. You can appeal after one month since your ban by sending an email to {} from the email address you've used to sign up.".format(glob.conf.extra["pep.py"]["support-email"]))
return packets
def loginLocked():
packets = packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.SINT32]])
packets += notification("Your account is locked. You can't log in, but your profile and scores are still visible from the website. If you want to unlock your account, send an email to {} from the email address you've used to sign up.".format(glob.conf.extra["support-email"]))
packets += notification("Your account is locked. You can't log in, but your profile and scores are still visible from the website. If you want to unlock your account, send an email to {} from the email address you've used to sign up.".format(glob.conf.extra["pep.py"]["support-email"]))
return packets
def loginError():

View File

@ -243,7 +243,7 @@ class handler(requestsManager.asyncRequestHandler):
@tornado.web.asynchronous
@tornado.gen.engine
def asyncGet(self):
html = "<html><head><title>MA MAURO ESISTE?</title><style type='text/css'>body{width:30%}</style></head><body><pre>"
html = "<html><head><title>MA MAURO ESISTE?</title><style type='text/css'>body{width:30%;background:#222;color:#fff;}</style></head><body><pre>"
html += " _ __<br>"
html += " (_) / /<br>"
html += " ______ __ ____ ____ / /____<br>"
@ -262,5 +262,5 @@ class handler(requestsManager.asyncRequestHandler):
html += " \\\"\"\"\"\"\"\"\"\"\"\"\"\"\"/<br>"
html += " \\ . .. .. . /<br>"
html += "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>"
html += "</marquee><br><strike>reverse engineering a protocol impossible to reverse engineer since always</strike><br>we are actually reverse engineering bancho successfully. for the third time.<br><br><i>&copy; Ripple team, 2016</i></pre></body></html>"
html += "</marquee><br><strike>reverse engineering a protocol impossible to reverse engineer since always</strike><br>we are actually reverse engineering bancho successfully. for the third time.<br><br>Running osufx branch.<br><i>&copy; Ripple team, 2016</i></pre></body></html>"
self.write(html)

View File

@ -73,6 +73,8 @@ class config:
self.config.get("localize","enable")
self.config.get("localize","ipapiurl")
self.config.get("custom", "config")
return True
except configparser.Error:
return False
@ -140,6 +142,9 @@ class config:
self.config.set("localize", "enable", "1")
self.config.set("localize", "ipapiurl", "http://ip.zxq.co")
self.config.add_section("custom")
self.config.set("custom", "config", "common/config.json")
# Write ini to file and close
self.config.write(f)
f.close()

View File

@ -27,8 +27,11 @@ def printServerStartHeader(asciiArt=True):
print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^{}".format(bcolors.ENDC))
printColored("> Welcome to pep.py osu!bancho server v{}".format(glob.VERSION), bcolors.GREEN)
printColored("> Common submodule v{}".format(glob.COMMON_VERSION), bcolors.GREEN)
printColored("> Made by the Ripple team", bcolors.GREEN)
printColored("> {}https://zxq.co/ripple/pep.py".format(bcolors.UNDERLINE), bcolors.GREEN)
printColored("> Custom branch by the osufx team (just Sunpy)", bcolors.GREEN)
printColored("> {}https://github.com/osufx/pep.py".format(bcolors.UNDERLINE), bcolors.GREEN)
printColored("> Press CTRL+C to exit\n", bcolors.GREEN)
def printNoNl(string):

View File

@ -49,3 +49,11 @@ restarting = False
startTime = int(time.time())
streams = streamList.streamList()
# Additional modifications
COMMON_VERSION_REQ = "1.2.1"
try:
with open("common/version") as f:
COMMON_VERSION = f.read().strip()
except:
COMMON_VERSION = "Unknown"

38
pep.py
View File

@ -1,7 +1,6 @@
import os
import sys
import threading
import json
from multiprocessing.pool import ThreadPool
import tornado.gen
import tornado.httpserver
@ -10,6 +9,10 @@ import tornado.web
from raven.contrib.tornado import AsyncSentryClient
import redis
import json
import shutil
from distutils.version import LooseVersion
from common import generalUtils, agpl
from common.constants import bcolors
from common.db import dbConnector
@ -71,11 +74,6 @@ if __name__ == "__main__":
consoleHelper.printNoNl("> Loading config file... ")
glob.conf = configHelper.config("config.ini")
# Read additional config file
consoleHelper.printNoNl("> Loading additional config file... ")
with open("config.json", "r") as f:
glob.conf.extra = json.load(f)
if glob.conf.default:
# We have generated a default config.ini, quit server
consoleHelper.printWarning()
@ -91,6 +89,34 @@ if __name__ == "__main__":
sys.exit()
else:
consoleHelper.printDone()
# Read additional config file
consoleHelper.printNoNl("> Loading additional config file... ")
try:
if not os.path.isfile(glob.conf.config["custom"]["config"]):
consoleHelper.printWarning()
consoleHelper.printColored("[!] Missing config file at {}; A default one has been generated at this location.".format(glob.conf.config["custom"]["config"]), bcolors.YELLOW)
shutil.copy("common/default_config.json", glob.conf.config["custom"]["config"])
with open(glob.conf.config["custom"]["config"], "r") as f:
glob.conf.extra = json.load(f)
consoleHelper.printDone()
except:
consoleHelper.printWarning()
consoleHelper.printColored("[!] Unable to load custom config at {}".format(glob.conf.config["custom"]["config"]), bcolors.RED)
consoleHelper.printColored("[!] Make sure you have the latest osufx common submodule!", bcolors.RED)
sys.exit()
# Check if running common module is usable
if glob.COMMON_VERSION == "Unknown":
consoleHelper.printWarning()
consoleHelper.printColored("[!] You do not seem to be using osufx's common submodule... nothing will work...", bcolors.RED)
consoleHelper.printColored("[!] You can download or fork the submodule from {}https://github.com/osufx/ripple-python-common".format(bcolors.UNDERLINE), bcolors.RED)
sys.exit()
elif LooseVersion(glob.COMMON_VERSION_REQ) > LooseVersion(glob.COMMON_VERSION):
consoleHelper.printColored("[!] Your common submodule version is below the required version number for this version of pep.py.", bcolors.RED)
consoleHelper.printColored("[!] You are highly adviced to update your common submodule as stability may vary with outdated modules.", bcolors.RED)
# Create data folder if needed
consoleHelper.printNoNl("> Checking folders... ")