def func(self): "create the new character" session = self.session player = self.account args = self.args if not args: session.msg({"alert": _("You should give the character a name.")}) return name = args["name"] if not name: session.msg({"alert": _("Name should not be empty.")}) return # sanity checks if not (0 < len(name) <= 30): # Nickname's length string = "\n\r Name can max be 30 characters or fewer." session.msg({"alert": string}) return # strip excessive spaces in playername nickname = re.sub(r"\s+", " ", name).strip() charmax = settings.MAX_NR_CHARACTERS if settings.MULTISESSION_MODE > 1 else 1 if player.db._playable_characters and len( player.db._playable_characters) >= charmax: session.msg({ "alert": _("You may only create a maximum of %i characters.") % charmax }) return if utils.search_db_data_type("nickname", name, settings.BASE_PLAYER_CHARACTER_TYPECLASS): # check if this name already exists. session.msg({ "alert": _("{rA character named '{w%s{r' already exists.{n") % name }) return try: create_character(player, name) 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() return session.msg({ "char_created": True, "char_all": player.get_all_characters() })
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
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()
def func(self): "create the new character" session = self.session player = self.account args = self.args if not args: session.msg({"alert":_("You should give the character a name.")}) return name = args["name"] if not name: session.msg({"alert":_("Name should not be empty.")}) return # sanity checks if not (0 < len(name) <= 30): # Nickname's length string = "\n\r Name can max be 30 characters or fewer." session.msg({"alert":string}) return # strip excessive spaces in playername nickname = re.sub(r"\s+", " ", name).strip() charmax = settings.MAX_NR_CHARACTERS if settings.MULTISESSION_MODE > 1 else 1 if player.db._playable_characters and len(player.db._playable_characters) >= charmax: session.msg({"alert":_("You may only create a maximum of %i characters.") % charmax}) return if utils.search_db_data_type("nickname", name, settings.BASE_PLAYER_CHARACTER_TYPECLASS): # check if this name already exists. session.msg({"alert":_("{rA character named '{w%s{r' already exists.{n") % name}) return try: create_character(player, name) 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() return
def func(self): "Do checks, create account and login." session = self.caller args = self.args try: playername = args["playername"] md5 = hashlib.md5() md5.update(playername) name_md5 = md5.hexdigest() except Exception: string = 'Syntax error!' logger.log_errmsg(string) session.msg({"alert": string}) return player = None character = None if AccountDB.objects.filter(username__iexact=name_md5): # Already has this player. Login. player = connect_normal_player(session, name_md5, name_md5) else: # Register player = create_normal_player(session, name_md5, name_md5) if player: session.sessionhandler.login(session, player) if player.db._last_puppet: character = player.db._last_puppet elif player.db._playable_characters: character = player.db._playable_characters[0] else: character = create_character(player, playername) if character: try: player.puppet_object(session, character) player.db._last_puppet = character except RuntimeError as exc: session.msg({ "alert": _("{rYou cannot become {C%s{n: %s") % (character.name, exc) })
def func(self): "Do checks, create account and login." session = self.caller args = self.args try: playername = args["playername"] md5 = hashlib.md5() md5.update(playername) name_md5 = md5.hexdigest() except Exception: string = 'Syntax error!' logger.log_errmsg(string) session.msg({"alert":string}) return player = None character = None if AccountDB.objects.filter(username__iexact=name_md5): # Already has this player. Login. player = connect_normal_player(session, name_md5, name_md5) else: # Register player = create_normal_player(session, name_md5, name_md5) if player: session.sessionhandler.login(session, player) if player.db._last_puppet: character = player.db._last_puppet elif player.db._playable_characters: character = player.db._playable_characters[0] else: character = create_character(player, playername) if character: try: player.puppet_object(session, character) player.db._last_puppet = character except RuntimeError as exc: session.msg({"alert":_("{rYou cannot become {C%s{n: %s") % (character.name, exc)})