Looking through our command code after a long hiatus, I realized that it was pretty much awful. So here's part 1 of the command interpreter overhaul.
- The command handler has been drastically simplified. We were doing way too much processing in the handler that should have been done in the individual command functions themselves. - The 'cdat' dict we were previously passing around has been replaced with a Command object that has useful methods for performing some of the parsing command functions will probably want to do from time to time. - All commands were updated to use the new Command object, tested, and cleaned up in general. - A lot of formatting was cleaned up. - A lot of previously un-found bugs and limitations were fixed. - The 'page' command has been broken out into its own file, since it's going to have a number of functions that would otherwise clutter commands/general.py. Expect a commit (probably later today) that will clean up the second half of cmdhandler.py.
This commit is contained in:
parent
37d66093cc
commit
d58f4eb517
16 changed files with 818 additions and 698 deletions
|
|
@ -5,56 +5,54 @@ are generally @-prefixed commands, but there are exceptions.
|
|||
from apps.objects.models import Object
|
||||
from src import defines_global
|
||||
from src import ansi
|
||||
from src import session_mgr
|
||||
from src.util import functions_general
|
||||
|
||||
def cmd_reload(cdat):
|
||||
def cmd_reload(command):
|
||||
"""
|
||||
Reloads all modules.
|
||||
"""
|
||||
session = cdat['session']
|
||||
session = command.session
|
||||
server = session.server.reload(session)
|
||||
|
||||
def cmd_boot(cdat):
|
||||
def cmd_boot(command):
|
||||
"""
|
||||
Boot a player object from the server.
|
||||
"""
|
||||
session = cdat['session']
|
||||
session = command.session
|
||||
pobject = session.get_pobject()
|
||||
args = cdat['uinput']['splitted'][1:]
|
||||
eq_args = ' '.join(args).split('=')
|
||||
searchstring = ''.join(eq_args[0])
|
||||
switches = cdat['uinput']['root_chunk'][1:]
|
||||
switch_quiet = False
|
||||
switch_port = False
|
||||
|
||||
if not pobject.is_staff():
|
||||
session.msg("You do not have permission to do that.")
|
||||
return
|
||||
|
||||
if "quiet" in switches:
|
||||
if "quiet" in command.command_switches:
|
||||
# Don't tell the player they've been disconnected, silently boot them.
|
||||
switch_quiet = True
|
||||
|
||||
if "port" in switches:
|
||||
if "port" in command.command_switches:
|
||||
# Boot by port number instead of name or dbref.
|
||||
switch_port = True
|
||||
|
||||
if len(args) == 0:
|
||||
if not command.command_argument:
|
||||
session.msg("Who would you like to boot?")
|
||||
return
|
||||
else:
|
||||
boot_list = []
|
||||
if switch_port:
|
||||
# Boot a particular port.
|
||||
sessions = session_mgr.get_session_list(True)
|
||||
for sess in sessions:
|
||||
if sess.getClientAddress()[1] == int(searchstring):
|
||||
# Find the session with the matching port number.
|
||||
if sess.getClientAddress()[1] == int(command.command_argument):
|
||||
boot_list.append(sess)
|
||||
# We're done here
|
||||
# Match found, kill the loop and continue with booting.
|
||||
break
|
||||
else:
|
||||
# Grab the objects that match
|
||||
objs = Objects.object.global_object_name_search(searchstring)
|
||||
objs = Object.objects.local_and_global_search(pobject,
|
||||
command.command_argument)
|
||||
|
||||
if len(objs) < 1:
|
||||
session.msg("Who would you like to boot?")
|
||||
if not objs:
|
||||
session.msg("No name or dbref match found for booting.")
|
||||
return
|
||||
|
||||
if not objs[0].is_player():
|
||||
|
|
@ -71,7 +69,15 @@ def cmd_boot(cdat):
|
|||
|
||||
if objs[0].is_connected_plr():
|
||||
boot_list.append(session_mgr.session_from_object(objs[0]))
|
||||
else:
|
||||
session.msg("That player is not connected.")
|
||||
return
|
||||
|
||||
if not boot_list:
|
||||
session.msg("No matches found.")
|
||||
return
|
||||
|
||||
# Carry out the booting of the sessions in the boot list.
|
||||
for boot in boot_list:
|
||||
if not switch_quiet:
|
||||
boot.msg("You have been disconnected by %s." % (pobject.name))
|
||||
|
|
@ -79,25 +85,24 @@ def cmd_boot(cdat):
|
|||
session_mgr.remove_session(boot)
|
||||
return
|
||||
|
||||
def cmd_newpassword(cdat):
|
||||
def cmd_newpassword(command):
|
||||
"""
|
||||
Set a player's password.
|
||||
"""
|
||||
session = cdat['session']
|
||||
session = command.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:])
|
||||
eq_args = command.command_argument.split('=', 1)
|
||||
searchstring = eq_args[0]
|
||||
newpass = eq_args[1]
|
||||
|
||||
if len(args) == 0:
|
||||
if not command.command_argument or len(searchstring) == 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 = Objects.object.standard_plr_objsearch(session, searchstring)
|
||||
target_obj = Object.objects.standard_plr_objsearch(session, searchstring)
|
||||
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
|
||||
if not target_obj:
|
||||
return
|
||||
|
|
@ -114,14 +119,15 @@ def cmd_newpassword(cdat):
|
|||
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),))
|
||||
target_obj.emit_to("%s has changed your password." %
|
||||
(pobject.get_name(show_dbref=False),))
|
||||
|
||||
def cmd_shutdown(cdat):
|
||||
def cmd_shutdown(command):
|
||||
"""
|
||||
Shut the server down gracefully.
|
||||
"""
|
||||
session = cdat['session']
|
||||
server = cdat['server']
|
||||
session = command.session
|
||||
server = command.server
|
||||
pobject = session.get_pobject()
|
||||
|
||||
session.msg('Shutting down...')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue