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:
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
14
src/alias_mgr.py
Normal 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),)
|
||||||
|
|
@ -45,6 +45,12 @@ def parse_ansi(string, strip_ansi=False, strip_formatting=False):
|
||||||
"""
|
"""
|
||||||
Parses a string, subbing color codes as needed.
|
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:
|
if strip_formatting:
|
||||||
char_return = ""
|
char_return = ""
|
||||||
char_tab = ""
|
char_tab = ""
|
||||||
|
|
|
||||||
|
|
@ -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
|
server module and the handle() function is hit every time a player sends
|
||||||
something.
|
something.
|
||||||
"""
|
"""
|
||||||
from traceback import format_exc
|
|
||||||
import time
|
import time
|
||||||
|
from traceback import format_exc
|
||||||
from src.objects.models import Object
|
from django.contrib.contenttypes.models import ContentType
|
||||||
import defines_global
|
import defines_global
|
||||||
import cmdtable
|
import cmdtable
|
||||||
import logger
|
import logger
|
||||||
import comsys
|
import comsys
|
||||||
|
import alias_mgr
|
||||||
|
|
||||||
class UnknownCommand(Exception):
|
class UnknownCommand(Exception):
|
||||||
"""
|
"""
|
||||||
|
|
@ -24,9 +24,9 @@ class ExitCommandHandler(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Command(object):
|
class Command(object):
|
||||||
# Reference to the master server object.
|
# The source object that the command originated from.
|
||||||
server = None
|
source_object = None
|
||||||
# The player session that the command originated from.
|
# The session that the command originated from (optional)
|
||||||
session = None
|
session = None
|
||||||
# The entire raw, un-parsed command.
|
# The entire raw, un-parsed command.
|
||||||
raw_input = None
|
raw_input = None
|
||||||
|
|
@ -62,7 +62,11 @@ class Command(object):
|
||||||
command string can't be parsed, it has no argument and is
|
command string can't be parsed, it has no argument and is
|
||||||
handled by the except ValueError block below.
|
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)
|
(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_argument = self.command_argument.strip()
|
||||||
self.command_string = self.command_string.strip()
|
self.command_string = self.command_string.strip()
|
||||||
"""
|
"""
|
||||||
|
|
@ -74,6 +78,13 @@ class Command(object):
|
||||||
self.command_string = None
|
self.command_string = None
|
||||||
if self.command_argument == '':
|
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:
|
except ValueError:
|
||||||
"""
|
"""
|
||||||
No arguments. IE: look, who.
|
No arguments. IE: look, who.
|
||||||
|
|
@ -83,12 +94,12 @@ class Command(object):
|
||||||
# Parse command_string for switches, regardless of what happens.
|
# Parse command_string for switches, regardless of what happens.
|
||||||
self.parse_command_switches()
|
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.
|
Instantiates the Command object and does some preliminary parsing.
|
||||||
"""
|
"""
|
||||||
self.server = server
|
|
||||||
self.raw_input = raw_input
|
self.raw_input = raw_input
|
||||||
|
self.source_object = source_object
|
||||||
self.session = session
|
self.session = session
|
||||||
# The work starts here.
|
# The work starts here.
|
||||||
self.parse_command()
|
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
|
them to drop if they don't send or receive something from the connection
|
||||||
for a while.
|
for a while.
|
||||||
"""
|
"""
|
||||||
if not command.command_string == 'idle':
|
if command.session and command.command_string != 'idle' \
|
||||||
# Anything other than an 'idle' command updates the public-facing idle
|
and command.command_string != None:
|
||||||
# time for the session.
|
# 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)
|
command.session.count_command(silently=False)
|
||||||
else:
|
elif command.session:
|
||||||
# User is hitting IDLE command. Don't update their publicly
|
# User is hitting IDLE command. Don't update their publicly
|
||||||
# facing idle time, drop out of command handler immediately.
|
# facing idle time, drop out of command handler immediately.
|
||||||
command.session.count_command(silently=True)
|
command.session.count_command(silently=True)
|
||||||
|
|
@ -147,8 +159,10 @@ def match_exits(command):
|
||||||
See if we can find an input match to exits.
|
See if we can find an input match to exits.
|
||||||
"""
|
"""
|
||||||
# If we're not logged in, don't check exits.
|
# If we're not logged in, don't check exits.
|
||||||
pobject = command.session.get_pobject()
|
source_object = command.source_object
|
||||||
exits = pobject.get_location().get_contents(filter_type=defines_global.OTYPE_EXIT)
|
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,
|
exit_matches = Object.objects.list_search_object_namestr(exits,
|
||||||
command.command_string,
|
command.command_string,
|
||||||
match_type="exact")
|
match_type="exact")
|
||||||
|
|
@ -160,13 +174,13 @@ def match_exits(command):
|
||||||
if targ_exit.get_home():
|
if targ_exit.get_home():
|
||||||
# SCRIPT: See if the player can traverse the exit
|
# SCRIPT: See if the player can traverse the exit
|
||||||
if not targ_exit.scriptlink.default_lock({
|
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:
|
else:
|
||||||
pobject.move_to(targ_exit.get_home())
|
source_object.move_to(targ_exit.get_home())
|
||||||
else:
|
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.
|
# We found a match, kill the command handler.
|
||||||
raise ExitCommandHandler
|
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,
|
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.
|
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,
|
||||||
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
|
over a channel, replace command_string with @cemit. If they're entering
|
||||||
a channel manipulation command, perform the operation and kill the things
|
a channel manipulation command, perform the operation and kill the things
|
||||||
immediately with a True value sent back to the command handler.
|
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,
|
if command.session and comsys.plr_has_channel(command.session,
|
||||||
alias_search=True, return_muted=True):
|
command.command_string, alias_search=True, return_muted=True):
|
||||||
|
|
||||||
calias = command.command_string
|
calias = command.command_string
|
||||||
cname = comsys.plr_cname_from_alias(command.session, calias)
|
cname = comsys.plr_cname_from_alias(command.session, calias)
|
||||||
|
|
||||||
if command.command_argument == "who":
|
if command.command_argument == "who":
|
||||||
comsys.msg_cwho(command.session, cname)
|
comsys.msg_cwho(command.source_object, cname)
|
||||||
raise ExitCommandHandler
|
raise ExitCommandHandler
|
||||||
elif command.command_argument == "on":
|
elif command.command_argument == "on":
|
||||||
comsys.plr_chan_on(command.session, calias)
|
comsys.plr_chan_on(command.session, calias)
|
||||||
|
|
@ -222,7 +238,7 @@ def match_channel(command):
|
||||||
comsys.plr_chan_off(command.session, calias)
|
comsys.plr_chan_off(command.session, calias)
|
||||||
raise ExitCommandHandler
|
raise ExitCommandHandler
|
||||||
elif command.command_argument == "last":
|
elif command.command_argument == "last":
|
||||||
comsys.msg_chan_hist(command.session, cname)
|
comsys.msg_chan_hist(command.source_object, cname)
|
||||||
raise ExitCommandHandler
|
raise ExitCommandHandler
|
||||||
|
|
||||||
second_arg = "%s=%s" % (cname, command.command_argument)
|
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 cmdtuple:
|
||||||
# If there is a permissions element to the entry, check perms.
|
# If there is a permissions element to the entry, check perms.
|
||||||
if eval_perms and cmdtuple[1]:
|
if eval_perms and cmdtuple[1]:
|
||||||
if not command.session.get_pobject().user_has_perm_list(cmdtuple[1]):
|
if not command.source_object.has_perm_list(cmdtuple[1]):
|
||||||
command.session.msg(defines_global.NOPERMS_MSG)
|
command.source_object.emit_to(defines_global.NOPERMS_MSG)
|
||||||
raise ExitCommandHandler
|
raise ExitCommandHandler
|
||||||
# If flow reaches this point, user has perms and command is ready.
|
# If flow reaches this point, user has perms and command is ready.
|
||||||
command.command_function = cmdtuple[0]
|
command.command_function = cmdtuple[0]
|
||||||
|
|
@ -256,16 +272,17 @@ def handle(command):
|
||||||
their input on to 'cmd_' and looking it up in the GenCommands
|
their input on to 'cmd_' and looking it up in the GenCommands
|
||||||
class.
|
class.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
|
||||||
server = command.server
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# TODO: Protect against non-standard characters.
|
# TODO: Protect against non-standard characters.
|
||||||
if not command.command_string:
|
if not command.command_string:
|
||||||
# Nothing sent in of value, ignore it.
|
# Nothing sent in of value, ignore it.
|
||||||
raise ExitCommandHandler
|
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 against the 'idle' command.
|
||||||
match_idle(command)
|
match_idle(command)
|
||||||
# See if this is an aliased command.
|
# See if this is an aliased command.
|
||||||
|
|
@ -276,10 +293,6 @@ def handle(command):
|
||||||
match_exits(command)
|
match_exits(command)
|
||||||
# Retrieve the appropriate (if any) command function.
|
# Retrieve the appropriate (if any) command function.
|
||||||
command_table_lookup(command, cmdtable.GLOBAL_CMD_TABLE)
|
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
|
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
|
codebase stabilizes, we will probably want something more
|
||||||
useful or give them the option to hide exception values.
|
useful or give them the option to hide exception values.
|
||||||
"""
|
"""
|
||||||
session.msg("Untrapped error, please file a bug report:\n%s" %
|
if command.source_object:
|
||||||
(format_exc(),))
|
command.source_object.emit_to("Untrapped error, please file a bug report:\n%s" %
|
||||||
logger.log_errmsg("Untrapped error, evoker %s: %s" %
|
(format_exc(),))
|
||||||
(session, format_exc()))
|
logger.log_errmsg("Untrapped error, evoker %s: %s" %
|
||||||
|
(command.source_object, format_exc()))
|
||||||
# Prevent things from falling through to UnknownCommand.
|
# Prevent things from falling through to UnknownCommand.
|
||||||
raise ExitCommandHandler
|
raise ExitCommandHandler
|
||||||
else:
|
else:
|
||||||
|
|
@ -313,5 +327,4 @@ def handle(command):
|
||||||
pass
|
pass
|
||||||
except UnknownCommand:
|
except UnknownCommand:
|
||||||
# Default fall-through. No valid command match.
|
# Default fall-through. No valid command match.
|
||||||
session.msg("Huh? (Type \"help\" for help.)")
|
command.source_object.emit_to("Huh? (Type \"help\" for help.)")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,8 @@
|
||||||
"""
|
"""
|
||||||
Comsys command module. Pretty much every comsys command should go here for
|
Comsys command module.
|
||||||
now.
|
|
||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
import src.comsys
|
import src.comsys
|
||||||
from src import defines_global
|
from src import defines_global
|
||||||
from src import ansi
|
from src import ansi
|
||||||
|
|
@ -18,11 +15,10 @@ def cmd_addcom(command):
|
||||||
Adds an alias for a channel.
|
Adds an alias for a channel.
|
||||||
addcom foo=Bar
|
addcom foo=Bar
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
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
|
return
|
||||||
|
|
||||||
eq_args = command.command_argument.split('=', 1)
|
eq_args = command.command_argument.split('=', 1)
|
||||||
|
|
@ -31,27 +27,28 @@ def cmd_addcom(command):
|
||||||
chan_name = eq_args[1]
|
chan_name = eq_args[1]
|
||||||
|
|
||||||
if len(eq_args) < 2 or len(chan_name) == 0:
|
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
|
return
|
||||||
|
|
||||||
if chan_alias in session.channels_subscribed:
|
if chan_alias in command.session.channels_subscribed:
|
||||||
session.msg("You are already on that channel.")
|
source_object.emit_to("You are already on that channel.")
|
||||||
return
|
return
|
||||||
|
|
||||||
name_matches = src.comsys.cname_search(chan_name, exact=True)
|
name_matches = src.comsys.cname_search(chan_name, exact=True)
|
||||||
|
|
||||||
if name_matches:
|
if name_matches:
|
||||||
chan_name_parsed = name_matches[0].get_name()
|
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))
|
(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.
|
# Announce the user's joining.
|
||||||
join_msg = "[%s] %s has joined the channel." % \
|
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)
|
src.comsys.send_cmessage(chan_name_parsed, join_msg)
|
||||||
else:
|
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):
|
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,
|
Removes the specified alias to a channel. If this is the last alias,
|
||||||
the user is effectively removed from the channel.
|
the user is effectively removed from the channel.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("You must specify a channel alias.")
|
source_object.emit_to("You must specify a channel alias.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if command.command_argument not in session.channels_subscribed:
|
if command.command_argument not in command.session.channels_subscribed:
|
||||||
session.msg("You are not on that channel.")
|
source_object.emit_to("You are not on that channel.")
|
||||||
return
|
return
|
||||||
|
|
||||||
chan_name = session.channels_subscribed[command.command_argument][0]
|
chan_name = command.session.channels_subscribed[command.command_argument][0]
|
||||||
session.msg("You have left %s." % (chan_name,))
|
source_object.emit_to("You have left %s." % (chan_name,))
|
||||||
src.comsys.plr_del_channel(session, command.command_argument)
|
src.comsys.plr_del_channel(command.session, command.command_argument)
|
||||||
|
|
||||||
# Announce the user's leaving.
|
# Announce the user's leaving.
|
||||||
leave_msg = "[%s] %s has left the channel." % \
|
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)
|
src.comsys.send_cmessage(chan_name, leave_msg)
|
||||||
|
|
||||||
def cmd_comlist(command):
|
def cmd_comlist(command):
|
||||||
"""
|
"""
|
||||||
Lists the channels a user is subscribed to.
|
Lists the channels a user is subscribed to.
|
||||||
"""
|
"""
|
||||||
|
source_object = command.source_object
|
||||||
session = command.session
|
session = command.session
|
||||||
|
|
||||||
session.msg("Alias Channel Status")
|
source_object.emit_to("Alias Channel Status")
|
||||||
for chan in session.channels_subscribed:
|
for chan in session.channels_subscribed:
|
||||||
if session.channels_subscribed[chan][1]:
|
if session.channels_subscribed[chan][1]:
|
||||||
chan_on = "On"
|
chan_on = "On"
|
||||||
else:
|
else:
|
||||||
chan_on = "Off"
|
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))
|
(chan, session.channels_subscribed[chan][0], chan_on))
|
||||||
session.msg("-- End of comlist --")
|
source_object.emit_to("-- End of comlist --")
|
||||||
|
|
||||||
def cmd_allcom(command):
|
def cmd_allcom(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -124,12 +121,14 @@ def cmd_clist(command):
|
||||||
Lists all available channels on the game.
|
Lists all available channels on the game.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
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():
|
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(),
|
('-', '-', chan.get_name(), chan.get_owner().get_name(),
|
||||||
'No Description'))
|
'No Description'))
|
||||||
session.msg("-- End of Channel List --")
|
source_object.emit_to("-- End of Channel List --")
|
||||||
|
|
||||||
def cmd_cdestroy(command):
|
def cmd_cdestroy(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -137,24 +136,24 @@ def cmd_cdestroy(command):
|
||||||
|
|
||||||
Destroys a channel.
|
Destroys a channel.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
cname = command.command_argument
|
cname = command.command_argument
|
||||||
|
|
||||||
if cname == '':
|
if not cname:
|
||||||
session.msg("You must supply a name!")
|
source_object.emit_to("You must supply a name!")
|
||||||
return
|
return
|
||||||
|
|
||||||
name_matches = src.comsys.cname_search(cname, exact=True)
|
name_matches = src.comsys.cname_search(cname, exact=True)
|
||||||
|
|
||||||
if not name_matches:
|
if not name_matches:
|
||||||
session.msg("Could not find channel %s." % (cname,))
|
source_object.emit_to("Could not find channel %s." % (cname,))
|
||||||
else:
|
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:
|
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()
|
name_matches.delete()
|
||||||
else:
|
else:
|
||||||
session.msg("Permission denied.")
|
source_object.emit_to("Permission denied.")
|
||||||
return
|
return
|
||||||
|
|
||||||
def cmd_cset(command):
|
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
|
they own or control it. It does not show the user's name unless they
|
||||||
provide the /sendername switch.
|
provide the /sendername switch.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Channel emit what?")
|
source_object.emit_to("Channel emit what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
eq_args = command.command_argument.split('=', 1)
|
eq_args = command.command_argument.split('=', 1)
|
||||||
|
|
||||||
if len(eq_args) != 2:
|
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
|
return
|
||||||
|
|
||||||
cname = eq_args[0]
|
cname = eq_args[0]
|
||||||
cmessage = eq_args[1]
|
cmessage = eq_args[1]
|
||||||
|
|
||||||
if len(cname) == 0:
|
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
|
return
|
||||||
if len(cmessage) == 0:
|
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
|
return
|
||||||
|
|
||||||
name_matches = src.comsys.cname_search(cname, exact=True)
|
name_matches = src.comsys.cname_search(cname, exact=True)
|
||||||
if name_matches:
|
if name_matches:
|
||||||
cname_parsed = name_matches[0].get_name()
|
cname_parsed = name_matches[0].get_name()
|
||||||
else:
|
else:
|
||||||
session.msg("Could not find channel %s." % (cname,))
|
source_object.emit_to("Could not find channel %s." % (cname,))
|
||||||
return
|
return
|
||||||
|
|
||||||
if "noheader" in command.command_switches:
|
if "noheader" in command.command_switches:
|
||||||
if not pobject.user_has_perm("objects.emit_commchannel"):
|
if not source_object.has_perm("objects.emit_commchannel"):
|
||||||
session.msg(defines_global.NOPERMS_MSG)
|
source_object.emit_to(defines_global.NOPERMS_MSG)
|
||||||
return
|
return
|
||||||
final_cmessage = cmessage
|
final_cmessage = cmessage
|
||||||
else:
|
else:
|
||||||
if "sendername" in command.command_switches:
|
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):
|
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
|
return
|
||||||
final_cmessage = "[%s] %s: %s" % (cname_parsed,
|
final_cmessage = "[%s] %s: %s" % (cname_parsed,
|
||||||
pobject.get_name(show_dbref=False),
|
source_object.get_name(show_dbref=False),
|
||||||
cmessage)
|
cmessage)
|
||||||
else:
|
else:
|
||||||
if not pobject.user_has_perm("objects.emit_commchannel"):
|
if not source_object.has_perm("objects.emit_commchannel"):
|
||||||
session.msg(defines_global.NOPERMS_MSG)
|
source_object.emit_to(defines_global.NOPERMS_MSG)
|
||||||
return
|
return
|
||||||
final_cmessage = "[%s] %s" % (cname_parsed, cmessage)
|
final_cmessage = "[%s] %s" % (cname_parsed, cmessage)
|
||||||
|
|
||||||
if not "quiet" in command.command_switches:
|
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)
|
src.comsys.send_cmessage(cname_parsed, final_cmessage)
|
||||||
|
|
||||||
def cmd_cwho(command):
|
def cmd_cwho(command):
|
||||||
|
|
@ -258,32 +256,32 @@ def cmd_cwho(command):
|
||||||
as well.
|
as well.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
session = command.session
|
||||||
pobject = session.get_pobject()
|
source_object = command.source_object
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("You must specify a channel name.")
|
source_object.emit_to("You must specify a channel name.")
|
||||||
return
|
return
|
||||||
|
|
||||||
channel_name = command.command_argument
|
channel_name = command.command_argument
|
||||||
|
|
||||||
if channel_name.strip() == '':
|
if channel_name.strip() == '':
|
||||||
session.msg("You must specify a channel name.")
|
source_object.emit_to("You must specify a channel name.")
|
||||||
return
|
return
|
||||||
|
|
||||||
name_matches = src.comsys.cname_search(channel_name, exact=True)
|
name_matches = src.comsys.cname_search(channel_name, exact=True)
|
||||||
|
|
||||||
if name_matches:
|
if name_matches:
|
||||||
# Check to make sure the user has permission to use @cwho.
|
# Check to make sure the user has permission to use @cwho.
|
||||||
is_channel_admin = pobject.user_has_perm("objects.channel_admin")
|
is_channel_admin = source_object.has_perm("objects.channel_admin")
|
||||||
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 or is_channel_admin:
|
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:
|
else:
|
||||||
session.msg("Permission denied.")
|
source_object.emit_to("Permission denied.")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
session.msg("No channel with that name was found.")
|
source_object.emit_to("No channel with that name was found.")
|
||||||
return
|
return
|
||||||
|
|
||||||
def cmd_ccreate(command):
|
def cmd_ccreate(command):
|
||||||
|
|
@ -293,27 +291,25 @@ def cmd_ccreate(command):
|
||||||
Creates a new channel with the invoker being the default owner.
|
Creates a new channel with the invoker being the default owner.
|
||||||
"""
|
"""
|
||||||
# TODO: Implement cmd_ccreate
|
# TODO: Implement cmd_ccreate
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
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
|
|
||||||
|
|
||||||
cname = command.command_argument
|
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)
|
name_matches = src.comsys.cname_search(cname, exact=True)
|
||||||
|
|
||||||
if name_matches:
|
if name_matches:
|
||||||
session.msg("A channel with that name already exists.")
|
source_object.emit_to("A channel with that name already exists.")
|
||||||
else:
|
else:
|
||||||
# Create and set the object up.
|
# Create and set the object up.
|
||||||
new_chan = src.comsys.create_channel(cname, pobject)
|
new_chan = src.comsys.create_channel(cname, source_object)
|
||||||
session.msg("Channel %s created." % (new_chan.get_name(),))
|
source_object.emit_to("Channel %s created." % (new_chan.get_name(),))
|
||||||
|
|
||||||
def cmd_cchown(command):
|
def cmd_cchown(command):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -20,33 +20,41 @@ def cmd_password(command):
|
||||||
|
|
||||||
@password <Oldpass>=<Newpass>
|
@password <Oldpass>=<Newpass>
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
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)
|
eq_args = command.command_argument.split('=', 1)
|
||||||
|
|
||||||
if len(eq_args) != 2:
|
if len(eq_args) != 2:
|
||||||
session.msg("Incorrect number of arguments.")
|
source_object.emit_to("Incorrect number of arguments.")
|
||||||
return
|
return
|
||||||
|
|
||||||
oldpass = eq_args[0]
|
oldpass = eq_args[0]
|
||||||
newpass = eq_args[1]
|
newpass = eq_args[1]
|
||||||
|
|
||||||
if len(oldpass) == 0:
|
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:
|
elif len(newpass) == 0:
|
||||||
session.msg("You must provide your new password.")
|
source_object.emit_to("You must provide your new password.")
|
||||||
else:
|
else:
|
||||||
uaccount = pobject.get_user_account()
|
uaccount = source_object.get_user_account()
|
||||||
|
|
||||||
if not uaccount.check_password(oldpass):
|
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:
|
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
|
return
|
||||||
else:
|
else:
|
||||||
uaccount.set_password(newpass)
|
uaccount.set_password(newpass)
|
||||||
uaccount.save()
|
uaccount.save()
|
||||||
session.msg("Password changed.")
|
source_object.emit_to("Password changed.")
|
||||||
|
|
||||||
def cmd_pemit(command):
|
def cmd_pemit(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -58,28 +66,25 @@ def cmd_emit(command):
|
||||||
"""
|
"""
|
||||||
Emits something to your location.
|
Emits something to your location.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
|
||||||
pobject = session.get_pobject()
|
|
||||||
message = command.command_argument
|
message = command.command_argument
|
||||||
|
|
||||||
if message:
|
if message:
|
||||||
pobject.get_location().emit_to_contents(message)
|
command.source_object.get_location().emit_to_contents(message)
|
||||||
else:
|
else:
|
||||||
session.msg("Emit what?")
|
command.source_object.emit_to("Emit what?")
|
||||||
|
|
||||||
def cmd_wall(command):
|
def cmd_wall(command):
|
||||||
"""
|
"""
|
||||||
Announces a message to all connected players.
|
Announces a message to all connected players.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
|
||||||
wallstring = command.command_argument
|
wallstring = command.command_argument
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not wallstring:
|
if not wallstring:
|
||||||
session.msg("Announce what?")
|
command.source_object.emit_to("Announce what?")
|
||||||
return
|
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)
|
session_mgr.announce_all(message)
|
||||||
|
|
||||||
def cmd_idle(command):
|
def cmd_idle(command):
|
||||||
|
|
@ -93,139 +98,134 @@ def cmd_inventory(command):
|
||||||
"""
|
"""
|
||||||
Shows a player's inventory.
|
Shows a player's inventory.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
source_object.emit_to("You are carrying:")
|
||||||
session.msg("You are carrying:")
|
|
||||||
|
|
||||||
for item in pobject.get_contents():
|
for item in source_object.get_contents():
|
||||||
session.msg(" %s" % (item.get_name(),))
|
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:
|
if money == 1:
|
||||||
money_name = ConfigValue.objects.get_configvalue("MONEY_NAME_SINGULAR")
|
money_name = ConfigValue.objects.get_configvalue("MONEY_NAME_SINGULAR")
|
||||||
else:
|
else:
|
||||||
money_name = ConfigValue.objects.get_configvalue("MONEY_NAME_PLURAL")
|
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):
|
def cmd_look(command):
|
||||||
"""
|
"""
|
||||||
Handle looking at objects.
|
Handle looking at objects.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
# If an argument is provided with the command, search for the object.
|
# If an argument is provided with the command, search for the object.
|
||||||
# else look at the current room.
|
# else look at the current room.
|
||||||
if command.command_argument:
|
if command.command_argument:
|
||||||
target_obj = Object.objects.standard_plr_objsearch(session,
|
target_obj = Object.objects.standard_objsearch(source_object,
|
||||||
command.command_argument)
|
command.command_argument)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
target_obj = pobject.get_location()
|
target_obj = source_object.get_location()
|
||||||
|
|
||||||
# SCRIPT: Get the item's appearance from the scriptlink.
|
# 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,
|
"target_obj": target_obj,
|
||||||
"pobject": pobject
|
"pobject": source_object
|
||||||
}))
|
}))
|
||||||
|
|
||||||
# SCRIPT: Call the object's script's a_desc() method.
|
# SCRIPT: Call the object's script's a_desc() method.
|
||||||
target_obj.scriptlink.a_desc({
|
target_obj.scriptlink.a_desc({
|
||||||
"target_obj": pobject
|
"target_obj": source_object
|
||||||
})
|
})
|
||||||
|
|
||||||
def cmd_get(command):
|
def cmd_get(command):
|
||||||
"""
|
"""
|
||||||
Get an object and put it in a player's inventory.
|
Get an object and put it in a player's inventory.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
obj_is_staff = source_object.is_staff()
|
||||||
plr_is_staff = pobject.is_staff()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Get what?")
|
source_object.emit_to("Get what?")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
target_obj = Object.objects.standard_plr_objsearch(session,
|
target_obj = Object.objects.standard_objsearch(source_object,
|
||||||
command.command_argument,
|
command.command_argument,
|
||||||
search_contents=False)
|
search_contents=False)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
if pobject == target_obj:
|
if source_object == target_obj:
|
||||||
session.msg("You can't get yourself.")
|
source_object.emit_to("You can't get yourself.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if not plr_is_staff and (target_obj.is_player() or target_obj.is_exit()):
|
if not obj_is_staff and (target_obj.is_player() or target_obj.is_exit()):
|
||||||
session.msg("You can't get that.")
|
source_object.emit_to("You can't get that.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if target_obj.is_room() or target_obj.is_garbage() or target_obj.is_going():
|
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
|
return
|
||||||
|
|
||||||
target_obj.move_to(pobject, quiet=True)
|
target_obj.move_to(source_object, quiet=True)
|
||||||
session.msg("You pick up %s." % (target_obj.get_name(show_dbref=False),))
|
source_object.emit_to("You pick up %s." % (target_obj.get_name(show_dbref=False),))
|
||||||
pobject.get_location().emit_to_contents("%s picks up %s." %
|
source_object.get_location().emit_to_contents("%s picks up %s." %
|
||||||
(pobject.get_name(show_dbref=False),
|
(source_object.get_name(show_dbref=False),
|
||||||
target_obj.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.
|
# SCRIPT: Call the object's script's a_get() method.
|
||||||
target_obj.scriptlink.a_get({
|
target_obj.scriptlink.a_get({
|
||||||
"pobject": pobject
|
"pobject": source_object
|
||||||
})
|
})
|
||||||
|
|
||||||
def cmd_drop(command):
|
def cmd_drop(command):
|
||||||
"""
|
"""
|
||||||
Drop an object from a player's inventory into their current location.
|
Drop an object from a player's inventory into their current location.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
obj_is_staff = source_object.is_staff()
|
||||||
plr_is_staff = pobject.is_staff()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Drop what?")
|
source_object.emit_to("Drop what?")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
target_obj = Object.objects.standard_plr_objsearch(session,
|
target_obj = Object.objects.standard_objsearch(source_object,
|
||||||
command.command_argument,
|
command.command_argument,
|
||||||
search_location=False)
|
search_location=False)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not pobject == target_obj.get_location():
|
if not source_object == target_obj.get_location():
|
||||||
session.msg("You don't appear to be carrying that.")
|
source_object.emit_to("You don't appear to be carrying that.")
|
||||||
return
|
return
|
||||||
|
|
||||||
target_obj.move_to(pobject.get_location(), quiet=True)
|
target_obj.move_to(source_object.get_location(), quiet=True)
|
||||||
session.msg("You drop %s." % (target_obj.get_name(show_dbref=False),))
|
source_object.emit_to("You drop %s." % (target_obj.get_name(show_dbref=False),))
|
||||||
pobject.get_location().emit_to_contents("%s drops %s." %
|
source_object.get_location().emit_to_contents("%s drops %s." %
|
||||||
(pobject.get_name(show_dbref=False),
|
(source_object.get_name(show_dbref=False),
|
||||||
target_obj.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.
|
# SCRIPT: Call the object's script's a_drop() method.
|
||||||
target_obj.scriptlink.a_drop({
|
target_obj.scriptlink.a_drop({
|
||||||
"pobject": pobject
|
"pobject": source_object
|
||||||
})
|
})
|
||||||
|
|
||||||
def cmd_examine(command):
|
def cmd_examine(command):
|
||||||
"""
|
"""
|
||||||
Detailed object examine command
|
Detailed object examine command
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
attr_search = False
|
attr_search = False
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
# If no arguments are provided, examine the invoker's location.
|
# If no arguments are provided, examine the invoker's location.
|
||||||
target_obj = pobject.get_location()
|
target_obj = source_object.get_location()
|
||||||
else:
|
else:
|
||||||
# Look for a slash in the input, indicating an attribute search.
|
# Look for a slash in the input, indicating an attribute search.
|
||||||
attr_split = command.command_argument.split("/", 1)
|
attr_split = command.command_argument.split("/", 1)
|
||||||
|
|
@ -241,21 +241,21 @@ def cmd_examine(command):
|
||||||
|
|
||||||
# Protect against stuff like: ex me/
|
# Protect against stuff like: ex me/
|
||||||
if attr_searchstr == '':
|
if attr_searchstr == '':
|
||||||
session.msg('No attribute name provided.')
|
source_object.emit_to('No attribute name provided.')
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
# No slash in argument, just examine an object.
|
# No slash in argument, just examine an object.
|
||||||
obj_searchstr = command.command_argument
|
obj_searchstr = command.command_argument
|
||||||
|
|
||||||
# Resolve the target object.
|
# Resolve the target object.
|
||||||
target_obj = Object.objects.standard_plr_objsearch(session,
|
target_obj = Object.objects.standard_objsearch(source_object,
|
||||||
obj_searchstr)
|
obj_searchstr)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
# If the user doesn't control the object, just look at it instead.
|
# 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'
|
command.command_string = 'look'
|
||||||
cmd_look(command)
|
cmd_look(command)
|
||||||
return
|
return
|
||||||
|
|
@ -268,28 +268,28 @@ def cmd_examine(command):
|
||||||
attr_matches = target_obj.attribute_namesearch(attr_searchstr)
|
attr_matches = target_obj.attribute_namesearch(attr_searchstr)
|
||||||
if attr_matches:
|
if attr_matches:
|
||||||
for attribute in attr_matches:
|
for attribute in attr_matches:
|
||||||
session.msg(attribute.get_attrline())
|
source_object.emit_to(attribute.get_attrline())
|
||||||
else:
|
else:
|
||||||
session.msg("No matching attributes found.")
|
source_object.emit_to("No matching attributes found.")
|
||||||
else:
|
else:
|
||||||
"""
|
"""
|
||||||
Player is examining an object. Return a full readout of attributes,
|
Player is examining an object. Return a full readout of attributes,
|
||||||
along with detailed information about said object.
|
along with detailed information about said object.
|
||||||
"""
|
"""
|
||||||
# Format the examine header area with general flag/type info.
|
# Format the examine header area with general flag/type info.
|
||||||
session.msg(target_obj.get_name(fullname=True))
|
source_object.emit_to(target_obj.get_name(fullname=True))
|
||||||
session.msg("Type: %s Flags: %s" % (target_obj.get_type(),
|
source_object.emit_to("Type: %s Flags: %s" % (target_obj.get_type(),
|
||||||
target_obj.get_flags()))
|
target_obj.get_flags()))
|
||||||
session.msg("Desc: %s" % target_obj.get_description(no_parsing=True))
|
source_object.emit_to("Desc: %s" % target_obj.get_description(no_parsing=True))
|
||||||
session.msg("Owner: %s " % (target_obj.get_owner(),))
|
source_object.emit_to("Owner: %s " % (target_obj.get_owner(),))
|
||||||
session.msg("Zone: %s" % (target_obj.get_zone(),))
|
source_object.emit_to("Zone: %s" % (target_obj.get_zone(),))
|
||||||
|
|
||||||
parent_str = target_obj.script_parent
|
parent_str = target_obj.script_parent
|
||||||
if parent_str and parent_str != '':
|
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():
|
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.
|
# Contents container lists for sorting by type.
|
||||||
con_players = []
|
con_players = []
|
||||||
|
|
@ -307,52 +307,52 @@ def cmd_examine(command):
|
||||||
|
|
||||||
# Render Contents display.
|
# Render Contents display.
|
||||||
if con_players or con_things:
|
if con_players or con_things:
|
||||||
session.msg("%sContents:%s" % (ansi.ansi["hilite"],
|
source_object.emit_to("%sContents:%s" % (ansi.ansi["hilite"],
|
||||||
ansi.ansi["normal"],))
|
ansi.ansi["normal"],))
|
||||||
for player in con_players:
|
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:
|
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.
|
# Render Exists display.
|
||||||
if con_exits:
|
if con_exits:
|
||||||
session.msg("%sExits:%s" % (ansi.ansi["hilite"],
|
source_object.emit_to("%sExits:%s" % (ansi.ansi["hilite"],
|
||||||
ansi.ansi["normal"],))
|
ansi.ansi["normal"],))
|
||||||
for exit in con_exits:
|
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).
|
# Render the object's home or destination (for exits).
|
||||||
if not target_obj.is_room():
|
if not target_obj.is_room():
|
||||||
if target_obj.is_exit():
|
if target_obj.is_exit():
|
||||||
# The Home attribute on an exit is really its destination.
|
# 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:
|
else:
|
||||||
# For everything else, home is home.
|
# 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.
|
# 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):
|
def cmd_quit(command):
|
||||||
"""
|
"""
|
||||||
Gracefully disconnect the user as per his own request.
|
Gracefully disconnect the user as per his own request.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
if command.session:
|
||||||
session.msg("Quitting!")
|
session = command.session
|
||||||
session.handle_close()
|
session.msg("Quitting!")
|
||||||
|
session.handle_close()
|
||||||
|
|
||||||
def cmd_who(command):
|
def cmd_who(command):
|
||||||
"""
|
"""
|
||||||
Generic WHO command.
|
Generic WHO command.
|
||||||
"""
|
"""
|
||||||
session_list = session_mgr.get_session_list()
|
session_list = session_mgr.get_session_list()
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
# In the case of the DOING command, don't show session data regardless.
|
# 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:
|
if command.extra_vars and command.extra_vars.get("show_session_data", None) == False:
|
||||||
show_session_data = False
|
show_session_data = False
|
||||||
else:
|
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
|
# Only those with the see_session_data or superuser status can see
|
||||||
# session details.
|
# session details.
|
||||||
|
|
@ -394,85 +394,82 @@ def cmd_who(command):
|
||||||
'')
|
'')
|
||||||
retval += '%d Players logged in.' % (len(session_list),)
|
retval += '%d Players logged in.' % (len(session_list),)
|
||||||
|
|
||||||
session.msg(retval)
|
source_object.emit_to(retval)
|
||||||
|
|
||||||
def cmd_say(command):
|
def cmd_say(command):
|
||||||
"""
|
"""
|
||||||
Room-based speech command.
|
Room-based speech command.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Say what?")
|
source_object.emit_to("Say what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
session_list = session_mgr.get_session_list()
|
|
||||||
pobject = session.get_pobject()
|
|
||||||
speech = command.command_argument
|
speech = command.command_argument
|
||||||
|
|
||||||
players_present = [player for player in session_list if player.get_pobject().get_location() == session.get_pobject().get_location() and player != session]
|
# Feedback for the object doing the talking.
|
||||||
|
source_object.emit_to("You say, '%s'" % (speech,))
|
||||||
|
|
||||||
retval = "You say, '%s'" % (speech,)
|
# Build the string to emit to neighbors.
|
||||||
for player in players_present:
|
emit_string = "%s says, '%s'" % (source_object.get_name(show_dbref=False),
|
||||||
player.msg("%s says, '%s'" % (pobject.get_name(show_dbref=False), speech,))
|
speech)
|
||||||
|
|
||||||
session.msg(retval)
|
source_object.get_location().emit_to_contents(emit_string,
|
||||||
|
exclude=source_object)
|
||||||
|
|
||||||
def cmd_pose(command):
|
def cmd_pose(command):
|
||||||
"""
|
"""
|
||||||
Pose/emote command.
|
Pose/emote command.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Do what?")
|
source_object.emit_to("Do what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
session_list = session_mgr.get_session_list()
|
pose_string = command.command_argument
|
||||||
speech = command.command_argument
|
|
||||||
|
|
||||||
if "nospace" in command.command_switches:
|
if "nospace" in command.command_switches:
|
||||||
# Output without a space between the player name and the emote.
|
# 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:
|
else:
|
||||||
# No switches, default.
|
# 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()]
|
source_object.get_location().emit_to_contents(sent_msg)
|
||||||
|
|
||||||
for player in players_present:
|
|
||||||
player.msg(sent_msg)
|
|
||||||
|
|
||||||
def cmd_help(command):
|
def cmd_help(command):
|
||||||
"""
|
"""
|
||||||
Help system commands.
|
Help system commands.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
topicstr = command.command_argument
|
topicstr = command.command_argument
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
topicstr = "Help Index"
|
topicstr = "Help Index"
|
||||||
elif len(topicstr) < 2 and not topicstr.isdigit():
|
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
|
return
|
||||||
|
|
||||||
topics = HelpEntry.objects.find_topicmatch(pobject, topicstr)
|
topics = HelpEntry.objects.find_topicmatch(source_object, topicstr)
|
||||||
|
|
||||||
if len(topics) == 0:
|
if len(topics) == 0:
|
||||||
session.msg("No matching topics found, please refine your search.")
|
source_object.emit_to("No matching topics found, please refine your search.")
|
||||||
suggestions = HelpEntry.objects.find_topicsuggestions(pobject, topicstr)
|
suggestions = HelpEntry.objects.find_topicsuggestions(source_object,
|
||||||
|
topicstr)
|
||||||
if len(suggestions) > 0:
|
if len(suggestions) > 0:
|
||||||
session.msg("Matching similarly named topics:")
|
source_object.emit_to("Matching similarly named topics:")
|
||||||
for result in suggestions:
|
for result in suggestions:
|
||||||
session.msg(" %s" % (result,))
|
source_object.emit_to(" %s" % (result,))
|
||||||
session.msg("You may type 'help <#>' to see any of these topics.")
|
source_object.emit_to("You may type 'help <#>' to see any of these topics.")
|
||||||
elif len(topics) > 1:
|
elif len(topics) > 1:
|
||||||
session.msg("More than one match found:")
|
source_object.emit_to("More than one match found:")
|
||||||
for result in topics:
|
for result in topics:
|
||||||
session.msg("%3d. %s" % (result.id, result.get_topicname()))
|
source_object.emit_to("%3d. %s" % (result.id, result.get_topicname()))
|
||||||
session.msg("You may type 'help <#>' to see any of these topics.")
|
source_object.emit_to("You may type 'help <#>' to see any of these topics.")
|
||||||
else:
|
else:
|
||||||
topic = topics[0]
|
topic = topics[0]
|
||||||
session.msg("\n\r"+ topic.get_entrytext_ingame())
|
source_object.emit_to("\n\r"+ topic.get_entrytext_ingame())
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,11 @@ import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from src.util import functions_general
|
from src.util import functions_general
|
||||||
|
|
||||||
if not functions_general.host_os_is('nt'):
|
if not functions_general.host_os_is('nt'):
|
||||||
# Don't import the resource module if the host OS is Windows.
|
# Don't import the resource module if the host OS is Windows.
|
||||||
import resource
|
import resource
|
||||||
|
|
||||||
import django
|
import django
|
||||||
|
|
||||||
from src.objects.models import Object
|
from src.objects.models import Object
|
||||||
from src import scheduler
|
from src import scheduler
|
||||||
from src import defines_global
|
from src import defines_global
|
||||||
|
|
@ -22,104 +20,104 @@ def cmd_version(command):
|
||||||
"""
|
"""
|
||||||
Version info command.
|
Version info command.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
|
||||||
retval = "-"*50 +"\n\r"
|
retval = "-"*50 +"\n\r"
|
||||||
retval += " Evennia %s\n\r" % (defines_global.EVENNIA_VERSION,)
|
retval += " Evennia %s\n\r" % (defines_global.EVENNIA_VERSION,)
|
||||||
retval += " Django %s\n\r" % (django.get_version())
|
retval += " Django %s\n\r" % (django.get_version())
|
||||||
retval += "-"*50
|
retval += "-"*50
|
||||||
session.msg(retval)
|
command.source_object.emit_to(retval)
|
||||||
|
|
||||||
def cmd_time(command):
|
def cmd_time(command):
|
||||||
"""
|
"""
|
||||||
Server local time.
|
Server local time.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
command.source_object.emit_to('Current server time : %s' %
|
||||||
session.msg('Current server time : %s' %
|
|
||||||
(time.strftime('%a %b %d %H:%M:%S %Y (%Z)', time.localtime(),)))
|
(time.strftime('%a %b %d %H:%M:%S %Y (%Z)', time.localtime(),)))
|
||||||
|
|
||||||
def cmd_uptime(command):
|
def cmd_uptime(command):
|
||||||
"""
|
"""
|
||||||
Server uptime and stats.
|
Server uptime and stats.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
server = command.server
|
server = command.session.server
|
||||||
start_delta = time.time() - server.start_time
|
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(),)))
|
(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),)))
|
(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))
|
functions_general.time_format(start_delta, style=2))
|
||||||
|
|
||||||
# os.getloadavg() is not available on Windows.
|
# os.getloadavg() is not available on Windows.
|
||||||
if not functions_general.host_os_is('nt'):
|
if not functions_general.host_os_is('nt'):
|
||||||
loadavg = os.getloadavg()
|
loadavg = os.getloadavg()
|
||||||
session.msg('Server load (1 min) : %.2f' %
|
source_object.emit_to('Server load (1 min) : %.2f' %
|
||||||
loadavg[0])
|
loadavg[0])
|
||||||
|
|
||||||
def cmd_list(command):
|
def cmd_list(command):
|
||||||
"""
|
"""
|
||||||
Shows some game related information.
|
Shows some game related information.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
server = command.session.server
|
||||||
pobject = session.get_pobject()
|
source_object = command.source_object
|
||||||
|
|
||||||
msg_invalid = "Unknown option. Use one of: commands, flags, process"
|
msg_invalid = "Unknown option. Use one of: commands, flags, process"
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg(msg_invalid)
|
source_object.emit_to(msg_invalid)
|
||||||
elif command.command_argument == "commands":
|
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":
|
elif command.command_argument == "process":
|
||||||
if not functions_general.host_os_is('nt'):
|
if not functions_general.host_os_is('nt'):
|
||||||
loadvg = os.getloadavg()
|
loadvg = os.getloadavg()
|
||||||
psize = resource.getpagesize()
|
psize = resource.getpagesize()
|
||||||
rusage = resource.getrusage(resource.RUSAGE_SELF)
|
rusage = resource.getrusage(resource.RUSAGE_SELF)
|
||||||
session.msg("Process ID: %10d %10d bytes per page" %
|
source_object.emit_to("Process ID: %10d %10d bytes per page" %
|
||||||
(os.getpid(), psize))
|
(os.getpid(), psize))
|
||||||
session.msg("Time used: %10d user %10d sys" %
|
source_object.emit_to("Time used: %10d user %10d sys" %
|
||||||
(rusage[0],rusage[1]))
|
(rusage[0],rusage[1]))
|
||||||
session.msg("Integral mem:%10d shared %10d private%10d stack" %
|
source_object.emit_to("Integral mem:%10d shared %10d private%10d stack" %
|
||||||
(rusage[3], rusage[4], rusage[5]))
|
(rusage[3], rusage[4], rusage[5]))
|
||||||
session.msg("Max res mem: %10d pages %10d bytes" %
|
source_object.emit_to("Max res mem: %10d pages %10d bytes" %
|
||||||
(rusage[2],rusage[2] * psize))
|
(rusage[2],rusage[2] * psize))
|
||||||
session.msg("Page faults: %10d hard %10d soft %10d swapouts" %
|
source_object.emit_to("Page faults: %10d hard %10d soft %10d swapouts" %
|
||||||
(rusage[7], rusage[6], rusage[8]))
|
(rusage[7], rusage[6], rusage[8]))
|
||||||
session.msg("Disk I/O: %10d reads %10d writes" %
|
source_object.emit_to("Disk I/O: %10d reads %10d writes" %
|
||||||
(rusage[9], rusage[10]))
|
(rusage[9], rusage[10]))
|
||||||
session.msg("Network I/O: %10d in %10d out" %
|
source_object.emit_to("Network I/O: %10d in %10d out" %
|
||||||
(rusage[12], rusage[11]))
|
(rusage[12], rusage[11]))
|
||||||
session.msg("Context swi: %10d vol %10d forced %10d sigs" %
|
source_object.emit_to("Context swi: %10d vol %10d forced %10d sigs" %
|
||||||
(rusage[14], rusage[15], rusage[13]))
|
(rusage[14], rusage[15], rusage[13]))
|
||||||
else:
|
else:
|
||||||
session.msg("Feature not available on Windows.")
|
source_object.emit_to("Feature not available on Windows.")
|
||||||
return
|
return
|
||||||
elif command.command_argument == "flags":
|
elif command.command_argument == "flags":
|
||||||
session.msg("Flags: "+" ".join(flags.SERVER_FLAGS))
|
source_object.emit_to("Flags: "+" ".join(flags.SERVER_FLAGS))
|
||||||
else:
|
else:
|
||||||
session.msg(msg_invalid)
|
source_object.emit_to(msg_invalid)
|
||||||
|
|
||||||
def cmd_ps(command):
|
def cmd_ps(command):
|
||||||
"""
|
"""
|
||||||
Shows the process/event table.
|
Shows the process/event table.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
session.msg("-- Interval Events --")
|
|
||||||
|
source_object.emit_to("-- Interval Events --")
|
||||||
for event in scheduler.schedule:
|
for event in scheduler.schedule:
|
||||||
session.msg(" [%d/%d] %s" % (scheduler.get_event_nextfire(event),
|
source_object.emit_to(" [%d/%d] %s" % (
|
||||||
scheduler.get_event_interval(event),
|
scheduler.get_event_nextfire(event),
|
||||||
scheduler.get_event_description(event)))
|
scheduler.get_event_interval(event),
|
||||||
session.msg("Totals: %d interval events" % (len(scheduler.schedule),))
|
scheduler.get_event_description(event)))
|
||||||
|
source_object.emit_to("Totals: %d interval events" % (len(scheduler.schedule),))
|
||||||
|
|
||||||
def cmd_stats(command):
|
def cmd_stats(command):
|
||||||
"""
|
"""
|
||||||
Shows stats about the database.
|
Shows stats about the database.
|
||||||
4012 objects = 144 rooms, 212 exits, 613 things, 1878 players. (1165 garbage)
|
4012 objects = 144 rooms, 212 exits, 613 things, 1878 players. (1165 garbage)
|
||||||
"""
|
"""
|
||||||
session = command.session
|
|
||||||
stats_dict = Object.objects.object_totals()
|
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["objects"],
|
||||||
stats_dict["rooms"],
|
stats_dict["rooms"],
|
||||||
stats_dict["exits"],
|
stats_dict["exits"],
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,15 @@ from src.objects.models import Object, Attribute
|
||||||
# We'll import this as the full path to avoid local variable clashes.
|
# We'll import this as the full path to avoid local variable clashes.
|
||||||
import src.flags
|
import src.flags
|
||||||
from src import ansi
|
from src import ansi
|
||||||
from src import session_mgr
|
|
||||||
|
|
||||||
def cmd_teleport(command):
|
def cmd_teleport(command):
|
||||||
"""
|
"""
|
||||||
Teleports an object somewhere.
|
Teleports an object somewhere.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Teleport where/what?")
|
source_object.emit_to("Teleport where/what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
eq_args = command.command_argument.split('=', 1)
|
eq_args = command.command_argument.split('=', 1)
|
||||||
|
|
@ -31,96 +29,80 @@ def cmd_teleport(command):
|
||||||
# a direct teleport, @tel <destination>.
|
# a direct teleport, @tel <destination>.
|
||||||
if len(eq_args) > 1:
|
if len(eq_args) > 1:
|
||||||
# Equal sign teleport.
|
# Equal sign teleport.
|
||||||
victim = Object.objects.standard_plr_objsearch(session, eq_args[0])
|
victim = Object.objects.standard_objsearch(source_object, eq_args[0])
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not victim:
|
if not victim:
|
||||||
return
|
return
|
||||||
|
|
||||||
destination = Object.objects.standard_plr_objsearch(session, eq_args[1])
|
destination = Object.objects.standard_objsearch(source_object, eq_args[1])
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not destination:
|
if not destination:
|
||||||
return
|
return
|
||||||
|
|
||||||
if victim.is_room():
|
if victim.is_room():
|
||||||
session.msg("You can't teleport a room.")
|
source_object.emit_to("You can't teleport a room.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if victim == destination:
|
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
|
return
|
||||||
session.msg("Teleported.")
|
source_object.emit_to("Teleported.")
|
||||||
victim.move_to(destination, quiet=tel_quietly)
|
victim.move_to(destination, quiet=tel_quietly)
|
||||||
else:
|
else:
|
||||||
# Direct teleport (no equal sign)
|
# Direct teleport (no equal sign)
|
||||||
target_obj = Object.objects.standard_plr_objsearch(session,
|
target_obj = Object.objects.standard_objsearch(source_object,
|
||||||
command.command_argument)
|
command.command_argument)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
if target_obj == pobject:
|
if target_obj == source_object:
|
||||||
session.msg("You can't teleport inside yourself!")
|
source_object.emit_to("You can't teleport inside yourself!")
|
||||||
return
|
return
|
||||||
session.msg("Teleported.")
|
source_object.emit_to("Teleported.")
|
||||||
|
|
||||||
pobject.move_to(target_obj, quiet=tel_quietly)
|
source_object.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"]))
|
|
||||||
|
|
||||||
def cmd_alias(command):
|
def cmd_alias(command):
|
||||||
"""
|
"""
|
||||||
Assigns an alias to a player object for ease of paging, etc.
|
Assigns an alias to a player object for ease of paging, etc.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Alias whom?")
|
source_object.emit_to("Alias whom?")
|
||||||
return
|
return
|
||||||
|
|
||||||
eq_args = command.command_argument.split('=', 1)
|
eq_args = command.command_argument.split('=', 1)
|
||||||
|
|
||||||
if len(eq_args) < 2:
|
if len(eq_args) < 2:
|
||||||
session.msg("Alias missing.")
|
source_object.emit_to("Alias missing.")
|
||||||
return
|
return
|
||||||
|
|
||||||
target_string = eq_args[0]
|
target_string = eq_args[0]
|
||||||
new_alias = eq_args[1]
|
new_alias = eq_args[1]
|
||||||
|
|
||||||
# An Object instance for the victim.
|
# An Object instance for the victim.
|
||||||
target = Object.objects.standard_plr_objsearch(session, target_string)
|
target = Object.objects.standard_objsearch(source_object, target_string)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not target:
|
if not target:
|
||||||
session.msg("I can't find that player.")
|
source_object.emit_to("I can't find that player.")
|
||||||
return
|
return
|
||||||
|
|
||||||
old_alias = target.get_attribute_value('ALIAS')
|
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():
|
if not duplicates or old_alias.lower() == new_alias.lower():
|
||||||
# Either no duplicates or just changing the case of existing alias.
|
# 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)
|
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()))
|
target.get_name()))
|
||||||
else:
|
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(),))
|
(target.get_name(),))
|
||||||
else:
|
else:
|
||||||
# Duplicates were found.
|
# 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
|
return
|
||||||
|
|
||||||
def cmd_wipe(command):
|
def cmd_wipe(command):
|
||||||
|
|
@ -128,12 +110,11 @@ def cmd_wipe(command):
|
||||||
Wipes an object's attributes, or optionally only those matching a search
|
Wipes an object's attributes, or optionally only those matching a search
|
||||||
string.
|
string.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
attr_search = False
|
attr_search = False
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Wipe what?")
|
source_object.emit_to("Wipe what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Look for a slash in the input, indicating an attribute wipe.
|
# Look for a slash in the input, indicating an attribute wipe.
|
||||||
|
|
@ -149,8 +130,8 @@ def cmd_wipe(command):
|
||||||
else:
|
else:
|
||||||
searchstr = command.command_argument
|
searchstr = command.command_argument
|
||||||
|
|
||||||
target_obj = Object.objects.standard_plr_objsearch(session, attr_split[0])
|
target_obj = Object.objects.standard_objsearch(source_object, attr_split[0])
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -162,43 +143,43 @@ def cmd_wipe(command):
|
||||||
if attr_matches:
|
if attr_matches:
|
||||||
for attr in attr_matches:
|
for attr in attr_matches:
|
||||||
target_obj.clear_attribute(attr.get_name())
|
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." % (
|
||||||
len(attr_matches)))
|
target_obj.get_name(),
|
||||||
|
len(attr_matches)))
|
||||||
else:
|
else:
|
||||||
session.msg("No matching attributes found.")
|
source_object.emit_to("No matching attributes found.")
|
||||||
else:
|
else:
|
||||||
# User didn't specify a wild-card string, wipe entire object.
|
# User didn't specify a wild-card string, wipe entire object.
|
||||||
attr_matches = target_obj.attribute_namesearch("*", exclude_noset=True)
|
attr_matches = target_obj.attribute_namesearch("*", exclude_noset=True)
|
||||||
for attr in attr_matches:
|
for attr in attr_matches:
|
||||||
target_obj.clear_attribute(attr.get_name())
|
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)))
|
len(attr_matches)))
|
||||||
|
|
||||||
def cmd_set(command):
|
def cmd_set(command):
|
||||||
"""
|
"""
|
||||||
Sets flags or attributes on objects.
|
Sets flags or attributes on objects.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Set what?")
|
source_object.emit_to("Set what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Break into target and value by the equal sign.
|
# Break into target and value by the equal sign.
|
||||||
eq_args = command.command_argument.split('=', 1)
|
eq_args = command.command_argument.split('=', 1)
|
||||||
if len(eq_args) < 2:
|
if len(eq_args) < 2:
|
||||||
# Equal signs are not optional for @set.
|
# Equal signs are not optional for @set.
|
||||||
session.msg("Set what?")
|
source_object.emit_to("Set what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
victim = Object.objects.standard_plr_objsearch(session, eq_args[0])
|
victim = Object.objects.standard_objsearch(source_object, eq_args[0])
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not victim:
|
if not victim:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not pobject.controls_other(victim):
|
if not source_object.controls_other(victim):
|
||||||
session.msg(defines_global.NOCONTROL_MSG)
|
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
||||||
return
|
return
|
||||||
|
|
||||||
attrib_args = eq_args[1].split(':', 1)
|
attrib_args = eq_args[1].split(':', 1)
|
||||||
|
|
@ -209,8 +190,8 @@ def cmd_set(command):
|
||||||
attrib_value = eq_args[1][splicenum:]
|
attrib_value = eq_args[1][splicenum:]
|
||||||
|
|
||||||
# In global_defines.py, see NOSET_ATTRIBS for protected attribute names.
|
# 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():
|
if not Attribute.objects.is_modifiable_attrib(attrib_name) and not source_object.is_superuser():
|
||||||
session.msg("You can't modify that attribute.")
|
source_object.emit_to("You can't modify that attribute.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if attrib_value:
|
if attrib_value:
|
||||||
|
|
@ -221,7 +202,7 @@ def cmd_set(command):
|
||||||
# No value was given, this means we delete the attribute.
|
# No value was given, this means we delete the attribute.
|
||||||
verb = 'cleared'
|
verb = 'cleared'
|
||||||
victim.clear_attribute(attrib_name)
|
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:
|
else:
|
||||||
# Flag manipulation form.
|
# Flag manipulation form.
|
||||||
flag_list = eq_args[1].split()
|
flag_list = eq_args[1].split()
|
||||||
|
|
@ -232,62 +213,60 @@ def cmd_set(command):
|
||||||
# We're un-setting the flag.
|
# We're un-setting the flag.
|
||||||
flag = flag[1:]
|
flag = flag[1:]
|
||||||
if not src.flags.is_modifiable_flag(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:
|
else:
|
||||||
session.msg('%s - %s cleared.' % (victim.get_name(),
|
source_object.emit_to('%s - %s cleared.' % (victim.get_name(),
|
||||||
flag.upper(),))
|
flag.upper(),))
|
||||||
victim.set_flag(flag, False)
|
victim.set_flag(flag, False)
|
||||||
else:
|
else:
|
||||||
# We're setting the flag.
|
# We're setting the flag.
|
||||||
if not src.flags.is_modifiable_flag(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:
|
else:
|
||||||
session.msg('%s - %s set.' % (victim.get_name(),
|
source_object.emit_to('%s - %s set.' % (victim.get_name(),
|
||||||
flag.upper(),))
|
flag.upper(),))
|
||||||
victim.set_flag(flag, True)
|
victim.set_flag(flag, True)
|
||||||
|
|
||||||
def cmd_find(command):
|
def cmd_find(command):
|
||||||
"""
|
"""
|
||||||
Searches for an object of a particular name.
|
Searches for an object of a particular name.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
can_find = source_object.has_perm("genperms.builder")
|
||||||
can_find = pobject.user_has_perm("genperms.builder")
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("No search pattern given.")
|
source_object.emit_to("No search pattern given.")
|
||||||
return
|
return
|
||||||
|
|
||||||
searchstring = command.command_argument
|
searchstring = command.command_argument
|
||||||
results = Object.objects.global_object_name_search(searchstring)
|
results = Object.objects.global_object_name_search(searchstring)
|
||||||
|
|
||||||
if len(results) > 0:
|
if len(results) > 0:
|
||||||
session.msg("Name matches for: %s" % (searchstring,))
|
source_object.emit_to("Name matches for: %s" % (searchstring,))
|
||||||
for result in results:
|
for result in results:
|
||||||
session.msg(" %s" % (result.get_name(fullname=True),))
|
source_object.emit_to(" %s" % (result.get_name(fullname=True),))
|
||||||
session.msg("%d matches returned." % (len(results),))
|
source_object.emit_to("%d matches returned." % (len(results),))
|
||||||
else:
|
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):
|
def cmd_create(command):
|
||||||
"""
|
"""
|
||||||
Creates a new object of type 'THING'.
|
Creates a new object of type 'THING'.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("You must supply a name!")
|
source_object.emit_to("You must supply a name!")
|
||||||
else:
|
else:
|
||||||
# Create and set the object up.
|
# Create and set the object up.
|
||||||
# TODO: This dictionary stuff is silly. Feex.
|
# TODO: This dictionary stuff is silly. Feex.
|
||||||
odat = {"name": command.command_argument,
|
odat = {"name": command.command_argument,
|
||||||
"type": 3,
|
"type": 3,
|
||||||
"location": pobject,
|
"location": source_object,
|
||||||
"owner": pobject}
|
"owner": source_object}
|
||||||
new_object = Object.objects.create_object(odat)
|
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):
|
def cmd_cpattr(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -295,12 +274,10 @@ def cmd_cpattr(command):
|
||||||
|
|
||||||
@cpattr <source object>/<attribute> = <target1>/[<attrname>] <target n>/[<attrname n>]
|
@cpattr <source object>/<attribute> = <target1>/[<attrname>] <target n>/[<attrname n>]
|
||||||
"""
|
"""
|
||||||
|
source_object = command.source_object
|
||||||
session = command.session
|
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("What do you want to copy?")
|
source_object.emit_to("What do you want to copy?")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Split up source and target[s] via the equals sign.
|
# Split up source and target[s] via the equals sign.
|
||||||
|
|
@ -308,7 +285,7 @@ def cmd_cpattr(command):
|
||||||
|
|
||||||
if len(eq_args) < 2:
|
if len(eq_args) < 2:
|
||||||
# There must be both a source and a target pair for cpattr
|
# 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
|
return
|
||||||
|
|
||||||
# Check that the source object and attribute exists, by splitting the eq_args 'source' entry with '/'
|
# 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()
|
source_attr_string = source[1].strip().upper()
|
||||||
|
|
||||||
# Check whether src_obj exists
|
# 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:
|
if not src_obj:
|
||||||
session.msg("Source object does not exist")
|
source_object.emit_to("Source object does not exist")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Check whether src_obj has src_attr
|
# Check whether src_obj has src_attr
|
||||||
src_attr = src_obj.attribute_namesearch(source_attr_string)
|
src_attr = src_obj.attribute_namesearch(source_attr_string)
|
||||||
|
|
||||||
if not src_attr:
|
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
|
return
|
||||||
|
|
||||||
# For each target object, check it exists
|
# For each target object, check it exists
|
||||||
|
|
@ -343,7 +320,7 @@ def cmd_cpattr(command):
|
||||||
|
|
||||||
# Does target exist?
|
# Does target exist?
|
||||||
if not tar_obj:
|
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 if target does not exist, but give error on this item
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -357,7 +334,6 @@ def cmd_cpattr(command):
|
||||||
# accordingly.
|
# accordingly.
|
||||||
|
|
||||||
# Does target attribute exist?
|
# Does target attribute exist?
|
||||||
|
|
||||||
tar_attr = tar_obj.attribute_namesearch(tar_attr_string)
|
tar_attr = tar_obj.attribute_namesearch(tar_attr_string)
|
||||||
|
|
||||||
# If the target object does not have the given attribute, make a new attr
|
# If the target object does not have the given attribute, make a new attr
|
||||||
|
|
@ -375,10 +351,8 @@ def cmd_nextfree(command):
|
||||||
"""
|
"""
|
||||||
Returns the next free object number.
|
Returns the next free object number.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
|
||||||
|
|
||||||
nextfree = Object.objects.get_nextfree_dbnum()
|
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):
|
def cmd_open(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -389,18 +363,17 @@ def cmd_open(command):
|
||||||
@open <Name>=<Dbref>
|
@open <Name>=<Dbref>
|
||||||
@open <Name>=<Dbref>,<Name>
|
@open <Name>=<Dbref>,<Name>
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Open an exit to where?")
|
source_object.emit_to("Open an exit to where?")
|
||||||
return
|
return
|
||||||
|
|
||||||
eq_args = command.command_argument.split('=', 1)
|
eq_args = command.command_argument.split('=', 1)
|
||||||
exit_name = eq_args[0]
|
exit_name = eq_args[0]
|
||||||
|
|
||||||
if len(exit_name) == 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
|
return
|
||||||
|
|
||||||
# If we have more than one entry in our '=' delimited argument list,
|
# 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:
|
if len(eq_args) > 1:
|
||||||
# Opening an exit to another location via @open <Name>=<Dbref>[,<Name>].
|
# Opening an exit to another location via @open <Name>=<Dbref>[,<Name>].
|
||||||
comma_split = eq_args[1].split(',', 1)
|
comma_split = eq_args[1].split(',', 1)
|
||||||
destination = Object.objects.standard_plr_objsearch(session,
|
destination = Object.objects.standard_objsearch(source_object,
|
||||||
comma_split[0])
|
comma_split[0])
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not destination:
|
if not destination:
|
||||||
return
|
return
|
||||||
|
|
||||||
if destination.is_exit():
|
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
|
return
|
||||||
|
|
||||||
odat = {"name": exit_name,
|
odat = {"name": exit_name,
|
||||||
"type": 4,
|
"type": 4,
|
||||||
"location": pobject.get_location(),
|
"location": source_object.get_location(),
|
||||||
"owner": pobject,
|
"owner": source_object,
|
||||||
"home":destination}
|
"home": destination}
|
||||||
new_object = Object.objects.create_object(odat)
|
new_object = Object.objects.create_object(odat)
|
||||||
|
|
||||||
session.msg("You open the an exit - %s to %s" % (new_object.get_name(),
|
source_object.emit_to("You open the an exit - %s to %s" % (
|
||||||
destination.get_name()))
|
new_object.get_name(),
|
||||||
|
destination.get_name()))
|
||||||
if len(comma_split) > 1:
|
if len(comma_split) > 1:
|
||||||
second_exit_name = ','.join(comma_split[1:])
|
second_exit_name = ','.join(comma_split[1:])
|
||||||
odat = {"name": second_exit_name,
|
odat = {"name": second_exit_name,
|
||||||
"type": 4,
|
"type": 4,
|
||||||
"location": destination,
|
"location": destination,
|
||||||
"owner": pobject,
|
"owner": source_object,
|
||||||
"home": pobject.get_location()}
|
"home": source_object.get_location()}
|
||||||
new_object = Object.objects.create_object(odat)
|
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(),
|
new_object.get_name(),
|
||||||
pobject.get_location().get_name()))
|
source_object.get_location().get_name()))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Create an un-linked exit.
|
# Create an un-linked exit.
|
||||||
odat = {"name": exit_name,
|
odat = {"name": exit_name,
|
||||||
"type": 4,
|
"type": 4,
|
||||||
"location": pobject.get_location(),
|
"location": source_object.get_location(),
|
||||||
"owner": pobject,
|
"owner": source_object,
|
||||||
"home":None}
|
"home": None}
|
||||||
new_object = Object.objects.create_object(odat)
|
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):
|
def cmd_chown(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -459,11 +433,10 @@ def cmd_chown(command):
|
||||||
Forms:
|
Forms:
|
||||||
@chown <Object>=<NewOwner>
|
@chown <Object>=<NewOwner>
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Change the ownership of what?")
|
source_object.emit_to("Change the ownership of what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
eq_args = command.command_argument.split('=', 1)
|
eq_args = command.command_argument.split('=', 1)
|
||||||
|
|
@ -471,37 +444,35 @@ def cmd_chown(command):
|
||||||
owner_name = eq_args[1]
|
owner_name = eq_args[1]
|
||||||
|
|
||||||
if len(target_name) == 0:
|
if len(target_name) == 0:
|
||||||
session.msg("Change the ownership of what?")
|
source_object.emit_to("Change the ownership of what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(eq_args) > 1:
|
if len(eq_args) > 1:
|
||||||
target_obj = Object.objects.standard_plr_objsearch(session, target_name)
|
target_obj = Object.objects.standard_objsearch(source_object, target_name)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not pobject.controls_other(target_obj):
|
if not source_object.controls_other(target_obj):
|
||||||
session.msg(defines_global.NOCONTROL_MSG)
|
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
||||||
return
|
return
|
||||||
|
|
||||||
owner_obj = Object.objects.standard_plr_objsearch(session, owner_name)
|
owner_obj = Object.objects.standard_objsearch(source_object, owner_name)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not owner_obj:
|
if not owner_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not owner_obj.is_player():
|
if not owner_obj.is_player():
|
||||||
session.msg("Only players may own objects.")
|
source_object.emit_to("Only players may own objects.")
|
||||||
return
|
return
|
||||||
if target_obj.is_player():
|
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
|
return
|
||||||
|
|
||||||
target_obj.set_owner(owner_obj)
|
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:
|
else:
|
||||||
# We haven't provided a target.
|
# 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
|
return
|
||||||
|
|
||||||
def cmd_chzone(command):
|
def cmd_chzone(command):
|
||||||
|
|
@ -512,11 +483,10 @@ def cmd_chzone(command):
|
||||||
Forms:
|
Forms:
|
||||||
@chzone <Object>=<NewZone>
|
@chzone <Object>=<NewZone>
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Change the zone of what?")
|
source_object.emit_to("Change the zone of what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
eq_args = command.command_argument.split('=', 1)
|
eq_args = command.command_argument.split('=', 1)
|
||||||
|
|
@ -524,36 +494,36 @@ def cmd_chzone(command):
|
||||||
zone_name = eq_args[1]
|
zone_name = eq_args[1]
|
||||||
|
|
||||||
if len(target_name) == 0:
|
if len(target_name) == 0:
|
||||||
session.msg("Change the zone of what?")
|
source_object.emit_to("Change the zone of what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(eq_args) > 1:
|
if len(eq_args) > 1:
|
||||||
target_obj = Object.objects.standard_plr_objsearch(session, target_name)
|
target_obj = Object.objects.standard_objsearch(source_object, target_name)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not pobject.controls_other(target_obj):
|
if not source_object.controls_other(target_obj):
|
||||||
session.msg(defines_global.NOCONTROL_MSG)
|
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Allow the clearing of a zone
|
# Allow the clearing of a zone
|
||||||
if zone_name.lower() == "none":
|
if zone_name.lower() == "none":
|
||||||
target_obj.set_zone(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
|
return
|
||||||
|
|
||||||
zone_obj = Object.objects.standard_plr_objsearch(session, zone_name)
|
zone_obj = Object.objects.standard_objsearch(source_object, zone_name)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not zone_obj:
|
if not zone_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
target_obj.set_zone(zone_obj)
|
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:
|
else:
|
||||||
# We haven't provided a target zone.
|
# 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
|
return
|
||||||
|
|
||||||
def cmd_link(command):
|
def cmd_link(command):
|
||||||
|
|
@ -563,11 +533,10 @@ def cmd_link(command):
|
||||||
Forms:
|
Forms:
|
||||||
@link <Object>=<Target>
|
@link <Object>=<Target>
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Link what?")
|
source_object.emit_to("Link what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
eq_args = command.command_argument.split('=', 1)
|
eq_args = command.command_argument.split('=', 1)
|
||||||
|
|
@ -575,36 +544,36 @@ def cmd_link(command):
|
||||||
dest_name = eq_args[1]
|
dest_name = eq_args[1]
|
||||||
|
|
||||||
if len(target_name) == 0:
|
if len(target_name) == 0:
|
||||||
session.msg("What do you want to link?")
|
source_object.emit_to("What do you want to link?")
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(eq_args) > 1:
|
if len(eq_args) > 1:
|
||||||
target_obj = Object.objects.standard_plr_objsearch(session, target_name)
|
target_obj = Object.objects.standard_objsearch(source_object, target_name)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not pobject.controls_other(target_obj):
|
if not source_object.controls_other(target_obj):
|
||||||
session.msg(defines_global.NOCONTROL_MSG)
|
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
||||||
return
|
return
|
||||||
|
|
||||||
# If we do something like "@link blah=", we unlink the object.
|
# If we do something like "@link blah=", we unlink the object.
|
||||||
if len(dest_name) == 0:
|
if len(dest_name) == 0:
|
||||||
target_obj.set_home(None)
|
target_obj.set_home(None)
|
||||||
session.msg("You have unlinked %s." % (target_obj,))
|
source_object.emit_to("You have unlinked %s." % (target_obj,))
|
||||||
return
|
return
|
||||||
|
|
||||||
destination = Object.objects.standard_plr_objsearch(session, dest_name)
|
destination = Object.objects.standard_objsearch(source_object, dest_name)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not destination:
|
if not destination:
|
||||||
return
|
return
|
||||||
|
|
||||||
target_obj.set_home(destination)
|
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:
|
else:
|
||||||
# We haven't provided a target.
|
# 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
|
return
|
||||||
|
|
||||||
def cmd_unlink(command):
|
def cmd_unlink(command):
|
||||||
|
|
@ -613,25 +582,24 @@ def cmd_unlink(command):
|
||||||
|
|
||||||
@unlink <Object>
|
@unlink <Object>
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Unlink what?")
|
source_object.emit_to("Unlink what?")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
target_obj = Object.objects.standard_plr_objsearch(session,
|
target_obj = Object.objects.standard_objsearch(source_object,
|
||||||
command.command_argument)
|
command.command_argument)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not pobject.controls_other(target_obj):
|
if not source_object.controls_other(target_obj):
|
||||||
session.msg(defines_global.NOCONTROL_MSG)
|
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
||||||
return
|
return
|
||||||
|
|
||||||
target_obj.set_home(None)
|
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):
|
def cmd_dig(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -639,21 +607,20 @@ def cmd_dig(command):
|
||||||
|
|
||||||
@dig <Name>
|
@dig <Name>
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
roomname = command.command_argument
|
roomname = command.command_argument
|
||||||
|
|
||||||
if not roomname:
|
if not roomname:
|
||||||
session.msg("You must supply a name!")
|
source_object.emit_to("You must supply a name!")
|
||||||
else:
|
else:
|
||||||
# Create and set the object up.
|
# Create and set the object up.
|
||||||
odat = {"name": roomname,
|
odat = {"name": roomname,
|
||||||
"type": 2,
|
"type": 2,
|
||||||
"location": None,
|
"location": None,
|
||||||
"owner": pobject}
|
"owner": source_object}
|
||||||
new_object = Object.objects.create_object(odat)
|
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):
|
def cmd_name(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -661,94 +628,102 @@ def cmd_name(command):
|
||||||
|
|
||||||
@name <Object>=<Value>
|
@name <Object>=<Value>
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("What do you want to name?")
|
source_object.emit_to("What do you want to name?")
|
||||||
return
|
return
|
||||||
|
|
||||||
eq_args = command.command_argument.split('=', 1)
|
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
|
# Only strip spaces from right side in case they want to be silly and
|
||||||
# have a left-padded object name.
|
# have a left-padded object name.
|
||||||
new_name = eq_args[1].rstrip()
|
new_name = eq_args[1].rstrip()
|
||||||
|
|
||||||
if len(eq_args) < 2 or eq_args[1] == '':
|
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:
|
else:
|
||||||
target_obj = Object.objects.standard_plr_objsearch(session, eq_args[0])
|
target_obj = Object.objects.standard_objsearch(source_object, eq_args[0])
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
ansi_name = ansi.parse_ansi(new_name, strip_formatting=True)
|
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)
|
target_obj.set_name(new_name)
|
||||||
|
|
||||||
def cmd_description(command):
|
def cmd_description(command):
|
||||||
"""
|
"""
|
||||||
Set an object's description.
|
Set an object's description.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("What do you want to describe?")
|
source_object.emit_to("What do you want to describe?")
|
||||||
return
|
return
|
||||||
|
|
||||||
eq_args = command.command_argument.split('=', 1)
|
eq_args = command.command_argument.split('=', 1)
|
||||||
|
|
||||||
if len(eq_args) < 2 or eq_args[1] == '':
|
if len(eq_args) < 2:
|
||||||
session.msg("How would you like to describe that object?")
|
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:
|
else:
|
||||||
target_obj = Object.objects.standard_plr_objsearch(session, eq_args[0])
|
source_object.emit_to("%s - DESCRIPTION set." % target_obj)
|
||||||
# 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,))
|
|
||||||
target_obj.set_description(new_desc)
|
target_obj.set_description(new_desc)
|
||||||
|
|
||||||
def cmd_destroy(command):
|
def cmd_destroy(command):
|
||||||
"""
|
"""
|
||||||
Destroy an object.
|
Destroy an object.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
switch_override = False
|
switch_override = False
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Destroy what?")
|
source_object.emit_to("Destroy what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Safety feature. Switch required to delete players and SAFE objects.
|
# Safety feature. Switch required to delete players and SAFE objects.
|
||||||
if "override" in command.command_switches:
|
if "override" in command.command_switches:
|
||||||
switch_override = True
|
switch_override = True
|
||||||
|
|
||||||
target_obj = Object.objects.standard_plr_objsearch(session,
|
target_obj = Object.objects.standard_objsearch(source_object,
|
||||||
command.command_argument)
|
command.command_argument)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
if target_obj.is_player():
|
if target_obj.is_player():
|
||||||
if pobject.id == target_obj.id:
|
if source_object.id == target_obj.id:
|
||||||
session.msg("You can't destroy yourself.")
|
source_object.emit_to("You can't destroy yourself.")
|
||||||
return
|
return
|
||||||
if not switch_override:
|
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
|
return
|
||||||
if target_obj.is_superuser():
|
if target_obj.is_superuser():
|
||||||
session.msg("You can't destroy a superuser.")
|
source_object.emit_to("You can't destroy a superuser.")
|
||||||
return
|
return
|
||||||
elif target_obj.is_going() or target_obj.is_garbage():
|
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
|
return
|
||||||
|
|
||||||
session.msg("You destroy %s." % (target_obj.get_name(),))
|
source_object.emit_to("You destroy %s." % target_obj.get_name())
|
||||||
target_obj.destroy()
|
target_obj.destroy()
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@ Paging command and support functions.
|
||||||
from src.objects.models import Object
|
from src.objects.models import Object
|
||||||
from src import defines_global
|
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
|
Returns a list of objects of the user's last paged list, or None if invalid
|
||||||
or non-existant.
|
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:
|
if last_paged_dbrefs is not False:
|
||||||
last_paged_objects = list()
|
last_paged_objects = list()
|
||||||
try:
|
try:
|
||||||
|
|
@ -25,29 +25,28 @@ def get_last_paged_objects(pobject):
|
||||||
return last_paged_objects
|
return last_paged_objects
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# Remove the invalid LASTPAGED attribute
|
# Remove the invalid LASTPAGED attribute
|
||||||
pobject.clear_attribute("LASTPAGED")
|
source_object.clear_attribute("LASTPAGED")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def cmd_page(command):
|
def cmd_page(command):
|
||||||
"""
|
"""
|
||||||
Send a message to target user (if online).
|
Send a message to target user (if online).
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
# Get the last paged person(s)
|
# 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
|
# 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
|
# then tell them who they last paged if they paged someone, if not
|
||||||
# tell them they haven't paged anyone.
|
# tell them they haven't paged anyone.
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
if last_paged_objects:
|
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])))
|
', '.join([x.name for x in last_paged_objects])))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
# No valid LASTPAGE values
|
# No valid LASTPAGE values
|
||||||
session.msg("You have not paged anyone.")
|
source_object.emit_to("You have not paged anyone.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Stores a list of targets
|
# Stores a list of targets
|
||||||
|
|
@ -62,7 +61,7 @@ def cmd_page(command):
|
||||||
|
|
||||||
# No valid last paged players found, error out.
|
# No valid last paged players found, error out.
|
||||||
if not targets:
|
if not targets:
|
||||||
session.msg("Page who?")
|
source_object.emit_to("Page who?")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
# For each of the targets listed, grab their objects and append
|
# For each of the targets listed, grab their objects and append
|
||||||
|
|
@ -75,7 +74,7 @@ def cmd_page(command):
|
||||||
targets.append(matched_object)
|
targets.append(matched_object)
|
||||||
else:
|
else:
|
||||||
# Search returned None
|
# Search returned None
|
||||||
session.msg("Player '%s' can not be found." % (
|
source_object.emit_to("Player '%s' can not be found." % (
|
||||||
target))
|
target))
|
||||||
|
|
||||||
# Depending on the argument provided, either send the entire thing as
|
# 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.
|
# arguments as the message to send.
|
||||||
message = command.command_argument
|
message = command.command_argument
|
||||||
|
|
||||||
sender_name = pobject.get_name(show_dbref=False)
|
sender_name = source_object.get_name(show_dbref=False)
|
||||||
# Build our messages
|
# Build our messages
|
||||||
target_message = "%s pages: %s"
|
target_message = "%s pages: %s"
|
||||||
sender_message = "You paged %s with '%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.emit_to(target_message % (sender_name, message))
|
||||||
target_names.append(target.get_name(show_dbref=False))
|
target_names.append(target.get_name(show_dbref=False))
|
||||||
else:
|
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)))
|
target.get_name(show_dbref=False)))
|
||||||
|
|
||||||
# Now send a confirmation to the person doing the paging.
|
# Now send a confirmation to the person doing the paging.
|
||||||
if len(target_names) > 0:
|
if len(target_names) > 0:
|
||||||
target_names_string = ', '.join(target_names)
|
target_names_string = ', '.join(target_names)
|
||||||
try:
|
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:
|
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
|
# Now set the LASTPAGED attribute
|
||||||
pobject.set_attribute("LASTPAGED", ','.join(
|
source_object.set_attribute("LASTPAGED", ','.join(
|
||||||
["#%d" % (x.id) for x in targets]))
|
["#%d" % (x.id) for x in targets]))
|
||||||
|
|
@ -7,12 +7,11 @@ def clear_cached_scripts(command):
|
||||||
"""
|
"""
|
||||||
Show the currently cached scripts.
|
Show the currently cached scripts.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
|
||||||
cache_dict = scripthandler.CACHED_SCRIPTS
|
cache_dict = scripthandler.CACHED_SCRIPTS
|
||||||
cache_size = len(cache_dict)
|
cache_size = len(cache_dict)
|
||||||
cache_dict.clear()
|
cache_dict.clear()
|
||||||
session.msg("Script parent cached cleared (%d previously in cache)." %
|
command.source_object.emit_to(
|
||||||
cache_size)
|
"Script parent cached cleared (%d previously in cache)." % cache_size)
|
||||||
|
|
||||||
def show_cached_scripts(command):
|
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,
|
dictionary. The next time an object needs the previously loaded scripts,
|
||||||
they are loaded again.
|
they are loaded again.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
|
||||||
cache_dict = scripthandler.CACHED_SCRIPTS
|
cache_dict = scripthandler.CACHED_SCRIPTS
|
||||||
|
|
||||||
retval = "Currently Cached Script Parents\n"
|
retval = "Currently Cached Script Parents\n"
|
||||||
|
|
@ -29,7 +27,7 @@ def show_cached_scripts(command):
|
||||||
retval += "\n " + script
|
retval += "\n " + script
|
||||||
retval += "\n" + "-" * 78 + "\n"
|
retval += "\n" + "-" * 78 + "\n"
|
||||||
retval += "%d cached parents" % len(cache_dict)
|
retval += "%d cached parents" % len(cache_dict)
|
||||||
session.msg(retval)
|
command.source_object.emit_to(retval)
|
||||||
|
|
||||||
def cmd_parent(command):
|
def cmd_parent(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -44,4 +42,4 @@ def cmd_parent(command):
|
||||||
clear_cached_scripts(command)
|
clear_cached_scripts(command)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
command.source_object.emit_to("Must be specified with one of the following switches: showcache, clearcache")
|
||||||
|
|
@ -12,16 +12,13 @@ def cmd_reload(command):
|
||||||
"""
|
"""
|
||||||
Reloads all modules.
|
Reloads all modules.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
command.source_object.emit_to("To be implemented...")
|
||||||
session.msg("To be implemented...")
|
|
||||||
#session.server.reload(session)
|
|
||||||
|
|
||||||
def cmd_boot(command):
|
def cmd_boot(command):
|
||||||
"""
|
"""
|
||||||
Boot a player object from the server.
|
Boot a player object from the server.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
switch_quiet = False
|
switch_quiet = False
|
||||||
switch_port = False
|
switch_port = False
|
||||||
|
|
||||||
|
|
@ -34,7 +31,7 @@ def cmd_boot(command):
|
||||||
switch_port = True
|
switch_port = True
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
session.msg("Who would you like to boot?")
|
source_object.emit_to("Who would you like to boot?")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
boot_list = []
|
boot_list = []
|
||||||
|
|
@ -49,39 +46,41 @@ def cmd_boot(command):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# Grab the objects that match
|
# 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)
|
command.command_argument)
|
||||||
|
|
||||||
if not objs:
|
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
|
return
|
||||||
|
|
||||||
if not objs[0].is_player():
|
if not objs[0].is_player():
|
||||||
session.msg("You can only boot players.")
|
source_object.emit_to("You can only boot players.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if not pobject.controls_other(objs[0]):
|
if not source_object.controls_other(objs[0]):
|
||||||
if objs[0].is_superuser():
|
if objs[0].is_superuser():
|
||||||
session.msg("You cannot boot a Wizard.")
|
source_object.emit_to("You cannot boot a Wizard.")
|
||||||
return
|
return
|
||||||
else:
|
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
|
return
|
||||||
|
|
||||||
if objs[0].is_connected_plr():
|
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:
|
else:
|
||||||
session.msg("That player is not connected.")
|
source_object.emit_to("That player is not connected.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if not boot_list:
|
if not boot_list:
|
||||||
session.msg("No matches found.")
|
source_object.emit_to("No matches found.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Carry out the booting of the sessions in the boot list.
|
# Carry out the booting of the sessions in the boot list.
|
||||||
for boot in boot_list:
|
for boot in boot_list:
|
||||||
if not switch_quiet:
|
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()
|
boot.disconnectClient()
|
||||||
session_mgr.remove_session(boot)
|
session_mgr.remove_session(boot)
|
||||||
return
|
return
|
||||||
|
|
@ -90,28 +89,27 @@ def cmd_newpassword(command):
|
||||||
"""
|
"""
|
||||||
Set a player's password.
|
Set a player's password.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
eq_args = command.command_argument.split('=', 1)
|
eq_args = command.command_argument.split('=', 1)
|
||||||
searchstring = eq_args[0]
|
searchstring = eq_args[0]
|
||||||
newpass = eq_args[1]
|
newpass = eq_args[1]
|
||||||
|
|
||||||
if not command.command_argument or len(searchstring) == 0:
|
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
|
return
|
||||||
if len(newpass) == 0:
|
if len(newpass) == 0:
|
||||||
session.msg("You must supply a new password.")
|
source_object.emit_to("You must supply a new password.")
|
||||||
return
|
return
|
||||||
|
|
||||||
target_obj = Object.objects.standard_plr_objsearch(session, searchstring)
|
target_obj = Object.objects.standard_objsearch(source_object, searchstring)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not target_obj.is_player():
|
if not target_obj.is_player():
|
||||||
session.msg("You can only change passwords on players.")
|
source_object.emit_to("You can only change passwords on players.")
|
||||||
elif not pobject.controls_other(target_obj):
|
elif not source_object.controls_other(target_obj):
|
||||||
session.msg("You do not control %s." % (target_obj.get_name(),))
|
source_object.emit_to("You do not control %s." % (target_obj.get_name(),))
|
||||||
else:
|
else:
|
||||||
uaccount = target_obj.get_user_account()
|
uaccount = target_obj.get_user_account()
|
||||||
if len(newpass) == 0:
|
if len(newpass) == 0:
|
||||||
|
|
@ -119,18 +117,14 @@ def cmd_newpassword(command):
|
||||||
else:
|
else:
|
||||||
uaccount.set_password(newpass)
|
uaccount.set_password(newpass)
|
||||||
uaccount.save()
|
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." %
|
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):
|
def cmd_shutdown(command):
|
||||||
"""
|
"""
|
||||||
Shut the server down gracefully.
|
Shut the server down gracefully.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
command.source_object.emit_to('Shutting down...')
|
||||||
server = command.server
|
print 'Server shutdown by %s' % (command.source_object.get_name(show_dbref=False),)
|
||||||
pobject = session.get_pobject()
|
command.session.server.shutdown()
|
||||||
|
|
||||||
session.msg('Shutting down...')
|
|
||||||
print 'Server shutdown by %s' % (pobject.get_name(show_dbref=False),)
|
|
||||||
server.shutdown()
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ from django.db.models import Q
|
||||||
from src.objects.models import Object
|
from src.objects.models import Object
|
||||||
from src import defines_global
|
from src import defines_global
|
||||||
|
|
||||||
def _parse_restriction_split(session, restriction_split, search_low_dbnum,
|
def _parse_restriction_split(source_object, restriction_split, search_low_dbnum,
|
||||||
search_high_dbnum):
|
search_high_dbnum):
|
||||||
"""
|
"""
|
||||||
Parses a split restriction string and sets some needed variables.
|
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:
|
try:
|
||||||
search_low_dbnum = int(restriction_split[1].strip())
|
search_low_dbnum = int(restriction_split[1].strip())
|
||||||
except ValueError:
|
except ValueError:
|
||||||
session.msg("Invalid value for low dbref limit.")
|
source_object.emit_to("Invalid value for low dbref limit.")
|
||||||
return False
|
return False
|
||||||
if restriction_size >= 3:
|
if restriction_size >= 3:
|
||||||
try:
|
try:
|
||||||
search_high_dbnum = int(restriction_split[2].strip())
|
search_high_dbnum = int(restriction_split[2].strip())
|
||||||
except ValueError:
|
except ValueError:
|
||||||
session.msg("Invalid value for high dbref limit.")
|
source_object.emit_to("Invalid value for high dbref limit.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return search_low_dbnum, search_high_dbnum
|
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.
|
Display the results to the searcher.
|
||||||
"""
|
"""
|
||||||
|
|
@ -50,33 +50,33 @@ def display_results(session, search_query):
|
||||||
|
|
||||||
# Render each section for different object types
|
# Render each section for different object types
|
||||||
if thing_list:
|
if thing_list:
|
||||||
session.msg("\n\rTHINGS:")
|
source_object.emit_to("\n\rTHINGS:")
|
||||||
for thing in thing_list:
|
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:
|
if exit_list:
|
||||||
session.msg("\n\rEXITS:")
|
source_object.emit_to("\n\rEXITS:")
|
||||||
for exit in exit_list:
|
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:
|
if room_list:
|
||||||
session.msg("\n\rROOMS:")
|
source_object.emit_to("\n\rROOMS:")
|
||||||
for room in room_list:
|
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:
|
if player_list:
|
||||||
session.msg("\n\rPLAYER:")
|
source_object.emit_to("\n\rPLAYER:")
|
||||||
for player in player_list:
|
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
|
# 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(room_list),
|
||||||
len(exit_list),
|
len(exit_list),
|
||||||
len(thing_list),
|
len(thing_list),
|
||||||
len(player_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):
|
search_restriction, search_low_dbnum, search_high_dbnum):
|
||||||
"""
|
"""
|
||||||
Builds and returns a QuerySet object, or None if an error occurs.
|
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
|
# Look up an Object matching the player search query
|
||||||
if search_player:
|
if search_player:
|
||||||
# Replace the string variable with an Object reference
|
# 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)
|
search_player)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results
|
# Use standard_objsearch to handle duplicate/nonexistant results
|
||||||
if not search_player:
|
if not search_player:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
@ -104,7 +104,7 @@ def build_query(session, search_query, search_player, search_type,
|
||||||
elif search_restriction == "player":
|
elif search_restriction == "player":
|
||||||
search_query = search_query.filter(type=defines_global.OTYPE_PLAYER)
|
search_query = search_query.filter(type=defines_global.OTYPE_PLAYER)
|
||||||
else:
|
else:
|
||||||
session.msg("Invalid class. See 'help SEARCH CLASSES'.")
|
source_object.emit_to("Invalid class. See 'help SEARCH CLASSES'.")
|
||||||
return None
|
return None
|
||||||
elif search_type == "parent":
|
elif search_type == "parent":
|
||||||
search_query = search_query.filter(script_parent__iexact=search_restriction)
|
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,
|
search_query = search_query.filter(name__icontains=search_restriction,
|
||||||
type=defines_global.OTYPE_PLAYER)
|
type=defines_global.OTYPE_PLAYER)
|
||||||
elif search_type == "zone":
|
elif search_type == "zone":
|
||||||
zone_obj = Object.objects.standard_plr_objsearch(session,
|
zone_obj = Object.objects.standard_objsearch(source_object,
|
||||||
search_restriction)
|
search_restriction)
|
||||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
# Use standard_objsearch to handle duplicate/nonexistant results.
|
||||||
if not zone_obj:
|
if not zone_obj:
|
||||||
return None
|
return None
|
||||||
search_query = search_query.filter(zone=zone_obj)
|
search_query = search_query.filter(zone=zone_obj)
|
||||||
elif search_type == "power":
|
elif search_type == "power":
|
||||||
# TODO: Need this once we have powers implemented.
|
# TODO: Need this once we have powers implemented.
|
||||||
session.msg("To be implemented...")
|
source_object.emit_to("To be implemented...")
|
||||||
return None
|
return None
|
||||||
elif search_type == "flags":
|
elif search_type == "flags":
|
||||||
flag_list = search_restriction.split()
|
flag_list = search_restriction.split()
|
||||||
#session.msg("restriction: %s" % flag_list)
|
#source_object.emit_to("restriction: %s" % flag_list)
|
||||||
for flag in flag_list:
|
for flag in flag_list:
|
||||||
search_query = search_query.filter(Q(flags__icontains=flag) | Q(nosave_flags__icontains=flag))
|
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.
|
Searches for owned objects as per MUX2.
|
||||||
"""
|
"""
|
||||||
session = command.session
|
source_object = command.source_object
|
||||||
pobject = session.get_pobject()
|
|
||||||
|
|
||||||
search_player = None
|
search_player = None
|
||||||
search_type = None
|
search_type = None
|
||||||
|
|
@ -159,7 +158,7 @@ def cmd_search(command):
|
||||||
search_high_dbnum = None
|
search_high_dbnum = None
|
||||||
|
|
||||||
if not command.command_argument:
|
if not command.command_argument:
|
||||||
search_player = "#" + str(pobject.id)
|
search_player = "#" + str(source_object.id)
|
||||||
else:
|
else:
|
||||||
first_check_split = command.command_argument.split(' ', 1)
|
first_check_split = command.command_argument.split(' ', 1)
|
||||||
if '=' in first_check_split[0]:
|
if '=' in first_check_split[0]:
|
||||||
|
|
@ -168,12 +167,12 @@ def cmd_search(command):
|
||||||
search_type = eq_split[0]
|
search_type = eq_split[0]
|
||||||
restriction_split = eq_split[1].split(',')
|
restriction_split = eq_split[1].split(',')
|
||||||
search_restriction = restriction_split[0].strip()
|
search_restriction = restriction_split[0].strip()
|
||||||
#session.msg("@search class=restriction")
|
#source_object.emit_to("@search class=restriction")
|
||||||
#session.msg("eq_split: %s" % eq_split)
|
#source_object.emit_to("eq_split: %s" % eq_split)
|
||||||
#session.msg("restriction_split: %s" % restriction_split)
|
#source_object.emit_to("restriction_split: %s" % restriction_split)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
search_low_dbnum, search_high_dbnum = _parse_restriction_split(session,
|
search_low_dbnum, search_high_dbnum = _parse_restriction_split(source_object,
|
||||||
restriction_split,
|
restriction_split,
|
||||||
search_low_dbnum,
|
search_low_dbnum,
|
||||||
search_high_dbnum)
|
search_high_dbnum)
|
||||||
|
|
@ -183,22 +182,22 @@ def cmd_search(command):
|
||||||
else:
|
else:
|
||||||
# @search player
|
# @search player
|
||||||
if len(first_check_split) == 1:
|
if len(first_check_split) == 1:
|
||||||
#session.msg("@search player")
|
#source_object.emit_to("@search player")
|
||||||
#session.msg(first_check_split)
|
#source_object.emit_to(first_check_split)
|
||||||
search_player = first_check_split[0]
|
search_player = first_check_split[0]
|
||||||
else:
|
else:
|
||||||
#session.msg("@search player class=restriction")
|
#source_object.emit_to("@search player class=restriction")
|
||||||
#session.msg(first_check_split)
|
#source_object.emit_to(first_check_split)
|
||||||
search_player = first_check_split[0]
|
search_player = first_check_split[0]
|
||||||
eq_split = first_check_split[1].split('=', 1)
|
eq_split = first_check_split[1].split('=', 1)
|
||||||
search_type = eq_split[0]
|
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(',')
|
restriction_split = eq_split[1].split(',')
|
||||||
search_restriction = restriction_split[0]
|
search_restriction = restriction_split[0]
|
||||||
#session.msg("restriction_split: %s" % restriction_split)
|
#source_object.emit_to("restriction_split: %s" % restriction_split)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
search_low_dbnum, search_high_dbnum = _parse_restriction_split(session,
|
search_low_dbnum, search_high_dbnum = _parse_restriction_split(source_object,
|
||||||
restriction_split,
|
restriction_split,
|
||||||
search_low_dbnum,
|
search_low_dbnum,
|
||||||
search_high_dbnum)
|
search_high_dbnum)
|
||||||
|
|
@ -207,11 +206,11 @@ def cmd_search(command):
|
||||||
|
|
||||||
search_query = Object.objects.all()
|
search_query = Object.objects.all()
|
||||||
|
|
||||||
#session.msg("search_player: %s" % search_player)
|
#source_object.emit_to("search_player: %s" % search_player)
|
||||||
#session.msg("search_type: %s" % search_type)
|
#source_object.emit_to("search_type: %s" % search_type)
|
||||||
#session.msg("search_restriction: %s" % search_restriction)
|
#source_object.emit_to("search_restriction: %s" % search_restriction)
|
||||||
#session.msg("search_lowdb: %s" % search_low_dbnum)
|
#source_object.emit_to("search_lowdb: %s" % search_low_dbnum)
|
||||||
#session.msg("search_highdb: %s" % search_high_dbnum)
|
#source_object.emit_to("search_highdb: %s" % search_high_dbnum)
|
||||||
|
|
||||||
# Clean up these variables for comparisons.
|
# Clean up these variables for comparisons.
|
||||||
try:
|
try:
|
||||||
|
|
@ -224,7 +223,7 @@ def cmd_search(command):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Build the search query.
|
# 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_restriction, search_low_dbnum,
|
||||||
search_high_dbnum)
|
search_high_dbnum)
|
||||||
|
|
||||||
|
|
@ -232,4 +231,4 @@ def cmd_search(command):
|
||||||
if search_query is None:
|
if search_query is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
display_results(session, search_query)
|
display_results(source_object, search_query)
|
||||||
|
|
@ -159,11 +159,11 @@ def plr_del_channel(session, alias):
|
||||||
"""
|
"""
|
||||||
del plr_get_cdict(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.
|
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.
|
channel_name: (str) The channel's full name.
|
||||||
"""
|
"""
|
||||||
cobj = get_cobj_from_name(channel_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")
|
time_str = entry.date_sent.strftime("%m.%d / %H:%M")
|
||||||
else:
|
else:
|
||||||
time_str = entry.date_sent.strftime("%H:%M")
|
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.
|
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.
|
channel_name: (str) The channel's full name.
|
||||||
"""
|
"""
|
||||||
pobject = session.get_pobject()
|
target_obj.emit_to("--- Users Listening to %s ---" % (channel_name,))
|
||||||
session.msg("--- Users Listening to %s ---" % (channel_name,))
|
|
||||||
for plr_sess in get_cwho_list(channel_name):
|
for plr_sess in get_cwho_list(channel_name):
|
||||||
session.msg(plr_sess.get_pobject().get_name(show_dbref=pobject.sees_dbrefs()))
|
target_obj.emit_to(plr_sess.get_pobject().get_name(show_dbref=target_obj.sees_dbrefs()))
|
||||||
session.msg("--- End Channel Listeners ---")
|
target_obj.emit_to("--- End Channel Listeners ---")
|
||||||
|
|
||||||
def get_cwho_list(channel_name, return_muted=False):
|
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")
|
chan_list = pobject.get_attribute_value("__CHANLIST")
|
||||||
if chan_list:
|
if chan_list:
|
||||||
session = session_mgr.session_from_object(pobject)
|
sessions = session_mgr.sessions_from_object(pobject)
|
||||||
session.channels_subscribed = simplejson.loads(chan_list)
|
for session in sessions:
|
||||||
|
session.channels_subscribed = simplejson.loads(chan_list)
|
||||||
|
|
||||||
def send_cmessage(channel_name, message):
|
def send_cmessage(channel_name, message):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -100,30 +100,29 @@ class ObjectManager(models.Manager):
|
||||||
return [prospect for prospect in searchlist if prospect.name_match(ostring, match_type=match_type)]
|
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,
|
search_location=True, dbref_only=False,
|
||||||
limit_types=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.
|
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.
|
ostring: (str) The string to match object names against.
|
||||||
"""
|
"""
|
||||||
pobject = session.get_pobject()
|
results = self.local_and_global_search(source_object, ostring,
|
||||||
results = self.local_and_global_search(pobject, ostring,
|
|
||||||
search_contents=search_contents,
|
search_contents=search_contents,
|
||||||
search_location=search_location,
|
search_location=search_location,
|
||||||
dbref_only=dbref_only,
|
dbref_only=dbref_only,
|
||||||
limit_types=limit_types)
|
limit_types=limit_types)
|
||||||
|
|
||||||
if len(results) > 1:
|
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:
|
for result in results:
|
||||||
session.msg(" %s" % (result.get_name(),))
|
source_object.emit_to(" %s" % (result.get_name(),))
|
||||||
return False
|
return False
|
||||||
elif len(results) == 0:
|
elif len(results) == 0:
|
||||||
session.msg("I don't see that here.")
|
source_object.emit_to("I don't see that here.")
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return results[0]
|
return results[0]
|
||||||
|
|
@ -182,11 +181,11 @@ class ObjectManager(models.Manager):
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def is_dbref(self, dbstring):
|
def is_dbref(self, dbstring, require_pound=True):
|
||||||
"""
|
"""
|
||||||
Is the input a well-formed dbref number?
|
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):
|
def dbref_search(self, dbref_string, limit_types=False):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -136,14 +136,14 @@ class Object(models.Model):
|
||||||
"""
|
"""
|
||||||
BEGIN COMMON METHODS
|
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():
|
if self.is_player():
|
||||||
return session_mgr.session_from_object(self)
|
return session_mgr.sessions_from_object(self)
|
||||||
else:
|
else:
|
||||||
return None
|
return []
|
||||||
|
|
||||||
def emit_to(self, message):
|
def emit_to(self, message):
|
||||||
"""
|
"""
|
||||||
|
|
@ -155,11 +155,17 @@ class Object(models.Model):
|
||||||
if not self.is_player():
|
if not self.is_player():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
session = self.get_session()
|
sessions = self.get_sessions()
|
||||||
if session:
|
for session in sessions:
|
||||||
session.msg(ansi.parse_ansi(message))
|
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):
|
def emit_to_contents(self, message, exclude=None):
|
||||||
"""
|
"""
|
||||||
|
|
@ -223,7 +229,7 @@ class Object(models.Model):
|
||||||
else:
|
else:
|
||||||
return False
|
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
|
Checks to see whether a user has the specified permission or is a super
|
||||||
user.
|
user.
|
||||||
|
|
@ -241,7 +247,7 @@ class Object(models.Model):
|
||||||
else:
|
else:
|
||||||
return False
|
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
|
Checks to see whether a user has the specified permission or is a super
|
||||||
user. This form accepts an iterable of strings representing permissions,
|
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
|
# When builder_override is enabled, a builder permission means
|
||||||
# the object controls the other.
|
# 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
|
return True
|
||||||
|
|
||||||
# They've failed to meet any of the above conditions.
|
# 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.
|
# See if we need to kick the player off.
|
||||||
session = self.get_session()
|
sessions = self.get_sessions()
|
||||||
if session:
|
for session in sessions:
|
||||||
session.msg("You have been destroyed, goodbye.")
|
session.msg("You have been destroyed, goodbye.")
|
||||||
session.handle_close()
|
session.handle_close()
|
||||||
|
|
||||||
|
|
@ -655,12 +661,11 @@ class Object(models.Model):
|
||||||
Is this object a connected player?
|
Is this object a connected player?
|
||||||
"""
|
"""
|
||||||
if self.is_player():
|
if self.is_player():
|
||||||
if self.get_session():
|
if self.get_sessions():
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
# No matches or not a player
|
||||||
else:
|
return False
|
||||||
return False
|
|
||||||
|
|
||||||
def get_owner(self):
|
def get_owner(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -798,9 +803,7 @@ class Object(models.Model):
|
||||||
if self.location.is_player():
|
if self.location.is_player():
|
||||||
self.location.emit_to("%s is now in your inventory." % (self.get_name()))
|
self.location.emit_to("%s is now in your inventory." % (self.get_name()))
|
||||||
|
|
||||||
session = self.get_session()
|
self.execute_cmd('look')
|
||||||
if force_look and self.is_player() and session:
|
|
||||||
self.get_session().execute_cmd('look')
|
|
||||||
|
|
||||||
def dbref_match(self, oname):
|
def dbref_match(self, oname):
|
||||||
"""
|
"""
|
||||||
|
|
@ -920,7 +923,7 @@ class CommChannel(models.Model):
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
ansi_name = models.CharField(max_length=255)
|
ansi_name = models.CharField(max_length=255)
|
||||||
owner = models.ForeignKey(Object, related_name="chan_owner")
|
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)
|
is_joined_by_default = models.BooleanField(default=False)
|
||||||
req_grp = models.ManyToManyField(Group, blank=True, null=True)
|
req_grp = models.ManyToManyField(Group, blank=True, null=True)
|
||||||
|
|
||||||
|
|
@ -1024,3 +1027,6 @@ class CommChannelMessage(models.Model):
|
||||||
class CommChannelMessageAdmin(admin.ModelAdmin):
|
class CommChannelMessageAdmin(admin.ModelAdmin):
|
||||||
list_display = ('channel', 'message')
|
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
|
||||||
|
|
@ -2,13 +2,17 @@
|
||||||
Utility functions for the Object class. These functions should not import
|
Utility functions for the Object class. These functions should not import
|
||||||
any models or modify the database.
|
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?
|
Is the input a well-formed dbref number?
|
||||||
"""
|
"""
|
||||||
# Strip the leading # sign if it's there.
|
# Strip the leading # sign if it's there.
|
||||||
if dbstring.startswith("#"):
|
if dbstring.startswith("#"):
|
||||||
dbstring = dbstring[1:]
|
dbstring = dbstring[1:]
|
||||||
|
else:
|
||||||
|
if require_pound:
|
||||||
|
# The pound sign was required and it didn't have it, fail out.
|
||||||
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# If this fails, it's probably not valid.
|
# If this fails, it's probably not valid.
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,13 @@ import time
|
||||||
from src import comsys
|
from src import comsys
|
||||||
|
|
||||||
class EvenniaBasicPlayer(object):
|
class EvenniaBasicPlayer(object):
|
||||||
def at_pre_login(self):
|
def at_pre_login(self, session):
|
||||||
"""
|
"""
|
||||||
Everything done here takes place before the player is actually
|
Everything done here takes place before the player is actually
|
||||||
'logged in', in a sense that they're not ready to send logged in
|
'logged in', in a sense that they're not ready to send logged in
|
||||||
commands or receive communication.
|
commands or receive communication.
|
||||||
"""
|
"""
|
||||||
pobject = self.source_obj
|
pobject = self.source_obj
|
||||||
session = pobject.get_session()
|
|
||||||
|
|
||||||
# Load the player's channels from their JSON __CHANLIST attribute.
|
# Load the player's channels from their JSON __CHANLIST attribute.
|
||||||
comsys.load_object_channels(pobject)
|
comsys.load_object_channels(pobject)
|
||||||
|
|
@ -24,15 +23,14 @@ class EvenniaBasicPlayer(object):
|
||||||
pobject.set_attribute("Lastsite", "%s" % (session.address[0],))
|
pobject.set_attribute("Lastsite", "%s" % (session.address[0],))
|
||||||
pobject.set_flag("CONNECTED", True)
|
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
|
The user is now logged in. This is what happens right after the moment
|
||||||
they are 'connected'.
|
they are 'connected'.
|
||||||
"""
|
"""
|
||||||
pobject = self.source_obj
|
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_location().emit_to_contents("%s has connected." %
|
||||||
(pobject.get_name(show_dbref=False),), exclude=pobject)
|
(pobject.get_name(show_dbref=False),), exclude=pobject)
|
||||||
session.execute_cmd("look")
|
pobject.execute_cmd("look")
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,18 @@ from twisted.application import internet, service
|
||||||
from twisted.internet import protocol, reactor, defer
|
from twisted.internet import protocol, reactor, defer
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.conf import settings
|
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.session import SessionProtocol
|
||||||
from src import scheduler
|
from src import scheduler
|
||||||
from src import logger
|
from src import logger
|
||||||
from src import session_mgr
|
from src import session_mgr
|
||||||
|
from src import alias_mgr
|
||||||
from src import cmdtable
|
from src import cmdtable
|
||||||
from src import initial_setup
|
from src import initial_setup
|
||||||
from src.util import functions_general
|
from src.util import functions_general
|
||||||
|
|
||||||
class EvenniaService(service.Service):
|
class EvenniaService(service.Service):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# This holds a dictionary of command aliases for cmdhandler.py
|
|
||||||
self.cmd_alias_list = {}
|
|
||||||
self.game_running = True
|
self.game_running = True
|
||||||
sys.path.append('.')
|
sys.path.append('.')
|
||||||
|
|
||||||
|
|
@ -38,29 +37,21 @@ class EvenniaService(service.Service):
|
||||||
print ' Game started for the first time, setting defaults.'
|
print ' Game started for the first time, setting defaults.'
|
||||||
initial_setup.handle_setup()
|
initial_setup.handle_setup()
|
||||||
|
|
||||||
# Load command aliases into memory for easy/quick access.
|
|
||||||
self.load_cmd_aliases()
|
|
||||||
self.start_time = time.time()
|
self.start_time = time.time()
|
||||||
|
|
||||||
print ' %s started on port(s):' % (ConfigValue.objects.get_configvalue('site_name'),)
|
print ' %s started on port(s):' % (ConfigValue.objects.get_configvalue('site_name'),)
|
||||||
for port in settings.GAMEPORTS:
|
for port in settings.GAMEPORTS:
|
||||||
print ' * %s' % (port)
|
print ' * %s' % (port)
|
||||||
|
|
||||||
|
# Cache the aliases from the database for quick access.
|
||||||
|
alias_mgr.load_cmd_aliases()
|
||||||
|
|
||||||
print '-'*50
|
print '-'*50
|
||||||
scheduler.start_events()
|
scheduler.start_events()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
BEGIN SERVER STARTUP METHODS
|
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):
|
def sqlite3_prep(self):
|
||||||
"""
|
"""
|
||||||
Optimize some SQLite stuff at startup since we can't save it to the
|
Optimize some SQLite stuff at startup since we can't save it to the
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,8 @@ needed to manage them.
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from twisted.conch.telnet import StatefulTelnetProtocol
|
from twisted.conch.telnet import StatefulTelnetProtocol
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from src.objects.models import Object, CommChannel
|
from src.objects.models import Object, CommChannel
|
||||||
from src.config.models import ConnectScreen, ConfigValue
|
from src.config.models import ConnectScreen, ConfigValue
|
||||||
from util import functions_general
|
from util import functions_general
|
||||||
|
|
@ -46,6 +43,7 @@ class SessionProtocol(StatefulTelnetProtocol):
|
||||||
self.address = self.getClientAddress()
|
self.address = self.getClientAddress()
|
||||||
self.name = None
|
self.name = None
|
||||||
self.uid = None
|
self.uid = None
|
||||||
|
self.pobject = None
|
||||||
self.logged_in = False
|
self.logged_in = False
|
||||||
# The time the user last issued a command.
|
# The time the user last issued a command.
|
||||||
self.cmd_last = time.time()
|
self.cmd_last = time.time()
|
||||||
|
|
@ -73,28 +71,20 @@ class SessionProtocol(StatefulTelnetProtocol):
|
||||||
def lineReceived(self, data):
|
def lineReceived(self, data):
|
||||||
"""
|
"""
|
||||||
Any line return indicates a command for the purpose of a MUD. So we take
|
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.
|
if self.pobject:
|
||||||
line = (''.join(data))
|
# Session is logged in, run through the normal object execution.
|
||||||
line = line.strip('\r')
|
self.pobject.execute_cmd(data, session=self)
|
||||||
uinput = line
|
else:
|
||||||
|
# Not logged in, manually execute the command.
|
||||||
|
cmdhandler.handle(cmdhandler.Command(None, data, session=self))
|
||||||
|
|
||||||
# The Command object has all of the methods for parsing and preparing
|
def execute_cmd(self, command_str):
|
||||||
# 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)
|
|
||||||
|
|
||||||
def execute_cmd(self, cmdstr):
|
|
||||||
"""
|
"""
|
||||||
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):
|
def count_command(self, silently=False):
|
||||||
"""
|
"""
|
||||||
|
|
@ -104,9 +94,9 @@ class SessionProtocol(StatefulTelnetProtocol):
|
||||||
"""
|
"""
|
||||||
# Store the timestamp of the user's last command.
|
# Store the timestamp of the user's last command.
|
||||||
self.cmd_last = time.time()
|
self.cmd_last = time.time()
|
||||||
# Increment the user's command counter.
|
|
||||||
self.cmd_total += 1
|
|
||||||
if not silently:
|
if not silently:
|
||||||
|
# Increment the user's command counter.
|
||||||
|
self.cmd_total += 1
|
||||||
# Player-visible idle time, not used in idle timeout calcs.
|
# Player-visible idle time, not used in idle timeout calcs.
|
||||||
self.cmd_last_visible = time.time()
|
self.cmd_last_visible = time.time()
|
||||||
|
|
||||||
|
|
@ -130,8 +120,14 @@ class SessionProtocol(StatefulTelnetProtocol):
|
||||||
"""
|
"""
|
||||||
Returns the object associated with a session.
|
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:
|
try:
|
||||||
|
# Cache the result in the session object for quick retrieval.
|
||||||
result = Object.objects.get(id=self.uid)
|
result = Object.objects.get(id=self.uid)
|
||||||
|
self.pobject = result
|
||||||
return result
|
return result
|
||||||
except:
|
except:
|
||||||
logger.log_errmsg("No pobject match for session uid: %s" % self.uid)
|
logger.log_errmsg("No pobject match for session uid: %s" % self.uid)
|
||||||
|
|
@ -162,11 +158,12 @@ class SessionProtocol(StatefulTelnetProtocol):
|
||||||
self.name = user.username
|
self.name = user.username
|
||||||
self.logged_in = True
|
self.logged_in = True
|
||||||
self.conn_time = time.time()
|
self.conn_time = time.time()
|
||||||
pobject = self.get_pobject()
|
# This will cache with the first call of this function.
|
||||||
session_mgr.disconnect_duplicate_session(self)
|
self.get_pobject()
|
||||||
|
#session_mgr.disconnect_duplicate_session(self)
|
||||||
|
|
||||||
pobject.scriptlink.at_pre_login()
|
self.pobject.scriptlink.at_pre_login(self)
|
||||||
pobject.scriptlink.at_post_login()
|
self.pobject.scriptlink.at_post_login(self)
|
||||||
|
|
||||||
logger.log_infomsg("Login: %s" % (self,))
|
logger.log_infomsg("Login: %s" % (self,))
|
||||||
|
|
||||||
|
|
@ -175,9 +172,9 @@ class SessionProtocol(StatefulTelnetProtocol):
|
||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
# In case the account and the object get out of sync, fix it.
|
# In case the account and the object get out of sync, fix it.
|
||||||
if pobject.name != user.username:
|
if self.pobject.name != user.username:
|
||||||
pobject.set_name(user.username)
|
self.pobject.set_name(user.username)
|
||||||
pobject.save()
|
self.pobject.save()
|
||||||
|
|
||||||
def msg(self, message):
|
def msg(self, message):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -77,31 +77,13 @@ def remove_session(session):
|
||||||
pass
|
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.
|
targobject: (Object) The object to match.
|
||||||
"""
|
"""
|
||||||
results = [prospect for prospect in session_list if prospect.get_pobject() == targobject]
|
return [prospect for prospect in session_list if prospect.get_pobject() == targ_object]
|
||||||
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
|
|
||||||
|
|
||||||
def announce_all(message, with_ann_prefix=True):
|
def announce_all(message, with_ann_prefix=True):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue