Make DEFAULT_CHANNELS auto-recreate missing channels. Add new CHANNEL_MUDINFO setting.

This commit is contained in:
Griatch 2019-09-08 00:09:00 +02:00
parent dd8b3c1ba2
commit c520ef86c9
6 changed files with 65 additions and 19 deletions

View file

@ -76,6 +76,12 @@ def check_errors(settings):
if hasattr(settings, "GAME_DIRECTORY_LISTING"):
raise DeprecationWarning(game_directory_deprecation)
chan_connectinfo = settings.CHANNEL_CONNECTINFO
if chan_connectinfo is not None and not isinstance(chan_connectinfo, dict):
raise DeprecationWarning("settings.CHANNEL_CONNECTINFO has changed. It "
"must now be either None or a dict "
"specifying the properties of the channel to create.")
def check_warnings(settings):
"""

View file

@ -124,6 +124,17 @@ def create_channels():
logger.log_info("Initial setup: Creating default channels ...")
goduser = get_god_account()
channel_mudinfo = settings.CHANNEL_MUDINFO
if not channel_mudinfo:
raise RuntimeError("settings.CHANNEL_MUDINFO must be defined.")
channel = create.create_channel(**channel_mudinfo)
channel.connect(goduser)
channel_connectinfo = settings.CHANNEL_CONNECTINFO
if channel_connectinfo:
channel = create.create_channel(**channel_connectinfo)
for channeldict in settings.DEFAULT_CHANNELS:
channel = create.create_channel(**channeldict)
channel.connect(goduser)

View file

@ -459,6 +459,30 @@ class Evennia(object):
TASK_HANDLER.load()
TASK_HANDLER.create_delays()
# check so default channels exist
from evennia.comms.models import ChannelDB
from evennia.accounts.models import AccountDB
from evennia.utils.create import create_channel
god_account = AccountDB.objects.get(id=1)
# mudinfo
mudinfo_chan = settings.CHANNEL_MUDINFO
if not mudinfo_chan:
raise RuntimeError("settings.CHANNEL_MUDINFO must be defined.")
if not ChannelDB.objects.filter(db_key=mudinfo_chan['key']):
channel = create_channel(**mudinfo_chan)
channel.connect(god_account)
# connectinfo
connectinfo_chan = settings.CHANNEL_MUDINFO
if connectinfo_chan:
if not ChannelDB.objects.filter(db_key=mudinfo_chan['key']):
channel = create_channel(**connectinfo_chan)
# default channels
for chan_info in settings.DEFAULT_CHANNELS:
if not ChannelDB.objects.filter(db_key=chan_info['key']):
channel = create_channel(**chan_info)
channel.connect(god_account)
# delete the temporary setting
ServerConfig.objects.conf("server_restart_mode", delete=True)

View file

@ -304,7 +304,7 @@ class ServerSession(Session):
cchan = channel and settings.CHANNEL_CONNECTINFO
if cchan:
try:
cchan = ChannelDB.objects.get_channel(cchan[0])
cchan = ChannelDB.objects.get_channel(cchan['key'])
cchan.msg("[%s]: %s" % (cchan.key, message))
except Exception:
logger.log_trace()