Beispiel #1
0
def do_quit(user, args):
    """
    Closes the user connection.
    """
    user.presenter.show_msg("&gYou are wracked with uncontrollable pain as you are extracted from the Matrix.&x")
    channels.do_info("{} has left the realm.".format(user.name))
    user.disconnect()
Beispiel #2
0
def do_login(user, args):
    """
    Function to register or login an existing user.
    """
    if len(args) == 0:
        user.presenter.show_msg("&RLogin Error.&x\r\n&GLogin:&x &g<username> <password>&x\r\n&CRegister:&x &cregister <username> <password> <password>&c")
        return

    if args[0] == 'register':
        if len(args) == 4 and args[2] == args[3]:
            if not re.match('^[\w-]', args[1]):
                user.presenter.show_msg("Invalid username, please only use alphanumerics.")
                return
            if len(args[1]) < 3:
                user.presenter.show_msg("Username is too short (min. 3).")
                return
            if len(args[1]) > 20:
                user.presenter.show_msg("Username is too long (max. 20).")
                return
            if str(args[1]).lower() in config.BANNED_NAMES:
                user.presenter.show_msg("That name is banned, sorry!")
                return
            if db.session.query(db.models.User).filter_by(name=args[1]).first() is not None:
                user.presenter.show_msg("Username '{}' is already taken, sorry.".format(args[1]))
                return
            dbUser = db.models.User(
                name = args[1],
                password = args[2],
                aliases = {},
                listening = ''.join([channel.key for channel in db.session.query(db.models.Channel).filter_by(default=True).all()])
            )
            db.session.add(dbUser)
            db.session.commit()
            user.load(dbUser)
            channels.do_info("{} has entered the realm.".format(user.name))
            do_look(user, None)
            return

    if len(args) == 2:
        dbUser = db.session.query(db.models.User).filter_by(name=args[0]).first()
        if dbUser is not None:
            if dbUser.verify_password(args[1]):
                user.load(dbUser)
                # TODO: Move this to user.flags
                if user.flags['banned']:
                    user.presenter.show_msg("Eeek! It looks like you're banned, buddy! Bye!")
                    do_quit(user, None)
                    return
                channels.do_info("{} has entered the realm.".format(user.name))
                do_look(user, None)
                return

    user.presenter.show_msg("&RLogin Error.&x\r\n&GLogin:&x &g<username> <password>&x\r\n&CRegister:&x &cregister <username> <password> <password>&c")