From c520ef86c9ac10df334f0060dd053d8677f6d9bc Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 8 Sep 2019 00:09:00 +0200 Subject: [PATCH] Make DEFAULT_CHANNELS auto-recreate missing channels. Add new CHANNEL_MUDINFO setting. --- CHANGELOG.md | 3 +++ evennia/server/deprecations.py | 6 ++++++ evennia/server/initial_setup.py | 11 ++++++++++ evennia/server/server.py | 24 +++++++++++++++++++++ evennia/server/serversession.py | 2 +- evennia/settings_default.py | 38 +++++++++++++++++---------------- 6 files changed, 65 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ec914a5cf..7e080f5576 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ without arguments starts a full interactive Python console. global scripts regardless of how they were created. - Change settings to always use lists instead of tuples, to make mutable settings easier to add to. (#1912) +- Make new `CHANNEL_MUDINFO` setting for specifying the mudinfo channel +- Make `CHANNEL_CONNECTINFO` take full channel definition +- Make `DEFAULT_CHANNELS` list auto-create channels missing at reload ## Evennia 0.9 (2018-2019) diff --git a/evennia/server/deprecations.py b/evennia/server/deprecations.py index 3920c50879..976040a8e9 100644 --- a/evennia/server/deprecations.py +++ b/evennia/server/deprecations.py @@ -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): """ diff --git a/evennia/server/initial_setup.py b/evennia/server/initial_setup.py index 759e15694a..793bc7b541 100644 --- a/evennia/server/initial_setup.py +++ b/evennia/server/initial_setup.py @@ -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) diff --git a/evennia/server/server.py b/evennia/server/server.py index 5a8f88f257..f5fea192e5 100644 --- a/evennia/server/server.py +++ b/evennia/server/server.py @@ -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) diff --git a/evennia/server/serversession.py b/evennia/server/serversession.py index 5ce1fdbe40..539d573f6f 100644 --- a/evennia/server/serversession.py +++ b/evennia/server/serversession.py @@ -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() diff --git a/evennia/settings_default.py b/evennia/settings_default.py index a7cc4c56f5..8820ba58f6 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -661,30 +661,32 @@ GUEST_LIST = ["Guest" + str(s + 1) for s in range(9)] # In-game Channels created from server start ###################################################################### -# This is a list of global channels created by the -# initialization script the first time Evennia starts. -# The superuser (user #1) will be automatically subscribed -# to all channels in this list. Each channel is described by -# a dictionary keyed with the same keys valid as arguments -# to the evennia.create.create_channel() function. -# Note: Evennia will treat the first channel in this list as -# the general "public" channel and the second as the -# general "mud info" channel. Other channels beyond that -# are up to the admin to design and call appropriately. +# The mudinfo channel must always exist; it is used by Evennia itself to +# relay status messages, connection info etc to staff. The superuser will be +# automatically subscribed to this channel and it will be recreated on a +# reload if deleted. This is a dict specifying the kwargs needed to create +# the channel . +CHANNEL_MUDINFO = { + "key": "MudInfo", + "aliases": "", + "desc": "Connection log", + "locks": "control:perm(Developer);listen:perm(Admin);send:false()"} +# These are additional channels to offer. Usually, at least 'public' +# should exist. The superuser will automatically be subscribed to all channels +# in this list. New entries will be created on the next reload. But +# removing or updating a same-key channel from this list will NOT automatically +# change/remove it in the game, that needs to be done manually. DEFAULT_CHANNELS = [ # public channel {"key": "Public", - "aliases": ('ooc', 'pub'), + "aliases": ('pub'), "desc": "Public discussion", "locks": "control:perm(Admin);listen:all();send:all()"}, - # connection/mud info - {"key": "MudInfo", - "aliases": "", - "desc": "Connection log", - "locks": "control:perm(Developer);listen:perm(Admin);send:false()"} ] -# Extra optional channel for receiving connection messages (" has (dis)connected"). -# While the MudInfo channel will also receieve this, this channel is meant for non-staffers. +# Optional channel info (same form as CHANNEL_MUDINFO) for the channel to +# receive connection messages (" has (dis)connected"). While the +# MudInfo channel will also receieve this info, this channel is meant for +# non-staffers. CHANNEL_CONNECTINFO = None ######################################################################