예제 #1
0
    def kickPlayer(self,
                   player,
                   kickReason=None,
                   kickDelay=None,
                   kickType=mm_utils.KickBanType.rcon):
        """Kick a player with a reason."""
        if self.__kickTimers.has_key(player.index):
            # Already scheduled for a kick
            self.mm.warn(
                "Kick failed ( Kick already in progress for player %d )" %
                (player.index))
            return False

        if kickType != mm_utils.KickBanType.rcon:
            self.mm.warn("Unsupported kick type '%d' (using %d instead)" %
                         (kickType, mm_utils.KickBanType.rcon))
            kickType = mm_utils.KickBanType.rcon

        try:
            player_name = player.getName()
        except RuntimeError:
            # player has already left?
            player_name = self.validatePlayerName(None)

        # Rcon kick method
        kickDelay = self.validateKickDelay(kickDelay)
        kickReason = self.validateKickReason(kickReason)
        msg = self.__config['kickMessage'] % (player_name, kickReason)
        mm_utils.msg_player(player.index, msg)
        player.mmKickReason = kickReason
        player.mmKickType = kickType
        self.__kickTimers[player.index] = bf2.Timer(self.kickPlayerNow,
                                                    kickDelay, 1, player)

        return True
예제 #2
0
	def kickPlayer( self, player, kickReason=None, kickDelay=None, kickType=mm_utils.KickBanType.rcon ):
		"""Kick a player with a reason."""
		if self.__kickTimers.has_key( player.index ):
			# Already scheduled for a kick
			self.mm.warn( "Kick failed ( Kick already in progress for player %d )" % ( player.index ) )	
			return False

		if kickType != mm_utils.KickBanType.rcon:
			self.mm.warn( "Unsupported kick type '%d' (using %d instead)" % ( kickType, mm_utils.KickBanType.rcon ) )
			kickType = mm_utils.KickBanType.rcon

		try:
			player_name = player.getName()
		except RuntimeError:
			# player has already left?
			player_name = self.validatePlayerName( None )

		# Rcon kick method
		kickDelay = self.validateKickDelay( kickDelay );
		kickReason = self.validateKickReason( kickReason )
		msg = self.__config['kickMessage'] % ( player_name, kickReason );
		mm_utils.msg_player( player.index, msg )
		player.mmKickReason = kickReason
		player.mmKickType = kickType
		self.__kickTimers[player.index] = bf2.Timer( self.kickPlayerNow, kickDelay, 1, player )

		return True
예제 #3
0
    def onChatMessage(self, playerid, text, channel, flags):
        """Check for in game commands."""
        if 1 != self.__state:
            return 0

        try:
            # Strip channel prefixes so commands can be used in all channels
            text = mm_utils.MsgChannels.named[channel].stripPrefix(text)
            self.mm.debug(2, "Chat[%d]: '%s'" % (playerid, text))
            player = bf2.playerManager.getPlayerByIndex(playerid)
            if player:
                prefix = self.__config['cmdPrefix']
                if text.startswith(prefix):
                    # We have a potential command
                    (cmd, args) = mm_utils.largs(text[len(prefix):], None, 2,
                                                 '', True)
                    self.mm.debug(2, "CMD?: '%s' '%s'" % (cmd, args))
                    if cmd in self.__igacmds:
                        # We have a command
                        cdkeyhash = mm_utils.get_cd_key_hash(player)
                        profileid = str(player.getProfileId())
                        playername = player.getName()
                        admins = self.__admins
                        self.mm.debug(
                            2, "Looking for: %s, %s, %s" %
                            (cdkeyhash, profileid, playername))
                        if cdkeyhash in admins:
                            # User is an admin
                            admin = cdkeyhash
                        elif profileid in admins:
                            # User is an admin
                            admin = profileid
                        elif playername in admins:
                            # User is an admin
                            admin = playername
                        else:
                            # User is not an admin
                            mm_utils.msg_player(
                                player.index,
                                self.__config['notAdminMessage'] %
                                (playername))
                            return

                        # User is an admin
                        details = self.__igacmds[cmd]
                        if details['priv'] in admins[admin] or 'all' in admins[
                                admin]:
                            self.runCmd(playerid, details['cmd'], args)
                        else:
                            mm_utils.msg_player(
                                player.index,
                                self.__config['notAuthedMessage'] %
                                (playername, cmd))
        except:
            self.mm.error("Oops bad", True)
예제 #4
0
	def onPlayerSpawn( self, player, soldier ):
		"""Announce to new spawning players."""
		if 1 != self.__state:
			return 0

		if self.__newPlayers.has_key( player.index ):
			# First spawn for this player, send message
			for msg in self.__joinMessages:
				for line in self.escape_codes( msg ).split( '|' ):
					line = self.unescape_codes( line.replace( '%player%', player.getName() ) );
					mm_utils.msg_player( player.index, line )
			del self.__newPlayers[player.index]
예제 #5
0
	def onPlayerSpawn( self, player, soldier ):
		"""Announce to new spawning players."""
		if 1 != self.__state:
			return 0

		if self.__newPlayers.has_key( player.index ):
			# First spawn for this player, send message
			for msg in self.__joinMessages:
				for line in msg.split( '|' ):
					line = line.replace( '%player%', player.getName() );
					mm_utils.msg_player( player.index, line )
			del self.__newPlayers[player.index]
예제 #6
0
	def __wordWarnKickPlayer( self, player, word ):
		"""Warn a player for using a kick word and kick / ban if needed."""
		kicker_info = self.playerKickerInfo( player )
		kicker_info.kickWordWarnings += 1
		if kicker_info.kickWordWarnings > self.__config['kickLimit']:
			return self.mm.banManager().kickPlayer( player, self.__config['kickWordReason'] )
		else:
			return mm_utils.msg_player( player.index, self.__config['warnWordMessage'] % player.getName() )
예제 #7
0
	def onChatMessage( self, playerid, text, channel, flags ):
		"""Check for in game commands."""
		if 1 != self.__state:
			return 0

		try:
			# Strip channel prefixes so commands can be used in all channels
			text = mm_utils.MsgChannels.named[channel].stripPrefix( text )
			self.mm.debug( 2, "Chat[%d]: '%s'" % ( playerid, text ) )
			player = bf2.playerManager.getPlayerByIndex( playerid )
			if player:
				prefix = self.__config['cmdPrefix']
				if text.startswith( prefix ):
					# We have a potential command
					( cmd, args ) = mm_utils.largs( text[len(prefix):], None, 2, '', True )
					self.mm.debug( 2, "CMD?: '%s' '%s'" % ( cmd, args ) )
					if cmd in self.__igacmds:
						# We have a command
						cdkeyhash = mm_utils.get_cd_key_hash( player )
						profileid = str( player.getProfileId() )
						playername = player.getName()
						admins = self.__admins
						self.mm.debug( 2, "Looking for: %s, %s, %s" % ( cdkeyhash, profileid, playername ) )
						if cdkeyhash in admins:
							# User is an admin
							admin = cdkeyhash
						elif profileid in admins:
							# User is an admin
							admin = profileid
						elif playername in admins:
							# User is an admin
							admin = playername
						else:
							# User is not an admin
							mm_utils.msg_player( player.index, self.__config['notAdminMessage'] % ( playername ) )
							return

						# User is an admin
						details = self.__igacmds[cmd]
						if details['priv'] in admins[admin] or 'all' in admins[admin]:
							self.runCmd( playerid, details['cmd'], args )
						else:
							mm_utils.msg_player( player.index, self.__config['notAuthedMessage'] % ( playername, cmd ) )
		except:
			self.mm.error( "Oops bad", True )
예제 #8
0
 def __wordWarnKickPlayer(self, player, word):
     """Warn a player for using a kick word and kick / ban if needed."""
     kicker_info = self.playerKickerInfo(player)
     kicker_info.kickWordWarnings += 1
     if kicker_info.kickWordWarnings > self.__config['kickLimit']:
         return self.mm.banManager().kickPlayer(
             player, self.__config['kickWordReason'])
     else:
         return mm_utils.msg_player(
             player.index,
             self.__config['warnWordMessage'] % player.getName())
