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

File diff suppressed because one or more lines are too long

14
src/alias_mgr.py Normal file
View file

@ -0,0 +1,14 @@
"""
Player command alias management stuff.
"""
from src.config.models import CommandAlias
CMD_ALIAS_LIST = {}
def load_cmd_aliases():
"""
Load up our command aliases.
"""
alias_list = CommandAlias.objects.all()
for alias in alias_list:
CMD_ALIAS_LIST[alias.user_input] = alias.equiv_command
print ' Command Aliases Loaded: %i' % (len(CMD_ALIAS_LIST),)

View file

@ -45,6 +45,12 @@ def parse_ansi(string, strip_ansi=False, strip_formatting=False):
"""
Parses a string, subbing color codes as needed.
"""
if string == None or string == '':
return ''
# Convert to string to prevent problems with lists, ints, and other types.
string = str(string)
if strip_formatting:
char_return = ""
char_tab = ""

View file

@ -3,14 +3,14 @@ This is the command processing module. It is instanced once in the main
server module and the handle() function is hit every time a player sends
something.
"""
from traceback import format_exc
import time
from src.objects.models import Object
from traceback import format_exc
from django.contrib.contenttypes.models import ContentType
import defines_global
import cmdtable
import logger
import comsys
import alias_mgr
class UnknownCommand(Exception):
"""
@ -24,9 +24,9 @@ class ExitCommandHandler(Exception):
pass
class Command(object):
# Reference to the master server object.
server = None
# The player session that the command originated from.
# The source object that the command originated from.
source_object = None
# The session that the command originated from (optional)
session = None
# The entire raw, un-parsed command.
raw_input = None
@ -62,7 +62,11 @@ class Command(object):
command string can't be parsed, it has no argument and is
handled by the except ValueError block below.
"""
# Lop off the return at the end.
self.raw_input = self.raw_input.strip('\r')
# Break the command up into the root command and its arguments.
(self.command_string, self.command_argument) = self.raw_input.split(' ', 1)
# Yank off trailing and leading spaces.
self.command_argument = self.command_argument.strip()
self.command_string = self.command_string.strip()
"""
@ -73,7 +77,14 @@ class Command(object):
if self.command_string == '':
self.command_string = None
if self.command_argument == '':
self.command_argument = None
self.command_argument = None
if self.command_string == None:
"""
This prevents any bad stuff from happening as a result of
trying to further parse a None object.
"""
return
except ValueError:
"""
No arguments. IE: look, who.
@ -83,12 +94,12 @@ class Command(object):
# Parse command_string for switches, regardless of what happens.
self.parse_command_switches()
def __init__(self, raw_input, server=None, session=None):
def __init__(self, source_object, raw_input, session=None):
"""
Instantiates the Command object and does some preliminary parsing.
"""
self.server = server
self.raw_input = raw_input
self.source_object = source_object
self.session = session
# The work starts here.
self.parse_command()
@ -132,11 +143,12 @@ def match_idle(command):
them to drop if they don't send or receive something from the connection
for a while.
"""
if not command.command_string == 'idle':
# Anything other than an 'idle' command updates the public-facing idle
# time for the session.
if command.session and command.command_string != 'idle' \
and command.command_string != None:
# Anything other than an 'idle' command or a blank return
# updates the public-facing idle time for the session.
command.session.count_command(silently=False)
else:
elif command.session:
# User is hitting IDLE command. Don't update their publicly
# facing idle time, drop out of command handler immediately.
command.session.count_command(silently=True)
@ -147,8 +159,10 @@ def match_exits(command):
See if we can find an input match to exits.
"""
# If we're not logged in, don't check exits.
pobject = command.session.get_pobject()
exits = pobject.get_location().get_contents(filter_type=defines_global.OTYPE_EXIT)
source_object = command.source_object
exits = source_object.get_location().get_contents(filter_type=defines_global.OTYPE_EXIT)
Object = ContentType.objects.get(app_label="objects",
model="object").model_class()
exit_matches = Object.objects.list_search_object_namestr(exits,
command.command_string,
match_type="exact")
@ -160,13 +174,13 @@ def match_exits(command):
if targ_exit.get_home():
# SCRIPT: See if the player can traverse the exit
if not targ_exit.scriptlink.default_lock({
"pobject": pobject
"pobject": source_object
}):
command.session.msg("You can't traverse that exit.")
source_object.emit_to("You can't traverse that exit.")
else:
pobject.move_to(targ_exit.get_home())
source_object.move_to(targ_exit.get_home())
else:
command.session.msg("That exit leads to nowhere.")
source_object.emit_to("That exit leads to nowhere.")
# We found a match, kill the command handler.
raise ExitCommandHandler
@ -179,7 +193,7 @@ def match_alias(command):
exist on the dict, just keep the command_string the same. If the key exists,
its value replaces the command_string. For example, sa -> say.
"""
command.command_string = command.server.cmd_alias_list.get(
command.command_string = alias_mgr.CMD_ALIAS_LIST.get(
command.command_string,
command.command_string)
@ -205,15 +219,17 @@ def match_channel(command):
over a channel, replace command_string with @cemit. If they're entering
a channel manipulation command, perform the operation and kill the things
immediately with a True value sent back to the command handler.
This only works with PLAYER objects at this point in time.
"""
if comsys.plr_has_channel(command.session, command.command_string,
alias_search=True, return_muted=True):
if command.session and comsys.plr_has_channel(command.session,
command.command_string, alias_search=True, return_muted=True):
calias = command.command_string
cname = comsys.plr_cname_from_alias(command.session, calias)
if command.command_argument == "who":
comsys.msg_cwho(command.session, cname)
comsys.msg_cwho(command.source_object, cname)
raise ExitCommandHandler
elif command.command_argument == "on":
comsys.plr_chan_on(command.session, calias)
@ -222,7 +238,7 @@ def match_channel(command):
comsys.plr_chan_off(command.session, calias)
raise ExitCommandHandler
elif command.command_argument == "last":
comsys.msg_chan_hist(command.session, cname)
comsys.msg_chan_hist(command.source_object, cname)
raise ExitCommandHandler
second_arg = "%s=%s" % (cname, command.command_argument)
@ -240,8 +256,8 @@ def command_table_lookup(command, command_table, eval_perms=True):
if cmdtuple:
# If there is a permissions element to the entry, check perms.
if eval_perms and cmdtuple[1]:
if not command.session.get_pobject().user_has_perm_list(cmdtuple[1]):
command.session.msg(defines_global.NOPERMS_MSG)
if not command.source_object.has_perm_list(cmdtuple[1]):
command.source_object.emit_to(defines_global.NOPERMS_MSG)
raise ExitCommandHandler
# If flow reaches this point, user has perms and command is ready.
command.command_function = cmdtuple[0]
@ -256,16 +272,17 @@ def handle(command):
their input on to 'cmd_' and looking it up in the GenCommands
class.
"""
session = command.session
server = command.server
try:
# TODO: Protect against non-standard characters.
if not command.command_string:
# Nothing sent in of value, ignore it.
raise ExitCommandHandler
if session.logged_in:
if command.session and not command.session.logged_in:
# Not logged in, look through the unlogged-in command table.
command_table_lookup(command, cmdtable.GLOBAL_UNCON_CMD_TABLE,
eval_perms=False)
else:
# Match against the 'idle' command.
match_idle(command)
# See if this is an aliased command.
@ -276,10 +293,6 @@ def handle(command):
match_exits(command)
# Retrieve the appropriate (if any) command function.
command_table_lookup(command, cmdtable.GLOBAL_CMD_TABLE)
else:
# Not logged in, look through the unlogged-in command table.
command_table_lookup(command, cmdtable.GLOBAL_UNCON_CMD_TABLE,
eval_perms=False)
"""
By this point, we assume that the user has entered a command and not
@ -297,10 +310,11 @@ def handle(command):
codebase stabilizes, we will probably want something more
useful or give them the option to hide exception values.
"""
session.msg("Untrapped error, please file a bug report:\n%s" %
(format_exc(),))
logger.log_errmsg("Untrapped error, evoker %s: %s" %
(session, format_exc()))
if command.source_object:
command.source_object.emit_to("Untrapped error, please file a bug report:\n%s" %
(format_exc(),))
logger.log_errmsg("Untrapped error, evoker %s: %s" %
(command.source_object, format_exc()))
# Prevent things from falling through to UnknownCommand.
raise ExitCommandHandler
else:
@ -313,5 +327,4 @@ def handle(command):
pass
except UnknownCommand:
# Default fall-through. No valid command match.
session.msg("Huh? (Type \"help\" for help.)")
command.source_object.emit_to("Huh? (Type \"help\" for help.)")

View file

@ -1,11 +1,8 @@
"""
Comsys command module. Pretty much every comsys command should go here for
now.
Comsys command module.
"""
import time
from django.conf import settings
import src.comsys
from src import defines_global
from src import ansi
@ -18,11 +15,10 @@ def cmd_addcom(command):
Adds an alias for a channel.
addcom foo=Bar
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("You need to specify a channel alias and name.")
source_object.emit_to("You need to specify a channel alias and name.")
return
eq_args = command.command_argument.split('=', 1)
@ -31,27 +27,28 @@ def cmd_addcom(command):
chan_name = eq_args[1]
if len(eq_args) < 2 or len(chan_name) == 0:
session.msg("You need to specify a channel name.")
source_object.emit_to("You need to specify a channel name.")
return
if chan_alias in session.channels_subscribed:
session.msg("You are already on that channel.")
if chan_alias in command.session.channels_subscribed:
source_object.emit_to("You are already on that channel.")
return
name_matches = src.comsys.cname_search(chan_name, exact=True)
if name_matches:
chan_name_parsed = name_matches[0].get_name()
session.msg("You join %s, with an alias of %s." % \
source_object.emit_to("You join %s, with an alias of %s." % \
(chan_name_parsed, chan_alias))
src.comsys.plr_set_channel(session, chan_alias, chan_name_parsed, True)
src.comsys.plr_set_channel(command.session, chan_alias,
chan_name_parsed, True)
# Announce the user's joining.
join_msg = "[%s] %s has joined the channel." % \
(chan_name_parsed, pobject.get_name(show_dbref=False))
(chan_name_parsed, source_object.get_name(show_dbref=False))
src.comsys.send_cmessage(chan_name_parsed, join_msg)
else:
session.msg("Could not find channel %s." % (chan_name,))
source_object.emit_to("Could not find channel %s." % (chan_name,))
def cmd_delcom(command):
"""
@ -60,42 +57,42 @@ def cmd_delcom(command):
Removes the specified alias to a channel. If this is the last alias,
the user is effectively removed from the channel.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("You must specify a channel alias.")
source_object.emit_to("You must specify a channel alias.")
return
if command.command_argument not in session.channels_subscribed:
session.msg("You are not on that channel.")
if command.command_argument not in command.session.channels_subscribed:
source_object.emit_to("You are not on that channel.")
return
chan_name = session.channels_subscribed[command.command_argument][0]
session.msg("You have left %s." % (chan_name,))
src.comsys.plr_del_channel(session, command.command_argument)
chan_name = command.session.channels_subscribed[command.command_argument][0]
source_object.emit_to("You have left %s." % (chan_name,))
src.comsys.plr_del_channel(command.session, command.command_argument)
# Announce the user's leaving.
leave_msg = "[%s] %s has left the channel." % \
(chan_name, pobject.get_name(show_dbref=False))
(chan_name, source_object.get_name(show_dbref=False))
src.comsys.send_cmessage(chan_name, leave_msg)
def cmd_comlist(command):
"""
Lists the channels a user is subscribed to.
"""
source_object = command.source_object
session = command.session
session.msg("Alias Channel Status")
source_object.emit_to("Alias Channel Status")
for chan in session.channels_subscribed:
if session.channels_subscribed[chan][1]:
chan_on = "On"
else:
chan_on = "Off"
session.msg("%-9.9s %-19.19s %s" %
source_object.emit_to("%-9.9s %-19.19s %s" %
(chan, session.channels_subscribed[chan][0], chan_on))
session.msg("-- End of comlist --")
source_object.emit_to("-- End of comlist --")
def cmd_allcom(command):
"""
@ -124,12 +121,14 @@ def cmd_clist(command):
Lists all available channels on the game.
"""
session = command.session
session.msg("** Channel Owner Description")
source_object = command.source_object
source_object.emit_to("** Channel Owner Description")
for chan in src.comsys.get_all_channels():
session.msg("%s%s %-13.13s %-15.15s %-45.45s" %
source_object.emit_to("%s%s %-14.13s%-22.15s%s" %
('-', '-', chan.get_name(), chan.get_owner().get_name(),
'No Description'))
session.msg("-- End of Channel List --")
source_object.emit_to("-- End of Channel List --")
def cmd_cdestroy(command):
"""
@ -137,24 +136,24 @@ def cmd_cdestroy(command):
Destroys a channel.
"""
session = command.session
source_object = command.source_object
cname = command.command_argument
if cname == '':
session.msg("You must supply a name!")
if not cname:
source_object.emit_to("You must supply a name!")
return
name_matches = src.comsys.cname_search(cname, exact=True)
if not name_matches:
session.msg("Could not find channel %s." % (cname,))
source_object.emit_to("Could not find channel %s." % (cname,))
else:
is_controlled_by_plr = name_matches[0].controlled_by(pobject)
is_controlled_by_plr = name_matches[0].controlled_by(source_object)
if is_controlled_by_plr:
session.msg("Channel %s destroyed." % (name_matches[0],))
source_object.emit_to("Channel %s destroyed." % (name_matches[0],))
name_matches.delete()
else:
session.msg("Permission denied.")
source_object.emit_to("Permission denied.")
return
def cmd_cset(command):
@ -195,58 +194,57 @@ def cmd_cemit(command):
they own or control it. It does not show the user's name unless they
provide the /sendername switch.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("Channel emit what?")
source_object.emit_to("Channel emit what?")
return
eq_args = command.command_argument.split('=', 1)
if len(eq_args) != 2:
session.msg("You must provide a channel name and a message to emit.")
source_object.emit_to("You must provide a channel name and a message to emit.")
return
cname = eq_args[0]
cmessage = eq_args[1]
if len(cname) == 0:
session.msg("You must provide a channel name to emit to.")
source_object.emit_to("You must provide a channel name to emit to.")
return
if len(cmessage) == 0:
session.msg("You must provide a message to emit.")
source_object.emit_to("You must provide a message to emit.")
return
name_matches = src.comsys.cname_search(cname, exact=True)
if name_matches:
cname_parsed = name_matches[0].get_name()
else:
session.msg("Could not find channel %s." % (cname,))
source_object.emit_to("Could not find channel %s." % (cname,))
return
if "noheader" in command.command_switches:
if not pobject.user_has_perm("objects.emit_commchannel"):
session.msg(defines_global.NOPERMS_MSG)
if not source_object.has_perm("objects.emit_commchannel"):
source_object.emit_to(defines_global.NOPERMS_MSG)
return
final_cmessage = cmessage
else:
if "sendername" in command.command_switches:
if not src.comsys.plr_has_channel(session, cname_parsed,
if not src.comsys.plr_has_channel(command.session, cname_parsed,
return_muted=False):
session.msg("You must be on %s to do that." % (cname_parsed,))
source_object.emit_to("You must be on %s to do that." % (cname_parsed,))
return
final_cmessage = "[%s] %s: %s" % (cname_parsed,
pobject.get_name(show_dbref=False),
source_object.get_name(show_dbref=False),
cmessage)
else:
if not pobject.user_has_perm("objects.emit_commchannel"):
session.msg(defines_global.NOPERMS_MSG)
if not source_object.has_perm("objects.emit_commchannel"):
source_object.emit_to(defines_global.NOPERMS_MSG)
return
final_cmessage = "[%s] %s" % (cname_parsed, cmessage)
if not "quiet" in command.command_switches:
session.msg("Sent - %s" % (name_matches[0],))
source_object.emit_to("Sent - %s" % (name_matches[0],))
src.comsys.send_cmessage(cname_parsed, final_cmessage)
def cmd_cwho(command):
@ -258,32 +256,32 @@ def cmd_cwho(command):
as well.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("You must specify a channel name.")
source_object.emit_to("You must specify a channel name.")
return
channel_name = command.command_argument
if channel_name.strip() == '':
session.msg("You must specify a channel name.")
source_object.emit_to("You must specify a channel name.")
return
name_matches = src.comsys.cname_search(channel_name, exact=True)
if name_matches:
# Check to make sure the user has permission to use @cwho.
is_channel_admin = pobject.user_has_perm("objects.channel_admin")
is_controlled_by_plr = name_matches[0].controlled_by(pobject)
is_channel_admin = source_object.has_perm("objects.channel_admin")
is_controlled_by_plr = name_matches[0].controlled_by(source_object)
if is_controlled_by_plr or is_channel_admin:
src.comsys.msg_cwho(session, channel_name)
src.comsys.msg_cwho(source_object, channel_name)
else:
session.msg("Permission denied.")
source_object.emit_to("Permission denied.")
return
else:
session.msg("No channel with that name was found.")
source_object.emit_to("No channel with that name was found.")
return
def cmd_ccreate(command):
@ -293,27 +291,25 @@ def cmd_ccreate(command):
Creates a new channel with the invoker being the default owner.
"""
# TODO: Implement cmd_ccreate
session = command.session
pobject = session.get_pobject()
if not command.command_argument:
session.msg("You must supply a name!")
return
if not pobject.user_has_perm("objects.channel_admin"):
session.msg("Permission denied.")
return
source_object = command.source_object
cname = command.command_argument
if not cname:
source_object.emit_to("You must supply a name!")
return
if not source_object.has_perm("objects.channel_admin"):
source_object.emit_to("Permission denied.")
return
name_matches = src.comsys.cname_search(cname, exact=True)
if name_matches:
session.msg("A channel with that name already exists.")
source_object.emit_to("A channel with that name already exists.")
else:
# Create and set the object up.
new_chan = src.comsys.create_channel(cname, pobject)
session.msg("Channel %s created." % (new_chan.get_name(),))
new_chan = src.comsys.create_channel(cname, source_object)
source_object.emit_to("Channel %s created." % (new_chan.get_name(),))
def cmd_cchown(command):
"""

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())

View file

@ -6,13 +6,11 @@ import os
import time
from src.util import functions_general
if not functions_general.host_os_is('nt'):
# Don't import the resource module if the host OS is Windows.
import resource
import django
from src.objects.models import Object
from src import scheduler
from src import defines_global
@ -22,104 +20,104 @@ def cmd_version(command):
"""
Version info command.
"""
session = command.session
retval = "-"*50 +"\n\r"
retval += " Evennia %s\n\r" % (defines_global.EVENNIA_VERSION,)
retval += " Django %s\n\r" % (django.get_version())
retval += "-"*50
session.msg(retval)
command.source_object.emit_to(retval)
def cmd_time(command):
"""
Server local time.
"""
session = command.session
session.msg('Current server time : %s' %
command.source_object.emit_to('Current server time : %s' %
(time.strftime('%a %b %d %H:%M:%S %Y (%Z)', time.localtime(),)))
def cmd_uptime(command):
"""
Server uptime and stats.
"""
session = command.session
server = command.server
source_object = command.source_object
server = command.session.server
start_delta = time.time() - server.start_time
session.msg('Current server time : %s' %
source_object.emit_to('Current server time : %s' %
(time.strftime('%a %b %d %H:%M %Y (%Z)', time.localtime(),)))
session.msg('Server start time : %s' %
source_object.emit_to('Server start time : %s' %
(time.strftime('%a %b %d %H:%M %Y', time.localtime(server.start_time),)))
session.msg('Server uptime : %s' %
source_object.emit_to('Server uptime : %s' %
functions_general.time_format(start_delta, style=2))
# os.getloadavg() is not available on Windows.
if not functions_general.host_os_is('nt'):
loadavg = os.getloadavg()
session.msg('Server load (1 min) : %.2f' %
source_object.emit_to('Server load (1 min) : %.2f' %
loadavg[0])
def cmd_list(command):
"""
Shows some game related information.
"""
session = command.session
pobject = session.get_pobject()
server = command.session.server
source_object = command.source_object
msg_invalid = "Unknown option. Use one of: commands, flags, process"
if not command.command_argument:
session.msg(msg_invalid)
source_object.emit_to(msg_invalid)
elif command.command_argument == "commands":
session.msg('Commands: '+ ' '.join(session.server.command_list()))
source_object.emit_to('Commands: '+ ' '.join(server.command_list()))
elif command.command_argument == "process":
if not functions_general.host_os_is('nt'):
loadvg = os.getloadavg()
psize = resource.getpagesize()
rusage = resource.getrusage(resource.RUSAGE_SELF)
session.msg("Process ID: %10d %10d bytes per page" %
(os.getpid(), psize))
session.msg("Time used: %10d user %10d sys" %
(rusage[0],rusage[1]))
session.msg("Integral mem:%10d shared %10d private%10d stack" %
(rusage[3], rusage[4], rusage[5]))
session.msg("Max res mem: %10d pages %10d bytes" %
(rusage[2],rusage[2] * psize))
session.msg("Page faults: %10d hard %10d soft %10d swapouts" %
(rusage[7], rusage[6], rusage[8]))
session.msg("Disk I/O: %10d reads %10d writes" %
(rusage[9], rusage[10]))
session.msg("Network I/O: %10d in %10d out" %
(rusage[12], rusage[11]))
session.msg("Context swi: %10d vol %10d forced %10d sigs" %
(rusage[14], rusage[15], rusage[13]))
source_object.emit_to("Process ID: %10d %10d bytes per page" %
(os.getpid(), psize))
source_object.emit_to("Time used: %10d user %10d sys" %
(rusage[0],rusage[1]))
source_object.emit_to("Integral mem:%10d shared %10d private%10d stack" %
(rusage[3], rusage[4], rusage[5]))
source_object.emit_to("Max res mem: %10d pages %10d bytes" %
(rusage[2],rusage[2] * psize))
source_object.emit_to("Page faults: %10d hard %10d soft %10d swapouts" %
(rusage[7], rusage[6], rusage[8]))
source_object.emit_to("Disk I/O: %10d reads %10d writes" %
(rusage[9], rusage[10]))
source_object.emit_to("Network I/O: %10d in %10d out" %
(rusage[12], rusage[11]))
source_object.emit_to("Context swi: %10d vol %10d forced %10d sigs" %
(rusage[14], rusage[15], rusage[13]))
else:
session.msg("Feature not available on Windows.")
source_object.emit_to("Feature not available on Windows.")
return
elif command.command_argument == "flags":
session.msg("Flags: "+" ".join(flags.SERVER_FLAGS))
source_object.emit_to("Flags: "+" ".join(flags.SERVER_FLAGS))
else:
session.msg(msg_invalid)
source_object.emit_to(msg_invalid)
def cmd_ps(command):
"""
Shows the process/event table.
"""
session = command.session
session.msg("-- Interval Events --")
source_object = command.source_object
source_object.emit_to("-- Interval Events --")
for event in scheduler.schedule:
session.msg(" [%d/%d] %s" % (scheduler.get_event_nextfire(event),
scheduler.get_event_interval(event),
scheduler.get_event_description(event)))
session.msg("Totals: %d interval events" % (len(scheduler.schedule),))
source_object.emit_to(" [%d/%d] %s" % (
scheduler.get_event_nextfire(event),
scheduler.get_event_interval(event),
scheduler.get_event_description(event)))
source_object.emit_to("Totals: %d interval events" % (len(scheduler.schedule),))
def cmd_stats(command):
"""
Shows stats about the database.
4012 objects = 144 rooms, 212 exits, 613 things, 1878 players. (1165 garbage)
"""
session = command.session
stats_dict = Object.objects.object_totals()
session.msg("%d objects = %d rooms, %d exits, %d things, %d players. (%d garbage)" %
command.source_object.emit_to(
"%d objects = %d rooms, %d exits, %d things, %d players. (%d garbage)" %
(stats_dict["objects"],
stats_dict["rooms"],
stats_dict["exits"],

View file

@ -5,17 +5,15 @@ from src.objects.models import Object, Attribute
# We'll import this as the full path to avoid local variable clashes.
import src.flags
from src import ansi
from src import session_mgr
def cmd_teleport(command):
"""
Teleports an object somewhere.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("Teleport where/what?")
source_object.emit_to("Teleport where/what?")
return
eq_args = command.command_argument.split('=', 1)
@ -31,96 +29,80 @@ def cmd_teleport(command):
# a direct teleport, @tel <destination>.
if len(eq_args) > 1:
# Equal sign teleport.
victim = Object.objects.standard_plr_objsearch(session, eq_args[0])
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
victim = Object.objects.standard_objsearch(source_object, eq_args[0])
# Use standard_objsearch to handle duplicate/nonexistant results.
if not victim:
return
destination = Object.objects.standard_plr_objsearch(session, eq_args[1])
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
destination = Object.objects.standard_objsearch(source_object, eq_args[1])
# Use standard_objsearch to handle duplicate/nonexistant results.
if not destination:
return
if victim.is_room():
session.msg("You can't teleport a room.")
source_object.emit_to("You can't teleport a room.")
return
if victim == destination:
session.msg("You can't teleport an object inside of itself!")
source_object.emit_to("You can't teleport an object inside of itself!")
return
session.msg("Teleported.")
source_object.emit_to("Teleported.")
victim.move_to(destination, quiet=tel_quietly)
else:
# Direct teleport (no equal sign)
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
if target_obj == pobject:
session.msg("You can't teleport inside yourself!")
if target_obj == source_object:
source_object.emit_to("You can't teleport inside yourself!")
return
session.msg("Teleported.")
source_object.emit_to("Teleported.")
pobject.move_to(target_obj, quiet=tel_quietly)
def cmd_stats(command):
"""
Shows stats about the database.
4012 objects = 144 rooms, 212 exits, 613 things, 1878 players. (1165 garbage)
"""
session = command.session
stats_dict = Object.objects.object_totals()
session.msg("%d objects = %d rooms, %d exits, %d things, %d players. (%d garbage)" %
(stats_dict["objects"],
stats_dict["rooms"],
stats_dict["exits"],
stats_dict["things"],
stats_dict["players"],
stats_dict["garbage"]))
source_object.move_to(target_obj, quiet=tel_quietly)
def cmd_alias(command):
"""
Assigns an alias to a player object for ease of paging, etc.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("Alias whom?")
source_object.emit_to("Alias whom?")
return
eq_args = command.command_argument.split('=', 1)
if len(eq_args) < 2:
session.msg("Alias missing.")
source_object.emit_to("Alias missing.")
return
target_string = eq_args[0]
new_alias = eq_args[1]
# An Object instance for the victim.
target = Object.objects.standard_plr_objsearch(session, target_string)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
target = Object.objects.standard_objsearch(source_object, target_string)
# Use standard_objsearch to handle duplicate/nonexistant results.
if not target:
session.msg("I can't find that player.")
source_object.emit_to("I can't find that player.")
return
old_alias = target.get_attribute_value('ALIAS')
duplicates = Object.objects.player_alias_search(pobject, new_alias)
duplicates = Object.objects.player_alias_search(source_object, new_alias)
if not duplicates or old_alias.lower() == new_alias.lower():
# Either no duplicates or just changing the case of existing alias.
if pobject.controls_other(target):
if source_object.controls_other(target):
target.set_attribute('ALIAS', new_alias)
session.msg("Alias '%s' set for %s." % (new_alias,
source_object.emit_to("Alias '%s' set for %s." % (new_alias,
target.get_name()))
else:
session.msg("You do not have access to set an alias for %s." %
source_object.emit_to("You do not have access to set an alias for %s." %
(target.get_name(),))
else:
# Duplicates were found.
session.msg("Alias '%s' is already in use." % (new_alias,))
source_object.emit_to("Alias '%s' is already in use." % (new_alias,))
return
def cmd_wipe(command):
@ -128,12 +110,11 @@ def cmd_wipe(command):
Wipes an object's attributes, or optionally only those matching a search
string.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
attr_search = False
if not command.command_argument:
session.msg("Wipe what?")
source_object.emit_to("Wipe what?")
return
# Look for a slash in the input, indicating an attribute wipe.
@ -149,8 +130,8 @@ def cmd_wipe(command):
else:
searchstr = command.command_argument
target_obj = Object.objects.standard_plr_objsearch(session, attr_split[0])
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
target_obj = Object.objects.standard_objsearch(source_object, attr_split[0])
# Use standard_objsearch to handle duplicate/nonexistant results.
if not target_obj:
return
@ -162,43 +143,43 @@ def cmd_wipe(command):
if attr_matches:
for attr in attr_matches:
target_obj.clear_attribute(attr.get_name())
session.msg("%s - %d attributes wiped." % (target_obj.get_name(),
len(attr_matches)))
source_object.emit_to("%s - %d attributes wiped." % (
target_obj.get_name(),
len(attr_matches)))
else:
session.msg("No matching attributes found.")
source_object.emit_to("No matching attributes found.")
else:
# User didn't specify a wild-card string, wipe entire object.
attr_matches = target_obj.attribute_namesearch("*", exclude_noset=True)
for attr in attr_matches:
target_obj.clear_attribute(attr.get_name())
session.msg("%s - %d attributes wiped." % (target_obj.get_name(),
source_object.emit_to("%s - %d attributes wiped." % (target_obj.get_name(),
len(attr_matches)))
def cmd_set(command):
"""
Sets flags or attributes on objects.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("Set what?")
source_object.emit_to("Set what?")
return
# Break into target and value by the equal sign.
eq_args = command.command_argument.split('=', 1)
if len(eq_args) < 2:
# Equal signs are not optional for @set.
session.msg("Set what?")
source_object.emit_to("Set what?")
return
victim = Object.objects.standard_plr_objsearch(session, eq_args[0])
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
victim = Object.objects.standard_objsearch(source_object, eq_args[0])
# Use standard_objsearch to handle duplicate/nonexistant results.
if not victim:
return
if not pobject.controls_other(victim):
session.msg(defines_global.NOCONTROL_MSG)
if not source_object.controls_other(victim):
source_object.emit_to(defines_global.NOCONTROL_MSG)
return
attrib_args = eq_args[1].split(':', 1)
@ -209,8 +190,8 @@ def cmd_set(command):
attrib_value = eq_args[1][splicenum:]
# In global_defines.py, see NOSET_ATTRIBS for protected attribute names.
if not Attribute.objects.is_modifiable_attrib(attrib_name) and not pobject.is_superuser():
session.msg("You can't modify that attribute.")
if not Attribute.objects.is_modifiable_attrib(attrib_name) and not source_object.is_superuser():
source_object.emit_to("You can't modify that attribute.")
return
if attrib_value:
@ -221,7 +202,7 @@ def cmd_set(command):
# No value was given, this means we delete the attribute.
verb = 'cleared'
victim.clear_attribute(attrib_name)
session.msg("%s - %s %s." % (victim.get_name(), attrib_name, verb))
source_object.emit_to("%s - %s %s." % (victim.get_name(), attrib_name, verb))
else:
# Flag manipulation form.
flag_list = eq_args[1].split()
@ -232,62 +213,60 @@ def cmd_set(command):
# We're un-setting the flag.
flag = flag[1:]
if not src.flags.is_modifiable_flag(flag):
session.msg("You can't set/unset the flag - %s." % (flag,))
source_object.emit_to("You can't set/unset the flag - %s." % (flag,))
else:
session.msg('%s - %s cleared.' % (victim.get_name(),
flag.upper(),))
source_object.emit_to('%s - %s cleared.' % (victim.get_name(),
flag.upper(),))
victim.set_flag(flag, False)
else:
# We're setting the flag.
if not src.flags.is_modifiable_flag(flag):
session.msg("You can't set/unset the flag - %s." % (flag,))
source_object.emit_to("You can't set/unset the flag - %s." % (flag,))
else:
session.msg('%s - %s set.' % (victim.get_name(),
flag.upper(),))
source_object.emit_to('%s - %s set.' % (victim.get_name(),
flag.upper(),))
victim.set_flag(flag, True)
def cmd_find(command):
"""
Searches for an object of a particular name.
"""
session = command.session
pobject = session.get_pobject()
can_find = pobject.user_has_perm("genperms.builder")
source_object = command.source_object
can_find = source_object.has_perm("genperms.builder")
if not command.command_argument:
session.msg("No search pattern given.")
source_object.emit_to("No search pattern given.")
return
searchstring = command.command_argument
results = Object.objects.global_object_name_search(searchstring)
if len(results) > 0:
session.msg("Name matches for: %s" % (searchstring,))
source_object.emit_to("Name matches for: %s" % (searchstring,))
for result in results:
session.msg(" %s" % (result.get_name(fullname=True),))
session.msg("%d matches returned." % (len(results),))
source_object.emit_to(" %s" % (result.get_name(fullname=True),))
source_object.emit_to("%d matches returned." % (len(results),))
else:
session.msg("No name matches found for: %s" % (searchstring,))
source_object.emit_to("No name matches found for: %s" % (searchstring,))
def cmd_create(command):
"""
Creates a new object of type 'THING'.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("You must supply a name!")
source_object.emit_to("You must supply a name!")
else:
# Create and set the object up.
# TODO: This dictionary stuff is silly. Feex.
odat = {"name": command.command_argument,
"type": 3,
"location": pobject,
"owner": pobject}
"location": source_object,
"owner": source_object}
new_object = Object.objects.create_object(odat)
session.msg("You create a new thing: %s" % (new_object,))
source_object.emit_to("You create a new thing: %s" % (new_object,))
def cmd_cpattr(command):
"""
@ -295,12 +274,10 @@ def cmd_cpattr(command):
@cpattr <source object>/<attribute> = <target1>/[<attrname>] <target n>/[<attrname n>]
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("What do you want to copy?")
source_object.emit_to("What do you want to copy?")
return
# Split up source and target[s] via the equals sign.
@ -308,7 +285,7 @@ def cmd_cpattr(command):
if len(eq_args) < 2:
# There must be both a source and a target pair for cpattr
session.msg("You have not supplied both a source and a target[s]")
source_object.emit_to("You have not supplied both a source and a target[s]")
return
# Check that the source object and attribute exists, by splitting the eq_args 'source' entry with '/'
@ -317,17 +294,17 @@ def cmd_cpattr(command):
source_attr_string = source[1].strip().upper()
# Check whether src_obj exists
src_obj = Object.objects.standard_plr_objsearch(session, source_string)
src_obj = Object.objects.standard_objsearch(source_object, source_string)
if not src_obj:
session.msg("Source object does not exist")
source_object.emit_to("Source object does not exist")
return
# Check whether src_obj has src_attr
src_attr = src_obj.attribute_namesearch(source_attr_string)
if not src_attr:
session.msg("Source object does not have attribute " + source[1].strip())
source_object.emit_to("Source object does not have attribute " + source[1].strip())
return
# For each target object, check it exists
@ -343,7 +320,7 @@ def cmd_cpattr(command):
# Does target exist?
if not tar_obj:
session.msg("Target object does not exist: " + tar_string)
source_object.emit_to("Target object does not exist: " + tar_string)
# Continue if target does not exist, but give error on this item
continue
@ -355,9 +332,8 @@ def cmd_cpattr(command):
# If however, the target attribute is given, check it exists and update
# accordingly.
# Does target attribute exist?
tar_attr = tar_obj.attribute_namesearch(tar_attr_string)
# If the target object does not have the given attribute, make a new attr
@ -374,11 +350,9 @@ def cmd_cpattr(command):
def cmd_nextfree(command):
"""
Returns the next free object number.
"""
session = command.session
"""
nextfree = Object.objects.get_nextfree_dbnum()
session.msg("Next free object number: #%s" % (nextfree,))
command.source_object.emit_to("Next free object number: #%s" % (nextfree,))
def cmd_open(command):
"""
@ -389,18 +363,17 @@ def cmd_open(command):
@open <Name>=<Dbref>
@open <Name>=<Dbref>,<Name>
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("Open an exit to where?")
source_object.emit_to("Open an exit to where?")
return
eq_args = command.command_argument.split('=', 1)
exit_name = eq_args[0]
if len(exit_name) == 0:
session.msg("You must supply an exit name.")
source_object.emit_to("You must supply an exit name.")
return
# If we have more than one entry in our '=' delimited argument list,
@ -409,47 +382,48 @@ def cmd_open(command):
if len(eq_args) > 1:
# Opening an exit to another location via @open <Name>=<Dbref>[,<Name>].
comma_split = eq_args[1].split(',', 1)
destination = Object.objects.standard_plr_objsearch(session,
destination = Object.objects.standard_objsearch(source_object,
comma_split[0])
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
# Use standard_objsearch to handle duplicate/nonexistant results.
if not destination:
return
if destination.is_exit():
session.msg("You can't open an exit to an exit!")
source_object.emit_to("You can't open an exit to an exit!")
return
odat = {"name": exit_name,
"type": 4,
"location": pobject.get_location(),
"owner": pobject,
"home":destination}
"location": source_object.get_location(),
"owner": source_object,
"home": destination}
new_object = Object.objects.create_object(odat)
session.msg("You open the an exit - %s to %s" % (new_object.get_name(),
destination.get_name()))
source_object.emit_to("You open the an exit - %s to %s" % (
new_object.get_name(),
destination.get_name()))
if len(comma_split) > 1:
second_exit_name = ','.join(comma_split[1:])
odat = {"name": second_exit_name,
"type": 4,
"location": destination,
"owner": pobject,
"home": pobject.get_location()}
"owner": source_object,
"home": source_object.get_location()}
new_object = Object.objects.create_object(odat)
session.msg("You open the an exit - %s to %s" % (
source_object.emit_to("You open the an exit - %s to %s" % (
new_object.get_name(),
pobject.get_location().get_name()))
source_object.get_location().get_name()))
else:
# Create an un-linked exit.
odat = {"name": exit_name,
"type": 4,
"location": pobject.get_location(),
"owner": pobject,
"home":None}
"location": source_object.get_location(),
"owner": source_object,
"home": None}
new_object = Object.objects.create_object(odat)
session.msg("You open an unlinked exit - %s" % (new_object,))
source_object.emit_to("You open an unlinked exit - %s" % (new_object,))
def cmd_chown(command):
"""
@ -459,11 +433,10 @@ def cmd_chown(command):
Forms:
@chown <Object>=<NewOwner>
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("Change the ownership of what?")
source_object.emit_to("Change the ownership of what?")
return
eq_args = command.command_argument.split('=', 1)
@ -471,37 +444,35 @@ def cmd_chown(command):
owner_name = eq_args[1]
if len(target_name) == 0:
session.msg("Change the ownership of what?")
source_object.emit_to("Change the ownership of what?")
return
if len(eq_args) > 1:
target_obj = Object.objects.standard_plr_objsearch(session, target_name)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
target_obj = Object.objects.standard_objsearch(source_object, target_name)
# Use standard_objsearch to handle duplicate/nonexistant results.
if not target_obj:
return
if not pobject.controls_other(target_obj):
session.msg(defines_global.NOCONTROL_MSG)
if not source_object.controls_other(target_obj):
source_object.emit_to(defines_global.NOCONTROL_MSG)
return
owner_obj = Object.objects.standard_plr_objsearch(session, owner_name)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
owner_obj = Object.objects.standard_objsearch(source_object, owner_name)
# Use standard_objsearch to handle duplicate/nonexistant results.
if not owner_obj:
return
if not owner_obj.is_player():
session.msg("Only players may own objects.")
source_object.emit_to("Only players may own objects.")
return
if target_obj.is_player():
session.msg("You may not change the ownership of player objects.")
source_object.emit_to("You may not change the ownership of player objects.")
return
target_obj.set_owner(owner_obj)
session.msg("%s now owns %s." % (owner_obj, target_obj))
source_object.emit_to("%s now owns %s." % (owner_obj, target_obj))
else:
# We haven't provided a target.
session.msg("Who should be the new owner of the object?")
source_object.emit_to("Who should be the new owner of the object?")
return
def cmd_chzone(command):
@ -512,11 +483,10 @@ def cmd_chzone(command):
Forms:
@chzone <Object>=<NewZone>
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("Change the zone of what?")
source_object.emit_to("Change the zone of what?")
return
eq_args = command.command_argument.split('=', 1)
@ -524,36 +494,36 @@ def cmd_chzone(command):
zone_name = eq_args[1]
if len(target_name) == 0:
session.msg("Change the zone of what?")
source_object.emit_to("Change the zone of what?")
return
if len(eq_args) > 1:
target_obj = Object.objects.standard_plr_objsearch(session, target_name)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
target_obj = Object.objects.standard_objsearch(source_object, target_name)
# Use standard_objsearch to handle duplicate/nonexistant results.
if not target_obj:
return
if not pobject.controls_other(target_obj):
session.msg(defines_global.NOCONTROL_MSG)
if not source_object.controls_other(target_obj):
source_object.emit_to(defines_global.NOCONTROL_MSG)
return
# Allow the clearing of a zone
if zone_name.lower() == "none":
target_obj.set_zone(None)
session.msg("%s is no longer zoned." % (target_obj))
source_object.emit_to("%s is no longer zoned." % (target_obj))
return
zone_obj = Object.objects.standard_plr_objsearch(session, zone_name)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
zone_obj = Object.objects.standard_objsearch(source_object, zone_name)
# Use standard_objsearch to handle duplicate/nonexistant results.
if not zone_obj:
return
target_obj.set_zone(zone_obj)
session.msg("%s is now in zone %s." % (target_obj, zone_obj))
source_object.emit_to("%s is now in zone %s." % (target_obj, zone_obj))
else:
# We haven't provided a target zone.
session.msg("What should the object's zone be set to?")
source_object.emit_to("What should the object's zone be set to?")
return
def cmd_link(command):
@ -563,11 +533,10 @@ def cmd_link(command):
Forms:
@link <Object>=<Target>
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("Link what?")
source_object.emit_to("Link what?")
return
eq_args = command.command_argument.split('=', 1)
@ -575,36 +544,36 @@ def cmd_link(command):
dest_name = eq_args[1]
if len(target_name) == 0:
session.msg("What do you want to link?")
source_object.emit_to("What do you want to link?")
return
if len(eq_args) > 1:
target_obj = Object.objects.standard_plr_objsearch(session, target_name)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
target_obj = Object.objects.standard_objsearch(source_object, target_name)
# Use standard_objsearch to handle duplicate/nonexistant results.
if not target_obj:
return
if not pobject.controls_other(target_obj):
session.msg(defines_global.NOCONTROL_MSG)
if not source_object.controls_other(target_obj):
source_object.emit_to(defines_global.NOCONTROL_MSG)
return
# If we do something like "@link blah=", we unlink the object.
if len(dest_name) == 0:
target_obj.set_home(None)
session.msg("You have unlinked %s." % (target_obj,))
source_object.emit_to("You have unlinked %s." % (target_obj,))
return
destination = Object.objects.standard_plr_objsearch(session, dest_name)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
destination = Object.objects.standard_objsearch(source_object, dest_name)
# Use standard_objsearch to handle duplicate/nonexistant results.
if not destination:
return
target_obj.set_home(destination)
session.msg("You link %s to %s." % (target_obj,destination))
source_object.emit_to("You link %s to %s." % (target_obj, destination))
else:
# We haven't provided a target.
session.msg("You must provide a destination to link to.")
source_object.emit_to("You must provide a destination to link to.")
return
def cmd_unlink(command):
@ -613,25 +582,24 @@ def cmd_unlink(command):
@unlink <Object>
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("Unlink what?")
source_object.emit_to("Unlink what?")
return
else:
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
if not pobject.controls_other(target_obj):
session.msg(defines_global.NOCONTROL_MSG)
if not source_object.controls_other(target_obj):
source_object.emit_to(defines_global.NOCONTROL_MSG)
return
target_obj.set_home(None)
session.msg("You have unlinked %s." % (target_obj.get_name(),))
source_object.emit_to("You have unlinked %s." % (target_obj.get_name(),))
def cmd_dig(command):
"""
@ -639,21 +607,20 @@ def cmd_dig(command):
@dig <Name>
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
roomname = command.command_argument
if not roomname:
session.msg("You must supply a name!")
source_object.emit_to("You must supply a name!")
else:
# Create and set the object up.
odat = {"name": roomname,
"type": 2,
"location": None,
"owner": pobject}
"owner": source_object}
new_object = Object.objects.create_object(odat)
session.msg("You create a new room: %s" % (new_object,))
source_object.emit_to("You create a new room: %s" % (new_object,))
def cmd_name(command):
"""
@ -661,94 +628,102 @@ def cmd_name(command):
@name <Object>=<Value>
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("What do you want to name?")
source_object.emit_to("What do you want to name?")
return
eq_args = command.command_argument.split('=', 1)
if len(eq_args) < 2:
source_object.emit_to("Name it what?")
return
# Only strip spaces from right side in case they want to be silly and
# have a left-padded object name.
new_name = eq_args[1].rstrip()
if len(eq_args) < 2 or eq_args[1] == '':
session.msg("What would you like to name that object?")
source_object.emit_to("What would you like to name that object?")
else:
target_obj = Object.objects.standard_plr_objsearch(session, eq_args[0])
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
target_obj = Object.objects.standard_objsearch(source_object, eq_args[0])
# Use standard_objsearch to handle duplicate/nonexistant results.
if not target_obj:
return
ansi_name = ansi.parse_ansi(new_name, strip_formatting=True)
session.msg("You have renamed %s to %s." % (target_obj, ansi_name))
source_object.emit_to("You have renamed %s to %s." % (target_obj,
ansi_name))
target_obj.set_name(new_name)
def cmd_description(command):
"""
Set an object's description.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
if not command.command_argument:
session.msg("What do you want to describe?")
source_object.emit_to("What do you want to describe?")
return
eq_args = command.command_argument.split('=', 1)
if len(eq_args) < 2 or eq_args[1] == '':
session.msg("How would you like to describe that object?")
if len(eq_args) < 2:
source_object.emit_to("How would you like to describe that object?")
return
target_obj = Object.objects.standard_objsearch(source_object, eq_args[0])
# Use standard_objsearch to handle duplicate/nonexistant results.
if not target_obj:
return
if not source_object.controls_other(target_obj):
source_object.emit_to(defines_global.NOCONTROL_MSG)
return
new_desc = eq_args[1]
if new_desc == '':
source_object.emit_to("%s - DESCRIPTION cleared." % target_obj)
target_obj.set_description(None)
else:
target_obj = Object.objects.standard_plr_objsearch(session, eq_args[0])
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
if not target_obj:
return
if not pobject.controls_other(target_obj):
session.msg(defines_global.NOCONTROL_MSG)
return
new_desc = eq_args[1]
session.msg("%s - DESCRIPTION set." % (target_obj,))
source_object.emit_to("%s - DESCRIPTION set." % target_obj)
target_obj.set_description(new_desc)
def cmd_destroy(command):
"""
Destroy an object.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
switch_override = False
if not command.command_argument:
session.msg("Destroy what?")
source_object.emit_to("Destroy what?")
return
# Safety feature. Switch required to delete players and SAFE objects.
if "override" in command.command_switches:
switch_override = True
target_obj = Object.objects.standard_plr_objsearch(session,
command.command_argument)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
target_obj = Object.objects.standard_objsearch(source_object,
command.command_argument)
# Use standard_objsearch to handle duplicate/nonexistant results.
if not target_obj:
return
if target_obj.is_player():
if pobject.id == target_obj.id:
session.msg("You can't destroy yourself.")
if source_object.id == target_obj.id:
source_object.emit_to("You can't destroy yourself.")
return
if not switch_override:
session.msg("You must use @destroy/override on players.")
source_object.emit_to("You must use @destroy/override on players.")
return
if target_obj.is_superuser():
session.msg("You can't destroy a superuser.")
source_object.emit_to("You can't destroy a superuser.")
return
elif target_obj.is_going() or target_obj.is_garbage():
session.msg("That object is already destroyed.")
source_object.emit_to("That object is already destroyed.")
return
session.msg("You destroy %s." % (target_obj.get_name(),))
source_object.emit_to("You destroy %s." % target_obj.get_name())
target_obj.destroy()

View file

@ -4,12 +4,12 @@ Paging command and support functions.
from src.objects.models import Object
from src import defines_global
def get_last_paged_objects(pobject):
def get_last_paged_objects(source_object):
"""
Returns a list of objects of the user's last paged list, or None if invalid
or non-existant.
"""
last_paged_dbrefs = pobject.get_attribute_value("LASTPAGED")
last_paged_dbrefs = source_object.get_attribute_value("LASTPAGED")
if last_paged_dbrefs is not False:
last_paged_objects = list()
try:
@ -25,29 +25,28 @@ def get_last_paged_objects(pobject):
return last_paged_objects
except ValueError:
# Remove the invalid LASTPAGED attribute
pobject.clear_attribute("LASTPAGED")
source_object.clear_attribute("LASTPAGED")
return None
def cmd_page(command):
"""
Send a message to target user (if online).
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
# Get the last paged person(s)
last_paged_objects = get_last_paged_objects(pobject)
last_paged_objects = get_last_paged_objects(source_object)
# If they don't give a target, or any data to send to the target
# then tell them who they last paged if they paged someone, if not
# tell them they haven't paged anyone.
if not command.command_argument:
if last_paged_objects:
session.msg("You last paged: %s." % (
source_object.emit_to("You last paged: %s." % (
', '.join([x.name for x in last_paged_objects])))
return
else:
# No valid LASTPAGE values
session.msg("You have not paged anyone.")
source_object.emit_to("You have not paged anyone.")
return
# Stores a list of targets
@ -62,7 +61,7 @@ def cmd_page(command):
# No valid last paged players found, error out.
if not targets:
session.msg("Page who?")
source_object.emit_to("Page who?")
return
else:
# For each of the targets listed, grab their objects and append
@ -75,7 +74,7 @@ def cmd_page(command):
targets.append(matched_object)
else:
# Search returned None
session.msg("Player '%s' can not be found." % (
source_object.emit_to("Player '%s' can not be found." % (
target))
# Depending on the argument provided, either send the entire thing as
@ -88,7 +87,7 @@ def cmd_page(command):
# arguments as the message to send.
message = command.command_argument
sender_name = pobject.get_name(show_dbref=False)
sender_name = source_object.get_name(show_dbref=False)
# Build our messages
target_message = "%s pages: %s"
sender_message = "You paged %s with '%s'."
@ -111,17 +110,19 @@ def cmd_page(command):
target.emit_to(target_message % (sender_name, message))
target_names.append(target.get_name(show_dbref=False))
else:
session.msg("Player %s does not exist or is not online." % (
source_object.emit_to("Player %s does not exist or is not online." % (
target.get_name(show_dbref=False)))
# Now send a confirmation to the person doing the paging.
if len(target_names) > 0:
target_names_string = ', '.join(target_names)
try:
session.msg(sender_message % (target_names_string, sender_name, message))
source_object.emit_to(sender_message % (target_names_string,
sender_name, message))
except TypeError:
session.msg(sender_message % (target_names_string, message))
source_object.emit_to(sender_message % (target_names_string,
message))
# Now set the LASTPAGED attribute
pobject.set_attribute("LASTPAGED", ','.join(
source_object.set_attribute("LASTPAGED", ','.join(
["#%d" % (x.id) for x in targets]))

View file

@ -7,12 +7,11 @@ def clear_cached_scripts(command):
"""
Show the currently cached scripts.
"""
session = command.session
cache_dict = scripthandler.CACHED_SCRIPTS
cache_size = len(cache_dict)
cache_dict.clear()
session.msg("Script parent cached cleared (%d previously in cache)." %
cache_size)
command.source_object.emit_to(
"Script parent cached cleared (%d previously in cache)." % cache_size)
def show_cached_scripts(command):
"""
@ -20,7 +19,6 @@ def show_cached_scripts(command):
dictionary. The next time an object needs the previously loaded scripts,
they are loaded again.
"""
session = command.session
cache_dict = scripthandler.CACHED_SCRIPTS
retval = "Currently Cached Script Parents\n"
@ -29,7 +27,7 @@ def show_cached_scripts(command):
retval += "\n " + script
retval += "\n" + "-" * 78 + "\n"
retval += "%d cached parents" % len(cache_dict)
session.msg(retval)
command.source_object.emit_to(retval)
def cmd_parent(command):
"""
@ -44,4 +42,4 @@ def cmd_parent(command):
clear_cached_scripts(command)
return
command.source_object.emit_to("Must be specified with one of the following switches: showcache, clearcache")

View file

@ -12,16 +12,13 @@ def cmd_reload(command):
"""
Reloads all modules.
"""
session = command.session
session.msg("To be implemented...")
#session.server.reload(session)
command.source_object.emit_to("To be implemented...")
def cmd_boot(command):
"""
Boot a player object from the server.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
switch_quiet = False
switch_port = False
@ -34,7 +31,7 @@ def cmd_boot(command):
switch_port = True
if not command.command_argument:
session.msg("Who would you like to boot?")
source_object.emit_to("Who would you like to boot?")
return
else:
boot_list = []
@ -49,39 +46,41 @@ def cmd_boot(command):
break
else:
# Grab the objects that match
objs = Object.objects.local_and_global_search(pobject,
objs = Object.objects.local_and_global_search(source_object,
command.command_argument)
if not objs:
session.msg("No name or dbref match found for booting.")
source_object.emit_to("No name or dbref match found for booting.")
return
if not objs[0].is_player():
session.msg("You can only boot players.")
source_object.emit_to("You can only boot players.")
return
if not pobject.controls_other(objs[0]):
if not source_object.controls_other(objs[0]):
if objs[0].is_superuser():
session.msg("You cannot boot a Wizard.")
source_object.emit_to("You cannot boot a Wizard.")
return
else:
session.msg("You do not have permission to boot that player.")
source_object.emit_to("You do not have permission to boot that player.")
return
if objs[0].is_connected_plr():
boot_list.append(session_mgr.session_from_object(objs[0]))
matches = session_mgr.sessions_from_object(objs[0])
for match in matches:
boot_list.append(match)
else:
session.msg("That player is not connected.")
source_object.emit_to("That player is not connected.")
return
if not boot_list:
session.msg("No matches found.")
source_object.emit_to("No matches found.")
return
# Carry out the booting of the sessions in the boot list.
for boot in boot_list:
if not switch_quiet:
boot.msg("You have been disconnected by %s." % (pobject.name))
boot.msg("You have been disconnected by %s." % (source_object.name))
boot.disconnectClient()
session_mgr.remove_session(boot)
return
@ -90,28 +89,27 @@ def cmd_newpassword(command):
"""
Set a player's password.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
eq_args = command.command_argument.split('=', 1)
searchstring = eq_args[0]
newpass = eq_args[1]
if not command.command_argument or len(searchstring) == 0:
session.msg("What player's password do you want to change")
source_object.emit_to("What player's password do you want to change")
return
if len(newpass) == 0:
session.msg("You must supply a new password.")
source_object.emit_to("You must supply a new password.")
return
target_obj = Object.objects.standard_plr_objsearch(session, searchstring)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
target_obj = Object.objects.standard_objsearch(source_object, searchstring)
# Use standard_objsearch to handle duplicate/nonexistant results.
if not target_obj:
return
if not target_obj.is_player():
session.msg("You can only change passwords on players.")
elif not pobject.controls_other(target_obj):
session.msg("You do not control %s." % (target_obj.get_name(),))
source_object.emit_to("You can only change passwords on players.")
elif not source_object.controls_other(target_obj):
source_object.emit_to("You do not control %s." % (target_obj.get_name(),))
else:
uaccount = target_obj.get_user_account()
if len(newpass) == 0:
@ -119,18 +117,14 @@ def cmd_newpassword(command):
else:
uaccount.set_password(newpass)
uaccount.save()
session.msg("%s - PASSWORD set." % (target_obj.get_name(),))
source_object.emit_to("%s - PASSWORD set." % (target_obj.get_name(),))
target_obj.emit_to("%s has changed your password." %
(pobject.get_name(show_dbref=False),))
(source_object.get_name(show_dbref=False),))
def cmd_shutdown(command):
"""
Shut the server down gracefully.
"""
session = command.session
server = command.server
pobject = session.get_pobject()
session.msg('Shutting down...')
print 'Server shutdown by %s' % (pobject.get_name(show_dbref=False),)
server.shutdown()
"""
command.source_object.emit_to('Shutting down...')
print 'Server shutdown by %s' % (command.source_object.get_name(show_dbref=False),)
command.session.server.shutdown()

View file

@ -5,8 +5,8 @@ from django.db.models import Q
from src.objects.models import Object
from src import defines_global
def _parse_restriction_split(session, restriction_split, search_low_dbnum,
search_high_dbnum):
def _parse_restriction_split(source_object, restriction_split, search_low_dbnum,
search_high_dbnum):
"""
Parses a split restriction string and sets some needed variables.
@ -17,18 +17,18 @@ def _parse_restriction_split(session, restriction_split, search_low_dbnum,
try:
search_low_dbnum = int(restriction_split[1].strip())
except ValueError:
session.msg("Invalid value for low dbref limit.")
source_object.emit_to("Invalid value for low dbref limit.")
return False
if restriction_size >= 3:
try:
search_high_dbnum = int(restriction_split[2].strip())
except ValueError:
session.msg("Invalid value for high dbref limit.")
source_object.emit_to("Invalid value for high dbref limit.")
return False
return search_low_dbnum, search_high_dbnum
def display_results(session, search_query):
def display_results(source_object, search_query):
"""
Display the results to the searcher.
"""
@ -50,33 +50,33 @@ def display_results(session, search_query):
# Render each section for different object types
if thing_list:
session.msg("\n\rTHINGS:")
source_object.emit_to("\n\rTHINGS:")
for thing in thing_list:
session.msg(thing.get_name(show_dbref=True, show_flags=True))
source_object.emit_to(thing.get_name(show_dbref=True, show_flags=True))
if exit_list:
session.msg("\n\rEXITS:")
source_object.emit_to("\n\rEXITS:")
for exit in exit_list:
session.msg(exit.get_name(show_dbref=True, show_flags=True))
source_object.emit_to(exit.get_name(show_dbref=True, show_flags=True))
if room_list:
session.msg("\n\rROOMS:")
source_object.emit_to("\n\rROOMS:")
for room in room_list:
session.msg(room.get_name(show_dbref=True, show_flags=True))
source_object.emit_to(room.get_name(show_dbref=True, show_flags=True))
if player_list:
session.msg("\n\rPLAYER:")
source_object.emit_to("\n\rPLAYER:")
for player in player_list:
session.msg(player.get_name(show_dbref=True, show_flags=True))
source_object.emit_to(player.get_name(show_dbref=True, show_flags=True))
# Show the total counts by type
session.msg("\n\rFound: Rooms...%d Exits...%d Things...%d Players...%d" % (
source_object.emit_to("\n\rFound: Rooms...%d Exits...%d Things...%d Players...%d" % (
len(room_list),
len(exit_list),
len(thing_list),
len(player_list)))
def build_query(session, search_query, search_player, search_type,
def build_query(source_object, search_query, search_player, search_type,
search_restriction, search_low_dbnum, search_high_dbnum):
"""
Builds and returns a QuerySet object, or None if an error occurs.
@ -84,9 +84,9 @@ def build_query(session, search_query, search_player, search_type,
# Look up an Object matching the player search query
if search_player:
# Replace the string variable with an Object reference
search_player = Object.objects.standard_plr_objsearch(session,
search_player = Object.objects.standard_objsearch(source_object,
search_player)
# Use standard_plr_objsearch to handle duplicate/nonexistant results
# Use standard_objsearch to handle duplicate/nonexistant results
if not search_player:
return None
@ -104,7 +104,7 @@ def build_query(session, search_query, search_player, search_type,
elif search_restriction == "player":
search_query = search_query.filter(type=defines_global.OTYPE_PLAYER)
else:
session.msg("Invalid class. See 'help SEARCH CLASSES'.")
source_object.emit_to("Invalid class. See 'help SEARCH CLASSES'.")
return None
elif search_type == "parent":
search_query = search_query.filter(script_parent__iexact=search_restriction)
@ -121,19 +121,19 @@ def build_query(session, search_query, search_player, search_type,
search_query = search_query.filter(name__icontains=search_restriction,
type=defines_global.OTYPE_PLAYER)
elif search_type == "zone":
zone_obj = Object.objects.standard_plr_objsearch(session,
zone_obj = Object.objects.standard_objsearch(source_object,
search_restriction)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
# Use standard_objsearch to handle duplicate/nonexistant results.
if not zone_obj:
return None
search_query = search_query.filter(zone=zone_obj)
elif search_type == "power":
# TODO: Need this once we have powers implemented.
session.msg("To be implemented...")
source_object.emit_to("To be implemented...")
return None
elif search_type == "flags":
flag_list = search_restriction.split()
#session.msg("restriction: %s" % flag_list)
#source_object.emit_to("restriction: %s" % flag_list)
for flag in flag_list:
search_query = search_query.filter(Q(flags__icontains=flag) | Q(nosave_flags__icontains=flag))
@ -149,8 +149,7 @@ def cmd_search(command):
"""
Searches for owned objects as per MUX2.
"""
session = command.session
pobject = session.get_pobject()
source_object = command.source_object
search_player = None
search_type = None
@ -159,7 +158,7 @@ def cmd_search(command):
search_high_dbnum = None
if not command.command_argument:
search_player = "#" + str(pobject.id)
search_player = "#" + str(source_object.id)
else:
first_check_split = command.command_argument.split(' ', 1)
if '=' in first_check_split[0]:
@ -168,12 +167,12 @@ def cmd_search(command):
search_type = eq_split[0]
restriction_split = eq_split[1].split(',')
search_restriction = restriction_split[0].strip()
#session.msg("@search class=restriction")
#session.msg("eq_split: %s" % eq_split)
#session.msg("restriction_split: %s" % restriction_split)
#source_object.emit_to("@search class=restriction")
#source_object.emit_to("eq_split: %s" % eq_split)
#source_object.emit_to("restriction_split: %s" % restriction_split)
try:
search_low_dbnum, search_high_dbnum = _parse_restriction_split(session,
search_low_dbnum, search_high_dbnum = _parse_restriction_split(source_object,
restriction_split,
search_low_dbnum,
search_high_dbnum)
@ -183,22 +182,22 @@ def cmd_search(command):
else:
# @search player
if len(first_check_split) == 1:
#session.msg("@search player")
#session.msg(first_check_split)
#source_object.emit_to("@search player")
#source_object.emit_to(first_check_split)
search_player = first_check_split[0]
else:
#session.msg("@search player class=restriction")
#session.msg(first_check_split)
#source_object.emit_to("@search player class=restriction")
#source_object.emit_to(first_check_split)
search_player = first_check_split[0]
eq_split = first_check_split[1].split('=', 1)
search_type = eq_split[0]
#session.msg("eq_split: %s" % eq_split)
#source_object.emit_to("eq_split: %s" % eq_split)
restriction_split = eq_split[1].split(',')
search_restriction = restriction_split[0]
#session.msg("restriction_split: %s" % restriction_split)
#source_object.emit_to("restriction_split: %s" % restriction_split)
try:
search_low_dbnum, search_high_dbnum = _parse_restriction_split(session,
search_low_dbnum, search_high_dbnum = _parse_restriction_split(source_object,
restriction_split,
search_low_dbnum,
search_high_dbnum)
@ -207,11 +206,11 @@ def cmd_search(command):
search_query = Object.objects.all()
#session.msg("search_player: %s" % search_player)
#session.msg("search_type: %s" % search_type)
#session.msg("search_restriction: %s" % search_restriction)
#session.msg("search_lowdb: %s" % search_low_dbnum)
#session.msg("search_highdb: %s" % search_high_dbnum)
#source_object.emit_to("search_player: %s" % search_player)
#source_object.emit_to("search_type: %s" % search_type)
#source_object.emit_to("search_restriction: %s" % search_restriction)
#source_object.emit_to("search_lowdb: %s" % search_low_dbnum)
#source_object.emit_to("search_highdb: %s" % search_high_dbnum)
# Clean up these variables for comparisons.
try:
@ -224,7 +223,7 @@ def cmd_search(command):
pass
# Build the search query.
search_query = build_query(session, search_query, search_player, search_type,
search_query = build_query(source_object, search_query, search_player, search_type,
search_restriction, search_low_dbnum,
search_high_dbnum)
@ -232,4 +231,4 @@ def cmd_search(command):
if search_query is None:
return
display_results(session, search_query)
display_results(source_object, search_query)

View file

@ -159,11 +159,11 @@ def plr_del_channel(session, alias):
"""
del plr_get_cdict(session)[alias]
def msg_chan_hist(session, channel_name):
def msg_chan_hist(target_obj, channel_name):
"""
Sends a listing of subscribers to a channel given a channel name.
session: (SessionProtocol) A reference to the player session.
target_obj: (Object) The object to send the history listing to.
channel_name: (str) The channel's full name.
"""
cobj = get_cobj_from_name(channel_name)
@ -175,20 +175,19 @@ def msg_chan_hist(session, channel_name):
time_str = entry.date_sent.strftime("%m.%d / %H:%M")
else:
time_str = entry.date_sent.strftime("%H:%M")
session.msg("[%s] %s" % (time_str, entry.message))
target_obj.emit_to("[%s] %s" % (time_str, entry.message))
def msg_cwho(session, channel_name):
def msg_cwho(target_obj, channel_name):
"""
Sends a listing of subscribers to a channel given a channel name.
session: (SessionProtocol) A reference to the player session.
target_obj: (Object) Send the cwho listing to this object.
channel_name: (str) The channel's full name.
"""
pobject = session.get_pobject()
session.msg("--- Users Listening to %s ---" % (channel_name,))
target_obj.emit_to("--- Users Listening to %s ---" % (channel_name,))
for plr_sess in get_cwho_list(channel_name):
session.msg(plr_sess.get_pobject().get_name(show_dbref=pobject.sees_dbrefs()))
session.msg("--- End Channel Listeners ---")
target_obj.emit_to(plr_sess.get_pobject().get_name(show_dbref=target_obj.sees_dbrefs()))
target_obj.emit_to("--- End Channel Listeners ---")
def get_cwho_list(channel_name, return_muted=False):
"""
@ -206,8 +205,9 @@ def load_object_channels(pobject):
"""
chan_list = pobject.get_attribute_value("__CHANLIST")
if chan_list:
session = session_mgr.session_from_object(pobject)
session.channels_subscribed = simplejson.loads(chan_list)
sessions = session_mgr.sessions_from_object(pobject)
for session in sessions:
session.channels_subscribed = simplejson.loads(chan_list)
def send_cmessage(channel_name, message):
"""

View file

@ -100,30 +100,29 @@ class ObjectManager(models.Manager):
return [prospect for prospect in searchlist if prospect.name_match(ostring, match_type=match_type)]
def standard_plr_objsearch(self, session, ostring, search_contents=True,
def standard_objsearch(self, source_object, ostring, search_contents=True,
search_location=True, dbref_only=False,
limit_types=False):
"""
Perform a standard object search via a player session, handling multiple
Perform a standard object search, handling multiple
results and lack thereof gracefully.
session: (SessionProtocol) Reference to the player's session.
source_object: (Object) The Object doing the searching
ostring: (str) The string to match object names against.
"""
pobject = session.get_pobject()
results = self.local_and_global_search(pobject, ostring,
results = self.local_and_global_search(source_object, ostring,
search_contents=search_contents,
search_location=search_location,
dbref_only=dbref_only,
limit_types=limit_types)
if len(results) > 1:
session.msg("More than one match found (please narrow target):")
source_object.emit_to("More than one match found (please narrow target):")
for result in results:
session.msg(" %s" % (result.get_name(),))
source_object.emit_to(" %s" % (result.get_name(),))
return False
elif len(results) == 0:
session.msg("I don't see that here.")
source_object.emit_to("I don't see that here.")
return False
else:
return results[0]
@ -182,11 +181,11 @@ class ObjectManager(models.Manager):
except IndexError:
return None
def is_dbref(self, dbstring):
def is_dbref(self, dbstring, require_pound=True):
"""
Is the input a well-formed dbref number?
"""
return util_object.is_dbref(dbstring)
return util_object.is_dbref(dbstring, require_pound=require_pound)
def dbref_search(self, dbref_string, limit_types=False):
"""

View file

@ -136,14 +136,14 @@ class Object(models.Model):
"""
BEGIN COMMON METHODS
"""
def get_session(self):
def get_sessions(self):
"""
Returns the session object for a player, or None if none exists.
Returns a list of sessions matching this object.
"""
if self.is_player():
return session_mgr.session_from_object(self)
return session_mgr.sessions_from_object(self)
else:
return None
return []
def emit_to(self, message):
"""
@ -155,11 +155,17 @@ class Object(models.Model):
if not self.is_player():
return False
session = self.get_session()
if session:
sessions = self.get_sessions()
for session in sessions:
session.msg(ansi.parse_ansi(message))
else:
return False
def execute_cmd(self, command_str, session=None):
"""
Do something as this object.
"""
# The Command object has all of the methods for parsing and preparing
# for searching and execution. Send it to the handler once populated.
cmdhandler.handle(cmdhandler.Command(self, command_str, session=session))
def emit_to_contents(self, message, exclude=None):
"""
@ -223,7 +229,7 @@ class Object(models.Model):
else:
return False
def user_has_perm(self, perm):
def has_perm(self, perm):
"""
Checks to see whether a user has the specified permission or is a super
user.
@ -241,7 +247,7 @@ class Object(models.Model):
else:
return False
def user_has_perm_list(self, perm_list):
def has_perm_list(self, perm_list):
"""
Checks to see whether a user has the specified permission or is a super
user. This form accepts an iterable of strings representing permissions,
@ -292,7 +298,7 @@ class Object(models.Model):
# When builder_override is enabled, a builder permission means
# the object controls the other.
if builder_override and not other_obj.is_player() and self.user_has_perm('genperms.builder'):
if builder_override and not other_obj.is_player() and self.has_perm('genperms.builder'):
return True
# They've failed to meet any of the above conditions.
@ -442,8 +448,8 @@ class Object(models.Model):
"""
# See if we need to kick the player off.
session = self.get_session()
if session:
sessions = self.get_sessions()
for session in sessions:
session.msg("You have been destroyed, goodbye.")
session.handle_close()
@ -655,12 +661,11 @@ class Object(models.Model):
Is this object a connected player?
"""
if self.is_player():
if self.get_session():
if self.get_sessions():
return True
else:
return False
else:
return False
# No matches or not a player
return False
def get_owner(self):
"""
@ -798,9 +803,7 @@ class Object(models.Model):
if self.location.is_player():
self.location.emit_to("%s is now in your inventory." % (self.get_name()))
session = self.get_session()
if force_look and self.is_player() and session:
self.get_session().execute_cmd('look')
self.execute_cmd('look')
def dbref_match(self, oname):
"""
@ -920,7 +923,7 @@ class CommChannel(models.Model):
name = models.CharField(max_length=255)
ansi_name = models.CharField(max_length=255)
owner = models.ForeignKey(Object, related_name="chan_owner")
description = models.CharField(max_length=80)
description = models.CharField(max_length=80, blank=True, null=True)
is_joined_by_default = models.BooleanField(default=False)
req_grp = models.ManyToManyField(Group, blank=True, null=True)
@ -1023,4 +1026,7 @@ class CommChannelMessage(models.Model):
class CommChannelMessageAdmin(admin.ModelAdmin):
list_display = ('channel', 'message')
admin.site.register(CommChannelMessage, CommChannelMessageAdmin)
admin.site.register(CommChannelMessage, CommChannelMessageAdmin)
# Deferred imports are poopy. This will require some thought to fix.
from src import cmdhandler

View file

@ -2,13 +2,17 @@
Utility functions for the Object class. These functions should not import
any models or modify the database.
"""
def is_dbref(dbstring):
def is_dbref(dbstring, require_pound=True):
"""
Is the input a well-formed dbref number?
"""
# Strip the leading # sign if it's there.
if dbstring.startswith("#"):
dbstring = dbstring[1:]
else:
if require_pound:
# The pound sign was required and it didn't have it, fail out.
return False
try:
# If this fails, it's probably not valid.

View file

@ -9,14 +9,13 @@ import time
from src import comsys
class EvenniaBasicPlayer(object):
def at_pre_login(self):
def at_pre_login(self, session):
"""
Everything done here takes place before the player is actually
'logged in', in a sense that they're not ready to send logged in
commands or receive communication.
"""
pobject = self.source_obj
session = pobject.get_session()
# Load the player's channels from their JSON __CHANLIST attribute.
comsys.load_object_channels(pobject)
@ -24,15 +23,14 @@ class EvenniaBasicPlayer(object):
pobject.set_attribute("Lastsite", "%s" % (session.address[0],))
pobject.set_flag("CONNECTED", True)
def at_post_login(self):
def at_post_login(self, session):
"""
The user is now logged in. This is what happens right after the moment
they are 'connected'.
"""
pobject = self.source_obj
session = pobject.get_session()
session.msg("You are now logged in as %s." % (pobject.name,))
pobject.emit_to("You are now logged in as %s." % (pobject.name,))
pobject.get_location().emit_to_contents("%s has connected." %
(pobject.get_name(show_dbref=False),), exclude=pobject)
session.execute_cmd("look")
pobject.execute_cmd("look")

View file

@ -4,19 +4,18 @@ from twisted.application import internet, service
from twisted.internet import protocol, reactor, defer
from django.db import connection
from django.conf import settings
from src.config.models import CommandAlias, ConfigValue
from src.config.models import ConfigValue
from src.session import SessionProtocol
from src import scheduler
from src import logger
from src import session_mgr
from src import alias_mgr
from src import cmdtable
from src import initial_setup
from src.util import functions_general
class EvenniaService(service.Service):
def __init__(self):
# This holds a dictionary of command aliases for cmdhandler.py
self.cmd_alias_list = {}
self.game_running = True
sys.path.append('.')
@ -38,29 +37,21 @@ class EvenniaService(service.Service):
print ' Game started for the first time, setting defaults.'
initial_setup.handle_setup()
# Load command aliases into memory for easy/quick access.
self.load_cmd_aliases()
self.start_time = time.time()
print ' %s started on port(s):' % (ConfigValue.objects.get_configvalue('site_name'),)
for port in settings.GAMEPORTS:
print ' * %s' % (port)
# Cache the aliases from the database for quick access.
alias_mgr.load_cmd_aliases()
print '-'*50
scheduler.start_events()
"""
BEGIN SERVER STARTUP METHODS
"""
def load_cmd_aliases(self):
"""
Load up our command aliases.
"""
alias_list = CommandAlias.objects.all()
for alias in alias_list:
self.cmd_alias_list[alias.user_input] = alias.equiv_command
print ' Command Aliases Loaded: %i' % (len(self.cmd_alias_list),)
pass
def sqlite3_prep(self):
"""
Optimize some SQLite stuff at startup since we can't save it to the

View file

@ -5,11 +5,8 @@ needed to manage them.
import time
import sys
from datetime import datetime
from twisted.conch.telnet import StatefulTelnetProtocol
from django.contrib.auth.models import User
from src.objects.models import Object, CommChannel
from src.config.models import ConnectScreen, ConfigValue
from util import functions_general
@ -46,6 +43,7 @@ class SessionProtocol(StatefulTelnetProtocol):
self.address = self.getClientAddress()
self.name = None
self.uid = None
self.pobject = None
self.logged_in = False
# The time the user last issued a command.
self.cmd_last = time.time()
@ -73,28 +71,20 @@ class SessionProtocol(StatefulTelnetProtocol):
def lineReceived(self, data):
"""
Any line return indicates a command for the purpose of a MUD. So we take
the user input and pass it to our command handler.
the user input and pass it to this session's pobject.
"""
# Clean up the input.
line = (''.join(data))
line = line.strip('\r')
uinput = line
# The Command object has all of the methods for parsing and preparing
# for searching and execution.
command = cmdhandler.Command(uinput,
server=self.factory.server,
session=self)
# Send the command object to the command handler for parsing
# and eventual execution.
cmdhandler.handle(command)
if self.pobject:
# Session is logged in, run through the normal object execution.
self.pobject.execute_cmd(data, session=self)
else:
# Not logged in, manually execute the command.
cmdhandler.handle(cmdhandler.Command(None, data, session=self))
def execute_cmd(self, cmdstr):
def execute_cmd(self, command_str):
"""
Executes a command as this session.
Sends a command to this session's object for processing.
"""
self.lineReceived(data=cmdstr)
self.pobject.execute_cmd(command_str, session=self)
def count_command(self, silently=False):
"""
@ -104,9 +94,9 @@ class SessionProtocol(StatefulTelnetProtocol):
"""
# Store the timestamp of the user's last command.
self.cmd_last = time.time()
# Increment the user's command counter.
self.cmd_total += 1
if not silently:
# Increment the user's command counter.
self.cmd_total += 1
# Player-visible idle time, not used in idle timeout calcs.
self.cmd_last_visible = time.time()
@ -130,8 +120,14 @@ class SessionProtocol(StatefulTelnetProtocol):
"""
Returns the object associated with a session.
"""
# If the pobject is already cached, return it and skip the lookup.
if self.pobject:
return self.pobject
try:
# Cache the result in the session object for quick retrieval.
result = Object.objects.get(id=self.uid)
self.pobject = result
return result
except:
logger.log_errmsg("No pobject match for session uid: %s" % self.uid)
@ -162,11 +158,12 @@ class SessionProtocol(StatefulTelnetProtocol):
self.name = user.username
self.logged_in = True
self.conn_time = time.time()
pobject = self.get_pobject()
session_mgr.disconnect_duplicate_session(self)
# This will cache with the first call of this function.
self.get_pobject()
#session_mgr.disconnect_duplicate_session(self)
pobject.scriptlink.at_pre_login()
pobject.scriptlink.at_post_login()
self.pobject.scriptlink.at_pre_login(self)
self.pobject.scriptlink.at_post_login(self)
logger.log_infomsg("Login: %s" % (self,))
@ -175,9 +172,9 @@ class SessionProtocol(StatefulTelnetProtocol):
user.save()
# In case the account and the object get out of sync, fix it.
if pobject.name != user.username:
pobject.set_name(user.username)
pobject.save()
if self.pobject.name != user.username:
self.pobject.set_name(user.username)
self.pobject.save()
def msg(self, message):
"""

View file

@ -77,31 +77,13 @@ def remove_session(session):
pass
def session_from_object(targobject):
def sessions_from_object(targ_object):
"""
Return the session object given a object (if there is one open).
Returns a list of matching session objects, or None if there are no matches.
session_list: (list) The server's session_list attribute.
targobject: (Object) The object to match.
"""
results = [prospect for prospect in session_list if prospect.get_pobject() == targobject]
if results:
return results[0]
else:
return False
def session_from_dbref(dbstring):
"""
Return the session object given a dbref (if there is one open).
dbstring: (int) The dbref number to match against.
"""
if is_dbref(dbstring):
results = [prospect for prospect in session_list if prospect.get_pobject().dbref_match(dbstring)]
if results:
return results[0]
else:
return False
return [prospect for prospect in session_list if prospect.get_pobject() == targ_object]
def announce_all(message, with_ann_prefix=True):
"""