Huge overhaul in the way objects and sessions are used with commands. We now pass all commands through objects (aside from unlogged commands), which means session.msg() is now deprecated for any use other than unlogged out.

As a side-effect of all of this, logging in more than once acts as behaves now. Also, this will allow things/rooms/exits (IE: not players) or un-logged in players to run commands or be forced to run them via @fo. All of this will bring us more in-line with MUX behavior.
This commit is contained in:
Greg Taylor 2009-01-24 20:30:46 +00:00
parent 50f4d04096
commit 9407eb0ee4
20 changed files with 680 additions and 712 deletions

View file

@ -20,33 +20,41 @@ def cmd_password(command):
@password <Oldpass>=<Newpass>
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
source_object.emit_to("This command requires arguments.")
return
if not source_object.is_player():
source_object.emit_to("This is only applicable for players.")
return
eq_args = command.command_argument.split('=', 1)
if len(eq_args) != 2:
session.msg("Incorrect number of arguments.")
source_object.emit_to("Incorrect number of arguments.")
return
oldpass = eq_args[0]
newpass = eq_args[1]
if len(oldpass) == 0:
session.msg("You must provide your old password.")
source_object.emit_to("You must provide your old password.")
elif len(newpass) == 0:
session.msg("You must provide your new password.")
source_object.emit_to("You must provide your new password.")
else:
uaccount = pobject.get_user_account()
uaccount = source_object.get_user_account()
if not uaccount.check_password(oldpass):
session.msg("The specified old password isn't correct.")
source_object.emit_to("The specified old password isn't correct.")
elif len(newpass) < 3:
session.msg("Passwords must be at least three characters long.")
source_object.emit_to("Passwords must be at least three characters long.")
return
else:
uaccount.set_password(newpass)
uaccount.save()
session.msg("Password changed.")
source_object.emit_to("Password changed.")
def cmd_pemit(command):
"""
@ -58,28 +66,25 @@ def cmd_emit(command):
"""
Emits something to your location.
"""
session = command.session
pobject = session.get_pobject()
message = command.command_argument
if message:
pobject.get_location().emit_to_contents(message)
command.source_object.get_location().emit_to_contents(message)
else:
session.msg("Emit what?")
command.source_object.emit_to("Emit what?")
def cmd_wall(command):
"""
Announces a message to all connected players.
"""
session = command.session
wallstring = command.command_argument
pobject = session.get_pobject()
if not wallstring:
session.msg("Announce what?")
command.source_object.emit_to("Announce what?")
return
message = "%s shouts \"%s\"" % (session.get_pobject().get_name(show_dbref=False), wallstring)
message = "%s shouts \"%s\"" % (
command.source_object.get_name(show_dbref=False), wallstring)
session_mgr.announce_all(message)
def cmd_idle(command):
@ -93,139 +98,134 @@ def cmd_inventory(command):
"""
Shows a player's inventory.
"""
session = command.session
pobject = session.get_pobject()
session.msg("You are carrying:")
source_object = command.source_object
source_object.emit_to("You are carrying:")
for item in pobject.get_contents():
session.msg(" %s" % (item.get_name(),))
for item in source_object.get_contents():
source_object.emit_to(" %s" % (item.get_name(),))
money = int(pobject.get_attribute_value("MONEY", default=0))
money = int(source_object.get_attribute_value("MONEY", default=0))
if money == 1:
money_name = ConfigValue.objects.get_configvalue("MONEY_NAME_SINGULAR")
else:
money_name = ConfigValue.objects.get_configvalue("MONEY_NAME_PLURAL")
session.msg("You have %d %s." % (money,money_name))
source_object.emit_to("You have %d %s." % (money, money_name))
def cmd_look(command):
"""
Handle looking at objects.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
# If an argument is provided with the command, search for the object.
# else look at the current room.
if command.command_argument:
target_obj = Object.objects.standard_plr_objsearch(session,
target_obj = Object.objects.standard_objsearch(source_object,
command.command_argument)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
# Use standard_objsearch to handle duplicate/nonexistant results.
if not target_obj:
return
else:
target_obj = pobject.get_location()
target_obj = source_object.get_location()
# SCRIPT: Get the item's appearance from the scriptlink.
session.msg(target_obj.scriptlink.return_appearance({
source_object.emit_to(target_obj.scriptlink.return_appearance({
"target_obj": target_obj,
"pobject": pobject
"pobject": source_object
}))
# SCRIPT: Call the object's script's a_desc() method.
target_obj.scriptlink.a_desc({
"target_obj": pobject
"target_obj": source_object
})
def cmd_get(command):
"""
Get an object and put it in a player's inventory.
"""
session = command.session
pobject = session.get_pobject()
plr_is_staff = pobject.is_staff()
source_object = command.source_object
obj_is_staff = source_object.is_staff()
if not command.command_argument:
session.msg("Get what?")
source_object.emit_to("Get what?")
return
else:
target_obj = Object.objects.standard_plr_objsearch(session,
target_obj = Object.objects.standard_objsearch(source_object,
command.command_argument,
search_contents=False)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
# Use standard_objsearch to handle duplicate/nonexistant results.
if not target_obj:
return
if pobject == target_obj:
session.msg("You can't get yourself.")
if source_object == target_obj:
source_object.emit_to("You can't get yourself.")
return
if not plr_is_staff and (target_obj.is_player() or target_obj.is_exit()):
session.msg("You can't get that.")
if not obj_is_staff and (target_obj.is_player() or target_obj.is_exit()):
source_object.emit_to("You can't get that.")
return
if target_obj.is_room() or target_obj.is_garbage() or target_obj.is_going():
session.msg("You can't get that.")
source_object.emit_to("You can't get that.")
return
target_obj.move_to(pobject, quiet=True)
session.msg("You pick up %s." % (target_obj.get_name(show_dbref=False),))
pobject.get_location().emit_to_contents("%s picks up %s." %
(pobject.get_name(show_dbref=False),
target_obj.move_to(source_object, quiet=True)
source_object.emit_to("You pick up %s." % (target_obj.get_name(show_dbref=False),))
source_object.get_location().emit_to_contents("%s picks up %s." %
(source_object.get_name(show_dbref=False),
target_obj.get_name(show_dbref=False)),
exclude=pobject)
exclude=source_object)
# SCRIPT: Call the object's script's a_get() method.
target_obj.scriptlink.a_get({
"pobject": pobject
"pobject": source_object
})
def cmd_drop(command):
"""
Drop an object from a player's inventory into their current location.
"""
session = command.session
pobject = session.get_pobject()
plr_is_staff = pobject.is_staff()
source_object = command.source_object
obj_is_staff = source_object.is_staff()
if not command.command_argument:
session.msg("Drop what?")
source_object.emit_to("Drop what?")
return
else:
target_obj = Object.objects.standard_plr_objsearch(session,
target_obj = Object.objects.standard_objsearch(source_object,
command.command_argument,
search_location=False)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
# Use standard_objsearch to handle duplicate/nonexistant results.
if not target_obj:
return
if not pobject == target_obj.get_location():
session.msg("You don't appear to be carrying that.")
if not source_object == target_obj.get_location():
source_object.emit_to("You don't appear to be carrying that.")
return
target_obj.move_to(pobject.get_location(), quiet=True)
session.msg("You drop %s." % (target_obj.get_name(show_dbref=False),))
pobject.get_location().emit_to_contents("%s drops %s." %
(pobject.get_name(show_dbref=False),
target_obj.move_to(source_object.get_location(), quiet=True)
source_object.emit_to("You drop %s." % (target_obj.get_name(show_dbref=False),))
source_object.get_location().emit_to_contents("%s drops %s." %
(source_object.get_name(show_dbref=False),
target_obj.get_name(show_dbref=False)),
exclude=pobject)
exclude=source_object)
# SCRIPT: Call the object's script's a_drop() method.
target_obj.scriptlink.a_drop({
"pobject": pobject
"pobject": source_object
})
def cmd_examine(command):
"""
Detailed object examine command
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
attr_search = False
if not command.command_argument:
# If no arguments are provided, examine the invoker's location.
target_obj = pobject.get_location()
target_obj = source_object.get_location()
else:
# Look for a slash in the input, indicating an attribute search.
attr_split = command.command_argument.split("/", 1)
@ -241,21 +241,21 @@ def cmd_examine(command):
# Protect against stuff like: ex me/
if attr_searchstr == '':
session.msg('No attribute name provided.')
source_object.emit_to('No attribute name provided.')
return
else:
# No slash in argument, just examine an object.
obj_searchstr = command.command_argument
# Resolve the target object.
target_obj = Object.objects.standard_plr_objsearch(session,
target_obj = Object.objects.standard_objsearch(source_object,
obj_searchstr)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
# Use standard_objsearch to handle duplicate/nonexistant results.
if not target_obj:
return
# If the user doesn't control the object, just look at it instead.
if not pobject.controls_other(target_obj, builder_override=True):
if not source_object.controls_other(target_obj, builder_override=True):
command.command_string = 'look'
cmd_look(command)
return
@ -268,28 +268,28 @@ def cmd_examine(command):
attr_matches = target_obj.attribute_namesearch(attr_searchstr)
if attr_matches:
for attribute in attr_matches:
session.msg(attribute.get_attrline())
source_object.emit_to(attribute.get_attrline())
else:
session.msg("No matching attributes found.")
source_object.emit_to("No matching attributes found.")
else:
"""
Player is examining an object. Return a full readout of attributes,
along with detailed information about said object.
"""
# Format the examine header area with general flag/type info.
session.msg(target_obj.get_name(fullname=True))
session.msg("Type: %s Flags: %s" % (target_obj.get_type(),
source_object.emit_to(target_obj.get_name(fullname=True))
source_object.emit_to("Type: %s Flags: %s" % (target_obj.get_type(),
target_obj.get_flags()))
session.msg("Desc: %s" % target_obj.get_description(no_parsing=True))
session.msg("Owner: %s " % (target_obj.get_owner(),))
session.msg("Zone: %s" % (target_obj.get_zone(),))
source_object.emit_to("Desc: %s" % target_obj.get_description(no_parsing=True))
source_object.emit_to("Owner: %s " % (target_obj.get_owner(),))
source_object.emit_to("Zone: %s" % (target_obj.get_zone(),))
parent_str = target_obj.script_parent
if parent_str and parent_str != '':
session.msg("Parent: %s " % (parent_str,))
source_object.emit_to("Parent: %s " % (parent_str,))
for attribute in target_obj.get_all_attributes():
session.msg(attribute.get_attrline())
source_object.emit_to(attribute.get_attrline())
# Contents container lists for sorting by type.
con_players = []
@ -307,52 +307,52 @@ def cmd_examine(command):
# Render Contents display.
if con_players or con_things:
session.msg("%sContents:%s" % (ansi.ansi["hilite"],
ansi.ansi["normal"],))
source_object.emit_to("%sContents:%s" % (ansi.ansi["hilite"],
ansi.ansi["normal"],))
for player in con_players:
session.msg('%s' % (player.get_name(fullname=True),))
source_object.emit_to('%s' % (player.get_name(fullname=True),))
for thing in con_things:
session.msg('%s' % (thing.get_name(fullname=True),))
source_object.emit_to('%s' % (thing.get_name(fullname=True),))
# Render Exists display.
if con_exits:
session.msg("%sExits:%s" % (ansi.ansi["hilite"],
source_object.emit_to("%sExits:%s" % (ansi.ansi["hilite"],
ansi.ansi["normal"],))
for exit in con_exits:
session.msg('%s' %(exit.get_name(fullname=True),))
source_object.emit_to('%s' %(exit.get_name(fullname=True),))
# Render the object's home or destination (for exits).
if not target_obj.is_room():
if target_obj.is_exit():
# The Home attribute on an exit is really its destination.
session.msg("Destination: %s" % (target_obj.get_home(),))
source_object.emit_to("Destination: %s" % (target_obj.get_home(),))
else:
# For everything else, home is home.
session.msg("Home: %s" % (target_obj.get_home(),))
source_object.emit_to("Home: %s" % (target_obj.get_home(),))
# This obviously isn't valid for rooms.
session.msg("Location: %s" % (target_obj.get_location(),))
source_object.emit_to("Location: %s" % (target_obj.get_location(),))
def cmd_quit(command):
"""
Gracefully disconnect the user as per his own request.
"""
session = command.session
session.msg("Quitting!")
session.handle_close()
if command.session:
session = command.session
session.msg("Quitting!")
session.handle_close()
def cmd_who(command):
"""
Generic WHO command.
"""
session_list = session_mgr.get_session_list()
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
# In the case of the DOING command, don't show session data regardless.
if command.extra_vars and command.extra_vars.get("show_session_data", None) == False:
show_session_data = False
else:
show_session_data = pobject.user_has_perm("genperms.see_session_data")
show_session_data = source_object.has_perm("genperms.see_session_data")
# Only those with the see_session_data or superuser status can see
# session details.
@ -394,85 +394,82 @@ def cmd_who(command):
'')
retval += '%d Players logged in.' % (len(session_list),)
session.msg(retval)
source_object.emit_to(retval)
def cmd_say(command):
"""
Room-based speech command.
"""
session = command.session
source_object = command.source_object
if not command.command_argument:
session.msg("Say what?")
source_object.emit_to("Say what?")
return
session_list = session_mgr.get_session_list()
pobject = session.get_pobject()
speech = command.command_argument
# Feedback for the object doing the talking.
source_object.emit_to("You say, '%s'" % (speech,))
players_present = [player for player in session_list if player.get_pobject().get_location() == session.get_pobject().get_location() and player != session]
# Build the string to emit to neighbors.
emit_string = "%s says, '%s'" % (source_object.get_name(show_dbref=False),
speech)
retval = "You say, '%s'" % (speech,)
for player in players_present:
player.msg("%s says, '%s'" % (pobject.get_name(show_dbref=False), speech,))
session.msg(retval)
source_object.get_location().emit_to_contents(emit_string,
exclude=source_object)
def cmd_pose(command):
"""
Pose/emote command.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("Do what?")
source_object.emit_to("Do what?")
return
session_list = session_mgr.get_session_list()
speech = command.command_argument
pose_string = command.command_argument
if "nospace" in command.command_switches:
# Output without a space between the player name and the emote.
sent_msg = "%s%s" % (pobject.get_name(show_dbref=False), speech)
sent_msg = "%s%s" % (source_object.get_name(show_dbref=False),
pose_string)
else:
# No switches, default.
sent_msg = "%s %s" % (pobject.get_name(show_dbref=False), speech)
sent_msg = "%s %s" % (source_object.get_name(show_dbref=False),
pose_string)
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(sent_msg)
source_object.get_location().emit_to_contents(sent_msg)
def cmd_help(command):
"""
Help system commands.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
topicstr = command.command_argument
if not command.command_argument:
topicstr = "Help Index"
elif len(topicstr) < 2 and not topicstr.isdigit():
session.msg("Your search query is too short. It must be at least three letters long.")
source_object.emit_to("Your search query is too short. It must be at least three letters long.")
return
topics = HelpEntry.objects.find_topicmatch(pobject, topicstr)
topics = HelpEntry.objects.find_topicmatch(source_object, topicstr)
if len(topics) == 0:
session.msg("No matching topics found, please refine your search.")
suggestions = HelpEntry.objects.find_topicsuggestions(pobject, topicstr)
source_object.emit_to("No matching topics found, please refine your search.")
suggestions = HelpEntry.objects.find_topicsuggestions(source_object,
topicstr)
if len(suggestions) > 0:
session.msg("Matching similarly named topics:")
source_object.emit_to("Matching similarly named topics:")
for result in suggestions:
session.msg(" %s" % (result,))
session.msg("You may type 'help <#>' to see any of these topics.")
source_object.emit_to(" %s" % (result,))
source_object.emit_to("You may type 'help <#>' to see any of these topics.")
elif len(topics) > 1:
session.msg("More than one match found:")
source_object.emit_to("More than one match found:")
for result in topics:
session.msg("%3d. %s" % (result.id, result.get_topicname()))
session.msg("You may type 'help <#>' to see any of these topics.")
source_object.emit_to("%3d. %s" % (result.id, result.get_topicname()))
source_object.emit_to("You may type 'help <#>' to see any of these topics.")
else:
topic = topics[0]
session.msg("\n\r"+ topic.get_entrytext_ingame())
source_object.emit_to("\n\r"+ topic.get_entrytext_ingame())