def func(self): """ Main puppet method """ player = self.player sessid = self.sessid new_character = None if not self.args: new_character = player.db._last_puppet if not new_character: self.msg("Usage: @ic <character>") return if not new_character: # search for a matching character new_character = search.object_search(self.args) if new_character: new_character = new_character[0] else: self.msg("That is not a valid character choice.") return # permission checks if player.get_puppet(sessid) == new_character: self.msg("{RYou already act as {c%s{n." % new_character.name) return if new_character.player: # may not puppet an already puppeted character if new_character.sessid.count() and new_character.player == player: # as a safeguard we allow "taking over" chars from your own sessions. if MULTISESSION_MODE in (1, 3): txt = "{c%s{n{G is now shared from another of your sessions.{n" txt2 = "Sharing {c%s{n with another of your sessions." else: txt = "{c%s{n{R is now acted from another of your sessions.{n" txt2 = "Taking over {c%s{n from another of your sessions." player.unpuppet_object(new_character.sessid.get()) player.msg(txt % (new_character.name), sessid=new_character.sessid.get()) self.msg(txt2 % new_character.name) elif new_character.player != player and new_character.player.is_connected: self.msg("{c%s{r is already acted by another player.{n" % new_character.name) return if not new_character.access(player, "puppet"): # main acccess check self.msg("{rYou may not become %s.{n" % new_character.name) return if player.puppet_object(sessid, new_character): player.db._last_puppet = new_character else: self.msg("{rYou cannot become {C%s{n." % new_character.name)
def func(self): """ Uses the Django admin api. Note that unlogged-in commands have a unique position in that their func() receives a session object instead of a source_object like all other types of logged-in commands (this is because there is no object yet before the player has logged in) """ session = self.caller args = self.args # extract quoted parts parts = shlex.split(args) if len(parts) == 2: playername = parts[0] password = parts[1] # Check for | syntax username_parts = playername.split('|') if len(username_parts) == 2: playername = username_parts[0] charname = username_parts[1] else: charname = None else: session.msg("\n\r Usage (without <>): connect <username> <password>, or connect <username>|<character> <password>") return # Match account name and check password player = PlayerDB.objects.get_player_from_name(playername) pswd = None if player: pswd = player.user.check_password(password) # pswd = player.check_password(password) # FIXME-UPDATE if not (player and pswd): # No playername or password match string = "Wrong login information given.\nIf you have spaces in your name or " string += "password, don't forget to enclose it in quotes. Also capitalization matters." string += "\nIf you are new you should first create a new account " string += "using the 'create' command." session.msg(string) return # Check IP and/or name bans bans = ServerConfig.objects.conf("server_bans") if bans and (any(tup[0]==player.name for tup in bans) or any(tup[2].match(session.address[0]) for tup in bans if tup[2])): # this is a banned IP or name! string = "{rYou have been banned and cannot continue from here." string += "\nIf you feel this ban is in error, please email an admin.{x" session.msg(string) session.execute_cmd("quit") return # Identify which character to puppet, if any if charname: # Find the explicitly requested character character = search.object_search(charname) if not character: session.msg("{rThat character name doesn't appear to be valid.{x") return character = character[0] if character in player.get_characters(): string = "{rThat does not appear to be one of your characters. Try logging in\n" string += "without specifying a character name, and examine your list of available\n" string += "characters.{x" session.msg(string) return elif player.db.pref_auto_ic: # Find the most recently puppeted character character = player.last_puppet() else: character = None # actually do the login. This will call all other hooks: # session.at_login() # player.at_init() # always called when object is loaded from disk # player.at_pre_login() # player.at_first_login() # only once # player.at_post_login(sessid=sessid) session.sessionhandler.login(session, player) # Now that we're connected, puppet the character, if requested. if character: session.msg('\n{WLogging directly into {c%s{W...\n' % (character.get_desc_styled_name(player))) player.do_puppet(session.sessid, character) player.at_display_context(session.sessid) player.at_display_alerts(session.sessid)