Make new users properly auto-join default channels. Resolve #3239

This commit is contained in:
Griatch 2023-08-06 21:19:13 +02:00
parent 84f609fc6f
commit 9f08b6c9df
2 changed files with 60 additions and 37 deletions

View file

@ -14,13 +14,13 @@ import re
import time
from random import getrandbits
import evennia
from django.conf import settings
from django.contrib.auth import authenticate, password_validation
from django.core.exceptions import ImproperlyConfigured, ValidationError
from django.utils import timezone
from django.utils.module_loading import import_string
from django.utils.translation import gettext as _
import evennia
from evennia.accounts.manager import AccountManager
from evennia.accounts.models import AccountDB
from evennia.commands.cmdsethandler import CmdSetHandler
@ -854,13 +854,28 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
if ip:
account.db.creator_ip = ip
# join the new account to the public channel
# join the new account to the public channels
pchannel = ChannelDB.objects.get_channel(settings.DEFAULT_CHANNELS[0]["key"])
if not pchannel or not pchannel.connect(account):
string = "New account '{account.key}' could not connect to public channel!"
errors.append(string)
logger.log_err(string)
# join the new account to the public channels
for chan_info in settings.DEFAULT_CHANNELS:
if chankey := chan_info.get("key"):
channel = ChannelDB.objects.get_channel(chankey)
if not channel or not (
channel.access(account, "listen") and channel.connect(account)
):
string = (
f"New account '{account.key}' could not connect to default channel"
f" '{chankey}'!"
)
logger.log_err(string)
else:
logger.log_err(f"Default channel '{chan_info}' is missing a 'key' field!")
if account and _AUTO_CREATE_CHARACTER_WITH_ACCOUNT:
# Auto-create a character to go with this account

View file

@ -6,9 +6,8 @@ import datetime
import re
from codecs import lookup as codecs_lookup
from django.conf import settings
import evennia
from django.conf import settings
from evennia.commands.cmdhandler import CMD_LOGINSTART
from evennia.comms.models import ChannelDB
from evennia.utils import class_from_module, create, gametime, logger, utils
@ -490,15 +489,24 @@ def _create_account(session, accountname, password, permissions, typeclass=None,
# hooks during login later)
new_account.db.FIRST_LOGIN = True
# join the new account to the public channel
pchannel = ChannelDB.objects.get_channel(settings.DEFAULT_CHANNELS[0]["key"])
if not pchannel or not pchannel.connect(new_account):
string = "New account '%s' could not connect to public channel!" % new_account.key
# join the new account to the public channels
for chan_info in settings.DEFAULT_CHANNELS:
if chankey := chan_info.get("key"):
channel = ChannelDB.objects.get_channel(chankey)
if not channel or not (
channel.access(new_account, "listen") and channel.connect(new_account)
):
string = (
f"New account '{new_account.key}' could not connect to default channel"
f" '{chankey}'!"
)
logger.log_err(string)
else:
logger.log_err(f"Default channel '{chan_info}' is missing a 'key' field!")
return new_account
def _create_character(session, new_account, typeclass, home, permissions):
def _create_character(session, new_account, typeclass, home, permissions):
"""
Helper function, creates a character based on an account's name.
This is meant for Guest and AUTO_CREATRE_CHARACTER_WITH_ACCOUNT=True situations.
@ -523,7 +531,7 @@ def _create_character(session, new_account, typeclass, home, permissions):
new_account.db._last_puppet = new_character
except Exception as e:
session.msg(
"There was an error creating the Character:\n%s\n If this problem persists, contact an"
" admin." % e
"There was an error creating the Character:\n%s\n If this problem persists, contact"
" an admin." % e
)
logger.log_trace()