Big re-organization of command functions. Introduced the commands directory to hold command modules. This will make it easier to sub-divide stuff as we pile on more commands, and for dropping in new optional command modules.
This commit is contained in:
parent
a10df7ec6b
commit
0e9732d49c
17 changed files with 535 additions and 527 deletions
0
commands/__init__.py
Normal file
0
commands/__init__.py
Normal file
293
commands/comsys.py
Normal file
293
commands/comsys.py
Normal file
|
|
@ -0,0 +1,293 @@
|
|||
import time
|
||||
|
||||
import settings
|
||||
import functions_general
|
||||
import functions_db
|
||||
import functions_help
|
||||
import functions_comsys
|
||||
import defines_global
|
||||
import ansi
|
||||
"""
|
||||
Comsys command module. Pretty much every comsys command should go here for
|
||||
now.
|
||||
"""
|
||||
|
||||
def cmd_addcom(cdat):
|
||||
"""
|
||||
addcom
|
||||
|
||||
Adds an alias for a channel.
|
||||
addcom foo=Bar
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
server = cdat['server']
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("You need to specify a channel alias and name.")
|
||||
return
|
||||
|
||||
eq_args = args[0].split('=')
|
||||
|
||||
if len(eq_args) < 2:
|
||||
session.msg("You need to specify a channel name.")
|
||||
return
|
||||
|
||||
chan_alias = eq_args[0]
|
||||
chan_name = eq_args[1]
|
||||
|
||||
if len(chan_name) == 0:
|
||||
session.msg("You need to specify a channel name.")
|
||||
return
|
||||
|
||||
if chan_alias in session.channels_subscribed:
|
||||
session.msg("You are already on that channel.")
|
||||
return
|
||||
|
||||
name_matches = functions_comsys.cname_search(chan_name, exact=True)
|
||||
|
||||
if name_matches:
|
||||
chan_name_parsed = name_matches[0].get_name()
|
||||
session.msg("You join %s, with an alias of %s." % \
|
||||
(chan_name_parsed, chan_alias))
|
||||
functions_comsys.plr_set_channel(session, chan_alias, chan_name_parsed, True)
|
||||
|
||||
# Announce the user's joining.
|
||||
join_msg = "[%s] %s has joined the channel." % \
|
||||
(chan_name_parsed, pobject.get_name(show_dbref=False))
|
||||
functions_comsys.send_cmessage(chan_name_parsed, join_msg)
|
||||
else:
|
||||
session.msg("Could not find channel %s." % (chan_name,))
|
||||
|
||||
def cmd_delcom(cdat):
|
||||
"""
|
||||
delcom
|
||||
|
||||
Removes the specified alias to a channel. If this is the last alias,
|
||||
the user is effectively removed from the channel.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
uinput= cdat['uinput']['splitted']
|
||||
chan_alias = ' '.join(uinput[1:])
|
||||
|
||||
if len(chan_alias) == 0:
|
||||
session.msg("You must specify a channel alias.")
|
||||
return
|
||||
|
||||
if chan_alias not in session.channels_subscribed:
|
||||
session.msg("You are not on that channel.")
|
||||
return
|
||||
|
||||
chan_name = session.channels_subscribed[chan_alias][0]
|
||||
session.msg("You have left %s." % (chan_name,))
|
||||
functions_comsys.plr_del_channel(session, chan_alias)
|
||||
|
||||
# Announce the user's leaving.
|
||||
leave_msg = "[%s] %s has left the channel." % \
|
||||
(chan_name, pobject.get_name(show_dbref=False))
|
||||
functions_comsys.send_cmessage(chan_name, leave_msg)
|
||||
|
||||
def cmd_comlist(cdat):
|
||||
"""
|
||||
Lists the channels a user is subscribed to.
|
||||
"""
|
||||
session = cdat['session']
|
||||
|
||||
session.msg("Alias Channel Status")
|
||||
for chan in session.channels_subscribed:
|
||||
if session.channels_subscribed[chan][1]:
|
||||
chan_on = "On"
|
||||
else:
|
||||
chan_on = "Off"
|
||||
|
||||
session.msg("%-9.9s %-19.19s %s" %
|
||||
(chan, session.channels_subscribed[chan][0], chan_on))
|
||||
session.msg("-- End of comlist --")
|
||||
|
||||
def cmd_allcom(cdat):
|
||||
"""
|
||||
allcom
|
||||
|
||||
Allows the user to universally turn off or on all channels they are on,
|
||||
as well as perform a "who" for all channels they are on.
|
||||
"""
|
||||
pass
|
||||
|
||||
def cmd_clearcom(cdat):
|
||||
"""
|
||||
clearcom
|
||||
|
||||
Effectively runs delcom on all channels the user is on. It will remove their aliases,
|
||||
remove them from the channel, and clear any titles they have set.
|
||||
"""
|
||||
pass
|
||||
|
||||
def cmd_clist(cdat):
|
||||
"""
|
||||
@clist
|
||||
|
||||
Lists all available channels on the game.
|
||||
"""
|
||||
session = cdat['session']
|
||||
session.msg("** Channel Owner Description")
|
||||
for chan in functions_comsys.get_all_channels():
|
||||
session.msg("%s%s %-13.13s %-15.15s %-45.45s" %
|
||||
('-', '-', chan.get_name(), chan.get_owner().get_name(), 'No Description'))
|
||||
session.msg("-- End of Channel List --")
|
||||
|
||||
def cmd_cdestroy(cdat):
|
||||
"""
|
||||
@cdestroy
|
||||
|
||||
Destroys a channel.
|
||||
"""
|
||||
session = cdat['session']
|
||||
uinput= cdat['uinput']['splitted']
|
||||
cname = ' '.join(uinput[1:])
|
||||
|
||||
if cname == '':
|
||||
session.msg("You must supply a name!")
|
||||
return
|
||||
|
||||
name_matches = functions_comsys.cname_search(cname, exact=True)
|
||||
|
||||
if not name_matches:
|
||||
session.msg("Could not find channel %s." % (cname,))
|
||||
else:
|
||||
session.msg("Channel %s destroyed." % (name_matches[0],))
|
||||
name_matches.delete()
|
||||
|
||||
def cmd_cset(cdat):
|
||||
"""
|
||||
@cset
|
||||
|
||||
Sets various flags on a channel.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def cmd_ccharge(cdat):
|
||||
"""
|
||||
@ccharge
|
||||
|
||||
Sets the cost to transmit over a channel. Default is free.
|
||||
"""
|
||||
pass
|
||||
|
||||
def cmd_cboot(cdat):
|
||||
"""
|
||||
@cboot
|
||||
|
||||
Kicks a player or object from the channel.
|
||||
"""
|
||||
pass
|
||||
|
||||
def cmd_cemit(cdat):
|
||||
"""
|
||||
@cemit
|
||||
@cemit/noheader <message>
|
||||
@cemit/sendername <message>
|
||||
|
||||
Allows the user to send a message over a channel as long as
|
||||
they own or control it. It does not show the user's name unless they
|
||||
provide the /sendername switch.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
server = cdat['server']
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
switches = cdat['uinput']['root_chunk'][1:]
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("Channel emit what?")
|
||||
return
|
||||
|
||||
# Combine the arguments into one string, split it by equal signs into
|
||||
# channel (entry 0 in the list), and message (entry 1 and above).
|
||||
eq_args = ' '.join(args).split('=')
|
||||
cname = eq_args[0]
|
||||
cmessage = ' '.join(eq_args[1:])
|
||||
if len(eq_args) != 2:
|
||||
session.msg("You must provide a channel name and a message to emit.")
|
||||
return
|
||||
if len(cname) == 0:
|
||||
session.msg("You must provide a channel name to emit to.")
|
||||
return
|
||||
if len(cmessage) == 0:
|
||||
session.msg("You must provide a message to emit.")
|
||||
return
|
||||
|
||||
name_matches = functions_comsys.cname_search(cname, exact=True)
|
||||
|
||||
try:
|
||||
# Safety first, kids!
|
||||
cname_parsed = name_matches[0].get_name()
|
||||
except:
|
||||
session.msg("Could not find channel %s." % (cname,))
|
||||
return
|
||||
|
||||
if "noheader" in switches:
|
||||
if not pobject.user_has_perm("objects.emit_commchannel"):
|
||||
session.msg(defines_global.NOPERMS_MSG)
|
||||
return
|
||||
final_cmessage = cmessage
|
||||
else:
|
||||
if "sendername" in switches:
|
||||
if not functions_comsys.plr_has_channel(session, cname_parsed, return_muted=False):
|
||||
session.msg("You must be on %s to do that." % (cname_parsed,))
|
||||
return
|
||||
final_cmessage = "[%s] %s: %s" % (cname_parsed, pobject.get_name(show_dbref=False), cmessage)
|
||||
else:
|
||||
if not pobject.user_has_perm("objects.emit_commchannel"):
|
||||
session.msg(defines_global.NOPERMS_MSG)
|
||||
return
|
||||
final_cmessage = "[%s] %s" % (cname_parsed, cmessage)
|
||||
|
||||
if not "quiet" in switches:
|
||||
session.msg("Sent - %s" % (name_matches[0],))
|
||||
functions_comsys.send_cmessage(cname_parsed, final_cmessage)
|
||||
|
||||
def cmd_cwho(cdat):
|
||||
"""
|
||||
@cwho
|
||||
|
||||
Displays the name, status and object type for a given channel.
|
||||
Adding /all after the channel name will list disconnected players
|
||||
as well.
|
||||
"""
|
||||
pass
|
||||
|
||||
def cmd_ccreate(cdat):
|
||||
"""
|
||||
@ccreate
|
||||
|
||||
Creates a new channel with the invoker being the default owner.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
uinput= cdat['uinput']['splitted']
|
||||
cname = ' '.join(uinput[1:])
|
||||
|
||||
if cname == '':
|
||||
session.msg("You must supply a name!")
|
||||
return
|
||||
|
||||
name_matches = functions_comsys.cname_search(cname, exact=True)
|
||||
|
||||
if name_matches:
|
||||
session.msg("A channel with that name already exists.")
|
||||
else:
|
||||
# Create and set the object up.
|
||||
cdat = {"name": cname, "owner": pobject}
|
||||
new_chan = functions_comsys.create_channel(cdat)
|
||||
session.msg("Channel %s created." % (new_chan.get_name(),))
|
||||
|
||||
def cmd_cchown(cdat):
|
||||
"""
|
||||
@cchown
|
||||
|
||||
Changes the owner of a channel.
|
||||
"""
|
||||
pass
|
||||
507
commands/general.py
Normal file
507
commands/general.py
Normal file
|
|
@ -0,0 +1,507 @@
|
|||
import os, time
|
||||
import settings
|
||||
import functions_general
|
||||
import functions_db
|
||||
import functions_help
|
||||
import defines_global
|
||||
import session_mgr
|
||||
import ansi
|
||||
"""
|
||||
Generic command module. Pretty much every command should go here for
|
||||
now.
|
||||
"""
|
||||
def cmd_password(cdat):
|
||||
"""
|
||||
Changes your own password.
|
||||
|
||||
@newpass <Oldpass>=<Newpass>
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
eq_args = ' '.join(args).split('=')
|
||||
oldpass = ''.join(eq_args[0])
|
||||
newpass = ''.join(eq_args[1:])
|
||||
|
||||
if len(oldpass) == 0:
|
||||
session.msg("You must provide your old password.")
|
||||
elif len(newpass) == 0:
|
||||
session.msg("You must provide your new password.")
|
||||
else:
|
||||
uaccount = pobject.get_user_account()
|
||||
|
||||
if not uaccount.check_password(oldpass):
|
||||
session.msg("The specified old password isn't correct.")
|
||||
elif len(newpass) < 3:
|
||||
session.msg("Passwords must be at least three characters long.")
|
||||
return
|
||||
else:
|
||||
uaccount.set_password(newpass)
|
||||
uaccount.save()
|
||||
session.msg("Password changed.")
|
||||
|
||||
def cmd_emit(cdat):
|
||||
"""
|
||||
Emits something to your location.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
uinput= cdat['uinput']['splitted']
|
||||
message = ' '.join(uinput[1:])
|
||||
|
||||
if message == '':
|
||||
session.msg("Emit what?")
|
||||
else:
|
||||
pobject.get_location().emit_to_contents(message)
|
||||
|
||||
def cmd_wall(cdat):
|
||||
"""
|
||||
Announces a message to all connected players.
|
||||
"""
|
||||
session = cdat['session']
|
||||
wallstring = ' '.join(cdat['uinput']['splitted'][1:])
|
||||
pobject = session.get_pobject()
|
||||
|
||||
if wallstring == '':
|
||||
session.msg("Announce what?")
|
||||
return
|
||||
|
||||
message = "%s shouts \"%s\"" % (session.get_pobject().get_name(show_dbref=False), wallstring)
|
||||
functions_general.announce_all(message)
|
||||
|
||||
def cmd_idle(cdat):
|
||||
"""
|
||||
Returns nothing, this lets the player set an idle timer without spamming
|
||||
his screen.
|
||||
"""
|
||||
pass
|
||||
|
||||
def cmd_inventory(cdat):
|
||||
"""
|
||||
Shows a player's inventory.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
session.msg("You are carrying:")
|
||||
|
||||
for item in pobject.get_contents():
|
||||
session.msg(" %s" % (item.get_name(),))
|
||||
|
||||
money = int(pobject.get_attribute_value("MONEY", default=0))
|
||||
if money == 1:
|
||||
money_name = functions_db.get_server_config("MONEY_NAME_SINGULAR")
|
||||
else:
|
||||
money_name = functions_db.get_server_config("MONEY_NAME_PLURAL")
|
||||
|
||||
session.msg("You have %d %s." % (money,money_name))
|
||||
|
||||
def cmd_look(cdat):
|
||||
"""
|
||||
Handle looking at objects.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
|
||||
if len(args) == 0:
|
||||
target_obj = pobject.get_location()
|
||||
else:
|
||||
target_obj = functions_db.standard_plr_objsearch(session, ' '.join(args))
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
retval = "%s\r\n%s" % (
|
||||
target_obj.get_name(),
|
||||
target_obj.get_description(),
|
||||
)
|
||||
session.msg(retval)
|
||||
|
||||
con_players = []
|
||||
con_things = []
|
||||
con_exits = []
|
||||
|
||||
for obj in target_obj.get_contents():
|
||||
if obj.is_player():
|
||||
if obj != pobject and obj.is_connected_plr():
|
||||
con_players.append(obj)
|
||||
elif obj.is_exit():
|
||||
con_exits.append(obj)
|
||||
else:
|
||||
con_things.append(obj)
|
||||
|
||||
if con_players:
|
||||
session.msg("%sPlayers:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
|
||||
for player in con_players:
|
||||
session.msg('%s' %(player.get_name(),))
|
||||
if con_things:
|
||||
session.msg("%sContents:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
|
||||
for thing in con_things:
|
||||
session.msg('%s' %(thing.get_name(),))
|
||||
if con_exits:
|
||||
session.msg("%sExits:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
|
||||
for exit in con_exits:
|
||||
session.msg('%s' %(exit.get_name(),))
|
||||
|
||||
def cmd_get(cdat):
|
||||
"""
|
||||
Get an object and put it in a player's inventory.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
plr_is_staff = pobject.is_staff()
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("Get what?")
|
||||
return
|
||||
else:
|
||||
target_obj = functions_db.standard_plr_objsearch(session, ' '.join(args), search_contents=False)
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
if pobject == target_obj:
|
||||
session.msg("You can't get yourself.")
|
||||
return
|
||||
|
||||
if not plr_is_staff and (target_obj.is_player() or target_obj.is_exit()):
|
||||
session.msg("You can't get that.")
|
||||
return
|
||||
|
||||
if target_obj.is_room() or target_obj.is_garbage() or target_obj.is_going():
|
||||
session.msg("You can't get that.")
|
||||
return
|
||||
|
||||
target_obj.move_to(pobject, quiet=True)
|
||||
session.msg("You pick up %s." % (target_obj.get_name(),))
|
||||
pobject.get_location().emit_to_contents("%s picks up %s." % (pobject.get_name(), target_obj.get_name()), exclude=pobject)
|
||||
|
||||
def cmd_drop(cdat):
|
||||
"""
|
||||
Drop an object from a player's inventory into their current location.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
plr_is_staff = pobject.is_staff()
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("Drop what?")
|
||||
return
|
||||
else:
|
||||
target_obj = functions_db.standard_plr_objsearch(session, ' '.join(args), search_location=False)
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
if not pobject == target_obj.get_location():
|
||||
session.msg("You don't appear to be carrying that.")
|
||||
return
|
||||
|
||||
target_obj.move_to(pobject.get_location(), quiet=True)
|
||||
session.msg("You drop %s." % (target_obj.get_name(),))
|
||||
pobject.get_location().emit_to_contents("%s drops %s." % (pobject.get_name(), target_obj.get_name()), exclude=pobject)
|
||||
|
||||
def cmd_examine(cdat):
|
||||
"""
|
||||
Detailed object examine command
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
attr_search = False
|
||||
|
||||
if len(args) == 0:
|
||||
# If no arguments are provided, examine the invoker's location.
|
||||
target_obj = pobject.get_location()
|
||||
else:
|
||||
# Look for a slash in the input, indicating an attribute search.
|
||||
attr_split = args[0].split("/")
|
||||
|
||||
# If the splitting by the "/" character returns a list with more than 1
|
||||
# entry, it's an attribute match.
|
||||
if len(attr_split) > 1:
|
||||
attr_search = True
|
||||
# Strip the object search string from the input with the
|
||||
# object/attribute pair.
|
||||
searchstr = attr_split[0]
|
||||
# Just in case there's a slash in an attribute name.
|
||||
attr_searchstr = '/'.join(attr_split[1:])
|
||||
else:
|
||||
searchstr = ' '.join(args)
|
||||
|
||||
target_obj = functions_db.standard_plr_objsearch(session, searchstr)
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
if attr_search:
|
||||
attr_matches = target_obj.attribute_namesearch(attr_searchstr)
|
||||
if attr_matches:
|
||||
for attribute in attr_matches:
|
||||
session.msg(attribute.get_attrline())
|
||||
else:
|
||||
session.msg("No matching attributes found.")
|
||||
# End attr_search if()
|
||||
else:
|
||||
session.msg("%s\r\n%s" % (
|
||||
target_obj.get_name(fullname=True),
|
||||
target_obj.get_description(no_parsing=True),
|
||||
))
|
||||
session.msg("Type: %s Flags: %s" % (target_obj.get_type(), target_obj.get_flags()))
|
||||
session.msg("Owner: %s " % (target_obj.get_owner(),))
|
||||
session.msg("Zone: %s" % (target_obj.get_zone(),))
|
||||
|
||||
for attribute in target_obj.get_all_attributes():
|
||||
session.msg(attribute.get_attrline())
|
||||
|
||||
con_players = []
|
||||
con_things = []
|
||||
con_exits = []
|
||||
|
||||
for obj in target_obj.get_contents():
|
||||
if obj.is_player():
|
||||
con_players.append(obj)
|
||||
elif obj.is_exit():
|
||||
con_exits.append(obj)
|
||||
elif obj.is_thing():
|
||||
con_things.append(obj)
|
||||
|
||||
if con_players or con_things:
|
||||
session.msg("%sContents:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
|
||||
for player in con_players:
|
||||
session.msg('%s' % (player.get_name(fullname=True),))
|
||||
for thing in con_things:
|
||||
session.msg('%s' % (thing.get_name(fullname=True),))
|
||||
|
||||
if con_exits:
|
||||
session.msg("%sExits:%s" % (ansi.ansi["hilite"], ansi.ansi["normal"],))
|
||||
for exit in con_exits:
|
||||
session.msg('%s' %(exit.get_name(fullname=True),))
|
||||
|
||||
if not target_obj.is_room():
|
||||
if target_obj.is_exit():
|
||||
session.msg("Destination: %s" % (target_obj.get_home(),))
|
||||
else:
|
||||
session.msg("Home: %s" % (target_obj.get_home(),))
|
||||
|
||||
session.msg("Location: %s" % (target_obj.get_location(),))
|
||||
|
||||
def cmd_page(cdat):
|
||||
"""
|
||||
Send a message to target user (if online).
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
server = cdat['server']
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("Page who/what?")
|
||||
return
|
||||
|
||||
# Combine the arguments into one string, split it by equal signs into
|
||||
# victim (entry 0 in the list), and message (entry 1 and above).
|
||||
eq_args = ' '.join(args).split('=')
|
||||
|
||||
# If no equal sign is in the passed arguments, see if the player has
|
||||
# a LASTPAGED attribute. If they do, default the page to them, if not,
|
||||
# don't touch anything and error out.
|
||||
if len(eq_args) == 1 and pobject.has_attribute("LASTPAGED"):
|
||||
eq_args.insert(0, "#%s" % (pobject.get_attribute_value("LASTPAGED"),))
|
||||
|
||||
if len(eq_args) > 1:
|
||||
target = functions_db.player_search(pobject, eq_args[0])
|
||||
message = ' '.join(eq_args[1:])
|
||||
|
||||
if len(target) == 0:
|
||||
session.msg("I don't recognize \"%s\"." % (eq_args[0].capitalize(),))
|
||||
return
|
||||
elif len(message) == 0:
|
||||
session.msg("I need a message to deliver.")
|
||||
return
|
||||
elif len(target) > 1:
|
||||
session.msg("Try a more unique spelling of their name.")
|
||||
return
|
||||
else:
|
||||
if target[0].is_connected_plr():
|
||||
target[0].emit_to("%s pages: %s" %
|
||||
(pobject.get_name(show_dbref=False), message))
|
||||
session.msg("You paged %s with '%s'." %
|
||||
(target[0].get_name(show_dbref=False), message))
|
||||
pobject.set_attribute("LASTPAGED", target[0].id)
|
||||
else:
|
||||
session.msg("Player %s does not exist or is not online." %
|
||||
(target[0].get_name(show_dbref=False),))
|
||||
else:
|
||||
session.msg("Page who?")
|
||||
return
|
||||
|
||||
def cmd_quit(cdat):
|
||||
"""
|
||||
Gracefully disconnect the user as per his own request.
|
||||
"""
|
||||
session = cdat['session']
|
||||
session.msg("Quitting!")
|
||||
session.handle_close()
|
||||
|
||||
def cmd_who(cdat):
|
||||
"""
|
||||
Generic WHO command.
|
||||
"""
|
||||
session_list = session_mgr.get_session_list()
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
show_session_data = pobject.user_has_perm("genperms.see_session_data")
|
||||
|
||||
# Only those with the see_session_data or superuser status can see
|
||||
# session details.
|
||||
if show_session_data:
|
||||
retval = "Player Name On For Idle Room Cmds Host\n\r"
|
||||
else:
|
||||
retval = "Player Name On For Idle\n\r"
|
||||
|
||||
for player in session_list:
|
||||
if not player.logged_in:
|
||||
continue
|
||||
delta_cmd = time.time() - player.cmd_last_visible
|
||||
delta_conn = time.time() - player.conn_time
|
||||
plr_pobject = player.get_pobject()
|
||||
|
||||
if show_session_data:
|
||||
retval += '%-16s%9s %4s%-3s#%-6d%5d%3s%-25s\r\n' % \
|
||||
(plr_pobject.get_name(show_dbref=False)[:25].ljust(27), \
|
||||
# On-time
|
||||
functions_general.time_format(delta_conn,0), \
|
||||
# Idle time
|
||||
functions_general.time_format(delta_cmd,1), \
|
||||
# Flags
|
||||
'', \
|
||||
# Location
|
||||
plr_pobject.get_location().id, \
|
||||
player.cmd_total, \
|
||||
# More flags?
|
||||
'', \
|
||||
player.address[0])
|
||||
else:
|
||||
retval += '%-16s%9s %4s%-3s\r\n' % \
|
||||
(plr_pobject.get_name(show_dbref=False)[:25].ljust(27), \
|
||||
# On-time
|
||||
functions_general.time_format(delta_conn,0), \
|
||||
# Idle time
|
||||
functions_general.time_format(delta_cmd,1), \
|
||||
# Flags
|
||||
'')
|
||||
retval += '%d Players logged in.' % (len(session_list),)
|
||||
|
||||
session.msg(retval)
|
||||
|
||||
def cmd_say(cdat):
|
||||
"""
|
||||
Room-based speech command.
|
||||
"""
|
||||
session = cdat['session']
|
||||
|
||||
if not functions_general.cmd_check_num_args(session, cdat['uinput']['splitted'], 1, errortext="Say what?"):
|
||||
return
|
||||
|
||||
session_list = session_mgr.get_session_list()
|
||||
pobject = session.get_pobject()
|
||||
speech = ' '.join(cdat['uinput']['splitted'][1:])
|
||||
|
||||
players_present = [player for player in session_list if player.get_pobject().get_location() == session.get_pobject().get_location() and player != session]
|
||||
|
||||
retval = "You say, '%s'" % (speech,)
|
||||
for player in players_present:
|
||||
player.msg("%s says, '%s'" % (pobject.get_name(show_dbref=False), speech,))
|
||||
|
||||
session.msg(retval)
|
||||
|
||||
def cmd_pose(cdat):
|
||||
"""
|
||||
Pose/emote command.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
switches = cdat['uinput']['root_chunk'][1:]
|
||||
|
||||
if not functions_general.cmd_check_num_args(session, cdat['uinput']['splitted'], 1, errortext="Do what?"):
|
||||
return
|
||||
|
||||
session_list = session_mgr.get_session_list()
|
||||
speech = ' '.join(cdat['uinput']['splitted'][1:])
|
||||
|
||||
if "nospace" in switches:
|
||||
sent_msg = "%s%s" % (pobject.get_name(show_dbref=False), speech)
|
||||
else:
|
||||
sent_msg = "%s %s" % (pobject.get_name(show_dbref=False), speech)
|
||||
|
||||
players_present = [player for player in session_list if player.get_pobject().get_location() == session.get_pobject().get_location()]
|
||||
|
||||
for player in players_present:
|
||||
player.msg(sent_msg)
|
||||
|
||||
def cmd_help(cdat):
|
||||
"""
|
||||
Help system commands.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
topicstr = ' '.join(cdat['uinput']['splitted'][1:])
|
||||
|
||||
if len(topicstr) == 0:
|
||||
topicstr = "Help Index"
|
||||
elif len(topicstr) < 2 and not topicstr.isdigit():
|
||||
session.msg("Your search query is too short. It must be at least three letters long.")
|
||||
return
|
||||
|
||||
topics = functions_help.find_topicmatch(pobject, topicstr)
|
||||
|
||||
if len(topics) == 0:
|
||||
session.msg("No matching topics found, please refine your search.")
|
||||
suggestions = functions_help.find_topicsuggestions(pobject, topicstr)
|
||||
if len(suggestions) > 0:
|
||||
session.msg("Matching similarly named topics:")
|
||||
for result in suggestions:
|
||||
session.msg(" %s" % (result,))
|
||||
session.msg("You may type 'help <#>' to see any of these topics.")
|
||||
elif len(topics) > 1:
|
||||
session.msg("More than one match found:")
|
||||
for result in topics:
|
||||
session.msg("%3d. %s" % (result.id, result.get_topicname()))
|
||||
session.msg("You may type 'help <#>' to see any of these topics.")
|
||||
else:
|
||||
topic = topics[0]
|
||||
session.msg("\r\n%s%s%s" % (ansi.ansi["hilite"], topic.get_topicname(), ansi.ansi["normal"]))
|
||||
session.msg(topic.get_entrytext_ingame())
|
||||
|
||||
def cmd_version(cdat):
|
||||
"""
|
||||
Version info command.
|
||||
"""
|
||||
session = cdat['session']
|
||||
retval = "-"*50 +"\n\r"
|
||||
retval += "Evennia %s\n\r" % (defines_global.EVENNIA_VERSION,)
|
||||
retval += "-"*50
|
||||
session.msg(retval)
|
||||
|
||||
def cmd_time(cdat):
|
||||
"""
|
||||
Server local time.
|
||||
"""
|
||||
session = cdat['session']
|
||||
session.msg('Current server time : %s' % (time.strftime('%a %b %d %H:%M %Y (%Z)', time.localtime(),)))
|
||||
|
||||
def cmd_uptime(cdat):
|
||||
"""
|
||||
Server uptime and stats.
|
||||
"""
|
||||
session = cdat['session']
|
||||
server = cdat['server']
|
||||
start_delta = time.time() - server.start_time
|
||||
loadavg = os.getloadavg()
|
||||
session.msg('Current server time : %s' % (time.strftime('%a %b %d %H:%M %Y (%Z)', time.localtime(),)))
|
||||
session.msg('Server start time : %s' % (time.strftime('%a %b %d %H:%M %Y', time.localtime(server.start_time),)))
|
||||
session.msg('Server uptime : %s' % functions_general.time_format(start_delta, style=2))
|
||||
session.msg('Server load (1 min) : %.2f' % loadavg[0])
|
||||
62
commands/info.py
Normal file
62
commands/info.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import os, resource
|
||||
|
||||
import functions_db
|
||||
import scheduler
|
||||
|
||||
def cmd_list(cdat):
|
||||
"""
|
||||
Shows some game related information.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
argstr = ''.join(args)
|
||||
|
||||
msg_invalid = "Unknown option. Use one of: commands, flags, process"
|
||||
|
||||
if len(argstr) == 0:
|
||||
session.msg(msg_invalid)
|
||||
elif argstr == "commands":
|
||||
session.msg('Commands: '+ ' '.join(session.server.command_list()))
|
||||
elif argstr == "process":
|
||||
loadvg = os.getloadavg()
|
||||
psize = resource.getpagesize()
|
||||
rusage = resource.getrusage(resource.RUSAGE_SELF)
|
||||
session.msg("Process ID: %10d %10d bytes per page" % (os.getpid(), psize))
|
||||
session.msg("Time used: %10d user %10d sys" % (rusage[0],rusage[1]))
|
||||
session.msg("Integral mem:%10d shared %10d private%10d stack" % (rusage[3], rusage[4], rusage[5]))
|
||||
session.msg("Max res mem: %10d pages %10d bytes" % (rusage[2],rusage[2] * psize))
|
||||
session.msg("Page faults: %10d hard %10d soft %10d swapouts" % (rusage[7], rusage[6], rusage[8]))
|
||||
session.msg("Disk I/O: %10d reads %10d writes" % (rusage[9], rusage[10]))
|
||||
session.msg("Network I/O: %10d in %10d out" % (rusage[12], rusage[11]))
|
||||
session.msg("Context swi: %10d vol %10d forced %10d sigs" % (rusage[14], rusage[15], rusage[13]))
|
||||
elif argstr == "flags":
|
||||
session.msg("Flags: "+" ".join(defines_global.SERVER_FLAGS))
|
||||
else:
|
||||
session.msg(msg_invalid)
|
||||
|
||||
def cmd_ps(cdat):
|
||||
"""
|
||||
Shows the process/event table.
|
||||
"""
|
||||
session = cdat['session']
|
||||
session.msg("-- Interval Events --")
|
||||
for event in scheduler.schedule:
|
||||
session.msg(" [%d/%d] %s" % (scheduler.get_event_nextfire(event),
|
||||
scheduler.get_event_interval(event),
|
||||
scheduler.get_event_description(event)))
|
||||
session.msg("Totals: %d interval events" % (len(scheduler.schedule),))
|
||||
|
||||
def cmd_stats(cdat):
|
||||
"""
|
||||
Shows stats about the database.
|
||||
4012 objects = 144 rooms, 212 exits, 613 things, 1878 players. (1165 garbage)
|
||||
"""
|
||||
session = cdat['session']
|
||||
stats_dict = functions_db.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"]))
|
||||
516
commands/objmanip.py
Normal file
516
commands/objmanip.py
Normal file
|
|
@ -0,0 +1,516 @@
|
|||
import ansi
|
||||
import session_mgr
|
||||
import functions_db
|
||||
|
||||
def cmd_teleport(cdat):
|
||||
"""
|
||||
Teleports an object somewhere.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
server = cdat['server']
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("Teleport where/what?")
|
||||
return
|
||||
|
||||
eq_args = args[0].split('=')
|
||||
search_str = ''.join(args)
|
||||
|
||||
# If we have more than one entry in our '=' delimited argument list,
|
||||
# then we're doing a @tel <victim>=<location>. If not, we're doing
|
||||
# a direct teleport, @tel <destination>.
|
||||
if len(eq_args) > 1:
|
||||
# Equal sign teleport.
|
||||
victim = functions_db.standard_plr_objsearch(session, eq_args[0])
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not victim:
|
||||
return
|
||||
|
||||
destination = functions_db.standard_plr_objsearch(session, eq_args[1])
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not destination:
|
||||
return
|
||||
|
||||
if victim.is_room():
|
||||
session.msg("You can't teleport a room.")
|
||||
return
|
||||
|
||||
if victim == destination:
|
||||
session.msg("You can't teleport an object inside of itself!")
|
||||
return
|
||||
session.msg("Teleported.")
|
||||
victim.move_to(destination)
|
||||
|
||||
# This is somewhat kludgy right now, we'll have to find a better way
|
||||
# to do it sometime else. If we can find a session in the server's
|
||||
# session list matching the object we're teleporting, force it to
|
||||
# look. This is going to typically be a player.
|
||||
victim_session = session_mgr.session_from_object(victim)
|
||||
if victim_session:
|
||||
victim_session.execute_cmd("look")
|
||||
|
||||
else:
|
||||
# Direct teleport (no equal sign)
|
||||
target_obj = functions_db.standard_plr_objsearch(session, search_str)
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
if target_obj == pobject:
|
||||
session.msg("You can't teleport inside yourself!")
|
||||
return
|
||||
session.msg("Teleported.")
|
||||
pobject.move_to(target_obj)
|
||||
session.execute_cmd("look")
|
||||
|
||||
def cmd_stats(cdat):
|
||||
"""
|
||||
Shows stats about the database.
|
||||
4012 objects = 144 rooms, 212 exits, 613 things, 1878 players. (1165 garbage)
|
||||
"""
|
||||
session = cdat['session']
|
||||
stats_dict = functions_db.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(cdat):
|
||||
"""
|
||||
Assigns an alias to a player object for ease of paging, etc.
|
||||
"""
|
||||
pass
|
||||
|
||||
def cmd_wipe(cdat):
|
||||
"""
|
||||
Wipes an object's attributes, or optionally only those matching a search
|
||||
string.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
attr_search = False
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("Wipe what?")
|
||||
return
|
||||
|
||||
# Look for a slash in the input, indicating an attribute wipe.
|
||||
attr_split = args[0].split("/")
|
||||
|
||||
# If the splitting by the "/" character returns a list with more than 1
|
||||
# entry, it's an attribute match.
|
||||
if len(attr_split) > 1:
|
||||
attr_search = True
|
||||
# Strip the object search string from the input with the
|
||||
# object/attribute pair.
|
||||
searchstr = attr_split[0]
|
||||
# Just in case there's a slash in an attribute name.
|
||||
attr_searchstr = '/'.join(attr_split[1:])
|
||||
else:
|
||||
searchstr = ' '.join(args)
|
||||
|
||||
target_obj = functions_db.standard_plr_objsearch(session, searchstr)
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
if attr_search:
|
||||
# User has passed an attribute wild-card string. Search for name matches
|
||||
# and wipe.
|
||||
attr_matches = target_obj.attribute_namesearch(attr_searchstr, exclude_noset=True)
|
||||
if attr_matches:
|
||||
for attr in attr_matches:
|
||||
target_obj.clear_attribute(attr.get_name())
|
||||
session.msg("%s - %d attributes wiped." % (target_obj.get_name(), len(attr_matches)))
|
||||
else:
|
||||
session.msg("No matching attributes found.")
|
||||
else:
|
||||
# User didn't specify a wild-card string, wipe entire object.
|
||||
attr_matches = target_obj.attribute_namesearch("*", exclude_noset=True)
|
||||
for attr in attr_matches:
|
||||
target_obj.clear_attribute(attr.get_name())
|
||||
session.msg("%s - %d attributes wiped." % (target_obj.get_name(), len(attr_matches)))
|
||||
|
||||
def cmd_set(cdat):
|
||||
"""
|
||||
Sets flags or attributes on objects.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
server = cdat['server']
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("Set what?")
|
||||
return
|
||||
|
||||
# There's probably a better way to do this. Break the arguments (minus
|
||||
# the root command) up so we have two items in the list, 0 being the victim,
|
||||
# 1 being the list of flags or the attribute/value pair.
|
||||
eq_args = ' '.join(args).split('=')
|
||||
|
||||
if len(eq_args) < 2:
|
||||
session.msg("Set what?")
|
||||
return
|
||||
|
||||
victim = functions_db.standard_plr_objsearch(session, eq_args[0])
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not victim:
|
||||
return
|
||||
|
||||
if not pobject.controls_other(victim):
|
||||
session.msg(defines_global.NOCONTROL_MSG)
|
||||
return
|
||||
|
||||
attrib_args = eq_args[1].split(':')
|
||||
|
||||
if len(attrib_args) > 1:
|
||||
# We're dealing with an attribute/value pair.
|
||||
attrib_name = attrib_args[0].upper()
|
||||
splicenum = eq_args[1].find(':') + 1
|
||||
attrib_value = eq_args[1][splicenum:]
|
||||
|
||||
# In global_defines.py, see NOSET_ATTRIBS for protected attribute names.
|
||||
if not functions_db.is_modifiable_attrib(attrib_name) and not pobject.is_superuser():
|
||||
session.msg("You can't modify that attribute.")
|
||||
return
|
||||
|
||||
if attrib_value:
|
||||
# An attribute value was specified, create or set the attribute.
|
||||
verb = 'set'
|
||||
victim.set_attribute(attrib_name, attrib_value)
|
||||
else:
|
||||
# No value was given, this means we delete the attribute.
|
||||
verb = 'cleared'
|
||||
victim.clear_attribute(attrib_name)
|
||||
session.msg("%s - %s %s." % (victim.get_name(), attrib_name, verb))
|
||||
else:
|
||||
# Flag manipulation form.
|
||||
flag_list = eq_args[1].split()
|
||||
|
||||
for flag in flag_list:
|
||||
flag = flag.upper()
|
||||
if flag[0] == '!':
|
||||
# We're un-setting the flag.
|
||||
flag = flag[1:]
|
||||
if not functions_db.is_modifiable_flag(flag):
|
||||
session.msg("You can't set/unset the flag - %s." % (flag,))
|
||||
else:
|
||||
session.msg('%s - %s cleared.' % (victim.get_name(), flag.upper(),))
|
||||
victim.set_flag(flag, False)
|
||||
else:
|
||||
# We're setting the flag.
|
||||
if not functions_db.is_modifiable_flag(flag):
|
||||
session.msg("You can't set/unset the flag - %s." % (flag,))
|
||||
else:
|
||||
session.msg('%s - %s set.' % (victim.get_name(), flag.upper(),))
|
||||
victim.set_flag(flag, True)
|
||||
|
||||
def cmd_find(cdat):
|
||||
"""
|
||||
Searches for an object of a particular name.
|
||||
"""
|
||||
session = cdat['session']
|
||||
server = cdat['server']
|
||||
searchstring = ' '.join(cdat['uinput']['splitted'][1:])
|
||||
pobject = session.get_pobject()
|
||||
can_find = pobject.user_has_perm("genperms.builder")
|
||||
|
||||
if searchstring == '':
|
||||
session.msg("No search pattern given.")
|
||||
return
|
||||
|
||||
results = functions_db.global_object_name_search(searchstring)
|
||||
|
||||
if len(results) > 0:
|
||||
session.msg("Name matches for: %s" % (searchstring,))
|
||||
for result in results:
|
||||
session.msg(" %s" % (result.get_name(fullname=True),))
|
||||
session.msg("%d matches returned." % (len(results),))
|
||||
else:
|
||||
session.msg("No name matches found for: %s" % (searchstring,))
|
||||
|
||||
def cmd_create(cdat):
|
||||
"""
|
||||
Creates a new object of type 'THING'.
|
||||
"""
|
||||
session = cdat['session']
|
||||
server = session.server
|
||||
pobject = session.get_pobject()
|
||||
uinput= cdat['uinput']['splitted']
|
||||
thingname = ' '.join(uinput[1:])
|
||||
|
||||
if thingname == '':
|
||||
session.msg("You must supply a name!")
|
||||
else:
|
||||
# Create and set the object up.
|
||||
odat = {"name": thingname, "type": 3, "location": pobject, "owner": pobject}
|
||||
new_object = functions_db.create_object(odat)
|
||||
|
||||
session.msg("You create a new thing: %s" % (new_object,))
|
||||
|
||||
def cmd_nextfree(cdat):
|
||||
"""
|
||||
Returns the next free object number.
|
||||
"""
|
||||
session = cdat['session']
|
||||
|
||||
nextfree = functions_db.get_nextfree_dbnum()
|
||||
if str(nextfree).isdigit():
|
||||
retval = "Next free object number: #%s" % (nextfree,)
|
||||
else:
|
||||
retval = "Next free object number: #%s (GARBAGE)" % (nextfree.id,)
|
||||
|
||||
session.msg(retval)
|
||||
|
||||
def cmd_open(cdat):
|
||||
"""
|
||||
Handle the opening of exits.
|
||||
|
||||
Forms:
|
||||
@open <Name>
|
||||
@open <Name>=<Dbref>
|
||||
@open <Name>=<Dbref>,<Name>
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
server = cdat['server']
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("Open an exit to where?")
|
||||
return
|
||||
|
||||
eq_args = ' '.join(args).split('=')
|
||||
exit_name = eq_args[0]
|
||||
|
||||
if len(exit_name) == 0:
|
||||
session.msg("You must supply an exit name.")
|
||||
return
|
||||
|
||||
# If we have more than one entry in our '=' delimited argument list,
|
||||
# then we're doing a @open <Name>=<Dbref>[,<Name>]. If not, we're doing
|
||||
# an un-linked exit, @open <Name>.
|
||||
if len(eq_args) > 1:
|
||||
# Opening an exit to another location via @open <Name>=<Dbref>[,<Name>].
|
||||
comma_split = eq_args[1].split(',')
|
||||
destination = functions_db.standard_plr_objsearch(session, comma_split[0])
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not destination:
|
||||
return
|
||||
|
||||
if destination.is_exit():
|
||||
session.msg("You can't open an exit to an exit!")
|
||||
return
|
||||
|
||||
odat = {"name": exit_name, "type": 4, "location": pobject.get_location(), "owner": pobject, "home":destination}
|
||||
new_object = functions_db.create_object(odat)
|
||||
|
||||
session.msg("You open the an exit - %s to %s" % (new_object.get_name(),destination.get_name()))
|
||||
|
||||
if len(comma_split) > 1:
|
||||
second_exit_name = ','.join(comma_split[1:])
|
||||
odat = {"name": second_exit_name, "type": 4, "location": destination, "owner": pobject, "home": pobject.get_location()}
|
||||
new_object = functions_db.create_object(odat)
|
||||
session.msg("You open the an exit - %s to %s" % (new_object.get_name(),pobject.get_location().get_name()))
|
||||
|
||||
else:
|
||||
# Create an un-linked exit.
|
||||
odat = {"name": exit_name, "type": 4, "location": pobject.get_location(), "owner": pobject, "home":None}
|
||||
new_object = functions_db.create_object(odat)
|
||||
|
||||
session.msg("You open an unlinked exit - %s" % (new_object,))
|
||||
|
||||
def cmd_link(cdat):
|
||||
"""
|
||||
Sets an object's home or an exit's destination.
|
||||
|
||||
Forms:
|
||||
@link <Object>=<Target>
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
server = cdat['server']
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("Link what?")
|
||||
return
|
||||
|
||||
eq_args = args[0].split('=')
|
||||
target_name = eq_args[0]
|
||||
dest_name = '='.join(eq_args[1:])
|
||||
|
||||
if len(target_name) == 0:
|
||||
session.msg("What do you want to link?")
|
||||
return
|
||||
|
||||
if len(eq_args) > 1:
|
||||
target_obj = functions_db.standard_plr_objsearch(session, target_name)
|
||||
# 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
|
||||
|
||||
# If we do something like "@link blah=", we unlink the object.
|
||||
if len(dest_name) == 0:
|
||||
target_obj.set_home(None)
|
||||
session.msg("You have unlinked %s." % (target_obj,))
|
||||
return
|
||||
|
||||
destination = functions_db.standard_plr_objsearch(session, dest_name)
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not destination:
|
||||
return
|
||||
|
||||
target_obj.set_home(destination)
|
||||
session.msg("You link %s to %s." % (target_obj,destination))
|
||||
|
||||
else:
|
||||
# We haven't provided a target.
|
||||
session.msg("You must provide a destination to link to.")
|
||||
return
|
||||
|
||||
def cmd_unlink(cdat):
|
||||
"""
|
||||
Unlinks an object.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("Unlink what?")
|
||||
return
|
||||
else:
|
||||
target_obj = functions_db.standard_plr_objsearch(session, ' '.join(args))
|
||||
# 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
|
||||
|
||||
target_obj.set_home(None)
|
||||
session.msg("You have unlinked %s." % (target_obj.get_name(),))
|
||||
|
||||
def cmd_dig(cdat):
|
||||
"""
|
||||
Creates a new object of type 'ROOM'.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
uinput= cdat['uinput']['splitted']
|
||||
roomname = ' '.join(uinput[1:])
|
||||
|
||||
if roomname == '':
|
||||
session.msg("You must supply a name!")
|
||||
else:
|
||||
# Create and set the object up.
|
||||
odat = {"name": roomname, "type": 2, "location": None, "owner": pobject}
|
||||
new_object = functions_db.create_object(odat)
|
||||
|
||||
session.msg("You create a new room: %s" % (new_object,))
|
||||
|
||||
def cmd_name(cdat):
|
||||
"""
|
||||
Handle naming an object.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
eq_args = ' '.join(args).split('=')
|
||||
searchstring = ''.join(eq_args[0])
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("What do you want to name?")
|
||||
elif len(eq_args) < 2:
|
||||
session.msg("What would you like to name that object?")
|
||||
else:
|
||||
target_obj = functions_db.standard_plr_objsearch(session, searchstring)
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
if len(eq_args[1]) == 0:
|
||||
session.msg("What would you like to name that object?")
|
||||
else:
|
||||
newname = '='.join(eq_args[1:])
|
||||
session.msg("You have renamed %s to %s." % (target_obj, ansi.parse_ansi(newname, strip_formatting=True)))
|
||||
target_obj.set_name(newname)
|
||||
|
||||
def cmd_description(cdat):
|
||||
"""
|
||||
Set an object's description.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
eq_args = ' '.join(args).split('=')
|
||||
searchstring = ''.join(eq_args[0])
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("What do you want to describe?")
|
||||
elif len(eq_args) < 2:
|
||||
session.msg("How would you like to describe that object?")
|
||||
else:
|
||||
target_obj = functions_db.standard_plr_objsearch(session, searchstring)
|
||||
# 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 = '='.join(eq_args[1:])
|
||||
session.msg("%s - DESCRIPTION set." % (target_obj,))
|
||||
target_obj.set_description(new_desc)
|
||||
|
||||
def cmd_destroy(cdat):
|
||||
"""
|
||||
Destroy an object.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
switches = cdat['uinput']['root_chunk'][1:]
|
||||
switch_override = False
|
||||
|
||||
if "override" in switches:
|
||||
switch_override = True
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("Destroy what?")
|
||||
return
|
||||
else:
|
||||
target_obj = functions_db.standard_plr_objsearch(session, ' '.join(args))
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
if target_obj.is_player():
|
||||
if pobject.id == target_obj.id:
|
||||
session.msg("You can't destroy yourself.")
|
||||
return
|
||||
if not switch_override:
|
||||
session.msg("You must use @destroy/override on players.")
|
||||
return
|
||||
if target_obj.is_superuser():
|
||||
session.msg("You can't destroy a superuser.")
|
||||
return
|
||||
elif target_obj.is_going() or target_obj.is_garbage():
|
||||
session.msg("That object is already destroyed.")
|
||||
return
|
||||
|
||||
session.msg("You destroy %s." % (target_obj.get_name(),))
|
||||
target_obj.destroy()
|
||||
65
commands/privileged.py
Normal file
65
commands/privileged.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import defines_global
|
||||
import functions_general
|
||||
import functions_db
|
||||
import ansi
|
||||
|
||||
"""
|
||||
This file contains commands that require special permissions to use. These
|
||||
are generally @-prefixed commands, but there are exceptions.
|
||||
"""
|
||||
|
||||
def cmd_reload(cdat):
|
||||
"""
|
||||
Reloads all modules.
|
||||
"""
|
||||
session = cdat['session']
|
||||
server = session.server.reload(session)
|
||||
|
||||
def cmd_newpassword(cdat):
|
||||
"""
|
||||
Set a player's password.
|
||||
"""
|
||||
session = cdat['session']
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
eq_args = ' '.join(args).split('=')
|
||||
searchstring = ''.join(eq_args[0])
|
||||
newpass = ''.join(eq_args[1:])
|
||||
|
||||
if len(args) == 0:
|
||||
session.msg("What player's password do you want to change")
|
||||
return
|
||||
if len(newpass) == 0:
|
||||
session.msg("You must supply a new password.")
|
||||
return
|
||||
|
||||
target_obj = functions_db.standard_plr_objsearch(session, searchstring)
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
||||
if not target_obj.is_player():
|
||||
session.msg("You can only change passwords on players.")
|
||||
elif not pobject.controls_other(target_obj):
|
||||
session.msg("You do not control %s." % (target_obj.get_name(),))
|
||||
else:
|
||||
uaccount = target_obj.get_user_account()
|
||||
if len(newpass) == 0:
|
||||
uaccount.set_password()
|
||||
else:
|
||||
uaccount.set_password(newpass)
|
||||
uaccount.save()
|
||||
session.msg("%s - PASSWORD set." % (target_obj.get_name(),))
|
||||
target_obj.emit_to("%s has changed your password." % (pobject.get_name(show_dbref=False),))
|
||||
|
||||
def cmd_shutdown(cdat):
|
||||
"""
|
||||
Shut the server down gracefully.
|
||||
"""
|
||||
session = cdat['session']
|
||||
server = cdat['server']
|
||||
pobject = session.get_pobject()
|
||||
|
||||
session.msg('Shutting down...')
|
||||
print 'Server shutdown by %s' % (pobject.get_name(show_dbref=False),)
|
||||
server.shutdown()
|
||||
92
commands/unloggedin.py
Normal file
92
commands/unloggedin.py
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
from django.contrib.auth.models import User
|
||||
import functions_db
|
||||
import functions_general
|
||||
|
||||
"""
|
||||
Commands that are available from the connect screen.
|
||||
"""
|
||||
|
||||
def cmd_connect(cdat):
|
||||
"""
|
||||
This is the connect command at the connection screen. Fairly simple,
|
||||
uses the Django database API and User model to make it extremely simple.
|
||||
"""
|
||||
|
||||
session = cdat['session']
|
||||
|
||||
# Argument check.
|
||||
if not functions_general.cmd_check_num_args(session, cdat['uinput']['splitted'], 2):
|
||||
return
|
||||
|
||||
uemail = cdat['uinput']['splitted'][1]
|
||||
password = cdat['uinput']['splitted'][2]
|
||||
|
||||
# Match an email address to an account.
|
||||
email_matches = functions_db.get_dbref_from_email(uemail)
|
||||
|
||||
autherror = "Specified email does not match any accounts!"
|
||||
# No username match
|
||||
if email_matches.count() == 0:
|
||||
session.msg(autherror)
|
||||
return
|
||||
|
||||
# We have at least one result, so we can check the password.
|
||||
user = email_matches[0]
|
||||
|
||||
if not user.check_password(password):
|
||||
session.msg(autherror)
|
||||
else:
|
||||
user = email_matches[0]
|
||||
uname = user.username
|
||||
session.login(user)
|
||||
|
||||
def cmd_create(cdat):
|
||||
"""
|
||||
Handle the creation of new accounts.
|
||||
"""
|
||||
session = cdat['session']
|
||||
|
||||
# Argument check.
|
||||
if not functions_general.cmd_check_num_args(session, cdat['uinput']['splitted'], 2):
|
||||
return
|
||||
|
||||
server = session.server
|
||||
quote_split = ' '.join(cdat['uinput']['splitted']).split("\"")
|
||||
|
||||
if len(quote_split) < 2:
|
||||
session.msg("You must enclose your username in quotation marks.")
|
||||
return
|
||||
|
||||
uname = quote_split[1]
|
||||
lastarg_split = quote_split[2].split()
|
||||
|
||||
if len(lastarg_split) != 2:
|
||||
session.msg("You must specify an email address, followed by a password!")
|
||||
return
|
||||
|
||||
email = lastarg_split[0]
|
||||
password = lastarg_split[1]
|
||||
|
||||
# Search for a user object with the specified username.
|
||||
account = User.objects.filter(username=uname)
|
||||
# Match an email address to an account.
|
||||
email_matches = functions_db.get_dbref_from_email(email)
|
||||
|
||||
if not account.count() == 0:
|
||||
session.msg("There is already a player with that name!")
|
||||
elif not email_matches.count() == 0:
|
||||
session.msg("There is already a player with that email address!")
|
||||
elif len(password) < 3:
|
||||
session.msg("Your password must be 3 characters or longer.")
|
||||
else:
|
||||
functions_db.create_user(cdat, uname, email, password)
|
||||
|
||||
def cmd_quit(cdat):
|
||||
"""
|
||||
We're going to maintain a different version of the quit command
|
||||
here for unconnected users for the sake of simplicity. The logged in
|
||||
version will be a bit more complicated.
|
||||
"""
|
||||
session = cdat['session']
|
||||
session.msg("Disconnecting...")
|
||||
session.handle_close()
|
||||
Loading…
Add table
Add a link
Reference in a new issue