diff --git a/evennia/accounts/accounts.py b/evennia/accounts/accounts.py index baf2c50d9..90760325a 100644 --- a/evennia/accounts/accounts.py +++ b/evennia/accounts/accounts.py @@ -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 diff --git a/evennia/commands/default/unloggedin.py b/evennia/commands/default/unloggedin.py index 97bc95356..574859ed2 100644 --- a/evennia/commands/default/unloggedin.py +++ b/evennia/commands/default/unloggedin.py @@ -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,40 +489,49 @@ 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 - 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(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): + """ + Helper function, creates a character based on an account's name. + This is meant for Guest and AUTO_CREATRE_CHARACTER_WITH_ACCOUNT=True situations. + """ + try: + new_character = create.create_object( + typeclass, key=new_account.key, home=home, permissions=permissions + ) + # set playable character list + new_account.db._playable_characters.append(new_character) -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. - """ - try: - new_character = create.create_object( - typeclass, key=new_account.key, home=home, permissions=permissions - ) - # set playable character list - new_account.db._playable_characters.append(new_character) + # allow only the character itself and the account to puppet this character (and Developers). + new_character.locks.add( + "puppet:id(%i) or pid(%i) or perm(Developer) or pperm(Developer)" + % (new_character.id, new_account.id) + ) - # allow only the character itself and the account to puppet this character (and Developers). - new_character.locks.add( - "puppet:id(%i) or pid(%i) or perm(Developer) or pperm(Developer)" - % (new_character.id, new_account.id) - ) - - # If no description is set, set a default description - if not new_character.db.desc: - new_character.db.desc = "This is a character." - # We need to set this to have ic auto-connect to this character - 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 - ) - logger.log_trace() + # If no description is set, set a default description + if not new_character.db.desc: + new_character.db.desc = "This is a character." + # We need to set this to have ic auto-connect to this character + 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 + ) + logger.log_trace()