__author__ = "Will Guaraldi <willg@bluesock.org>"
__version__ = "1.0 (15 January, 2004)"
__description__ = "Some nice Lyntin hacker commands."
import string, os
from lyntin import config, ansi, utils, exported
from lyntin.modules import modutils
commands_dict = {}
def exatel_cmd(ses, args, input):
if ses._name == "common":
exported.write_error("common session!")
return
output = list(ses._socket._controllog)
exported.write_message("%stelnet sequences:%s\n%s" %
(ansi.get_color("yellow"), ansi.get_color("default"), "\n".join(output)))
return
commands_dict["exatel"] = (exatel_cmd, "")
def wprint_cmd(ses, args, input):
window = args["window"]
text = args["text"] + "\n"
ui = str(exported.get_engine().getUI().__class__)
if ui.find("Tkui") != -1:
exported.get_engine().getUI().writeWindow(window, text)
else:
exported.write_message(output)
commands_dict["wprint"] = (wprint_cmd, "window text=")
def printmodules_cmd(ses, args, input):
exported.write_message("Lyntin modules currently loaded:\n")
exported.write_message(utils.columnize(config.lyntinmodules))
commands_dict["printmodules"] = (printmodules_cmd, "")
def printhooks_cmd(ses, args, input):
name = args["name"]
e = exported.get_engine()
hlist = e._hooks.keys()
if not name:
exported.write_message("hooks available:")
exported.write_message(utils.columnize(hlist))
return
if name not in hlist:
exported.write_error("no hook by that name. '%s'")
exported.write_error(utils.columnize(hlist))
return
h = exported.get_hook(name)
output = []
keys = h._prioritymap.keys()
keys.sort()
for mem in keys:
hooklist = h._prioritymap[mem]
for mem2 in hooklist:
output.append("%d: %s" % (mem, mem2))
exported.write_message(("registered to %s:\n" % name) + string.join(output, "\n"))
commands_dict["printhooks"] = (printhooks_cmd, "name=")
def testansi_cmd(session, args, input):
keys = ansi.STYLEMAP.keys()
keys.sort()
for color in keys:
val = ansi.STYLEMAP[color]
exported.write_message(chr(27) + "[" + val + "m" + "test" + chr(27) + "[0m" + " - " + color)
return
commands_dict["testansi"] = (testansi_cmd,"")
def log_everything_cmd(ses, args, input):
onoff = args["onoff"]
if onoff:
exported.hook_register("mud_filter_hook", log_everything_filter, 0)
exported.write_message("logging everything: on")
else:
exported.hook_unregister("mud_filter_hook", log_everything_filter)
exported.write_message("logging everything: off")
commands_dict["logall"] = (log_everything_cmd, "onoff:boolean")
def log_hook_cmd(ses, args, input):
hook = args["hook"]
onoff = args["onoff"]
if hook == "to_user_hook":
exported.write_error("This is really _not_ a good idea to do.")
return
hm = exported.get_manager("hook")
hlist = hm.getHookList()
if hook not in hlist:
exported.write_error("Hook %s does not exist." % hook)
return
h = exported.get_hook(hook)
if onoff:
h.register(hook_debug)
exported.write_message("Registered with %s." % hook)
else:
h.unregister(hook_debug)
exported.write_message("Unregistered with %s." % hook)
commands_dict["loghook"] = (log_hook_cmd, "hook onoff:boolean")
def log_everything_filter(args):
text = args["data"]
codes = ( (chr(27), "ESC"),
(chr(10), "CR"),
(chr(8), "BS"),
(chr(13), "LF") )
d = text
for a, b in codes:
d = d.replace(a, b)
print "===%s===" % d
return text
def hook_debug(args):
exported.write_message("SPAMHOOK: %s" % repr(args))
def load():
modutils.load_commands(commands_dict)
def unload():
modutils.unload_commands(commands_dict)