mirror of
https://github.com/evennia/evennia.git
synced 2025-10-29 19:35:56 +00:00
Add secret_settings and mechanisms for managing it. This allows for easier hiding game- and server-specific settings when sharing the game dir with others.
This commit is contained in:
parent
b269ef265e
commit
167d09b4cd
@ -25,9 +25,9 @@ __pycache__
|
||||
*.restart
|
||||
*.db3
|
||||
|
||||
# Installation-specific.
|
||||
# Installation-specific.
|
||||
# For group efforts, comment out some or all of these.
|
||||
server/conf/settings.py
|
||||
server/conf/secret_settings.py
|
||||
server/logs/*.log.*
|
||||
web/static/*
|
||||
web/media/*
|
||||
17
evennia/game_template/server/conf/secret_settings.py
Normal file
17
evennia/game_template/server/conf/secret_settings.py
Normal file
@ -0,0 +1,17 @@
|
||||
"""
|
||||
This file is meant for when you want to share your game dir with
|
||||
others but don't want to share all details of your specific game
|
||||
or local server setup. The settings in this file will override those
|
||||
in settings.py and is in .gitignore by default.
|
||||
|
||||
A good guideline when sharing your game dir is that you want your
|
||||
game to run correctly also without this file and only use this
|
||||
to override your public, shared settings.
|
||||
|
||||
"""
|
||||
|
||||
# The secret key is randomly seeded upon creation. It is used to sign
|
||||
# Django's cookies and should not be publicly known. It should also
|
||||
# generally not be changed once people have registered with the game
|
||||
# since it will invalidate their existing sessions.
|
||||
SECRET_KEY = {secret_key}
|
||||
@ -19,6 +19,9 @@ paths (path.to.module) should be given relative to the game's root
|
||||
folder (typeclasses.foo) whereas paths within the Evennia library
|
||||
needs to be given explicitly (evennia.foo).
|
||||
|
||||
If you want to share your game dir, including its settings, you can
|
||||
put secret game- or server-specific settings in secret_settings.py.
|
||||
|
||||
"""
|
||||
|
||||
# Use the defaults from Evennia unless explicitly overridden
|
||||
@ -31,13 +34,11 @@ from evennia.settings_default import *
|
||||
# This is the name of your game. Make it catchy!
|
||||
SERVERNAME = {servername}
|
||||
|
||||
######################################################################
|
||||
# Django web features
|
||||
######################################################################
|
||||
|
||||
|
||||
# The secret key is randomly seeded upon creation. It is used to sign
|
||||
# Django's cookies. Do not share this with anyone. Changing it will
|
||||
# log out all active web browsing sessions. Game web client sessions
|
||||
# may survive.
|
||||
SECRET_KEY = {secret_key}
|
||||
######################################################################
|
||||
# Settings given in secret_settings.py override those in this file.
|
||||
######################################################################
|
||||
try:
|
||||
from server.conf.secret_settings import *
|
||||
except ImportError:
|
||||
print "secret_settings.py file not found or failed to import."
|
||||
|
||||
@ -506,7 +506,7 @@ def create_secret_key():
|
||||
return secret_key
|
||||
|
||||
|
||||
def create_settings_file(init=True):
|
||||
def create_settings_file(init=True, secret_settings=False):
|
||||
"""
|
||||
Uses the template settings file to build a working settings file.
|
||||
|
||||
@ -514,18 +514,27 @@ def create_settings_file(init=True):
|
||||
init (bool): This is part of the normal evennia --init
|
||||
operation. If false, this function will copy a fresh
|
||||
template file in (asking if it already exists).
|
||||
secret_settings (bool, optional): If False, create settings.py, otherwise
|
||||
create the secret_settings.py file.
|
||||
|
||||
"""
|
||||
settings_path = os.path.join(GAMEDIR, "server", "conf", "settings.py")
|
||||
if secret_settings:
|
||||
settings_path = os.path.join(GAMEDIR, "server", "conf", "secret_settings.py")
|
||||
setting_dict = {"secret_key": "\'%s\'" % create_secret_key()}
|
||||
else:
|
||||
settings_path = os.path.join(GAMEDIR, "server", "conf", "settings.py")
|
||||
setting_dict = {
|
||||
"settings_default": os.path.join(EVENNIA_LIB, "settings_default.py"),
|
||||
"servername": "\"%s\"" % GAMEDIR.rsplit(os.path.sep, 1)[1].capitalize(),
|
||||
"secret_key": "\'%s\'" % create_secret_key()}
|
||||
|
||||
if not init:
|
||||
# if not --init mode, settings file may already exist from before
|
||||
if os.path.exists(settings_path):
|
||||
inp = input("server/conf/settings.py already exists. "
|
||||
"Do you want to reset it? y/[N]> ")
|
||||
inp = input("%s already exists. Do you want to reset it? y/[N]> " % settings_path)
|
||||
if not inp.lower() == 'y':
|
||||
print ("Aborted.")
|
||||
sys.exit()
|
||||
return
|
||||
else:
|
||||
print ("Reset the settings file.")
|
||||
|
||||
@ -535,12 +544,6 @@ def create_settings_file(init=True):
|
||||
with open(settings_path, 'r') as f:
|
||||
settings_string = f.read()
|
||||
|
||||
# tweak the settings
|
||||
setting_dict = {
|
||||
"settings_default": os.path.join(EVENNIA_LIB, "settings_default.py"),
|
||||
"servername": "\"%s\"" % GAMEDIR.rsplit(os.path.sep, 1)[1].capitalize(),
|
||||
"secret_key": "\'%s\'" % create_secret_key()}
|
||||
|
||||
settings_string = settings_string.format(**setting_dict)
|
||||
|
||||
with open(settings_path, 'w') as f:
|
||||
@ -564,8 +567,13 @@ def create_game_directory(dirname):
|
||||
sys.exit()
|
||||
# copy template directory
|
||||
shutil.copytree(EVENNIA_TEMPLATE, GAMEDIR)
|
||||
# rename gitignore to .gitignore
|
||||
os.rename(os.path.join(GAMEDIR, 'gitignore'),
|
||||
os.path.join(GAMEDIR, '.gitignore'))
|
||||
|
||||
# pre-build settings file in the new GAMEDIR
|
||||
create_settings_file()
|
||||
create_settings_file(secret_settings=True)
|
||||
|
||||
|
||||
def create_superuser():
|
||||
|
||||
@ -174,7 +174,7 @@ class Evennia(object):
|
||||
# (see https://github.com/evennia/evennia/issues/1128)
|
||||
def _wrap_sigint_handler(*args):
|
||||
from twisted.internet.defer import Deferred
|
||||
if WEBSERVER_ENABLED:
|
||||
if hasattr(self, "webroot"):
|
||||
d = self.web_root.empty_threadpool()
|
||||
d.addCallback(lambda _: self.shutdown(_reactor_stopping=True))
|
||||
else:
|
||||
@ -399,7 +399,7 @@ class Evennia(object):
|
||||
# for Windows we need to remove pid files manually
|
||||
os.remove(SERVER_PIDFILE)
|
||||
|
||||
if WEBSERVER_ENABLED:
|
||||
if hasattr(self, "web_root"): # not set very first start
|
||||
yield self.web_root.empty_threadpool()
|
||||
|
||||
if not _reactor_stopping:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user