Some code cleanup and clarification in comments.
This commit is contained in:
parent
2640bd057a
commit
4bd567386f
12 changed files with 351 additions and 66 deletions
|
|
@ -9,8 +9,10 @@ from src import defines_global
|
|||
from src import ansi
|
||||
from src.util import functions_general
|
||||
from src.cmdtable import GLOBAL_CMD_TABLE
|
||||
from src.imc2.models import IMC2ChannelMapping
|
||||
from src.imc2.packets import IMC2PacketIceMsgBroadcasted
|
||||
#from src.imc2.models import IMC2ChannelMapping
|
||||
#from src.imc2.packets import IMC2PacketIceMsgBroadcasted
|
||||
#from src.irc.models import IRCChannelMapping
|
||||
#from src.irc.connection import IRC_CHANNELS
|
||||
|
||||
def cmd_addcom(command):
|
||||
"""
|
||||
|
|
@ -233,7 +235,7 @@ def cmd_cemit(command):
|
|||
|
||||
cname = eq_args[0]
|
||||
cmessage = eq_args[1]
|
||||
|
||||
final_cmessage = cmessage
|
||||
if len(cname) == 0:
|
||||
source_object.emit_to("You must provide a channel name to emit to.")
|
||||
return
|
||||
|
|
@ -247,7 +249,7 @@ def cmd_cemit(command):
|
|||
else:
|
||||
source_object.emit_to("Could not find channel %s." % (cname,))
|
||||
return
|
||||
|
||||
|
||||
# If this is False, don't show the channel header before
|
||||
# the message. For example: [Public] Woohoo!
|
||||
show_channel_header = True
|
||||
|
|
@ -274,22 +276,11 @@ def cmd_cemit(command):
|
|||
if not "quiet" in command.command_switches:
|
||||
source_object.emit_to("Sent - %s" % (name_matches[0],))
|
||||
comsys.send_cmessage(cname_parsed, final_cmessage,
|
||||
show_header=show_channel_header)
|
||||
show_header=show_channel_header)
|
||||
|
||||
if settings.IMC2_ENABLED:
|
||||
# Look for IMC2 channel maps. If one is found, send an ice-msg-b
|
||||
# packet to the network.
|
||||
try:
|
||||
from src.imc2.connection import IMC2_PROTOCOL_INSTANCE
|
||||
map = IMC2ChannelMapping.objects.get(channel__name=cname_parsed)
|
||||
packet = IMC2PacketIceMsgBroadcasted(map.imc2_server_name,
|
||||
map.imc2_channel_name,
|
||||
source_object,
|
||||
cmessage)
|
||||
IMC2_PROTOCOL_INSTANCE.send_packet(packet)
|
||||
except IMC2ChannelMapping.DoesNotExist:
|
||||
# No map found, do nothing.
|
||||
pass
|
||||
#pipe to external channels (IRC, IMC) eventually mapped to this channel
|
||||
comsys.send_cexternal(cname_parsed, "[%s] %s" % (cname_parsed,final_cmessage))
|
||||
|
||||
GLOBAL_CMD_TABLE.add_command("@cemit", cmd_cemit),
|
||||
|
||||
def cmd_cwho(command):
|
||||
|
|
@ -362,7 +353,7 @@ def cmd_ccreate(command):
|
|||
new_chan = comsys.create_channel(cname, source_object)
|
||||
source_object.emit_to("Channel %s created." % (new_chan.get_name(),))
|
||||
GLOBAL_CMD_TABLE.add_command("@ccreate", cmd_ccreate,
|
||||
priv_tuple=("objects.add_commchannel")),
|
||||
priv_tuple=("objects.add_commchannel",))
|
||||
|
||||
def cmd_cchown(command):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -7,14 +7,17 @@ from src.config.models import ConfigValue
|
|||
from src.objects.models import Object
|
||||
from src import defines_global
|
||||
from src import ansi
|
||||
from src import comsys
|
||||
from src.util import functions_general
|
||||
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):
|
||||
"""
|
||||
Shows a player's inventory.
|
||||
|
|
@ -114,4 +117,62 @@ def cmd_imcstatus(command):
|
|||
retval += '-' * 50
|
||||
|
||||
source_object.emit_to(retval)
|
||||
GLOBAL_CMD_TABLE.add_command("imcstatus", cmd_imcstatus)
|
||||
GLOBAL_CMD_TABLE.add_command("imcstatus", cmd_imcstatus)
|
||||
|
||||
|
||||
def cmd_IMC2chan(command):
|
||||
"""
|
||||
@imc2chan 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.
|
||||
"""
|
||||
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 IMCchannel channel")
|
||||
return
|
||||
imc_channel, channel = args.split()
|
||||
imclist = IMC2_CHANLIST.get_channel_list()
|
||||
if imc_channel not in [c.localname for c in imclist]:
|
||||
source_object.emit_to("IMC channel '%s' not found." % imc_channel)
|
||||
return
|
||||
else:
|
||||
imc_channel = filter(lambda c: c.localname==imc_channel,imclist)
|
||||
if imc_channel: imc_channel = imc_channel[0]
|
||||
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()
|
||||
|
||||
server,name = imc_channel.name.split(":")
|
||||
|
||||
mapping.imc2_server_name = server.strip() #settings.IMC2_SERVER_ADDRESS
|
||||
mapping.imc2_channel_name = name.strip() #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,auto_help=True,staff_help=True,
|
||||
priv_tuple=("objects.add_commchannel",))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue