Exemplo n.º 1
0
 def delete(self):
     """
     Deletes channel while also cleaning up channelhandler
     """
     super(ChannelDB, self).delete()
     from src.comms.channelhandler import CHANNELHANDLER
     CHANNELHANDLER.update()
Exemplo n.º 2
0
 def delete(self):
     """
     Deletes channel while also cleaning up channelhandler
     """
     _GA(self, "attributes").clear()
     _GA(self, "aliases").clear()
     super(ChannelDB, self).delete()
     from src.comms.channelhandler import CHANNELHANDLER
     CHANNELHANDLER.update()
Exemplo n.º 3
0
 def delete(self):
     """
     Deletes channel while also cleaning up channelhandler
     """
     super(ChannelDB, self).delete()
     _GA(self, "attributes").clear()
     _GA(self, "aliases").clear()
     from src.comms.channelhandler import CHANNELHANDLER
     CHANNELHANDLER.update()
Exemplo n.º 4
0
 def del_channel(self, channelkey):
     """
     Delete channel matching channelkey.
     Also cleans up channelhandler.
     """
     channels = self.filter(db_key__iexact=channelkey)
     if not channels:
         # no aliases allowed for deletion.
         return False
     for channel in channels:
         channel.delete()
     from src.comms.channelhandler import CHANNELHANDLER
     CHANNELHANDLER.update()
     return None
Exemplo n.º 5
0
 def _get_channel_cmdsets(player, player_cmdset):
     "Channel-cmdsets"
     # Create cmdset for all player's available channels
     channel_cmdset = None
     if not player_cmdset.no_channels:
         channel_cmdset = yield CHANNELHANDLER.get_cmdset(player)
     returnValue(channel_cmdset)
Exemplo n.º 6
0
 def _get_channel_cmdsets(player, player_cmdset):
     "Channel-cmdsets"
     # Create cmdset for all player's available channels
     channel_cmdset = None
     if not player_cmdset.no_channels:
         channel_cmdset = yield CHANNELHANDLER.get_cmdset(player)
     returnValue(channel_cmdset)
Exemplo n.º 7
0
    def func(self):
        "implement the function"

        if not self.args or not self.rhs:
            string = "Usage: @cboot[/quiet] <channel> = <player> [:reason]"
            self.msg(string)
            return

        channel = find_channel(self.caller, self.lhs)
        if not channel:
            return
        reason = ""
        if ":" in self.rhs:
            playername, reason = self.rhs.rsplit(":", 1)
            searchstring = playername.lstrip('*')
        else:
            searchstring = self.rhs.lstrip('*')
        player = self.caller.search(searchstring, player=True)
        if not player:
            return
        if reason:
            reason = " (reason: %s)" % reason
        if not channel.access(self.caller, "control"):
            string = "You don't control this channel."
            self.msg(string)
            return
        if not player.dbobj in channel.db_subscriptions.all():
            string = "Player %s is not connected to channel %s." % (
                player.key, channel.key)
            self.msg(string)
            return
        if not "quiet" in self.switches:
            string = "%s boots %s from channel.%s" % (self.caller, player.key,
                                                      reason)
            channel.msg(string)
        # find all player's nicks linked to this channel and delete them
        for nick in [
                nick for nick in player.character.nicks.get(
                    category="channel") or []
                if nick.db_real.lower() == channel.key
        ]:
            nick.delete()
        # disconnect player
        channel.disconnect(player)
        CHANNELHANDLER.update()
Exemplo n.º 8
0
    def func(self):
        "implement the function"

        if not self.args or not self.rhs:
            string = "Usage: @cboot[/quiet] <channel> = <player> [:reason]"
            self.msg(string)
            return

        channel = find_channel(self.caller, self.lhs)
        if not channel:
            return
        reason = ""
        if ":" in self.rhs:
            playername, reason = self.rhs.rsplit(":", 1)
            searchstring = playername.lstrip('*')
        else:
            searchstring = self.rhs.lstrip('*')
        player = self.caller.search(searchstring, player=True)
        if not player:
            return
        if reason:
            reason = " (reason: %s)" % reason
        if not channel.access(self.caller, "control"):
            string = "You don't control this channel."
            self.msg(string)
            return
        if not player.dbobj in channel.db_subscriptions.all():
            string = "Player %s is not connected to channel %s." % (player.key, channel.key)
            self.msg(string)
            return
        if not "quiet" in self.switches:
            string = "%s boots %s from channel.%s" % (self.caller, player.key, reason)
            channel.msg(string)
        # find all player's nicks linked to this channel and delete them
        for nick in [nick for nick in
                     player.character.nicks.get(category="channel") or []
                     if nick.db_real.lower() == channel.key]:
            nick.delete()
        # disconnect player
        channel.disconnect(player)
        CHANNELHANDLER.update()
