#playerSort.py # #date: 16-05-2010 #author: peppervieze #discription: This file will sort the players between teams. Admin tags and excluded from the sort. People without correct tags will be kicked. #tags like [WaW] can be person specific([WaW] peppervieze is valid, [WaW] sombody isnt. #current tag list: #<--------allied: #MGen #62Brig #62Col #62LtCol #62Maj #62BdSM # #B62|Ct #B62|Lt #B62|2Lt #B62|RS #B62|CS #B62|PS #B62|Ss #B62|Sg #B62|Cp #B62|Lc #B62|Pv # #Q62|Ct #Q62|Lt #Q62|2Lt #Q62|RS #Q62|CS #Q62|PS #Q62|Ss #Q62|Sg #Q62|Cp #Q62|Lc #Q62|Pv # #H62|Ct #H62|Lt #H62|2Lt #H62|RS #H62|CS #H62|PS #H62|Ss #H62|Sg #H62|Cp #H62|Lc #H62|Pv # #M62|Ct #M62|Lt #M62|2Lt #M62|RS #M62|CS #M62|PS #M62|Ss #M62|Sg #M62|Cp #M62|Lc #M62|Pv # #L62|SL #L62|FL #L62|PO #L62|WO #L62|Fs #L62|Fc #L62|La # #<--------axis: # #Ka**** #Ka*** #Ka** #Ka* #Ka*^ # #KaK~~~ #KaK~~ #KaK~ #KaKF~ #KaK^^^ #KaK^^ #KaK^ #KaK/// #KaK// #KaK/ #KaK # #KaR~~~ #KaR~~ #KaR~ #KaRF~ #KaR^^^ #KaR^^ #KaR^ #KaR/// #KaR// #KaR/ #KaR # #KaP~~~ #KaP~~ #KaP~ #KaPF~ #KaP^^^ #KaP^^ #KaP^ #KaP/// #KaP// #KaP/ #KaP # #KaX~~~ #KaX~~ #KaX~ #KaXF~ #KaX^^^ #KaX^^ #KaX^ #KaX/// #KaX// #KaX/ #KaX # #KaL~~~ #KaL~~ #KaL~ #KaLF~ #KaL^^^ #KaL^^ #KaL^ #KaL/// #KaL// #KaL/ #KaL #-------------- import host import bf2 #constants GAME_PLAYING = 1 GAME_END = 2 GAME_PRE_GAME = 3 G_DEBUG = 1 #vars adminNames = ['[waw] peppervieze', 'adminanem here'] tagAllied = ['62MGen','62Brig','62Col','62LtCol','62Maj','62BdSM', 'B62|Ct','B62|Lt','B62|2Lt','B62|RS','B62|CS','B62|PS','B62|Ss','B62|Sg','B62|Cp','B62|Lc','B62|Pv', 'Q62|Ct','Q62|Lt','Q62|2Lt','Q62|RS','Q62|CS','Q62|PS','Q62|Ss','Q62|Sg','Q62|Cp','Q62|Lc','Q62|Pv', 'H62|Ct','H62|Lt','H62|2Lt','H62|RS','H62|CS','H62|PS','H62|Ss','H62|Sg','H62|Cp','H62|Lc','H62|Pv', 'M62|Ct','M62|Lt','M62|2Lt','M62|RS','M62|CS','M62|PS','M62|Ss','M62|Sg','M62|Cp','M62|Lc','M62|Pv', 'L62|SL','L62|FL','L62|PO','L62|WO','L62|Fs','L62|Fc','L62|La'] tagAxis = ['Ka****','Ka***','Ka**','Ka*','Ka*', 'KaK~~~','KaK~~','KaK~','KaKF~','KaK^^^','KaK^^','KaK^','KaK///','KaK//','KaK/','KaK', 'KaR~~~','KaR~~','KaR~','KaRF~','KaR^^^','KaR^^','KaR^','KaR///','KaR//','KaR/','KaR', 'KaP~~~','KaP~~','KaP~','KaPF~','KaP^^^','KaP^^','KaP^','KaP///','KaP//','KaP/','KaP', 'KaX~~~','KaX~~','KaX~','KaXF~','KaX^^^','KaX^^','KaX^','KaX///','KaX//','KaX/','KaX', 'KaL~~~','KaL~~','KaL~','KaLF~','KaL^^^','KaL^^','KaL^','KaL///','KaL//','KaL/','KaL'] tags = [] team1 = [] team2 = [] def init(): print '[playerSort.py] initializing' #register game event handlers host.registerGameStatusHandler(onGameStatusChanged) host.registerHandler('PlayerConnect', onPlayerConnect) host.registerHandler('PlayerChangeTeams', onTeamChange) #add it all to the array. tags.append(tagAxis) tags.append(tagAllied) print '[playerSort.py] finished initializing' def broadCast(msg): host.rcon_invoke('game.sayTeam ' + '1' + ' "' + msg + '"') host.rcon_invoke('game.sayTeam ' + '2' + ' "' + msg + '"') def onGameStatusChanged(status): #Game status changes in here. if status != GAME_PLAYING: return #intercept the connection events. def onPlayerConnect(player): sortPlayer(player) #set player team based on the results from sortPlayer #if a players switches team we must know if its good or bad. def onTeamChange(player, isHuman): if isHuman: sortPlayer(player) #data contains : (playerTeam, player, newTeam) def forceSort(data): try: currTeam = data[0] player = data[1] newTeam = data[2] player.timer. destroy() player.timer = None player.setTeam(newTeam) except Exception, e: print 'Arrr: ', e pass #this functions sorts the player and returns the team he should go to. def sortPlayer(player): #print 'Received player: ', player #print 'Player is connected' playerName = player.getName() #print 'PlayerName: ', playerName for aName in adminNames: if playerName == aName: return correctTeam = False playerTeam = player.getTeam() try: playerTag = findTag(playerName) except Exception, e: print 'something went wrong - ',e pass secondLoop = 0 if playerTag == 'notag': #print '[playerSort.py] kicking player for wrong tag: ', playerName try: #print 'oplayerindex: ', player.index host.rcon_invoke('admin.kickPlayer ' + str(player.index) ) broadCast(str('Kicked ' + str(playerName) + '. Player has wrong tag.') ) except Exception, e: broadCast( str('failed to Kick ' + str(playerName) + '. Player still has wrong tag') ) #print 'Failed to kick: ', e pass return #kick the player if playerTeam == 1: secondLoop = 1 for tag in tags[playerTeam-1]: if tag == playerTag: correctTeam = True if correctTeam != True: for tag in tags[secondLoop]: if tag == playerTag: correctTeam = False if not correctTeam: if playerTeam == 1: player.timer = bf2.Timer(forceSort, 5, 1, (playerTeam, player, 2) ) if playerTeam == 2: player.timer = bf2.Timer(forceSort, 5, 1, (playerTeam, player, 1) ) def findTag(name): pName = name strTag = '' hasTag = False for team in tags: if hasTag is True: break #print 'team: ', team for tag in team: #print 'tag: ', tag i = 0 strTag = '' while(i < len(tag)): if pName[i] == tag[i]: strTag += pName[i] #print 'strTag: ', strTag else: #print 'Not the tag we are looking for.' break i += 1 #print 'playerTag: ', strTag, ' tag: ', tag if strTag == tag: hasTag = True break if hasTag == True: return strTag else: return 'notag' #loop through name to find the tag.