예제 #1
0
    def onPlayerNameValidated(self, realNick, oldNick, realPID, oldPID,
                              player):
        self.mm.debug(
            3,
            "Player Name Validated realNick: '%s', oldNick: '%s', realPID: %s, oldPID: %s, player: %d"
            % (realNick, oldNick, realPID, oldPID, player.index))

        if realNick != oldNick:
            # Nick Hacker ban
            self.mm.banManager().banPlayer(
                player, self.__config['nameHackBanReason'],
                self.__config['banPeriod'], self.__config['kickBanType'],
                self.__config['banType'], 'ModManager PlayerConnect',
                self.__config['kickDelay'])
            if self.__config['nameHackBanAnnouncement']:
                msg = self.__config['nameHackBanAnnouncement'] % (oldNick,
                                                                  realNick)
                mm_utils.msg_server(msg)
                self.mm.info(msg)
            return

        if realPID != oldPID:
            # PID Hacker ban
            self.mm.banManager().banPlayer(
                player, self.__config['pidHackBanReason'],
                self.__config['banPeriod'], self.__config['kickBanType'],
                self.__config['banType'], 'ModManager PlayerConnect',
                self.__config['kickDelay'])
            # Announcement
            if self.__config['pidHackBanAnnouncement']:
                msg = self.__config['pidHackBanAnnouncement'] % (
                    oldNick, oldPID, realPID)
                mm_utils.msg_server(msg)
                self.mm.info(msg)
예제 #2
0
    def announce(self, data):
        idx = 0

        if self.__showOrdered:
            idx = self.showRuleIdx
            self.showRuleIdx += 1
            if self.showRuleIdx == len(self.__rules):
                self.showRuleIdx = 0
        else:
            while True:
                # Prevent showing the last shown rule again
                idx = random.choice(range(len(self.__rules)))
                if idx != self.showRuleIdx:
                    break
            self.showRuleIdx = idx

        rule = self.__rules[idx]

        if len(self.__rulePrefix) > 0:
            rule = self.__rulePrefix.replace('%number%', str(idx + 1)) + rule

        if self.__showBold:
            rule = "§2" + rule

        if self.__showOrange:
            rule = "|c1234" + rule

        mm_utils.msg_server(rule)
예제 #3
0
    def expireBan(self, banKey, skipSave=False):
        """Remove an expired ban on a player."""
        ban = self.__bans[banKey]

        self.__removeBan(banKey, 'Expired', skipSave)

        msg = self.__config['unbanMessage'] % (ban['nick'], "Expired")
        mm_utils.msg_server(msg)
    def onUpdate(self, data):
        """Process updates."""
        if not self.checkEnable():
            return

        currentTime = host.timer_getWallTime()

        newPending = {}
        for attacker in self.hasPendingTks.iterkeys():
            newList = []

            for tk in attacker.tkData.pending:
                tkDate = tk[0]
                tkVictim = tk[1]

                # check if there is a pending TK with time expired
                if tkDate + self.__config['punishTime'] < currentTime:
                    if bf2.serverSettings.getTKPunishByDefault():
                        attacker.tkData.punished += 1
                        self.checkPunishLimit(attacker)

                        tkVictim.tkData.timesPunished += 1
                        if self.__config['announcePunishments']:
                            try:
                                msg = self.__config['punishMessage'] % (
                                    tkVictim.getName(), attacker.getName(),
                                    tkVictim.getName(),
                                    tkVictim.tkData.timesPunished,
                                    tkVictim.tkData.timesForgiven)
                                mm_utils.msg_server(msg)
                                self.mm.info(msg)
                            except Exception, details:
                                self.mm.error("Error announcing Punish (%s)" %
                                              details)
                    else:
                        tkVictim.tkData.timesForgiven += 1
                        if 2 == self.__config['announcePunishments']:
                            try:
                                msg = self.__config['forgiveMessage'] % (
                                    tkVictim.getName(), attacker.getName(),
                                    tkVictim.getName(),
                                    tkVictim.tkData.timesPunished,
                                    tkVictim.tkData.timesForgiven)
                                mm_utils.msg_server(msg)
                                self.mm.info(msg)
                            except Exception, details:
                                self.mm.error("Error announcing forgive (%s)" %
                                              details)

                    # remove player from global list, if it was the last tk
                    if len(attacker.tkData.pending) == 1:
                        pass
                    else:
                        newPending[attacker] = 1

                else:
                    newList += [tk]
                    newPending[attacker] = 1
    def executePunishAction(self, victim, punish):
        """Punish or forgive a player."""
        if not self.checkEnable() or not victim or not victim.isValid():
            return

        attacker = victim.tkData.lastTKedBy
        if attacker == None or not attacker.isValid():
            return

        currentTime = host.timer_getWallTime()

        newList = []
        for tk in attacker.tkData.pending:
            tkDate = tk[0]
            tkVictim = tk[1]

            # if the attacker had a pending tk, and time has not run out
            if tkVictim == victim and tkDate + self.__config[
                    'punishTime'] > currentTime:
                if punish:
                    attacker.tkData.punished += 1
                    bf2.gameLogic.sendClientCommand(
                        -1, TK_PUNISH_COMMANDID,
                        (0, victim.index,
                         attacker.index))  # 100 = tkpunish event, 0 = punish
                    tkVictim.tkData.timesPunished += 1
                    if self.__config['announcePunishments']:
                        try:
                            msg = self.__config['punishMessage'] % (
                                tkVictim.getName(), attacker.getName(),
                                tkVictim.getName(),
                                tkVictim.tkData.timesPunished,
                                tkVictim.tkData.timesForgiven)
                            mm_utils.msg_server(msg)
                            self.mm.info(msg)
                        except Exception, details:
                            self.mm.error("Error announcing forgive (%s)" %
                                          details)
                else:
                    bf2.gameLogic.sendClientCommand(
                        -1, TK_PUNISH_COMMANDID,
                        (1, victim.index,
                         attacker.index))  # 100 = tkpunish event, 1 = forgive
                    tkVictim.tkData.timesForgiven += 1
                    if 2 == self.__config['announcePunishments']:
                        try:
                            msg = self.__config['forgiveMessage'] % (
                                tkVictim.getName(), attacker.getName(),
                                tkVictim.getName(),
                                tkVictim.tkData.timesPunished,
                                tkVictim.tkData.timesForgiven)
                            mm_utils.msg_server(msg)
                            self.mm.info(msg)
                        except Exception, details:
                            self.mm.error("Error announcing forgive (%s)" %
                                          details)