Exemplo n.º 9
0
    def func(self):
        "Destroy objects cleanly."
        caller = self.caller

        if not self.args:
            self.msg("Usage: @cdestroy <channelname>")
            return
        channel = find_channel(caller, self.args)
        if not channel:
            self.msg("Could not find channel %s." % self.args)
            return
        if not channel.access(caller, 'control'):
            self.msg("You are not allowed to do that.")
            return
        channel_key = channel.key
        message = "%s is being destroyed. Make sure to change your aliases." % channel_key
        msgobj = create.create_message(caller, message, channel)
        channel.msg(msgobj)
        channel.delete()
        CHANNELHANDLER.update()
        self.msg("Channel '%s' was destroyed." % channel_key)
Exemplo n.º 10
0
    def func(self):
        "Destroy objects cleanly."
        caller = self.caller

        if not self.args:
            self.msg("Usage: @cdestroy <channelname>")
            return
        channel = find_channel(caller, self.args)
        if not channel:
            self.msg("Could not find channel %s." % self.args)
            return
        if not channel.access(caller, 'control'):
            self.msg("You are not allowed to do that.")
            return
        channel_key = channel.key
        message = "%s is being destroyed. Make sure to change your aliases." % channel_key
        msgobj = create.create_message(caller, message, channel)
        channel.msg(msgobj)
        channel.delete()
        CHANNELHANDLER.update()
        self.msg("Channel '%s' was destroyed." % channel_key)
Exemplo n.º 11
0
def get_and_merge_cmdsets(caller):
    """
    Gather all relevant cmdsets and merge them. Note
    that this is only relevant for logged-in callers.

    Note that this function returns a deferred!
    """
    # The calling object's cmdset
    try:
        yield caller.at_cmdset_get()
    except Exception:
        logger.log_trace()
    try:
        caller_cmdset = caller.cmdset.current
    except AttributeError:
        caller_cmdset = None

    # Create cmdset for all player's available channels
    channel_cmdset = None
    if not caller_cmdset.no_channels:
        channel_cmdset = yield CHANNELHANDLER.get_cmdset(caller)

    # Gather cmdsets from location, objects in location or carried
    local_objects_cmdsets = [None]
    try:
        location = caller.location
    except Exception:
        location = None
    if location and not caller_cmdset.no_objs:
        # Gather all cmdsets stored on objects in the room and
        # also in the caller's inventory and the location itself
        local_objlist = yield location.contents_get(exclude=caller.dbobj) + caller.contents + [location]
        for obj in local_objlist:
            try:
                # call hook in case we need to do dynamic changing to cmdset
                yield obj.at_cmdset_get()
            except Exception:
                logger.log_trace()
        # the call-type lock is checked here, it makes sure a player is not seeing e.g. the commands
        # on a fellow player (which is why the no_superuser_bypass must be True)
        local_objects_cmdsets = yield [obj.cmdset.current for obj in local_objlist
                                       if (obj.cmdset.current and obj.locks.check(caller, 'call', no_superuser_bypass=True))]
        for cset in local_objects_cmdsets:
            #This is necessary for object sets, or we won't be able to separate
            #the command sets from each other in a busy room.
            cset.old_duplicates = cset.duplicates
            cset.duplicates = True

    # Player object's commandsets
    try:
        player_cmdset = caller.player.cmdset.current
    except AttributeError:
        player_cmdset = None

    cmdsets = yield [caller_cmdset] + [player_cmdset] + [channel_cmdset] + local_objects_cmdsets
    # weed out all non-found sets
    cmdsets = yield [cmdset for cmdset in cmdsets if cmdset and cmdset.key!="Empty"]
    # report cmdset errors to user (these should already have been logged)
    yield [caller.msg(cmdset.errmessage) for cmdset in cmdsets if cmdset.key == "_CMDSET_ERROR"]

    if cmdsets:
        # we group and merge all same-prio cmdsets separately (this avoids order-dependent
        # clashes in certain cases, such as when duplicates=True)
        tempmergers = {}
        for cmdset in cmdsets:
            prio = cmdset.priority
            if prio in tempmergers:
                # merge same-prio cmdset together separately
                tempmergers[prio] = yield cmdset + tempmergers[prio]
            else:
                tempmergers[prio] = cmdset

        # sort cmdsets after reverse priority (highest prio are merged in last)
        cmdsets = yield sorted(tempmergers.values(), key=lambda x: x.priority)

        # Merge all command sets into one, beginning with the lowest-prio one
        cmdset = cmdsets.pop(0)
        for merging_cmdset in cmdsets:
            #print "<%s(%s,%s)> onto <%s(%s,%s)>" % (merging_cmdset.key, merging_cmdset.priority, merging_cmdset.mergetype,
            #                                        cmdset.key, cmdset.priority, cmdset.mergetype)
            cmdset = yield merging_cmdset + cmdset
    else:
        cmdset = None

    for cset in (cset for cset in local_objects_cmdsets if cset):
        cset.duplicates = cset.old_duplicates
    returnValue(cmdset)