From 7012960a708eefa63d1ba60af5ff647b1c53243c Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Thu, 26 Apr 2007 20:32:56 +0000 Subject: [PATCH] Remove get_ansiname() by condensing functionality into get_name(). Removed session debug statements I had in for testing. --- apps/objects/models.py | 34 ++++++++++++------------- commands_general.py | 56 ++++++++++++++++++++++++++++-------------- commands_privileged.py | 14 +++++------ session_mgr.py | 13 ++++++---- 4 files changed, 68 insertions(+), 49 deletions(-) diff --git a/apps/objects/models.py b/apps/objects/models.py index b0c68a6e97..9fc54d0a1b 100755 --- a/apps/objects/models.py +++ b/apps/objects/models.py @@ -182,32 +182,30 @@ class Object(models.Model): def get_user_account(self): """ - Returns the player object's account object. + Returns the player object's account object (User object). """ if not self.is_player(): return False return User.objects.get(id=self.id) - def get_name(self, fullname=False): + def get_name(self, fullname=False, show_dbref=True, no_ansi=False): """ Returns an object's name. """ + if not no_ansi and self.ansi_name: + name_string = self.ansi_name + else: + name_string = self.name + + if show_dbref: + dbref_string = "(#%s%s)" % (self.id, self.flag_string()) + else: + dbref_string = "" + if fullname: - return "%s(#%s%s)" % (ansi.parse_ansi(self.name, strip_ansi=True),self.id, self.flag_string()) + return "%s%s" % (ansi.parse_ansi(name_string, strip_ansi=no_ansi), dbref_string) else: - return "%s(#%s%s)" % (ansi.parse_ansi(self.name.split(';')[0], strip_ansi=True), self.id, self.flag_string()) - - def get_ansiname(self, fullname=False): - """ - Returns an object's ANSI'd name. - """ - if self.ansi_name: - if fullname: - return "%s(#%s%s)" % (ansi.parse_ansi(self.ansi_name), self.id, self.flag_string()) - else: - return "%s(#%s%s)" % (ansi.parse_ansi(self.ansi_name.split(';')[0]), self.id, self.flag_string()) - else: - return self.get_name() + return "%s%s" % (ansi.parse_ansi(name_string.split(';')[0], strip_ansi=no_ansi), dbref_string) def set_description(self, new_desc): """ @@ -501,13 +499,13 @@ class Object(models.Model): """ if not quiet: if self.get_location(): - self.get_location().emit_to_contents("%s has left." % (self.get_ansiname(),), exclude=self) + self.get_location().emit_to_contents("%s has left." % (self.get_name(),), exclude=self) self.location = target self.save() if not quiet: - self.get_location().emit_to_contents("%s has arrived." % (self.get_ansiname(),), exclude=self) + self.get_location().emit_to_contents("%s has arrived." % (self.get_name(),), exclude=self) def dbref_match(self, oname): """ diff --git a/commands_general.py b/commands_general.py index 43a529239b..255d4049d5 100644 --- a/commands_general.py +++ b/commands_general.py @@ -27,7 +27,7 @@ def cmd_inventory(cdat): session.msg("You are carrying:") for item in pobject.get_contents(): - session.msg(" %s" % (item.get_ansiname(),)) + session.msg(" %s" % (item.get_name(),)) money = int(pobject.get_attribute_value("MONEY", default=0)) if money == 1: @@ -53,7 +53,7 @@ def cmd_look(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result.get_ansiname(),)) + session.msg(" %s" % (result.get_name(),)) return elif len(results) == 0: session.msg("I don't see that here.") @@ -62,7 +62,7 @@ def cmd_look(cdat): target_obj = results[0] retval = "%s\r\n%s" % ( - target_obj.get_ansiname(), + target_obj.get_name(), target_obj.get_description(), ) session.msg(retval) @@ -83,15 +83,15 @@ def cmd_look(cdat): if con_players: session.msg("%sPlayers:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],)) for player in con_players: - session.msg('%s' %(player.get_ansiname(),)) + session.msg('%s' %(player.get_name(),)) if con_things: session.msg("%sContents:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],)) for thing in con_things: - session.msg('%s' %(thing.get_ansiname(),)) + session.msg('%s' %(thing.get_name(),)) if con_exits: session.msg("%sExits:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],)) for exit in con_exits: - session.msg('%s' %(exit.get_ansiname(),)) + session.msg('%s' %(exit.get_name(),)) def cmd_get(cdat): """ @@ -111,7 +111,7 @@ def cmd_get(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result.get_ansiname(),)) + session.msg(" %s" % (result.get_name(),)) return elif len(results) == 0: session.msg("I don't see that here.") @@ -133,8 +133,8 @@ def cmd_get(cdat): return target_obj.move_to(pobject, quiet=True) - session.msg("You pick up %s." % (target_obj.get_ansiname(),)) - pobject.get_location().emit_to_contents("%s picks up %s." % (pobject.get_ansiname(), target_obj.get_ansiname()), exclude=pobject) + session.msg("You pick up %s." % (target_obj.get_name(),)) + pobject.get_location().emit_to_contents("%s picks up %s." % (pobject.get_name(), target_obj.get_name()), exclude=pobject) def cmd_drop(cdat): """ @@ -154,7 +154,7 @@ def cmd_drop(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result.get_ansiname(),)) + session.msg(" %s" % (result.get_name(),)) return elif len(results) == 0: session.msg("You don't appear to be carrying that.") @@ -168,8 +168,8 @@ def cmd_drop(cdat): return target_obj.move_to(pobject.get_location(), quiet=True) - session.msg("You drop %s." % (target_obj.get_ansiname(),)) - pobject.get_location().emit_to_contents("%s drops %s." % (pobject.get_ansiname(), target_obj.get_ansiname()), exclude=pobject) + session.msg("You drop %s." % (target_obj.get_name(),)) + pobject.get_location().emit_to_contents("%s drops %s." % (pobject.get_name(), target_obj.get_name()), exclude=pobject) def cmd_examine(cdat): """ @@ -187,7 +187,7 @@ def cmd_examine(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result.get_ansiname(),)) + session.msg(" %s" % (result.get_name(),)) return elif len(results) == 0: session.msg("I don't see that here.") @@ -195,7 +195,7 @@ def cmd_examine(cdat): else: target_obj = results[0] session.msg("%s\r\n%s" % ( - target_obj.get_ansiname(fullname=True), + target_obj.get_name(fullname=True), target_obj.get_description(no_parsing=True), )) session.msg("Type: %s Flags: %s" % (target_obj.get_type(), target_obj.get_flags())) @@ -220,14 +220,14 @@ def cmd_examine(cdat): if con_players or con_things: session.msg("%sContents:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],)) for player in con_players: - session.msg('%s' % (player.get_ansiname(fullname=True),)) + session.msg('%s' % (player.get_name(fullname=True),)) for thing in con_things: - session.msg('%s' % (thing.get_ansiname(fullname=True),)) + session.msg('%s' % (thing.get_name(fullname=True),)) if con_exits: session.msg("%sExits:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],)) for exit in con_exits: - session.msg('%s' %(exit.get_ansiname(fullname=True),)) + session.msg('%s' %(exit.get_name(fullname=True),)) if not target_obj.is_room(): if target_obj.is_exit(): @@ -285,7 +285,7 @@ def cmd_say(cdat): """ session = cdat['session'] - if not functions_general.cmd_check_num_args(session, cdat['uinput']['splitted'], 1, errortext="Say What?"): + if not functions_general.cmd_check_num_args(session, cdat['uinput']['splitted'], 1, errortext="Say what?"): return session_list = session_mgr.get_session_list() @@ -296,9 +296,27 @@ def cmd_say(cdat): retval = "You say, '%s'" % (speech,) for player in players_present: - player.msg("%s says, '%s'" % (pobject.get_name(), speech,)) + player.msg("%s says, '%s'" % (pobject.get_name(show_dbref=False), speech,)) session.msg(retval) + +def cmd_pose(cdat): + """ + Pose/emote command. + """ + session = cdat['session'] + + if not functions_general.cmd_check_num_args(session, cdat['uinput']['splitted'], 1, errortext="Do what?"): + return + + session_list = session_mgr.get_session_list() + pobject = session.get_pobject() + speech = ' '.join(cdat['uinput']['splitted'][1:]) + + players_present = [player for player in session_list if player.get_pobject().get_location() == session.get_pobject().get_location()] + + for player in players_present: + player.msg("%s %s" % (pobject.get_name(show_dbref=False), speech)) def cmd_help(cdat): """ diff --git a/commands_privileged.py b/commands_privileged.py index 3a9338aa60..010c06f153 100644 --- a/commands_privileged.py +++ b/commands_privileged.py @@ -39,7 +39,7 @@ def cmd_destroy(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result.get_ansiname(),)) + session.msg(" %s" % (result.get_name(),)) return elif len(results) == 0: session.msg("I don't see that here.") @@ -119,7 +119,7 @@ def cmd_description(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result.get_ansiname(),)) + session.msg(" %s" % (result.get_name(),)) return elif len(results) == 0: session.msg("I don't see that here.") @@ -154,7 +154,7 @@ def cmd_newpassword(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result.get_ansiname(),)) + session.msg(" %s" % (result.get_name(),)) elif len(results) == 0: session.msg("I don't see that here.") elif not pobject.controls_other(results[0]): @@ -219,7 +219,7 @@ def cmd_name(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result.get_ansiname(),)) + session.msg(" %s" % (result.get_name(),)) return elif len(results) == 0: session.msg("I don't see that here.") @@ -435,7 +435,7 @@ def cmd_unlink(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result.get_ansiname(),)) + session.msg(" %s" % (result.get_name(),)) return elif len(results) == 0: session.msg("I don't see that here.") @@ -504,7 +504,7 @@ def cmd_teleport(cdat): if len(results) > 1: session.msg("More than one match found (please narrow target):") for result in results: - session.msg(" %s" % (result.get_ansiname(),)) + session.msg(" %s" % (result.get_name(),)) elif len(results) == 0: session.msg("I don't see that here.") return @@ -609,7 +609,7 @@ def cmd_find(cdat): if len(results) > 0: session.msg("Name matches for: %s" % (searchstring,)) for result in results: - session.msg(" %s" % (result.get_ansiname(fullname=True),)) + session.msg(" %s" % (result.get_name(fullname=True),)) session.msg("%d matches returned." % (len(results),)) else: session.msg("No name matches found for: %s" % (searchstring,)) diff --git a/session_mgr.py b/session_mgr.py index 27acba49c7..14c8765801 100644 --- a/session_mgr.py +++ b/session_mgr.py @@ -24,11 +24,14 @@ def check_all_sessions(): """ Check all currently connected sessions and see if any are dead. """ - for sess in get_session_list(): - if not sess.writable() or not sess.readable(): - print 'Problematic Session:' - print 'Readable ', sess.readable() - print 'Writable ', sess.writable() + pass + #for sess in get_session_list(): + ## This doesn't seem to provide an accurate indication of timed out + ## sessions. + #if not sess.writable() or not sess.readable(): + # print 'Problematic Session:' + # print 'Readable ', sess.readable() + # print 'Writable ', sess.writable() def remove_session(session):