#!/usr/bin/env python # -*- coding: utf-8 # Copyright (C) 2010-2011 Stefan Hacker # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # - Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # - Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # - Neither the name of the Mumble Developers nor the names of its # contributors may be used to endorse or promote products derived from this # software without specific prior written permission. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # `AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # onjoin.py # This module allows moving players into a specific channel once # they connect regardless of which channel they were in when they left. # from mumo_module import (commaSeperatedIntegers, MumoModule) import re class onjoin(MumoModule): default_config = {'onjoin':( ('servers', commaSeperatedIntegers, []), ), 'all':( ('channel', int, 1), ), lambda x: re.match('server_\d+', x):( ('channel', int, 1), ) } def __init__(self, name, manager, configuration = None): MumoModule.__init__(self, name, manager, configuration) self.murmur = manager.getMurmurModule() def connected(self): manager = self.manager() log = self.log() log.debug("Register for Server callbacks") servers = self.cfg().onjoin.servers if not servers: servers = manager.SERVERS_ALL manager.subscribeServerCallbacks(self, servers) def disconnected(self): pass # #--- Server callback functions # def userConnected(self, server, state, context = None): log = self.log() sid = server.id() try: scfg = getattr(self.cfg(), 'server_%d' % sid) except AttributeError: scfg = self.cfg().all if state.channel != scfg.channel: log.debug("Moving user '%s' from channel %d to %d on server %d", state.name, state.channel, scfg.channel, sid) state.channel = scfg.channel try: server.setState(state) except self.murmur.InvalidChannelException: log.error("Moving user '%s' failed, target channel %d does not exist on server %d", state.name, scfg.channel, sid) def userDisconnected(self, server, state, context = None): pass def userStateChanged(self, server, state, context = None): pass def userTextMessage(self, server, user, message, current=None): pass def channelCreated(self, server, state, context = None): pass def channelRemoved(self, server, state, context = None): pass def channelStateChanged(self, server, state, context = None): pass