示例#1
0
    def run(self):
        timeout = 2
        round_ = None

        while not self.stopped():
            try:
                stat = live_stats_queue.get(True, 2)
            except Queue.Empty:
                continue
            if stat['type'] == 'kill':
                # Detect if is an autokill !!!
                # Check rank
                player = stat['data']['killer']
                round_ = stat['data']['round']
                if round_ is None:
                    continue
                data = {}
                data['kstats'], data['vstats'], data['pstats'] = get_player_stats(player)
                score = get_player_score(player, data)
                if score > 0 and score in [x[1] for x in ranks]:
                    # New rank
                    new_rank = get_rank(player, data)
                    rank_name = ranks[new_rank][0]
                    msg = """%s is now "%s" """ % (player, rank_name)
                    econ_command_queue.put({'type': 'broadcast', 'data': {'message': msg}})
                # Check live achievements
                for key, achievement in achievement_livestat_list.items():
                    achievement(stat['data'])
            if stat['type'] == 'join':
                player = stat['data']['player']
                rank = get_rank(player)
                rank_name = ranks[rank][0]
                msg = "WELCOME to the '%s' %s" % (rank_name, player)
                econ_command_queue.put({'type': 'broadcast', 'data': {'message': msg}})
示例#2
0
def livestat_multi_kill(new_data):
    def reduce_data(ret, data):
        if data["killer"] != data["victim"] and ret[1] and data["killer"] == player:
            return (ret[0] + 1, True)
        return (ret[0], False)

    player = new_data["killer"]
    round_ = new_data["round"]
    data = kill_table.find({"$and": [{"$or": [{"killer": player}, {"victim": player}]}, {"round": round_}]}).sort(
        "when", DESCENDING
    )

    multi_level = reduce(reduce_data, data, (0, True))
    multikill_name = multikill_list.get(multi_level[0], None)
    if multikill_name:
        msg = "(%s) !!! %s !!! (%s kills)" % (player, multikill_name[0].upper(), multi_level[0])
        econ_command_queue.put({"type": "broadcast", "data": {"message": msg}})
示例#3
0
    def run(self):

        timeout = 2
        self.round_ = None
        self.gametype = None
        # Map is None at Starting then is it possible ???
        self.map_ = None
        if self.debug:
            f = open('teeawards.log', 'w')

        while not self.stopped():