예제 #9
0
	def cmdWarnPlayer( self, ctx, cmd ):
		"""Send a message to a specific player."""
		( playerid, msg ) = mm_utils.largs( cmd, None, 2, '' )

		player = mm_utils.find_player( playerid, True )

		if player is None:
			ctx.write( 'Error: player %s not found\n' % playerid )
			self.mm.error( "Failed to find player %s" % playerid )
		else:
			lmsg = msg.lower()
			if self.__warnings.has_key( lmsg ):
				# message shortcut replace
				msg = self.__warnings[lmsg]

			msg = self.__config['warningPrefix'] + msg
			msg = msg.replace( '%player%', player.getName().strip( ' ' ) );
			msg = msg.replace( '%action%', self.__config['warningAction'] );
			msg = msg.replace( '%admin%', ctx.bf2ccClient.adminName );

			mm_utils.msg_player( player.index, msg )
			ctx.write( 'Chat sent to player %s\n' % playerid )
예제 #10
0
    def cmdWarnPlayer(self, ctx, cmd):
        """Send a message to a specific player."""
        (playerid, msg) = mm_utils.largs(cmd, None, 2, '')

        player = mm_utils.find_player(playerid, True)

        if player is None:
            ctx.write('Error: player %s not found\n' % playerid)
            self.mm.error("Failed to find player %s" % playerid)
        else:
            lmsg = msg.lower()
            if self.__warnings.has_key(lmsg):
                # message shortcut replace
                msg = self.__warnings[lmsg]

            msg = self.__config['warningPrefix'] + msg
            msg = msg.replace('%player%',
                              player.getName().strip(' '))
            msg = msg.replace('%action%', self.__config['warningAction'])
            msg = msg.replace('%admin%', ctx.bf2ccClient.adminName)

            mm_utils.msg_player(player.index, msg)
            ctx.write('Chat sent to player %s\n' % playerid)
예제 #11
0
 def __wordWarnBanPlayer(self, player, word):
     """Warn a player for using a kick word and kick / ban if needed."""
     kicker_info = player.mmKickerInfo
     kicker_info.banWordWarnings += 1
     if kicker_info.banWordWarnings > self.__config['banLimit']:
         return self.mm.banManager().banPlayer(
             player, self.__config['banWordReason'],
             self.__config['banPeriod'], mm_utils.KickBanType.rcon,
             mm_utils.BanMethod.key, 'ModManager Kicker',
             self.__config['kickDelay'])
     else:
         return mm_utils.msg_player(
             player.index,
             self.__config['warnWordMessage'] % player.getName())
예제 #12
0
    def banPlayer(self,
                  player,
                  banReason=None,
                  banPeriod=None,
                  banType=None,
                  banMethod=None,
                  bannedBy=None,
                  banDelay=None):
        """Ban a player for a given period with a reason."""
        if self.__banTimers.has_key(player.index):
            # We already have a ban scheduled for this player
            self.mm.warn(
                "Ban failed ( Ban already in progress for player %d )" %
                (player.index))
            return False

        # N.B. We store a copy of key player info in case they leave before the ban activates
        try:
            player_name = player.getName()
        except RuntimeError:
            # player has already left?
            player_name = None

        try:
            player_profileid = player.getProfileId()
        except RuntimeError:
            # player has already left?
            player_profileid = self.validateBanProfileId(None)

        try:
            player_address = player.getAddress()
        except RuntimeError:
            # player has already left?
            player_address = None

        cdkeyhash = self.validateBanCdKeyHash(mm_utils.get_cd_key_hash(player))
        player_address = self.validateBanAddress(player_address)
        player.mmBanDetails = {
            'reason': self.validateBanReason(banReason),
            'period': self.validateBanPeriod(banPeriod),
            'type': self.validateBanType(banType),
            'method': self.validateBanMethod(banMethod, cdkeyhash,
                                             player_address),
            'by': self.validateBannedBy(bannedBy),
            'name': self.validatePlayerName(player_name),
            'profileid': player_profileid,
            'address': player_address,
            'cdkeyhash': cdkeyhash
        }

        if mm_utils.BanMethod.key == player.mmBanDetails['method']:
            if player.mmBanDetails['cdkeyhash'] is None:
                # Can't ban this player: Ban by cdkeyhash and no cdkeyhash information
                self.mm.error(
                    "Ban failed ( Unable to determine cdkeyhash for player %d '%s' )"
                    % (player.index, player_name))
                return False

        elif mm_utils.BanMethod.address == player.mmBanDetails['method']:
            if player.mmBanDetails['address'] is None:
                # Can't ban this player: Ban by address and no address information
                self.mm.error(
                    "Ban failed ( Unable to determine address for player %d '%s' )"
                    % (player.index, player_name))
                return False

        banDelay = self.validateBanDelay(banDelay)

        if 0 != banDelay:
            msg = self.__config['banMessage'] % (player.mmBanDetails['name'],
                                                 player.mmBanDetails['reason'])
            mm_utils.msg_player(player.index, msg)

            self.__banTimers[player.index] = bf2.Timer(self.banPlayerNow,
                                                       banDelay, 1, player)
        else:
            self.banPlayerNow(player)
예제 #13
0
	def banPlayer( self, player, banReason=None, banPeriod=None, banType=None, banMethod=None, bannedBy=None, banDelay=None ):
		"""Ban a player for a given period with a reason."""
		if self.__banTimers.has_key( player.index ):
			# We already have a ban scheduled for this player
			self.mm.warn( "Ban failed ( Ban already in progress for player %d )" % ( player.index ) )	
			return False

		# N.B. We store a copy of key player info in case they leave before the ban activates
		try:
			player_name = player.getName()
		except RuntimeError:
			# player has already left?
			player_name = None

		try:
			player_profileid = player.getProfileId()
		except RuntimeError:
			# player has already left?
			player_profileid = self.validateBanProfileId( None )

		try:
			player_address = player.getAddress()
		except RuntimeError:
			# player has already left?
			player_address = None

		cdkeyhash = self.validateBanCdKeyHash( mm_utils.get_cd_key_hash( player ) )
		player_address = self.validateBanAddress( player_address )
		player.mmBanDetails = {
			'reason': self.validateBanReason( banReason ),
			'period': self.validateBanPeriod( banPeriod ),
			'type' : self.validateBanType( banType ),
			'method': self.validateBanMethod( banMethod, cdkeyhash, player_address ),
			'by': self.validateBannedBy( bannedBy ),
			'name': self.validatePlayerName( player_name ),
			'profileid': player_profileid,
			'address': player_address,
			'cdkeyhash': cdkeyhash 
		}

		if mm_utils.BanMethod.key == player.mmBanDetails['method']:
			if player.mmBanDetails['cdkeyhash'] is None:
				# Can't ban this player: Ban by cdkeyhash and no cdkeyhash information
				self.mm.error( "Ban failed ( Unable to determine cdkeyhash for player %d '%s' )" % ( player.index, player_name ) )	
				return False

		elif mm_utils.BanMethod.address == player.mmBanDetails['method']:
			if player.mmBanDetails['address'] is None:
				# Can't ban this player: Ban by address and no address information
				self.mm.error( "Ban failed ( Unable to determine address for player %d '%s' )" % ( player.index, player_name ) )	
				return False

		banDelay = self.validateBanDelay( banDelay )

		if 0 != banDelay:
			msg = self.__config['banMessage'] % ( player.mmBanDetails['name'], player.mmBanDetails['reason'] )
			mm_utils.msg_player( player.index, msg )

			self.__banTimers[player.index] = bf2.Timer( self.banPlayerNow, banDelay, 1, player )
		else:
			self.banPlayerNow( player )