Implemented imcwhois command as part of the imcinfo command cluster.
This commit is contained in:
parent
36bc29865b
commit
b856cb8faf
6 changed files with 45 additions and 229 deletions
|
|
@ -850,7 +850,7 @@ class CmdIRC2Chan(MuxCommand):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = "@irc2chan"
|
key = "@irc2chan"
|
||||||
locks = "cmd:serversetting(IRC_ENABLED) and perm(Wizards)"
|
locks = "cmd:serversetting(IRC_ENABLED) and perm(Immortals)"
|
||||||
help_category = "Comms"
|
help_category = "Comms"
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
|
|
@ -1011,18 +1011,21 @@ class CmdIMC2Chan(MuxCommand):
|
||||||
return
|
return
|
||||||
self.caller.msg("Connection created. Connecting to IMC2 server.")
|
self.caller.msg("Connection created. Connecting to IMC2 server.")
|
||||||
|
|
||||||
|
|
||||||
class CmdIMCInfo(MuxCommand):
|
class CmdIMCInfo(MuxCommand):
|
||||||
"""
|
"""
|
||||||
imcchanlist
|
imcinfo - package of imc info commands
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
@imcinfo[/switches]
|
@imcinfo[/switches]
|
||||||
@imcchanlist - list imc2 channels
|
@imcchanlist - list imc2 channels
|
||||||
@imclist - list connected muds
|
@imclist - list connected muds
|
||||||
|
@imcwhois <playername> - whois info about a remote player
|
||||||
|
|
||||||
Switches:
|
Switches for @imcinfo:
|
||||||
channels - as @imcchanlist (default)
|
channels - as @imcchanlist (default)
|
||||||
games or muds - as @imclist
|
games or muds - as @imclist
|
||||||
|
whois - as @imcwhois (requires an additional argument)
|
||||||
update - force an update of all lists
|
update - force an update of all lists
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1030,8 +1033,8 @@ class CmdIMCInfo(MuxCommand):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = "@imcinfo"
|
key = "@imcinfo"
|
||||||
aliases = ["@imcchanlist", "@imclist"]
|
aliases = ["@imcchanlist", "@imclist", "@imcwhois"]
|
||||||
locks = "cmd: serversetting(IMC2_ENABLED) or perm(Immortals)"
|
locks = "cmd: serversetting(IMC2_ENABLED) and perm(Wizards)"
|
||||||
help_category = "Comms"
|
help_category = "Comms"
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
|
|
@ -1088,6 +1091,17 @@ class CmdIMCInfo(MuxCommand):
|
||||||
string += "\n" + "".join(row)
|
string += "\n" + "".join(row)
|
||||||
string += "\n %i Muds found." % nmuds
|
string += "\n %i Muds found." % nmuds
|
||||||
self.caller.msg(string)
|
self.caller.msg(string)
|
||||||
|
|
||||||
|
elif "whois" in self.switches or self.cmdstring == "@imcwhois":
|
||||||
|
# find out about a player
|
||||||
|
if not self.args:
|
||||||
|
self.caller.msg("Usage: @imcwhois <playername>")
|
||||||
|
return
|
||||||
|
from src.comms.imc2 import IMC2_CONNECTIONS
|
||||||
|
self.caller.msg("Sending IMC whois request. If you receive no response, no matches were found.")
|
||||||
|
for comm in IMC2_CONNECTIONS:
|
||||||
|
comm.msg_imc2(None, from_obj=self.caller.player, packet_type="imcwhois", data={"target":self.args})
|
||||||
|
|
||||||
elif not self.switches or "channels" in self.switches or self.cmdstring == "@imcchanlist":
|
elif not self.switches or "channels" in self.switches or self.cmdstring == "@imcchanlist":
|
||||||
# show channels
|
# show channels
|
||||||
from src.comms.imc2 import IMC2_CHANLIST, IMC2_CONNECTIONS
|
from src.comms.imc2 import IMC2_CHANLIST, IMC2_CONNECTIONS
|
||||||
|
|
@ -1133,7 +1147,7 @@ class CmdIMCTell(MuxCommand):
|
||||||
|
|
||||||
key = "imctell"
|
key = "imctell"
|
||||||
aliases = ["imcpage", "imc2tell", "imc2page"]
|
aliases = ["imcpage", "imc2tell", "imc2page"]
|
||||||
locks = "cmd: serversetting(IMC2_ENABLED) or perm(Immortals)"
|
locks = "cmd: serversetting(IMC2_ENABLED)"
|
||||||
help_category = "Comms"
|
help_category = "Comms"
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
|
|
|
||||||
|
|
@ -1,211 +0,0 @@
|
||||||
"""
|
|
||||||
IMC2 user and administrative commands.
|
|
||||||
"""
|
|
||||||
from django.conf import settings
|
|
||||||
from src import comsys
|
|
||||||
from src.cmdtable import GLOBAL_CMD_TABLE
|
|
||||||
from src.ansi import parse_ansi
|
|
||||||
from src.imc2.imc_ansi import IMCANSIParser
|
|
||||||
from src.imc2 import connection as imc2_conn
|
|
||||||
from src.imc2.packets import *
|
|
||||||
from src.imc2.models import IMC2ChannelMapping
|
|
||||||
from src.imc2.trackers import IMC2_MUDLIST, IMC2_CHANLIST
|
|
||||||
from src.channels.models import CommChannel
|
|
||||||
|
|
||||||
def cmd_imcwhois(command):
|
|
||||||
"""
|
|
||||||
imcwhois
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
imcwhois
|
|
||||||
|
|
||||||
IMC2 command. Shows a player's inventory.
|
|
||||||
"""
|
|
||||||
source_object = command.source_object
|
|
||||||
if not command.command_argument:
|
|
||||||
source_object.emit_to("Get what?")
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
source_object.emit_to("Sending IMC whois request. If you receive no response, no matches were found.")
|
|
||||||
packet = IMC2PacketWhois(source_object, command.command_argument)
|
|
||||||
imc2_conn.IMC2_PROTOCOL_INSTANCE.send_packet(packet)
|
|
||||||
GLOBAL_CMD_TABLE.add_command("imcwhois", cmd_imcwhois, help_category="Comms")
|
|
||||||
|
|
||||||
# def cmd_imcansi(command):
|
|
||||||
# """
|
|
||||||
# imcansi
|
|
||||||
|
|
||||||
# Usage:
|
|
||||||
# imcansi <string>
|
|
||||||
|
|
||||||
# Test IMC ANSI conversion.
|
|
||||||
# """
|
|
||||||
# source_object = command.source_object
|
|
||||||
# if not command.command_argument:
|
|
||||||
# source_object.emit_to("You must provide a string to convert.")
|
|
||||||
# return
|
|
||||||
# else:
|
|
||||||
# retval = parse_ansi(command.command_argument, parser=IMCANSIParser())
|
|
||||||
# source_object.emit_to(retval)
|
|
||||||
# GLOBAL_CMD_TABLE.add_command("imcansi", cmd_imcansi, help_category="Comms")
|
|
||||||
|
|
||||||
# def cmd_imcicerefresh(command):
|
|
||||||
# """
|
|
||||||
# imcicerefresh
|
|
||||||
|
|
||||||
# Usage:
|
|
||||||
# imcicerefresh
|
|
||||||
|
|
||||||
# IMC2: Semds an ice-refresh packet.
|
|
||||||
# """
|
|
||||||
# source_object = command.source_object
|
|
||||||
# packet = IMC2PacketIceRefresh()
|
|
||||||
# imc2_conn.IMC2_PROTOCOL_INSTANCE.send_packet(packet)
|
|
||||||
# source_object.emit_to("Sent")
|
|
||||||
# GLOBAL_CMD_TABLE.add_command("imcicerefresh", cmd_imcicerefresh, help_category="Comms")
|
|
||||||
|
|
||||||
# def cmd_imcchanlist(command):
|
|
||||||
# """
|
|
||||||
# imcchanlist
|
|
||||||
|
|
||||||
# Usage:
|
|
||||||
# imcchanlist
|
|
||||||
|
|
||||||
# Shows the list of cached channels from the IMC2 Channel list.
|
|
||||||
# """
|
|
||||||
# source_object = command.source_object
|
|
||||||
|
|
||||||
# retval = 'Channels on %s\n\r' % imc2_conn.IMC2_PROTOCOL_INSTANCE.network_name
|
|
||||||
|
|
||||||
# retval += ' Full Name Name Owner Perm Policy\n\r'
|
|
||||||
# retval += ' --------- ---- ----- ---- ------\n\r'
|
|
||||||
# for channel in IMC2_CHANLIST.get_channel_list():
|
|
||||||
# retval += ' %-18s %-10s %-15s %-7s %s\n\r' % (channel.name,
|
|
||||||
# channel.localname,
|
|
||||||
# channel.owner,
|
|
||||||
# channel.level,
|
|
||||||
# channel.policy)
|
|
||||||
# retval += '%s channels found.' % len(IMC2_CHANLIST.chan_list)
|
|
||||||
# source_object.emit_to(retval)
|
|
||||||
# GLOBAL_CMD_TABLE.add_command("imcchanlist", cmd_imcchanlist, help_category="Comms")
|
|
||||||
|
|
||||||
# def cmd_imclist(command):
|
|
||||||
# """
|
|
||||||
# imclist
|
|
||||||
|
|
||||||
# Usage:
|
|
||||||
# imclist
|
|
||||||
|
|
||||||
# Shows the list of cached games from the IMC2 Mud list.
|
|
||||||
# """
|
|
||||||
# source_object = command.source_object
|
|
||||||
|
|
||||||
# retval = 'Active MUDs on %s\n\r' % imc2_conn.IMC2_PROTOCOL_INSTANCE.network_name
|
|
||||||
|
|
||||||
# for mudinfo in IMC2_MUDLIST.get_mud_list():
|
|
||||||
# mudline = ' %-20s %s' % (mudinfo.name, mudinfo.versionid)
|
|
||||||
# retval += '%s\n\r' % mudline[:78]
|
|
||||||
# retval += '%s active MUDs found.' % len(IMC2_MUDLIST.mud_list)
|
|
||||||
# source_object.emit_to(retval)
|
|
||||||
# GLOBAL_CMD_TABLE.add_command("imclist", cmd_imclist, help_category="Comms")
|
|
||||||
|
|
||||||
# def cmd_imcstatus(command):
|
|
||||||
# """
|
|
||||||
# imcstatus
|
|
||||||
|
|
||||||
# Usage:
|
|
||||||
# imcstatus
|
|
||||||
|
|
||||||
# Shows some status information for your IMC2 connection.
|
|
||||||
# """
|
|
||||||
# source_object = command.source_object
|
|
||||||
# # This manages our game's plugged in services.
|
|
||||||
# collection = command.session.server.service_collection
|
|
||||||
# # Retrieve the IMC2 service.
|
|
||||||
# service = collection.getServiceNamed('IMC2')
|
|
||||||
|
|
||||||
# if service.running == 1:
|
|
||||||
# status_string = 'Running'
|
|
||||||
# else:
|
|
||||||
# status_string = 'Inactive'
|
|
||||||
|
|
||||||
# # Build the output to emit to the player.
|
|
||||||
# retval = '-' * 50
|
|
||||||
# retval += '\n\r'
|
|
||||||
# retval += 'IMC Status\n\r'
|
|
||||||
# retval += ' * MUD Name: %s\n\r' % (settings.IMC2_MUDNAME)
|
|
||||||
# retval += ' * Status: %s\n\r' % (status_string)
|
|
||||||
# retval += ' * Debugging Mode: %s\n\r' % (settings.IMC2_DEBUG)
|
|
||||||
# retval += ' * IMC Network Address: %s\n\r' % (settings.IMC2_SERVER_ADDRESS)
|
|
||||||
# retval += ' * IMC Network Port: %s\n\r' % (settings.IMC2_SERVER_PORT)
|
|
||||||
# retval += '-' * 50
|
|
||||||
|
|
||||||
# source_object.emit_to(retval)
|
|
||||||
# GLOBAL_CMD_TABLE.add_command("imcstatus", cmd_imcstatus,
|
|
||||||
# priv_tuple=('imc2.admin_imc_channels',), help_category="Comms")
|
|
||||||
|
|
||||||
|
|
||||||
# def cmd_IMC2chan(command):
|
|
||||||
# """
|
|
||||||
# @imc2chan
|
|
||||||
|
|
||||||
# Usage:
|
|
||||||
# @imc2chan <IMCServer> : <IMCchannel> <channel>
|
|
||||||
|
|
||||||
# Links an IMC channel to an existing evennia
|
|
||||||
# channel. You can link as many existing
|
|
||||||
# evennia channels as you like to the
|
|
||||||
# IMC channel this way. Running the command with an
|
|
||||||
# existing mapping will re-map the channels.
|
|
||||||
|
|
||||||
# Use 'imcchanlist' to get a list of IMC channels and
|
|
||||||
# servers. Note that both are case sensitive.
|
|
||||||
# """
|
|
||||||
# source_object = command.source_object
|
|
||||||
# if not settings.IMC2_ENABLED:
|
|
||||||
# s = """IMC is not enabled. You need to activate it in game/settings.py."""
|
|
||||||
# source_object.emit_to(s)
|
|
||||||
# return
|
|
||||||
# args = command.command_argument
|
|
||||||
# if not args or len(args.split()) != 2 :
|
|
||||||
# source_object.emit_to("Usage: @imc2chan IMCServer:IMCchannel channel")
|
|
||||||
# return
|
|
||||||
# #identify the server-channel pair
|
|
||||||
# imcdata, channel = args.split()
|
|
||||||
# if not ":" in imcdata:
|
|
||||||
# source_object.emit_to("You need to supply an IMC Server:Channel pair.")
|
|
||||||
# return
|
|
||||||
# imclist = IMC2_CHANLIST.get_channel_list()
|
|
||||||
# imc_channels = filter(lambda c: c.name == imcdata, imclist)
|
|
||||||
# if not imc_channels:
|
|
||||||
# source_object.emit_to("IMC server and channel '%s' not found." % imcdata)
|
|
||||||
# return
|
|
||||||
# else:
|
|
||||||
# imc_server_name, imc_channel_name = imcdata.split(":")
|
|
||||||
|
|
||||||
# #find evennia channel
|
|
||||||
# try:
|
|
||||||
# chanobj = comsys.get_cobj_from_name(channel)
|
|
||||||
# except CommChannel.DoesNotExist:
|
|
||||||
# source_object.emit_to("Local channel '%s' not found (use real name, not alias)." % channel)
|
|
||||||
# return
|
|
||||||
|
|
||||||
# #create the mapping.
|
|
||||||
# outstring = ""
|
|
||||||
# mapping = IMC2ChannelMapping.objects.filter(channel__name=channel)
|
|
||||||
# if mapping:
|
|
||||||
# mapping = mapping[0]
|
|
||||||
# outstring = "Replacing %s. New " % mapping
|
|
||||||
# else:
|
|
||||||
# mapping = IMC2ChannelMapping()
|
|
||||||
|
|
||||||
# mapping.imc2_server_name = imc_server_name
|
|
||||||
# mapping.imc2_channel_name = imc_channel_name
|
|
||||||
# mapping.channel = chanobj
|
|
||||||
# mapping.save()
|
|
||||||
# outstring += "Mapping set: %s." % mapping
|
|
||||||
# source_object.emit_to(outstring)
|
|
||||||
|
|
||||||
# GLOBAL_CMD_TABLE.add_command("@imc2chan",cmd_IMC2chan,
|
|
||||||
# priv_tuple=("imc2.admin_imc_channels",), help_category="Comms")
|
|
||||||
|
|
||||||
|
|
@ -328,6 +328,11 @@ class IMC2Protocol(telnet.StatefulTelnetProtocol):
|
||||||
destination = data.get("destination", "Unknown")
|
destination = data.get("destination", "Unknown")
|
||||||
self.send_packet(pck.IMC2PacketTell(from_name, target, destination, message))
|
self.send_packet(pck.IMC2PacketTell(from_name, target, destination, message))
|
||||||
|
|
||||||
|
elif packet_type == "imcwhois":
|
||||||
|
# send a whois request
|
||||||
|
if type(data) == dict:
|
||||||
|
target = data.get("target", "Unknown")
|
||||||
|
self.send_packet(pck.IMC2PacketWhois(from_obj.id, target))
|
||||||
|
|
||||||
class IMC2Factory(protocol.ClientFactory):
|
class IMC2Factory(protocol.ClientFactory):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,15 @@ special markup strings.
|
||||||
This is a IMC2 complacent version.
|
This is a IMC2 complacent version.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from src.utils.ansi import ANSIParser, ANSITable
|
import re
|
||||||
|
from src.utils.ansi import ANSIParser, ANSITable, parse_ansi
|
||||||
|
|
||||||
class IMCANSIParser(ANSIParser):
|
class IMCANSIParser(ANSIParser):
|
||||||
"""
|
"""
|
||||||
This parser is per the IMC2 specification.
|
This parser is per the IMC2 specification.
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ansi_subs = [
|
self.ansi_map = [
|
||||||
# Random
|
# Random
|
||||||
(r'~Z', ANSITable.ansi["normal"]),
|
(r'~Z', ANSITable.ansi["normal"]),
|
||||||
# Dark Grey
|
# Dark Grey
|
||||||
|
|
@ -58,9 +59,17 @@ class IMCANSIParser(ANSIParser):
|
||||||
(r'\\r', ANSITable.ansi["normal"]),
|
(r'\\r', ANSITable.ansi["normal"]),
|
||||||
(r'\\n', ANSITable.ansi["return"]),
|
(r'\\n', ANSITable.ansi["return"]),
|
||||||
]
|
]
|
||||||
|
# prepare regex matching
|
||||||
|
self.ansi_sub = [(re.compile(sub[0], re.DOTALL), sub[1])
|
||||||
|
for sub in self.ansi_map]
|
||||||
|
# prepare matching ansi codes overall
|
||||||
|
self.ansi_regex = re.compile("\033\[[0-9;]+m")
|
||||||
|
|
||||||
|
|
||||||
|
ANSI_PARSER = IMCANSIParser()
|
||||||
|
|
||||||
def parse_ansi(*args, **kwargs):
|
def parse_ansi(string, strip_ansi=False, parser=ANSI_PARSER):
|
||||||
"""
|
"""
|
||||||
Shortcut to use the IMC2 ANSI parser.
|
Shortcut to use the IMC2 ANSI parser.
|
||||||
"""
|
"""
|
||||||
return ansi.parse_ansi(parser=IMCANSIParser(), *args, **kwargs)
|
return parser.parse_ansi(string, strip_ansi=strip_ansi)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
"""
|
"""
|
||||||
This module handles some of the -reply packets like whois-reply.
|
This module handles some of the -reply packets like whois-reply.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from src.objects.models import ObjectDB
|
from src.objects.models import ObjectDB
|
||||||
from src.comms.imc2lib import imc2_ansi
|
from src.comms.imc2lib import imc2_ansi
|
||||||
|
|
@ -7,10 +8,9 @@ from src.comms.imc2lib import imc2_ansi
|
||||||
def handle_whois_reply(packet):
|
def handle_whois_reply(packet):
|
||||||
try:
|
try:
|
||||||
pobject = ObjectDB.objects.get(id=packet.target)
|
pobject = ObjectDB.objects.get(id=packet.target)
|
||||||
response_text = imc_ansi.parse_ansi(packet.optional_data.get('text',
|
response_text = imc2_ansi.parse_ansi(packet.optional_data.get('text', 'Unknown'))
|
||||||
'Unknown'))
|
string = 'Whois reply from %s: %s' % (packet.origin, response_text)
|
||||||
pobject.emit_to('Whois reply from %s: %s' % (packet.origin,
|
pobject.msg(string.strip())
|
||||||
response_text))
|
except ObjectDB.DoesNotExist:
|
||||||
except Object.DoesNotExist:
|
|
||||||
# No match found for whois sender. Ignore it.
|
# No match found for whois sender. Ignore it.
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -653,10 +653,9 @@ class IMC2PacketWhois(IMC2Packet):
|
||||||
Example:
|
Example:
|
||||||
You@YourMUD 1234567890 YourMUD whois dude@* level=5
|
You@YourMUD 1234567890 YourMUD whois dude@* level=5
|
||||||
"""
|
"""
|
||||||
def __init__(self, pobject, whois_target):
|
def __init__(self, pobject_id, whois_target):
|
||||||
super(IMC2PacketWhois, self).__init__()
|
super(IMC2PacketWhois, self).__init__()
|
||||||
# Use the dbref, it's easier to trace back for the whois-reply.
|
self.sender = pobject_id # Use the dbref, it's easier to trace back for the whois-reply.
|
||||||
self.sender = pobject.id
|
|
||||||
self.packet_type = 'whois'
|
self.packet_type = 'whois'
|
||||||
self.target = whois_target
|
self.target = whois_target
|
||||||
self.destination = '*'
|
self.destination = '*'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue