def login_method_handler(sock, arg): args = arg.split() if len(args) == 0: return args[0] = args[0].lower() if "create".startswith(args[0]): if len(args) != 3: return elif mudsys.account_exists(args[1]): sock.send("{cAn account by that name already exists.{n\r\n") elif not check_acct_name(args[1]): txt = "{cThat is an invalid account name. Your account name must "\ "only consist of characters and numbers, and it must be " \ "4 and 12 characters in length. The first character MUST be "\ "a letter. Please pick another.{n" sock.send(mud.format_string(txt, False)) elif not try_create_account(sock, args[1], args[2]): sock.send("Your account was unable to be created.") elif "load".startswith(args[0]): if len(args) != 3: return elif not try_load_account(sock, args[1], args[2]): sock.send("{cInvalid account name or password.{n\r\n") elif "guest".startswith(args[0]): if (mudsys.sys_getval("lockdown") != '' and not utils.is_keyword(mudsys.sys_getval("lockdown"), "player")): sock.send("{cThe mud is currently locked out to new players.{n\r\n") else: sock.pop_ih() hooks.run("create_guest", hooks.build_info("sk", (sock,)))
def try_create_account(sock, name, psswd): if mudsys.account_exists(name): return False elif mudsys.account_creating(name): return False elif not check_acct_name(name): return False else: # creating a new account mud.log_string("Account '" + name + "' is trying to create.") # create our new account acct = mudsys.create_account(name) if acct == None: return False else: mudsys.attach_account_socket(acct, sock) mudsys.set_password(acct, psswd) sock.pop_ih() sock.push_ih(acct_menu_handler, acct_main_menu) #sock.push_ih(acct_finish_handler, acct_finish_prompt) # log that the account created mud.log_string("New account '" + acct.name + "' has created.") # register and save the account to disk mudsys.do_register(acct) return True return False
def try_load_account(sock, name, psswd): '''Attempt to load an account with the given name and password.''' if not mudsys.account_exists(name): return False else: acct = mudsys.load_account(name) if not mudsys.password_matches(acct, psswd): return False # successful load mudsys.attach_account_socket(acct, sock) sock.pop_ih() sock.push_ih(acct_menu_handler, acct_main_menu) return True return False