예제 #6
0
    def unbanPlayer(self, banKey, unBanReason=None):
        """Unban a player."""
        result = False
        ban = self.__bans[banKey]

        result = self.__removeBan(banKey, unBanReason)

        msg = self.__config['unbanMessage'] % (ban['nick'], unBanReason)
        mm_utils.msg_server(msg)

        return result
예제 #7
0
    def onChatMessage(self, playerIdx, text, channel, flags):
        if playerIdx == -1:
            return

        text = text.replace("HUD_CHAT_DEADPREFIX", "")

        if text.strip().lower() != "/rules":
            return

        rules = "Rules: " + ", ".join(self.__rules)
        mm_utils.msg_server(rules)
예제 #8
0
	def announce( self, details ):
		"""Announce the message to the server."""
		self.mm.debug( 2, "Announcer: '%s'" % details['text'] )

		#  Escape color / size codes
		try:
			for line in self.escape_codes( details['text'] ).split( '|' ):
				mm_utils.msg_server( self.unescape_codes( line ) )
		except:
			self.mm.error( "Aaaaa '%s'" % details['text'], True )

		return 1
예제 #9
0
    def announce(self, details):
        """Announce the message to the server."""
        self.mm.debug(2, "Announcer: '%s'" % details['text'])

        #  Escape color / size codes
        try:
            for line in self.escape_codes(details['text']).split('|'):
                mm_utils.msg_server(self.unescape_codes(line))
        except:
            self.mm.error("Aaaaa '%s'" % details['text'], True)

        return 1
