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

@ -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)

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()

View File

@ -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 ("<account> 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 ("<account> has (dis)connected"). While the
# MudInfo channel will also receieve this info, this channel is meant for
# non-staffers.
CHANNEL_CONNECTINFO = None
######################################################################