mirror of
https://github.com/evennia/evennia.git
synced 2026-03-30 04:27:16 +02:00
Cleanups and bug fixes. Fixed the @unlink command and also made it overally more stable. Resolves issue 161. Added more string conversion routines to handle non-ascii variables being stored in an Attribute. Resolves issue 160.
This commit is contained in:
parent
14db4bea4d
commit
7d30b337d9
27 changed files with 873 additions and 1048 deletions
|
|
@ -371,7 +371,7 @@ class CmdCreate(ObjManipCommand):
|
|||
# create object (if not a valid typeclass, the default
|
||||
# object typeclass will automatically be used)
|
||||
|
||||
lockstring = "owner:id(%s);examine:perm(Builders);delete:id(%s) or perm(Wizards);get:all()" % (caller.id, caller.id)
|
||||
lockstring = "control:id(%s);examine:perm(Builders);delete:id(%s) or perm(Wizards);get:all()" % (caller.id, caller.id)
|
||||
obj = create.create_object(typeclass, name, caller,
|
||||
home=caller, aliases=aliases, locks=lockstring)
|
||||
if not obj:
|
||||
|
|
@ -489,7 +489,7 @@ class CmdDesc(MuxCommand):
|
|||
obj = caller
|
||||
desc = self.args
|
||||
# storing the description
|
||||
obj.db.desc = desc
|
||||
obj.db.desc = desc
|
||||
caller.msg("The description was set on %s." % obj.key)
|
||||
|
||||
|
||||
|
|
@ -607,7 +607,10 @@ class CmdDig(ObjManipCommand):
|
|||
new_room = create.create_object(typeclass, room["name"],
|
||||
aliases=room["aliases"])
|
||||
new_room.locks.add(lockstring)
|
||||
room_string = "Created room '%s' of type %s." % (new_room.name, typeclass)
|
||||
alias_string = ""
|
||||
if new_room.aliases:
|
||||
alias_string = " (%s)" % ", ".join(new_room_aliases)
|
||||
room_string = "Created room %s(%s)%s of type %s." % (new_room, new_room.dbref, alias_string, typeclass)
|
||||
|
||||
exit_to_string = ""
|
||||
exit_back_string = ""
|
||||
|
|
@ -637,9 +640,12 @@ class CmdDig(ObjManipCommand):
|
|||
aliases=to_exit["aliases"])
|
||||
new_to_exit.destination = new_room
|
||||
new_to_exit.locks.add(lockstring)
|
||||
exit_to_string = "\nCreated new Exit to new room: %s (aliases: %s)."
|
||||
exit_to_string = exit_to_string % (new_to_exit.name,
|
||||
new_to_exit.aliases)
|
||||
alias_string = ""
|
||||
if new_to_exit.aliases:
|
||||
alias_string = " (%s)" % ", ".join(new_to_exit.aliases)
|
||||
exit_to_string = "\nCreated Exit from %s to %s: %s(%s)%s."
|
||||
exit_to_string = exit_to_string % (location.name, new_room.name, new_to_exit,
|
||||
new_to_exit.dbref, alias_string)
|
||||
|
||||
if len(self.rhs_objs) > 1:
|
||||
# Building the exit back to the current room
|
||||
|
|
@ -666,9 +672,12 @@ class CmdDig(ObjManipCommand):
|
|||
aliases=back_exit["aliases"])
|
||||
new_back_exit.destination = location
|
||||
new_back_exit.locks.add(lockstring)
|
||||
exit_back_string = "\nExit back from new room: %s (aliases: %s)."
|
||||
exit_back_string = exit_back_string % (new_back_exit.name,
|
||||
new_back_exit.aliases)
|
||||
alias_string = ""
|
||||
if new_back_exit.aliases:
|
||||
alias_string = " (%s)" % ", ".join(new_back_exit.aliases)
|
||||
exit_back_string = "\nCreated Exit back from %s to %s: %s(%s)%s."
|
||||
exit_back_string = exit_back_string % (new_room.name, location.name,
|
||||
new_back_exit, new_back_exit.dbref, alias_string)
|
||||
caller.msg("%s%s%s" % (room_string, exit_to_string, exit_back_string))
|
||||
if new_room and 'teleport' in self.switches:
|
||||
caller.move_to(new_room)
|
||||
|
|
@ -682,17 +691,16 @@ class CmdLink(MuxCommand):
|
|||
@link[/switches] <object> = <target>
|
||||
@link[/switches] <object> =
|
||||
@link[/switches] <object>
|
||||
|
||||
Switches:
|
||||
twoway - this is only useful when both <object>
|
||||
and <target> are Exits. If so, a link back
|
||||
from <target> to <object> will also be created.
|
||||
|
||||
Switch:
|
||||
twoway - connect two exits. For this to, BOTH <object>
|
||||
and <target> must be exit objects.
|
||||
|
||||
|
||||
If <object> is an exit, set its destination. For all other object types, this
|
||||
command sets the object's Home.
|
||||
The second form sets the destination/home to None and the third form inspects
|
||||
the current value of destination/home on <object>.
|
||||
If <object> is an exit, set its destination to <target>. Two-way operation
|
||||
instead sets the destination to the *locations* of the respective given
|
||||
arguments.
|
||||
The second form (a lone =) sets the destination to None (same as the @unlink command)
|
||||
and the third form (without =) just shows the currently set destination.
|
||||
"""
|
||||
|
||||
key = "@link"
|
||||
|
|
@ -719,25 +727,25 @@ class CmdLink(MuxCommand):
|
|||
# this means a target name was given
|
||||
target = caller.search(self.rhs, global_search=True)
|
||||
if not target:
|
||||
return
|
||||
# if obj is an exit (has property destination),
|
||||
# set that, otherwise set home.
|
||||
if obj.destination:
|
||||
obj.destination = target
|
||||
if "twoway" in self.switches:
|
||||
if target.destination:
|
||||
target.destination = obj
|
||||
string = "Link created %s <-> %s (two-way)." % (obj.name, target.name)
|
||||
else:
|
||||
string = "Cannot create two-way link to non-exit."
|
||||
string += " Link created %s -> %s (one way)." % (obj.name, target.name)
|
||||
else:
|
||||
string = "Link created %s -> %s (one way)." % (obj.name, target.name)
|
||||
return
|
||||
|
||||
string = ""
|
||||
if not obj.destination:
|
||||
string += "Note: %s(%s) did not have a destination set before. Make sure you linked the right thing." % (obj.name,obj.dbref)
|
||||
if "twoway" in self.switches:
|
||||
if not (target.location and obj.location):
|
||||
string = "To create a two-way link, %s and %s must both have a location" % (obj, target)
|
||||
string += " (i.e. they cannot be rooms, but should be exits)."
|
||||
self.caller.msg(string)
|
||||
return
|
||||
if not target.destination:
|
||||
string += "\nNote: %s(%s) did not have a destination set before. Make sure you linked the right thing." % (target.name, target.dbref)
|
||||
obj.destination = target.location
|
||||
target.destination = obj.location
|
||||
string += "\nLink created %s (in %s) <-> %s (in %s) (two-way)." % (obj.name, obj.location, target.name, target.location)
|
||||
else:
|
||||
# obj is not an exit (has not property destination),
|
||||
# so set home instead
|
||||
obj.home = target
|
||||
string = "Set %s's home to %s." % (obj.name, target.name)
|
||||
obj.destination = target
|
||||
string += "\nLink created %s -> %s (one way)." % (obj.name, target)
|
||||
|
||||
elif self.rhs == None:
|
||||
# this means that no = was given (otherwise rhs
|
||||
|
|
@ -745,20 +753,20 @@ class CmdLink(MuxCommand):
|
|||
# the home/destination on object
|
||||
dest = obj.destination
|
||||
if dest:
|
||||
"%s is an exit to %s." % (obj.name, dest.name)
|
||||
string = "%s is an exit to %s." % (obj.name, dest.name)
|
||||
else:
|
||||
string = "%s has home %s." % (obj.name, obj.home)
|
||||
string = "%s is not an exit. Its home location is %s." % obj.home
|
||||
|
||||
else:
|
||||
# We gave the command @link 'obj = ' which means we want to
|
||||
# clear destination or set home to None.
|
||||
# clear destination.
|
||||
if obj.destination:
|
||||
del obj.destination
|
||||
string = "Exit %s no longer links anywhere." % obj.name
|
||||
obj.destination = None
|
||||
string = "Former exit %s no longer links anywhere." % obj.name
|
||||
else:
|
||||
del obj.home
|
||||
string = "%s no longer has a home." % obj.name
|
||||
string = "%s had no destination to unlink." % obj.name
|
||||
# give feedback
|
||||
caller.msg(string)
|
||||
caller.msg(string.strip())
|
||||
|
||||
class CmdUnLink(CmdLink):
|
||||
"""
|
||||
|
|
@ -794,6 +802,54 @@ class CmdUnLink(CmdLink):
|
|||
# call the @link functionality
|
||||
super(CmdUnLink, self).func()
|
||||
|
||||
class CmdHome(CmdLink):
|
||||
"""
|
||||
@home - control an object's home location
|
||||
|
||||
Usage:
|
||||
@home <obj> [= home_location]
|
||||
|
||||
The "home" location is a "safety" location for objects; they
|
||||
will be moved there if their current location ceases to exist. All
|
||||
objects should always have a home location for this reason.
|
||||
It is also a convenient target of the "home" command.
|
||||
|
||||
If no location is given, just view the object's home location.
|
||||
"""
|
||||
|
||||
key = "@home"
|
||||
locks = "cmd:perm(@home) or perm(Builders)"
|
||||
help_category = "Building"
|
||||
|
||||
def func(self):
|
||||
"implement the command"
|
||||
if not self.args:
|
||||
string = "Usage: @home <obj> [= home_location]"
|
||||
self.caller.msg(string)
|
||||
return
|
||||
|
||||
obj = self.caller.search(self.lhs, global_search=True)
|
||||
if not obj:
|
||||
return
|
||||
if not self.rhs:
|
||||
# just view
|
||||
home = obj.home
|
||||
if not home:
|
||||
string = "This object has no home location set!"
|
||||
else:
|
||||
string = "%s's home is set to %s(%s)." % (obj, home, home.dbref)
|
||||
else:
|
||||
# set a home location
|
||||
new_home = self.caller.search(self.rhs, global_search=True)
|
||||
if not new_home:
|
||||
return
|
||||
old_home = obj.home
|
||||
obj.home = new_home
|
||||
if old_home:
|
||||
string = "%s's home location was changed from %s(%s) to %s(%s)." % (old_home, old_home.dbref, new_home, new_home.dbref)
|
||||
else:
|
||||
string = "%s' home location was set to %s(%s)." % (new_home, new_home.dbref)
|
||||
self.caller.msg(string)
|
||||
|
||||
class CmdListCmdSets(MuxCommand):
|
||||
"""
|
||||
|
|
@ -1454,7 +1510,7 @@ class CmdExamine(ObjManipCommand):
|
|||
perms = ["<Superuser>"]
|
||||
elif not perms:
|
||||
perms = ["<None>"]
|
||||
string += "\n{wPlayer Perms/Locks{n: %s" % (", ".join(perms))
|
||||
string += "\n{wPlayer Perms{n: %s" % (", ".join(perms))
|
||||
|
||||
string += "\n{wTypeclass{n: %s (%s)" % (obj.typeclass, obj.typeclass_path)
|
||||
string += "\n{wLocation{n: %s" % obj.location
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ class DefaultCmdSet(CmdSet):
|
|||
self.add(building.CmdTypeclass())
|
||||
self.add(building.CmdLock())
|
||||
self.add(building.CmdScript())
|
||||
self.add(building.CmdHome())
|
||||
|
||||
# Comm commands
|
||||
self.add(comms.CmdAddCom())
|
||||
|
|
@ -88,6 +89,7 @@ class DefaultCmdSet(CmdSet):
|
|||
self.add(comms.CmdCdesc())
|
||||
self.add(comms.CmdPage())
|
||||
self.add(comms.CmdIRC2Chan())
|
||||
self.add(comms.CmdIMC2Chan())
|
||||
|
||||
# Batchprocessor commands
|
||||
self.add(batchprocess.CmdBatchCommands())
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ Comsys command module.
|
|||
"""
|
||||
from django.conf import settings
|
||||
from src.comms.models import Channel, Msg, PlayerChannelConnection, ExternalChannelConnection
|
||||
from src.comms import irc
|
||||
from src.comms import irc, imc2
|
||||
from src.comms.channelhandler import CHANNELHANDLER
|
||||
from src.utils import create, utils
|
||||
from src.commands.default.muxcommand import MuxCommand
|
||||
|
|
@ -892,16 +892,20 @@ class CmdIRC2Chan(MuxCommand):
|
|||
except Exception:
|
||||
string = "IRC bot definition '%s' is not valid." % self.rhs
|
||||
self.caller.msg(string)
|
||||
return
|
||||
return
|
||||
|
||||
if 'disconnect' in self.switches or 'remove' in self.switches or 'delete' in self.switches:
|
||||
chanmatch = find_channel(self.caller, channel, silent=True)
|
||||
if chanmatch:
|
||||
channel = chanmatch.key
|
||||
|
||||
ok = irc.delete_connection(irc_network, irc_port, irc_channel, irc_botname)
|
||||
if not ok:
|
||||
self.caller.msg("IRC connection/bot could not be removed, does it exist?")
|
||||
else:
|
||||
self.caller.msg("IRC connection destroyed.")
|
||||
return
|
||||
|
||||
|
||||
channel = find_channel(self.caller, channel)
|
||||
if not channel:
|
||||
return
|
||||
|
|
@ -910,3 +914,92 @@ class CmdIRC2Chan(MuxCommand):
|
|||
self.caller.msg("This IRC connection already exists.")
|
||||
return
|
||||
self.caller.msg("Connection created. Starting IRC bot.")
|
||||
|
||||
class CmdIMC2Chan(MuxCommand):
|
||||
"""
|
||||
imc2chan - link an evennia channel to imc2
|
||||
|
||||
Usage:
|
||||
@imc2chan[/switches] <evennia_channel> = <imc2network> <port> <imc2channel> <imc2_client_pwd> <imc2_server_pwd>
|
||||
|
||||
Switches:
|
||||
/disconnect - this will delete the bot and remove the imc2 connection to the channel.
|
||||
/remove - "
|
||||
/list - show all imc2<->evennia mappings
|
||||
|
||||
Example:
|
||||
@imc2chan myimcchan = server02.mudbytes.net 9000 ievennia Gjds8372 LAKdf84e
|
||||
|
||||
Connect an existing evennia channel to an IMC2 network and channel. You must have registered with the network
|
||||
beforehand and obtained valid server- and client passwords. You will always connect using the name of your
|
||||
mud, as defined by settings.SERVERNAME, so make sure this was the name you registered to the imc2 network.
|
||||
|
||||
"""
|
||||
|
||||
key = "@imc2chan"
|
||||
locks = "cmd:serversetting(IMC2_ENABLED) and perm(Wizards)"
|
||||
help_category = "Comms"
|
||||
|
||||
def func(self):
|
||||
"Setup the imc-channel mapping"
|
||||
|
||||
if 'list' in self.switches:
|
||||
# show all connections
|
||||
connections = ExternalChannelConnection.objects.filter(db_external_key__startswith='imc2_')
|
||||
if connections:
|
||||
cols = [["Evennia channel"], ["IMC channel"]]
|
||||
for conn in connections:
|
||||
cols[0].append(conn.channel.key)
|
||||
cols[1].append(" ".join(conn.external_config.split('|')))
|
||||
ftable = utils.format_table(cols)
|
||||
string = ""
|
||||
for ir, row in enumerate(ftable):
|
||||
if ir == 0:
|
||||
string += "{w%s{n" % "".join(row)
|
||||
else:
|
||||
string += "\n" + "".join(row)
|
||||
self.caller.msg(string)
|
||||
else:
|
||||
self.caller.msg("No connections found.")
|
||||
return
|
||||
|
||||
if not settings.IMC2_ENABLED:
|
||||
string = """IMC2 is not enabled. You need to activate it in game/settings.py."""
|
||||
self.caller.msg(string)
|
||||
return
|
||||
if not self.args or not self.rhs:
|
||||
string = "Usage: @imc2chan[/switches] <evennia_channel> = <imc2network> <port> <imc2channel> <client_pwd> <server_pwd>"
|
||||
self.caller.msg(string)
|
||||
return
|
||||
channel = self.lhs
|
||||
try:
|
||||
imc2_network, imc2_port, imc2_channel, imc2_client_pwd, imc2_server_pwd = [part.strip() for part in self.rhs.split(None, 4)]
|
||||
except Exception:
|
||||
string = "IMC2 connnection definition '%s' is not valid." % self.rhs
|
||||
self.caller.msg(string)
|
||||
return
|
||||
|
||||
# get the name to use for connecting
|
||||
mudname = settings.SERVERNAME
|
||||
|
||||
if 'disconnect' in self.switches or 'remove' in self.switches or 'delete' in self.switches:
|
||||
chanmatch = find_channel(self.caller, channel, silent=True)
|
||||
if chanmatch:
|
||||
channel = chanmatch.key
|
||||
|
||||
ok = imc2.delete_connection(channel, imc2_network, imc2_port, imc2_channel, mudname)
|
||||
if not ok:
|
||||
self.caller.msg("IMC2 connection could not be removed, does it exist?")
|
||||
else:
|
||||
self.caller.msg("IMC2 connection destroyed.")
|
||||
return
|
||||
|
||||
channel = find_channel(self.caller, channel)
|
||||
if not channel:
|
||||
return
|
||||
|
||||
ok = imc2.create_connection(channel, imc2_network, imc2_port, imc2_channel, mudname, imc2_client_pwd, imc2_server_pwd)
|
||||
if not ok:
|
||||
self.caller.msg("This IMC2 connection already exists.")
|
||||
return
|
||||
self.caller.msg("Connection created. Connecting to IMC2 server.")
|
||||
|
|
|
|||
|
|
@ -109,103 +109,103 @@ def cmd_imclist(command):
|
|||
source_object.emit_to(retval)
|
||||
GLOBAL_CMD_TABLE.add_command("imclist", cmd_imclist, help_category="Comms")
|
||||
|
||||
def cmd_imcstatus(command):
|
||||
"""
|
||||
imcstatus
|
||||
# def cmd_imcstatus(command):
|
||||
# """
|
||||
# imcstatus
|
||||
|
||||
Usage:
|
||||
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')
|
||||
# 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'
|
||||
# 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
|
||||
# # 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")
|
||||
# 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
|
||||
# def cmd_IMC2chan(command):
|
||||
# """
|
||||
# @imc2chan
|
||||
|
||||
Usage:
|
||||
@imc2chan <IMCServer> : <IMCchannel> <channel>
|
||||
# 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.
|
||||
# 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(":")
|
||||
# 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
|
||||
# #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()
|
||||
# #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)
|
||||
# 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")
|
||||
# GLOBAL_CMD_TABLE.add_command("@imc2chan",cmd_IMC2chan,
|
||||
# priv_tuple=("imc2.admin_imc_channels",), help_category="Comms")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,130 +0,0 @@
|
|||
"""
|
||||
IRC-related commands
|
||||
"""
|
||||
from twisted.application import internet
|
||||
from django.conf import settings
|
||||
from src.irc.connection import IRC_CHANNELS
|
||||
from src.irc.models import IRCChannelMapping
|
||||
from src import comsys
|
||||
from src.cmdtable import GLOBAL_CMD_TABLE
|
||||
from src.channels.models import CommChannel
|
||||
|
||||
def cmd_IRC2chan(command):
|
||||
"""
|
||||
@irc2chan - link irc to ingame channel
|
||||
|
||||
Usage:
|
||||
@irc2chan <#IRCchannel> <local channel>
|
||||
|
||||
Links an IRC channel (including #) to an existing
|
||||
evennia channel. You can link as many existing
|
||||
evennia channels as you like to the
|
||||
IRC channel this way. Running the command with an
|
||||
existing mapping will re-map the channels.
|
||||
|
||||
"""
|
||||
source_object = command.source_object
|
||||
if not settings.IRC_ENABLED:
|
||||
s = """IRC 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: @irc2chan IRCchannel channel")
|
||||
return
|
||||
irc_channel, channel = args.split()
|
||||
if irc_channel not in [o.factory.channel for o in IRC_CHANNELS]:
|
||||
source_object.emit_to("IRC channel '%s' not found." % irc_channel)
|
||||
return
|
||||
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 = IRCChannelMapping.objects.filter(channel__name=channel)
|
||||
if mapping:
|
||||
mapping = mapping[0]
|
||||
outstring = "Replacing %s. New " % mapping
|
||||
else:
|
||||
mapping = IRCChannelMapping()
|
||||
|
||||
mapping.irc_server_name = settings.IRC_NETWORK
|
||||
mapping.irc_channel_name = irc_channel
|
||||
mapping.channel = chanobj
|
||||
mapping.save()
|
||||
outstring += "Mapping set: %s." % mapping
|
||||
source_object.emit_to(outstring)
|
||||
|
||||
GLOBAL_CMD_TABLE.add_command("@irc2chan",cmd_IRC2chan,
|
||||
priv_tuple=("irc.admin_irc_channels",),
|
||||
help_category="Comms")
|
||||
|
||||
def cmd_IRCjoin(command):
|
||||
"""
|
||||
@ircjoin - join a new irc channel
|
||||
|
||||
Usage:
|
||||
@ircjoin <#IRCchannel>
|
||||
|
||||
Attempts to connect a bot to a new IRC channel (don't forget that
|
||||
IRC channels begin with a #).
|
||||
The bot uses the connection details defined in the main settings.
|
||||
|
||||
Observe that channels added using this command does not survive a reboot.
|
||||
"""
|
||||
|
||||
source_object = command.source_object
|
||||
arg = command.command_argument
|
||||
if not arg:
|
||||
source_object.emit_to("Usage: @ircjoin #irc_channel")
|
||||
return
|
||||
channel = arg.strip()
|
||||
if channel[0] != "#": channel = "#%s" % channel
|
||||
|
||||
if not settings.IRC_ENABLED:
|
||||
source_object.emit_to("IRC services are not active. You need to turn them on in preferences.")
|
||||
return
|
||||
|
||||
#direct creation of bot (do not add to services)
|
||||
from src.irc.connection import connect_to_IRC
|
||||
connect_to_IRC(settings.IRC_NETWORK,
|
||||
settings.IRC_PORT,
|
||||
channel, settings.IRC_NICKNAME)
|
||||
|
||||
# ---below should be checked so as to add subequent IRC bots to Services.
|
||||
# it adds just fine, but the bot does not connect. /Griatch
|
||||
# from src.irc.connection import IRC_BotFactory
|
||||
# from src.server import mud_service
|
||||
# irc = internet.TCPClient(settings.IRC_NETWORK,
|
||||
# settings.IRC_PORT,
|
||||
# IRC_BotFactory(channel,
|
||||
# settings.IRC_NETWORK,
|
||||
# settings.IRC_NICKNAME))
|
||||
# irc.setName("%s:%s" % ("IRC",channel))
|
||||
# irc.setServiceParent(mud_service.service_collection)
|
||||
|
||||
GLOBAL_CMD_TABLE.add_command("@ircjoin",cmd_IRCjoin,
|
||||
priv_tuple=("irc.admin_irc_channels",),
|
||||
help_category="Comms")
|
||||
|
||||
def cmd_IRCchanlist(command):
|
||||
"""
|
||||
ircchanlist
|
||||
|
||||
Usage:
|
||||
ircchanlist
|
||||
|
||||
Lists all externally available IRC channels.
|
||||
"""
|
||||
source_object = command.source_object
|
||||
s = "Available IRC channels:"
|
||||
for c in IRC_CHANNELS:
|
||||
s += "\n %s \t(nick '%s') on %s" % (c.factory.channel,
|
||||
c.factory.nickname,
|
||||
c.factory.network,)
|
||||
source_object.emit_to(s)
|
||||
GLOBAL_CMD_TABLE.add_command("ircchanlist", cmd_IRCchanlist,
|
||||
help_category="Comms")
|
||||
|
|
@ -1,263 +0,0 @@
|
|||
"""
|
||||
These commands typically are to do with building or modifying Objects.
|
||||
"""
|
||||
from django.conf import settings
|
||||
from src.permissions.permissions import has_perm, has_perm_string
|
||||
from src.objects.models import ObjectDB, ObjAttribute
|
||||
from game.gamesrc.commands.default.muxcommand import MuxCommand
|
||||
from src.utils import create, utils
|
||||
|
||||
|
||||
##
|
||||
## def cmd_chown(command):
|
||||
## """
|
||||
## @chown - change ownerships
|
||||
|
||||
## Usage:
|
||||
## @chown <Object> = <NewOwner>
|
||||
|
||||
## Changes the ownership of an object. The new owner specified must be a
|
||||
## player object.
|
||||
## """
|
||||
## caller = command.caller
|
||||
|
||||
## if not command.command_argument:
|
||||
## caller.msg("Usage: @chown <object> = <newowner>")
|
||||
## return
|
||||
|
||||
## eq_args = command.command_argument.split('=', 1)
|
||||
## target_name = eq_args[0]
|
||||
## owner_name = eq_args[1]
|
||||
|
||||
## if len(target_name) == 0:
|
||||
## caller.msg("Change the ownership of what?")
|
||||
## return
|
||||
|
||||
## if len(eq_args) > 1:
|
||||
## target_obj = caller.search_for_object(target_name)
|
||||
## # Use search_for_object to handle duplicate/nonexistant results.
|
||||
## if not target_obj:
|
||||
## return
|
||||
|
||||
## if not caller.controls_other(target_obj) and not caller.has_perm("objects.admin_ownership"):
|
||||
## caller.msg(defines_global.NOCONTROL_MSG)
|
||||
## return
|
||||
|
||||
## owner_obj = caller.search_for_object(owner_name)
|
||||
## # Use search_for_object to handle duplicate/nonexistant results.
|
||||
## if not owner_obj:
|
||||
## return
|
||||
## if not owner_obj.is_player():
|
||||
## caller.msg("Only players may own objects.")
|
||||
## return
|
||||
## if target_obj.is_player():
|
||||
## caller.msg("You may not change the ownership of player objects.")
|
||||
## return
|
||||
|
||||
## target_obj.set_owner(owner_obj)
|
||||
## caller.msg("%s now owns %s." % (owner_obj, target_obj))
|
||||
## else:
|
||||
## # We haven't provided a target.
|
||||
## caller.msg("Who should be the new owner of the object?")
|
||||
## return
|
||||
## GLOBAL_CMD_TABLE.add_command("@chown", cmd_chown, priv_tuple=("objects.modify_attributes",
|
||||
## "objects.admin_ownership"),
|
||||
## help_category="Building" )
|
||||
|
||||
|
||||
|
||||
#NOT VALID IN NEW SYSTEM!
|
||||
## def cmd_lock(command):
|
||||
## """
|
||||
## @lock - limit use of objects
|
||||
|
||||
## Usage:
|
||||
## @lock[/switch] <obj> [:type] [= <key>[,key2,key3,...]]
|
||||
|
||||
## Switches:
|
||||
## add - add a lock (default) from object
|
||||
## del - remove a lock from object
|
||||
## list - view all locks on object (default)
|
||||
## type:
|
||||
## DefaultLock - the default lock type (default)
|
||||
## UseLock - prevents usage of objects' commands
|
||||
## EnterLock - blocking objects from entering the object
|
||||
|
||||
## Locks an object for everyone except those matching the keys.
|
||||
## The keys can be of the following types (and searched in this order):
|
||||
## - a user #dbref (#2, #45 etc)
|
||||
## - a Group name (Builder, Immortal etc, case sensitive)
|
||||
## - a Permission string (genperms.get, etc)
|
||||
## - a Function():return_value pair. (ex: alliance():Red). The
|
||||
## function() is called on the locked object (if it exists) and
|
||||
## if its return value matches the Key is passed. If no
|
||||
## return_value is given, matches against True.
|
||||
## - an Attribute:return_value pair (ex: key:yellow_key). The
|
||||
## Attribute is the name of an attribute defined on the locked
|
||||
## object. If this attribute has a value matching return_value,
|
||||
## the lock is passed. If no return_value is given,
|
||||
## attributes will be searched, requiring a True
|
||||
## value.
|
||||
|
||||
## If no keys at all are given, the object is locked for everyone.
|
||||
## When the lock blocks a user, you may customize which error is given by
|
||||
## storing error messages in an attribute. For DefaultLocks, UseLocks and
|
||||
## EnterLocks, these attributes are called lock_msg, use_lock_msg and
|
||||
## enter_lock_msg respectively.
|
||||
|
||||
## [[lock_types]]
|
||||
|
||||
## Lock types:
|
||||
|
||||
## Name: Affects: Effect:
|
||||
## -----------------------------------------------------------------------
|
||||
## DefaultLock: Exits: controls who may traverse the exit to
|
||||
## its destination.
|
||||
## Rooms: controls whether the player sees a failure
|
||||
## message after the room description when
|
||||
## looking at the room.
|
||||
## Players/Things: controls who may 'get' the object.
|
||||
|
||||
## UseLock: All but Exits: controls who may use commands defined on
|
||||
## the locked object.
|
||||
|
||||
## EnterLock: Players/Things: controls who may enter/teleport into
|
||||
## the object.
|
||||
## VisibleLock: Players/Things: controls if the object is visible to
|
||||
## someone using the look command.
|
||||
|
||||
## Fail messages echoed to the player are stored in the attributes 'lock_msg',
|
||||
## 'use_lock_msg', 'enter_lock_msg' and 'visible_lock_msg' on the locked object
|
||||
## in question. If no such message is stored, a default will be used (or none at
|
||||
## all in some cases).
|
||||
## """
|
||||
|
||||
## caller = command.caller
|
||||
## arg = command.command_argument
|
||||
## switches = command.command_switches
|
||||
|
||||
## if not arg:
|
||||
## caller.msg("Usage: @lock[/switch] <obj> [:type] [= <key>[,key2,key3,...]]")
|
||||
## return
|
||||
## keys = ""
|
||||
## #deal with all possible arguments.
|
||||
## try:
|
||||
## lside, keys = arg.split("=",1)
|
||||
## except ValueError:
|
||||
## lside = arg
|
||||
## lside, keys = lside.strip(), keys.strip()
|
||||
## try:
|
||||
## obj_name, ltype = lside.split(":",1)
|
||||
## except:
|
||||
## obj_name = lside
|
||||
## ltype = "DefaultLock"
|
||||
## obj_name, ltype = obj_name.strip(), ltype.strip()
|
||||
|
||||
## if ltype not in ["DefaultLock","UseLock","EnterLock","VisibleLock"]:
|
||||
## caller.msg("Lock type '%s' not recognized." % ltype)
|
||||
## return
|
||||
|
||||
## obj = caller.search_for_object(obj_name)
|
||||
## if not obj:
|
||||
## return
|
||||
|
||||
## obj_locks = obj.LOCKS
|
||||
|
||||
## if "list" in switches:
|
||||
## if not obj_locks:
|
||||
## s = "There are no locks on %s." % obj.name
|
||||
## else:
|
||||
## s = "Locks on %s:" % obj.name
|
||||
## s += obj_locks.show()
|
||||
## caller.msg(s)
|
||||
## return
|
||||
|
||||
## # we are trying to change things. Check permissions.
|
||||
## if not caller.controls_other(obj):
|
||||
## caller.msg(defines_global.NOCONTROL_MSG)
|
||||
## return
|
||||
|
||||
## if "del" in switches:
|
||||
## # clear a lock
|
||||
## if obj_locks:
|
||||
## if not obj_locks.has_type(ltype):
|
||||
## caller.msg("No %s set on this object." % ltype)
|
||||
## else:
|
||||
## obj_locks.del_type(ltype)
|
||||
## obj.LOCKS = obj_locks
|
||||
## caller.msg("Cleared lock %s on %s." % (ltype, obj.name))
|
||||
## else:
|
||||
## caller.msg("No %s set on this object." % ltype)
|
||||
## return
|
||||
## else:
|
||||
## #try to add a lock
|
||||
## if not obj_locks:
|
||||
## obj_locks = locks.Locks()
|
||||
## if not keys:
|
||||
## #add an impassable lock
|
||||
## obj_locks.add_type(ltype, locks.Key())
|
||||
## caller.msg("Added impassable '%s' lock to %s." % (ltype, obj.name))
|
||||
## else:
|
||||
## keys = [k.strip() for k in keys.split(",")]
|
||||
## obj_keys, group_keys, perm_keys = [], [], []
|
||||
## func_keys, attr_keys = [], []
|
||||
## allgroups = [g.name for g in Group.objects.all()]
|
||||
## allperms = ["%s.%s" % (p.content_type.app_label, p.codename)
|
||||
## for p in Permission.objects.all()]
|
||||
## for key in keys:
|
||||
## #differentiate different type of keys
|
||||
## if Object.objects.is_dbref(key):
|
||||
## # this is an object key, like #2, #6 etc
|
||||
## obj_keys.append(key)
|
||||
## elif key in allgroups:
|
||||
## # a group key
|
||||
## group_keys.append(key)
|
||||
## elif key in allperms:
|
||||
## # a permission string
|
||||
## perm_keys.append(key)
|
||||
## elif '()' in key:
|
||||
## # a function()[:returnvalue] tuple.
|
||||
## # Check if we also request a return value
|
||||
## funcname, rvalue = [k.strip() for k in key.split('()',1)]
|
||||
## if not funcname:
|
||||
## funcname = "lock_func"
|
||||
## rvalue = rvalue.lstrip(':')
|
||||
## if not rvalue:
|
||||
## rvalue = True
|
||||
## # pack for later adding.
|
||||
## func_keys.append((funcname, rvalue))
|
||||
## elif ':' in key:
|
||||
## # an attribute[:returnvalue] tuple.
|
||||
## attr_name, rvalue = [k.strip() for k in key.split(':',1)]
|
||||
## # pack for later adding
|
||||
## attr_keys.append((attr_name, rvalue))
|
||||
## else:
|
||||
## caller.msg("Key '%s' is not recognized as a valid dbref, group or permission." % key)
|
||||
## return
|
||||
## # Create actual key objects from the respective lists
|
||||
## keys = []
|
||||
## if obj_keys:
|
||||
## keys.append(locks.ObjKey(obj_keys))
|
||||
## if group_keys:
|
||||
## keys.append(locks.GroupKey(group_keys))
|
||||
## if perm_keys:
|
||||
## keys.append(locks.PermKey(perm_keys))
|
||||
## if func_keys:
|
||||
## keys.append(locks.FuncKey(func_keys, obj.dbref))
|
||||
## if attr_keys:
|
||||
## keys.append(locks.AttrKey(attr_keys))
|
||||
|
||||
## #store the keys in the lock
|
||||
## obj_locks.add_type(ltype, keys)
|
||||
## kstring = " "
|
||||
## for key in keys:
|
||||
## kstring += " %s," % key
|
||||
## kstring = kstring[:-1]
|
||||
## caller.msg("Added lock '%s' to %s with keys%s." % (ltype, obj.name, kstring))
|
||||
## obj.LOCKS = obj_locks
|
||||
## GLOBAL_CMD_TABLE.add_command("@lock", cmd_lock, priv_tuple=("objects.create",), help_category="Building")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue