Make new users properly auto-join default channels. Resolve #3239
This commit is contained in:
parent
84f609fc6f
commit
9f08b6c9df
2 changed files with 60 additions and 37 deletions
|
|
@ -14,13 +14,13 @@ import re
|
||||||
import time
|
import time
|
||||||
from random import getrandbits
|
from random import getrandbits
|
||||||
|
|
||||||
|
import evennia
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth import authenticate, password_validation
|
from django.contrib.auth import authenticate, password_validation
|
||||||
from django.core.exceptions import ImproperlyConfigured, ValidationError
|
from django.core.exceptions import ImproperlyConfigured, ValidationError
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.module_loading import import_string
|
from django.utils.module_loading import import_string
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
import evennia
|
|
||||||
from evennia.accounts.manager import AccountManager
|
from evennia.accounts.manager import AccountManager
|
||||||
from evennia.accounts.models import AccountDB
|
from evennia.accounts.models import AccountDB
|
||||||
from evennia.commands.cmdsethandler import CmdSetHandler
|
from evennia.commands.cmdsethandler import CmdSetHandler
|
||||||
|
|
@ -854,13 +854,28 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
|
||||||
if ip:
|
if ip:
|
||||||
account.db.creator_ip = 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"])
|
pchannel = ChannelDB.objects.get_channel(settings.DEFAULT_CHANNELS[0]["key"])
|
||||||
if not pchannel or not pchannel.connect(account):
|
if not pchannel or not pchannel.connect(account):
|
||||||
string = "New account '{account.key}' could not connect to public channel!"
|
string = "New account '{account.key}' could not connect to public channel!"
|
||||||
errors.append(string)
|
errors.append(string)
|
||||||
logger.log_err(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:
|
if account and _AUTO_CREATE_CHARACTER_WITH_ACCOUNT:
|
||||||
# Auto-create a character to go with this account
|
# Auto-create a character to go with this account
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,8 @@ import datetime
|
||||||
import re
|
import re
|
||||||
from codecs import lookup as codecs_lookup
|
from codecs import lookup as codecs_lookup
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
import evennia
|
import evennia
|
||||||
|
from django.conf import settings
|
||||||
from evennia.commands.cmdhandler import CMD_LOGINSTART
|
from evennia.commands.cmdhandler import CMD_LOGINSTART
|
||||||
from evennia.comms.models import ChannelDB
|
from evennia.comms.models import ChannelDB
|
||||||
from evennia.utils import class_from_module, create, gametime, logger, utils
|
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)
|
# hooks during login later)
|
||||||
new_account.db.FIRST_LOGIN = True
|
new_account.db.FIRST_LOGIN = True
|
||||||
|
|
||||||
# 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"])
|
for chan_info in settings.DEFAULT_CHANNELS:
|
||||||
if not pchannel or not pchannel.connect(new_account):
|
if chankey := chan_info.get("key"):
|
||||||
string = "New account '%s' could not connect to public channel!" % new_account.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)
|
logger.log_err(string)
|
||||||
|
else:
|
||||||
|
logger.log_err(f"Default channel '{chan_info}' is missing a 'key' field!")
|
||||||
|
|
||||||
return new_account
|
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.
|
Helper function, creates a character based on an account's name.
|
||||||
This is meant for Guest and AUTO_CREATRE_CHARACTER_WITH_ACCOUNT=True situations.
|
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
|
new_account.db._last_puppet = new_character
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
session.msg(
|
session.msg(
|
||||||
"There was an error creating the Character:\n%s\n If this problem persists, contact an"
|
"There was an error creating the Character:\n%s\n If this problem persists, contact"
|
||||||
" admin." % e
|
" an admin." % e
|
||||||
)
|
)
|
||||||
logger.log_trace()
|
logger.log_trace()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue