예제 #1
0
def create_normal_player(session, playername, password):
    """
    Create a new player.
    """
    # sanity checks
    if not re.findall('^[\w. @+-]+$',
                      playername) or not (0 < len(playername) <= 32):
        # this echoes the restrictions made by django's auth
        # module (except not allowing spaces, for convenience of
        # logging in).
        string = "\n\r Playername can max be 32 characters or fewer. Letters, spaces, digits and @/./+/-/_ only."
        session.msg({"alert": string})
        return
    # strip excessive spaces in playername
    playername = re.sub(r"\s+", " ", playername).strip()
    if PlayerDB.objects.filter(username__iexact=playername):
        # player already exists (we also ignore capitalization here)
        session.msg({
            "alert":
            _("Sorry, there is already a player with the name '%s'.") %
            playername
        })
        return
    # Reserve playernames found in GUEST_LIST
    if settings.GUEST_LIST and playername.lower() in (
            guest.lower() for guest in settings.GUEST_LIST):
        string = "\n\r That name is reserved. Please choose another Playername."
        session.msg({"alert": string})
        return

    if not re.findall('^[\w. @+-]+$', password) or not (3 < len(password)):
        string = "\n\r Password should be longer than 3 characers. Letters, spaces, digits and @\.\+\-\_ only." \
                 "\nFor best security, make it longer than 8 characters. You can also use a phrase of" \
                 "\nmany words if you enclose the password in quotes."
        session.msg({"alert": string})
        return

    # Check IP and/or name bans
    bans = ServerConfig.objects.conf("server_bans")
    if bans and (any(tup[0] == playername.lower()
                     for tup in bans) or any(tup[2].match(session.address)
                                             for tup in bans if tup[2])):
        # this is a banned IP or name!
        string = "{rYou have been banned and cannot continue from here." \
                 "\nIf you feel this ban is in error, please email an admin.{x"
        session.msg({"alert": string})
        session.execute_cmd('{"cmd":"quit","args":""}')
        return

    # everything's ok. Create the new player account.
    new_player = None
    try:
        new_player = create_player(playername, password)
    except Exception, e:
        # We are in the middle between logged in and -not, so we have
        # to handle tracebacks ourselves at this point. If we don't,
        # we won't see any errors at all.
        session.msg(
            {"alert": _("There was an error creating the Player: %s" % e)})
        logger.log_tracemsg()
예제 #2
0
def create_guest_player(session):
    """
    Creates a guest player/character for this session, if one is available.

    Args:
    session (Session): the session which will use the guest player/character.

    Returns:
    GUEST_ENABLED (boolean), player (Player):
    the boolean is whether guest accounts are enabled at all.
    the Player which was created from an available guest name.
    """
    # check if guests are enabled.
    if not settings.GUEST_ENABLED:
        return False, None

    # Check IP bans.
    bans = ServerConfig.objects.conf("server_bans")
    if bans and any(tup[2].match(session.address) for tup in bans if tup[2]):
        # this is a banned IP!
        string = "{rYou have been banned and cannot continue from here." \
            "\nIf you feel this ban is in error, please email an admin.{x"
        session.msg(string)
        session.sessionhandler.disconnect(session, "Good bye! Disconnecting.")
        return True, None

    try:
        # Find an available guest name.
        playername = None
        for playername in settings.GUEST_LIST:
            if not AccountDB.objects.filter(
                    username__iexact=playername).count():
                break
            playername = None
        if playername == None:
            session.msg(
                "All guest accounts are in use. Please try again later.")
            return True, None

        password = "******" % getrandbits(64)
        permissions = settings.PERMISSION_GUEST_DEFAULT
        new_player = create_player(playername,
                                   password,
                                   permissions=permissions)
        if new_player:
            create_character(new_player, playername, permissions=permissions)

    except Exception as e:
        # We are in the middle between logged in and -not, so we have
        # to handle tracebacks ourselves at this point. If we don't,
        # we won't see any errors at all.
        session.msg(
            {"alert": _("There was an error creating the Player: %s" % e)})
        logger.log_trace()
    finally:
        return True, new_player
