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 pagedlist(category_map, order=None, header=None, height=21): """Display lists of information as flips within a book. category_map is a mapping between section headers and lists of entries to display for that category. If you are only displaying one category, have a map from the section header, Topics, to your list of entries. If the categories should be displayed in a specific (or partially specific) order, that can be specified. Header is text that can appear at front of the book display. """ buf = [] # split our header into rows if we have one hrows = [] if header != None: hrows = mud.format_string(header, False, 76).strip().split("\r\n") # build our full list of orderings if order == None: order = [] for category in category_map.iterkeys(): if not category in order: order.append(category) # build our page entries. This includes categories and category items entries = [] for category in order: if not category in category_map: continue # add a space between categories if len(entries) > 0: entries.append("") entries.append(category.capitalize()) for item in category_map[category]: entries.append(" %s" % item) # append our header if we have one if len(hrows) > 0: buf.append(table_border) for hrow in hrows: buf.append(table_row(hrow)) # build our page contents, one page at a time, until we are out of entries pages = [] last_cat = None while len(entries) > 0: page = [] plen = height - 2 # minus 2 for the borders # we're still on the first flip of the book; header is displayed if len(pages) <= 2: plen -= len(hrows) + 1 # plus 1 for the row above it # add items to the page until we are full while len(entries) > 0 and len(page) < plen: entry = entries.pop(0) # is this a blank row, and are we at the head of the page? if entry == "" and len(page) == 0: continue # is this a category header? if not entry.startswith(" "): last_cat = entry # are we continuing an old category? if entry.startswith(" ") and len(page) == 0 and last_cat != None: page.append("%s (cont.)" % last_cat) page.append(entry) # did we have anything added to it? if len(page) > 0: pages.append(page) # take our pages by twos and turn them into table rows i = 0 while i < len(pages): page1 = pages[i] page2 = [] if i + 1 < len(pages): page2 = pages[i + 1] # append the rows and page contents buf.append(table_border) buf.extend(table_splitrows(page1, page2)) buf.append(table_border) i += 2 buf.append("") return buf
def pagedlist(category_map, order=None, header=None, height=21): """Display lists of information as flips within a book. category_map is a mapping between section headers and lists of entries to display for that category. If you are only displaying one category, have a map from the section header, Topics, to your list of entries. If the categories should be displayed in a specific (or partially specific) order, that can be specified. Header is text that can appear at front of the book display. """ buf = [ ] # split our header into rows if we have one hrows = [ ] if header != None: hrows = mud.format_string(header, False, 76).strip().split("\r\n") # build our full list of orderings if order == None: order = [ ] for category in category_map.iterkeys(): if not category in order: order.append(category) # build our page entries. This includes categories and category items entries = [ ] for category in order: if not category in category_map: continue # add a space between categories if len(entries) > 0: entries.append("") entries.append(category.capitalize()) for item in category_map[category]: entries.append(" %s" % item) # append our header if we have one if len(hrows) > 0: buf.append(table_border) for hrow in hrows: buf.append(table_row(hrow)) # build our page contents, one page at a time, until we are out of entries pages = [ ] last_cat = None while len(entries) > 0: page = [ ] plen = height - 2 # minus 2 for the borders # we're still on the first flip of the book; header is displayed if len(pages) <= 2: plen -= len(hrows) + 1 # plus 1 for the row above it # add items to the page until we are full while len(entries) > 0 and len(page) < plen: entry = entries.pop(0) # is this a blank row, and are we at the head of the page? if entry == "" and len(page) == 0: continue # is this a category header? if not entry.startswith(" "): last_cat = entry # are we continuing an old category? if entry.startswith(" ") and len(page)==0 and last_cat != None: page.append("%s (cont.)" % last_cat) page.append(entry) # did we have anything added to it? if len(page) > 0: pages.append(page) # take our pages by twos and turn them into table rows i = 0 while i < len(pages): page1 = pages[i] page2 = [ ] if i+1 < len(pages): page2 = pages[i+1] # append the rows and page contents buf.append(table_border) buf.extend(table_splitrows(page1, page2)) buf.append(table_border) i += 2 buf.append("") return buf