#            print "read"
            ready, _, _ = select.select([self.master], [], [], timeout)
            if not ready:
                continue
            lines = os.read(self.master, 512)
            if self.manager.conf['conf'].get('record_stats', '1') == '0':
                continue

            for line in lines.splitlines():
                # Skip empty lines
                if line == '':
                    continue
                # Join team:
                elif re.match("\[(.*)\]\[game\]: team_join player='.*:(.*)' team=(.*)", line):
                    when, player, team = re.match("\[(.*)\]\[game\]: team_join player='.*:(.*)' team=(.*)", line).groups()
                    if self.debug:
                        print "JOIN: ", player, team
                    when = datetime.fromtimestamp(int(when, 16))
                    data = {'when': when,  'player': player.strip(), 'team': team.strip(), 'round': self.round_, 'map': self.map_, 'gametype': self.gametype} 
                    self.manager.join_table.save(data)
                    live_stats_queue.put({'type': 'join', 'data': data})
                # Other Join team ???: (Fixed in teeworlds 0.6.2 ??????)
                elif re.match(".*_join player='.*:(.*)' team=(.*)", line):
                    when, player, team = re.match(" ?t?e?am_join player='.*:(.*)' team=(.*)", line).groups()
                    if self.debug:
                        print "JOIN_other: ", player, team
                    when = datetime.fromtimestamp(int(when, 16))
                    data = {'when': when,  'player': player.strip(), 'team': team.strip(), 'round': self.round_, 'map': self.map_, 'gametype': self.gametype} 
                    self.manager.join_table.save(data)
                    live_stats_queue.put({'type': 'join', 'data': data})
                # Change team
                elif re.match("\[(.*)\]\[game\]: team_join player='.*:(.*)' m_Team=(.*)", line):
                    when, player, team = re.match("\[(.*)\]\[game\]: team_join player='.*:(.*)' m_Team=(.*)", line).groups()
                    if self.debug:
                        print "Change team:", player, team
                    when = datetime.fromtimestamp(int(when, 16))
                    data = {'when': when,  'player': player.strip(), 'team': team.strip(), 'round': self.round_, 'map': self.map_, 'gametype': self.gametype}
                    self.manager.changeteam_table.save(data)
                    # KICK THE PLAYER !!!!!
                    # JUST FOR don't f**k stats or NOT ??
                # Change name
                elif re.match("\[(.*)\]\[chat\]: \*\*\* '(.*)' changed name to '(.*)'", line):
                    when, name, new_name = re.match("\[(.*)\]\[chat\]: \*\*\* '(.*)' changed name to '(.*)'", line).groups()
                    if self.debug:
                        print "Change name: ", name, " -> ", new_name
                    when = datetime.fromtimestamp(int(when, 16))

                    data = {'when': when,  'name': name.strip(), 'new_name': new_name.strip(), 'round': self.round_, 'map': self.map_, 'gametype': self.gametype}
                    self.manager.changename_table.save(data)
                    econ_command_queue.put({'type': 'kick',
                                            'data': {'player': new_name,
                                                     'message': 'You have to reconnect when you change your name'
                                                    }
                                           })
                # Start round
                elif re.match("\[(.*)\]\[game\]: start round type='(.*)' teamplay='([0-9]*)'", line):
                    when, gametype, teamplay = re.match("\[(.*)\]\[game\]: start round type='(.*)' teamplay='([0-9]*)'", line).groups()
                    when = datetime.fromtimestamp(int(when, 16))
                    data = {'when': when,  'gametype': gametype.strip(), 'teamplay': teamplay.strip(), 'map': self.map_}
                    # NEED TO BE SURE THAT IS NOT A STARTROUND JUST BEFORE A CHANGE MAP .... handled in changemap section (the next one) 
                    if self.debug:
                        print "START ROUND:", gametype, "TEAMPLAY", teamplay, self.map_
                    self.round_ = self.manager.round_table.save(data)
                    self.gametype = gametype
                # Change map
                elif re.match("\[(.*)\]\[datafile\]: loading done. datafile='(.*)'", line):
                    when, raw_map = re.match("\[(.*)\]\[datafile\]: loading done. datafile='(.*)'", line).groups()
                    when = datetime.fromtimestamp(int(when, 16))
                    map_name = os.path.basename(raw_map)
                    data = {'when': when,  'map': map_name.strip()}
                    self.map_ = self.manager.map_table.save(data)
                    # DELETE BAD LAST ROUND
                    if self.round_:
                        if self.debug:
                            print "DELETE BAD LAST ROUND"
                        self.manager.round_table.remove(self.round_)
                    if self.debug:
                        print "CHANGE MAP", map_name, self.map_
                    self.round_ = None
                    self.gametype = None
                # Kick
                elif re.match("\[(.*)\]\[chat\]: \*\*\* '(.*)' has left the game \(Kicked for inactivity\)", line):
                    when, player = re.match("\[(.*)\]\[chat\]: \*\*\* '(.*)' has left the game \(Kicked for inactivity\)", line).groups()
                    if self.debug:
                        print "KICKED", player
                    when = datetime.fromtimestamp(int(when, 16))
                    data = {'when': when,  'player': player.strip(), 'round': self.round_, 'map': self.map_, 'gametype': self.gametype}
                    self.manager.kick_table.save(data)
                # Timeout
                elif re.match("\[(.*)\]\[chat\]: \*\*\* '(.*)' has left the game \(Timeout\)", line):
                    when, player = re.match("\[(.*)\]\[chat\]: \*\*\* '(.*)' has left the game \(Timeout\)", line).groups()
                    if self.debug:
                        print "TIMEOUT", player
                    when = datetime.fromtimestamp(int(when, 16))
                    data = {'when': when,  'player': player.strip(), 'round': self.round_, 'map': self.map_, 'gametype': self.gametype}
                    self.manager.timeout_table.save(data)
                # Leave game
                elif re.match("\[(.*)\]\[game\]: leave player='[0-9]*:(.*)'", line):
                    when, player = re.match("\[(.*)\]\[game\]: leave player='[0-9]*:(.*)'", line).groups()
                    if self.debug:
                        print "LEAVE", player
                        print line
                    when = datetime.fromtimestamp(int(when, 16))
                    data = {'when': when,  'player': player.strip(), 'round': self.round_, 'map': self.map_, 'gametype': self.gametype}
                    self.manager.leave_table.save(data)
                # Pickup
                elif re.match("\[(.*)\]\[game\]: pickup player='.*:(.*)' item=(.*)$", line):
                    when, player, item = re.match("\[(.*)\]\[game\]: pickup player='.*:(.*)' item=(.*\/.*)$", line).groups()
                    when = datetime.fromtimestamp(int(when, 16))
                    if self.debug:
                        print "PICKUP: ", when, player, item
                    data = {'when': when,  'player': player.strip(), 'item': item.strip(), 'round': self.round_, 'gametype': self.gametype}
                    self.manager.pickup_table.save(data)
                # Kill
                elif re.match("\[(.*)\]\[game\]: kill killer='.*:(.*)' victim='.*:(.*)' weapon=(.*) special=(.*)", line):
                    when, killer, victim, weapon, special = re.match("\[(.*)\]\[game\]: kill killer='.*:(.*)' victim='.*:(.*)' weapon=(.*) special=(.*)", line).groups()
                    when = datetime.fromtimestamp(int(when, 16))
                    if self.debug:
                        print when, killer, "KILL", victim, "with", weapon, "and special", special
                    data = {'when': when, 'killer': killer.strip(), 'victim': victim.strip(),
                            'weapon': weapon.strip(), 'special': special.strip(), 'round': self.round_, 'map': self.map_, 'gametype': self.gametype}
                    self.manager.kill_table.save(data)
                    live_stats_queue.put({'type': 'kill', 'data': data})
                # Get Flag
                elif re.match("\[(.*)\]\[game\]: flag_grab player='.*:(.*)'", line):
                    when, player = re.match("\[(.*)\]\[game\]: flag_grab player='.*:(.*)'", line).groups()
                    when = datetime.fromtimestamp(int(when, 16))
                    data = {'when': when, 'player': player, 'round': self.round_, 'map': self.map_, 'gametype': self.gametype}
                    if self.debug:
                        print when, player, "GET FLAG"
                    self.manager.flaggrab_table.save(data)
                # Return Flag
                elif re.match("\[(.*)\]\[game\]: flag_return player='.*:(.*)'", line):
                    when, player = re.match("\[(.*)\]\[game\]: flag_return player='.*:(.*)'", line).groups()
                    when = datetime.fromtimestamp(int(when, 16))
                    data = {'when': when, 'player': player, 'round': self.round_, 'map': self.map_, 'gametype': self.gametype}
                    if self.debug:
                        print when, player, "RETURN FLAG"
                    self.manager.flagreturn_table.save(data)
                # Capture Flag
                elif re.match("\[(.*)\]\[game\]: flag_capture player='.*:(.*)'", line):
                    when, player = re.match("\[(.*)\]\[game\]: flag_capture player='.*:(.*)'", line).groups()
                    when = datetime.fromtimestamp(int(when, 16))
                    data = {'when': when, 'player': player, 'round': self.round_, 'map': self.map_, 'gametype': self.gametype}
                    if self.debug:
                        print when, player, "CAPTURE FLAG"
                    self.manager.flagcapture_table.save(data)
                # Other
                else:
                    if self.debug:
                        f.write("NON CAPTURED LINE: " + line)
                        f.write("\n")
                        print "NON CAPTURED LINE", line
        if self.debug:
            f.close()