예제 #3
0
def create_normal_player(session, playername, password):
    """
    Create a new player.
    """
    # sanity checks
    if not re.findall('^[\w. @+-]+$', playername) or not (0 < len(playername) <= 32):
        # this echoes the restrictions made by django's auth
        # module (except not allowing spaces, for convenience of
        # logging in).
        string = "\n\r Playername can max be 32 characters or fewer. Letters, spaces, digits and @/./+/-/_ only."
        session.msg({"alert":string})
        return
    # strip excessive spaces in playername
    playername = re.sub(r"\s+", " ", playername).strip()
    if AccountDB.objects.filter(username__iexact=playername):
        # player already exists (we also ignore capitalization here)
        session.msg({"alert":_("Sorry, there is already a player with the name '%s'.") % playername})
        return
    # Reserve playernames found in GUEST_LIST
    if settings.GUEST_LIST and playername.lower() in (guest.lower() for guest in settings.GUEST_LIST):
        string = "\n\r That name is reserved. Please choose another Playername."
        session.msg({"alert":string})
        return

    if not re.findall('^[\w. @+-]+$', password) or not (3 < len(password)):
        string = "\n\r Password should be longer than 3 characers. Letters, spaces, digits and @\.\+\-\_ only." \
                 "\nFor best security, make it longer than 8 characters. You can also use a phrase of" \
                 "\nmany words if you enclose the password in quotes."
        session.msg({"alert":string})
        return

    # Check IP and/or name bans
    bans = ServerConfig.objects.conf("server_bans")
    if bans and (any(tup[0]==playername.lower() for tup in bans)
                 or
                 any(tup[2].match(session.address) for tup in bans if tup[2])):
        # this is a banned IP or name!
        string = "{rYou have been banned and cannot continue from here." \
                 "\nIf you feel this ban is in error, please email an admin.{x"
        session.msg({"alert":string})
        session.execute_cmd('{"cmd":"quit","args":""}')
        return

    # everything's ok. Create the new player account.
    new_player = None
    try:
        new_player = create_player(playername, password)
    except Exception, e:
        # We are in the middle between logged in and -not, so we have
        # to handle tracebacks ourselves at this point. If we don't,
        # we won't see any errors at all.
        session.msg({"alert":_("There was an error creating the Player: %s" % e)})
        logger.log_tracemsg()
예제 #4
0
def create_guest_player(session):
    """
    Creates a guest player/character for this session, if one is available.

    Args:
    session (Session): the session which will use the guest player/character.

    Returns:
    GUEST_ENABLED (boolean), player (Player):
    the boolean is whether guest accounts are enabled at all.
    the Player which was created from an available guest name.
    """
    # check if guests are enabled.
    if not settings.GUEST_ENABLED:
        return False, None

    # Check IP bans.
    bans = ServerConfig.objects.conf("server_bans")
    if bans and any(tup[2].match(session.address) for tup in bans if tup[2]):
        # this is a banned IP!
        string = "{rYou have been banned and cannot continue from here." \
            "\nIf you feel this ban is in error, please email an admin.{x"
        session.msg(string)
        session.sessionhandler.disconnect(session, "Good bye! Disconnecting.")
        return True, None

    try:
        # Find an available guest name.
        playername = None
        for playername in settings.GUEST_LIST:
            if not AccountDB.objects.filter(username__iexact=playername).count():
                break
            playername = None
        if playername == None:
            session.msg("All guest accounts are in use. Please try again later.")
            return True, None

        password = "******" % getrandbits(64)
        permissions = settings.PERMISSION_GUEST_DEFAULT
        new_player = create_player(playername, password, permissions=permissions)
        if new_player:
            create_character(new_player, playername, permissions=permissions)

    except Exception, e:
        # We are in the middle between logged in and -not, so we have
        # to handle tracebacks ourselves at this point. If we don't,
        # we won't see any errors at all.
        session.msg({"alert":_("There was an error creating the Player: %s" % e)})
        logger.log_trace()