예제 #10
0
	def onUpdate( self, data ):
		"""Process updates."""
		if not self.checkEnable():
			return

		currentTime = host.timer_getWallTime()

		newPending = {}
		for attacker in self.hasPendingTks.iterkeys():
			newList = []

			for tk in attacker.tkData.pending:
				tkDate = tk[0]
				tkVictim = tk[1]

				# check if there is a pending TK with time expired
				if tkDate + self.__config['punishTime'] < currentTime:
					if bf2.serverSettings.getTKPunishByDefault():
						attacker.tkData.punished += 1
						self.checkPunishLimit(attacker)

						tkVictim.tkData.timesPunished += 1
						if self.__config['announcePunishments']:
							try:
								msg = self.__config['punishMessage'] % ( tkVictim.getName(), attacker.getName(), tkVictim.getName(), tkVictim.tkData.timesPunished, tkVictim.tkData.timesForgiven )
								mm_utils.msg_server( msg )
								self.mm.info( msg )
							except Exception, details:
								self.mm.error( "Error announcing Punish (%s)" % details )
					else:
						tkVictim.tkData.timesForgiven += 1
						if 2 == self.__config['announcePunishments']:
							try:
								msg = self.__config['forgiveMessage'] % ( tkVictim.getName(), attacker.getName(), tkVictim.getName(), tkVictim.tkData.timesPunished, tkVictim.tkData.timesForgiven )
								mm_utils.msg_server( msg )
								self.mm.info( msg )
							except Exception, details:
								self.mm.error( "Error announcing forgive (%s)" % details )

					# remove player from global list, if it was the last tk
					if len(attacker.tkData.pending) == 1:
						pass
					else:
						newPending[attacker] = 1

				else:
					newList += [tk]
					newPending[attacker] = 1
예제 #11
0
	def executePunishAction( self, victim, punish ):
		"""Punish or forgive a player."""
		if not self.checkEnable() or not victim or not victim.isValid():
			return

		attacker = victim.tkData.lastTKedBy
		if attacker == None or not attacker.isValid():
			return

		currentTime = host.timer_getWallTime()

		newList = []
		for tk in attacker.tkData.pending:
			tkDate = tk[0]
			tkVictim = tk[1]

			# if the attacker had a pending tk, and time has not run out
			if tkVictim == victim and tkDate + self.__config['punishTime'] > currentTime:
				if punish:
					attacker.tkData.punished += 1
					bf2.gameLogic.sendClientCommand(-1, TK_PUNISH_COMMANDID, (0, victim.index, attacker.index)) # 100 = tkpunish event, 0 = punish
					tkVictim.tkData.timesPunished += 1
					if self.__config['announcePunishments']:
						try:
							msg = self.__config['punishMessage'] % ( tkVictim.getName(), attacker.getName(), tkVictim.getName(), tkVictim.tkData.timesPunished, tkVictim.tkData.timesForgiven )
							mm_utils.msg_server( msg )
							self.mm.info( msg )
						except Exception, details:
							self.mm.error( "Error announcing forgive (%s)" % details )
				else:
					bf2.gameLogic.sendClientCommand(-1, TK_PUNISH_COMMANDID, (1, victim.index, attacker.index)) # 100 = tkpunish event, 1 = forgive
					tkVictim.tkData.timesForgiven += 1
					if 2 == self.__config['announcePunishments']:
						try:
							msg = self.__config['forgiveMessage'] % ( tkVictim.getName(), attacker.getName(), tkVictim.getName(), tkVictim.tkData.timesPunished, tkVictim.tkData.timesForgiven )
							mm_utils.msg_server( msg )
							self.mm.info( msg )
						except Exception, details:
							self.mm.error( "Error announcing forgive (%s)" % details )
예제 #12
0
    def maplistLogic(self, playerConnected=False):
        playerCount = 0

        if host.sgl_getIsAIGame():
            for player in bf2.playerManager.getPlayers():
                if not player.isAIPlayer():
                    playerCount += 1
        else:
            playerCount = bf2.playerManager.getNumberOfPlayers()

        if not playerConnected:
            playerCount -= 1

        for treshhold in self.__maplists.keys():
            if playerCount >= treshhold:
                self.__nextMapList = treshhold

        if self.__currentMapList != self.__nextMapList:
            if self.__lastAnnouncedMapList != self.__nextMapList:
                mm_utils.msg_server("New maplist set: " +
                                    self.__maplists[self.__nextMapList])
                self.__lastAnnouncedMapList = self.__nextMapList

            if self.__force:
                if self.__shuffle:
                    maps = readMaps(self.__maplistPath +
                                    self.__maplists[self.__nextMapList])
                    maps = shuffleMaps(
                        maps, "gpm_ti")  # TODO: Create modmanager setting
                    loadMaps(maps)
                else:
                    host.rcon_invoke("maplist.configFile " +
                                     self.__maplistPath +
                                     self.__maplists[self.__nextMapList])
                    host.rcon_invoke("maplist.load")
                host.rcon_invoke("admin.runNextLevel")
                self.__currentMapList = self.__nextMapList
예제 #13
0
	def announce( self, details ):
		"""Announce the message to the server."""
		self.mm.debug( 2, "Announcer: '%s'" % details['text'] )
		for line in details['text'].split( '|' ):
			mm_utils.msg_server( line )
		return 1