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
5 changed files with 50 additions and 24 deletions
|
|
@ -25,9 +25,9 @@ __pycache__
|
||||||
*.restart
|
*.restart
|
||||||
*.db3
|
*.db3
|
||||||
|
|
||||||
# Installation-specific.
|
# Installation-specific.
|
||||||
# For group efforts, comment out some or all of these.
|
# For group efforts, comment out some or all of these.
|
||||||
server/conf/settings.py
|
server/conf/secret_settings.py
|
||||||
server/logs/*.log.*
|
server/logs/*.log.*
|
||||||
web/static/*
|
web/static/*
|
||||||
web/media/*
|
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
|
folder (typeclasses.foo) whereas paths within the Evennia library
|
||||||
needs to be given explicitly (evennia.foo).
|
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
|
# 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!
|
# This is the name of your game. Make it catchy!
|
||||||
SERVERNAME = {servername}
|
SERVERNAME = {servername}
|
||||||
|
|
||||||
######################################################################
|
|
||||||
# Django web features
|
|
||||||
######################################################################
|
|
||||||
|
|
||||||
|
######################################################################
|
||||||
# The secret key is randomly seeded upon creation. It is used to sign
|
# Settings given in secret_settings.py override those in this file.
|
||||||
# Django's cookies. Do not share this with anyone. Changing it will
|
######################################################################
|
||||||
# log out all active web browsing sessions. Game web client sessions
|
try:
|
||||||
# may survive.
|
from server.conf.secret_settings import *
|
||||||
SECRET_KEY = {secret_key}
|
except ImportError:
|
||||||
|
print "secret_settings.py file not found or failed to import."
|
||||||
|
|
|
||||||
|
|
@ -506,7 +506,7 @@ def create_secret_key():
|
||||||
return 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.
|
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
|
init (bool): This is part of the normal evennia --init
|
||||||
operation. If false, this function will copy a fresh
|
operation. If false, this function will copy a fresh
|
||||||
template file in (asking if it already exists).
|
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:
|
||||||
# if not --init mode, settings file may already exist from before
|
# if not --init mode, settings file may already exist from before
|
||||||
if os.path.exists(settings_path):
|
if os.path.exists(settings_path):
|
||||||
inp = input("server/conf/settings.py already exists. "
|
inp = input("%s already exists. Do you want to reset it? y/[N]> " % settings_path)
|
||||||
"Do you want to reset it? y/[N]> ")
|
|
||||||
if not inp.lower() == 'y':
|
if not inp.lower() == 'y':
|
||||||
print ("Aborted.")
|
print ("Aborted.")
|
||||||
sys.exit()
|
return
|
||||||
else:
|
else:
|
||||||
print ("Reset the settings file.")
|
print ("Reset the settings file.")
|
||||||
|
|
||||||
|
|
@ -535,12 +544,6 @@ def create_settings_file(init=True):
|
||||||
with open(settings_path, 'r') as f:
|
with open(settings_path, 'r') as f:
|
||||||
settings_string = f.read()
|
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)
|
settings_string = settings_string.format(**setting_dict)
|
||||||
|
|
||||||
with open(settings_path, 'w') as f:
|
with open(settings_path, 'w') as f:
|
||||||
|
|
@ -564,8 +567,13 @@ def create_game_directory(dirname):
|
||||||
sys.exit()
|
sys.exit()
|
||||||
# copy template directory
|
# copy template directory
|
||||||
shutil.copytree(EVENNIA_TEMPLATE, GAMEDIR)
|
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
|
# pre-build settings file in the new GAMEDIR
|
||||||
create_settings_file()
|
create_settings_file()
|
||||||
|
create_settings_file(secret_settings=True)
|
||||||
|
|
||||||
|
|
||||||
def create_superuser():
|
def create_superuser():
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ class Evennia(object):
|
||||||
# (see https://github.com/evennia/evennia/issues/1128)
|
# (see https://github.com/evennia/evennia/issues/1128)
|
||||||
def _wrap_sigint_handler(*args):
|
def _wrap_sigint_handler(*args):
|
||||||
from twisted.internet.defer import Deferred
|
from twisted.internet.defer import Deferred
|
||||||
if WEBSERVER_ENABLED:
|
if hasattr(self, "webroot"):
|
||||||
d = self.web_root.empty_threadpool()
|
d = self.web_root.empty_threadpool()
|
||||||
d.addCallback(lambda _: self.shutdown(_reactor_stopping=True))
|
d.addCallback(lambda _: self.shutdown(_reactor_stopping=True))
|
||||||
else:
|
else:
|
||||||
|
|
@ -399,7 +399,7 @@ class Evennia(object):
|
||||||
# for Windows we need to remove pid files manually
|
# for Windows we need to remove pid files manually
|
||||||
os.remove(SERVER_PIDFILE)
|
os.remove(SERVER_PIDFILE)
|
||||||
|
|
||||||
if WEBSERVER_ENABLED:
|
if hasattr(self, "web_root"): # not set very first start
|
||||||
yield self.web_root.empty_threadpool()
|
yield self.web_root.empty_threadpool()
|
||||||
|
|
||||||
if not _reactor_stopping:
|
if not _reactor_stopping:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue