Example #1
0
 def _addto_watchlist(self):
     if g.thread_check_vac.is_alive():
         AW.MyAlertWindow(
             self.window,
             "VAC checking in progress, please wait!\n1 player / sec")
         return
     to_add = set()
     for i2 in range(1, 11):
         if getattr(self, "btn_rad" + str(i2)).value.get() == tk.TRUE:
             link = g.profile_links[getattr(self,
                                            "label_player" + str(i2)).frame]
             if link == "":
                 continue
             to_add.add(link)
     if len(to_add):
         try:
             rfile = open(g.exec_path + "watchlist", "r", encoding="utf-8")
             for line in rfile:
                 player = WP.MyWatchPlayer(line)
                 if player.link in to_add:
                     to_add.remove(player.link)
                     if not len(to_add):
                         break
         except Exception:
             AW.MyAlertWindow(self.window, "Error opening WatchList (read)")
             return
         try:
             rfile.close()
         except Exception:
             pass
         try:
             wfile = open(g.exec_path + "watchlist", "a", encoding="utf-8")
         except Exception:
             AW.MyAlertWindow(self.window,
                              "Error opening WatchList (append)")
             return
         dtt = dt.datetime.now().strftime("%d-%b-%Y %H:%M:%S")
         map2 = g.demo_stats["otherdata"]["map"]
         if g.demo_nrplayers == 4:
             map2 += "_2v2"
         for player in g.demo_stats[len(g.demo_stats) - 1].pscore:
             if player.player.profile in to_add:
                 name = player.player.name
                 link = player.player.profile[player.player.profile.
                                              rfind("/") + 1:]
                 kad = "{} / {} / {}".format(player.k, player.a, player.d)
                 wfile.write("{} {} {} {}={} ".format(
                     link, "N", dtt, len(name), name))
                 wfile.write("{}={} {}={}\n".format(len(kad), kad,
                                                    len(map2), map2))
                 to_add.remove(player.player.profile)
                 if not len(to_add):
                     break
         try:
             wfile.close()
         except Exception:
             pass
Example #2
0
def download_from_link(link, button):
    # global g.settings_dict
    if not len(link):
        return
    r = req.get(link, stream=True)
    chunk_size = 16384
    size_total = int(r.headers["Content-Length"])
    g.demo_date = r.headers["last-modified"]
    g.demo_date = dt.datetime.strptime(g.demo_date, "%a, %d %b %Y %H:%M:%S %Z").replace(tzinfo=dt.timezone.utc)
    size_total_mb = str(int(size_total / (1 << 20))) + "MB"
    size_curr = 0
    if g.settings_dict["rename_dl"] is False:
        name = g.list_links[-1][g.list_links[-1].rfind("/") + 1:]
    else:
        name = return_demo_name()
        name = name + ".dem.bz2"
    try:
        os.makedirs(g.settings_dict["dl_loc"], exist_ok=True)
        i2 = 1
        while os.path.isfile(g.settings_dict["dl_loc"] + name[:-4]):
            if i2 == 1:
                name = name[:-8] + str(i2) + ".dem.bz2"
            else:
                name = name[:-(8 + len(str(i2)))] + str(i2) + ".dem.bz2"
            i2 += 1
        dest1 = open(g.settings_dict["dl_loc"] + name, "wb")
    except Exception:
        AW.MyAlertWindow(g.app.window, "Error downloading file")
        button.text.set("Download DEMO")
        return
    g.demo_name = name[:-4]
    with dest1 as dest:
        for chunk in r.iter_content(chunk_size=chunk_size):
            dest.write(chunk)
            percent = int(size_curr / size_total * 100)
            button.text.set(str(percent) + "%  of  " + size_total_mb)
            size_curr += chunk_size
    button.text.set("extracting...")
    name = name[:name.rfind(".")]
    try:
        file1 = bz2.BZ2File(g.settings_dict["dl_loc"] + name + ".bz2")
        dest1 = open(g.settings_dict["dl_loc"] + name, "wb")
    except Exception:
        AW.MyAlertWindow(g.app.window, "Error extracting file")
        button.text.set("Download DEMO")
        return
    with file1 as file, dest1 as dest:
        shutil.copyfileobj(file, dest, chunk_size)
    os.remove(g.settings_dict["dl_loc"] + name + ".bz2")
    analyze_demo(g.settings_dict["dl_loc"] + name, button)
    if g.settings_dict["delete_after"] is True:
        os.remove(g.settings_dict["dl_loc"] + name)
Example #3
0
def actual_check_vac():
    # global g.event_check_vac
    newbans = 0
    newpb = ""
    failed = 0
    try:
        rfile = open(g.exec_path + "watchlist", "r", encoding="utf-8")
        wfile = open(g.exec_path + "watchlist.temp", "w", encoding="utf-8")
    except Exception:
        AW.MyAlertWindow(g.app.window, "Error4 opening WatchList")
        return
    for line in rfile:
        player = WP.MyWatchPlayer(line)
        if player.banned == "Y":
            wfile.write(player.ret_string())
            continue
        r = req.get(player.link)
        if r.status_code == req.codes.ok:
            i3 = r.content.find(b" day(s) since last ban")
            if i3 == -1:
                wfile.write(player.ret_string())
                continue
            data = r.content[:i3]
            days = data[data.rfind(b"\t") + 1:i3].decode("utf-8")
            delta = str(dt.datetime.now() - player.dtt)
            delta = delta[:delta.find(" day")]
            try:
                days = int(days)
                delta = int(delta)
            except Exception:
                delta = 0
            if days in (0, 1) or days <= delta:
                newbans += 1
                player.banned = "Y"
                newpb += player.name + "\n"
            wfile.write(player.ret_string())
        else:
            failed += 1
            wfile.write(player.ret_string())
        g.event_check_vac.wait(1)
    wfile.close()
    rfile.close()
    g.event_check_vac.wait(3)
    os.remove(g.exec_path + "watchlist")
    os.rename(g.exec_path + "watchlist.temp", g.exec_path + "watchlist")
    text = "{} new bans.\n".format(newbans)
    text += newpb
    if failed > 0:
        text += "Failed to check {} players".format(failed)
    AW.MyAlertWindow(g.app.window, text)
Example #4
0
def analyze_demo(path, button):
    # global g.demo_stats, g.demo_nrplayers
    button.text.set("analyzing...")
    g.demo_stats = dp.DemoParser(path, ent="NONE")
    g.demo_stats.subscribe_to_event("parser_start", my.new_demo)
    g.demo_stats.subscribe_to_event("gevent_player_team", my.player_team)
    g.demo_stats.subscribe_to_event("gevent_player_death", my.player_death)
    g.demo_stats.subscribe_to_event("gevent_player_spawn", my.player_spawn)
    g.demo_stats.subscribe_to_event("gevent_bot_takeover", my.bot_takeover)
    g.demo_stats.subscribe_to_event("gevent_begin_new_match",
                                    my.begin_new_match)
    g.demo_stats.subscribe_to_event("gevent_round_end", my.round_end)
    g.demo_stats.subscribe_to_event("gevent_round_officially_ended",
                                    my.round_officially_ended)
    g.demo_stats.subscribe_to_event("parser_update_pinfo", my.update_pinfo)
    g.demo_stats.subscribe_to_event("cmd_dem_stop", my.cmd_dem_stop)
    try:
        g.demo_stats.parse()
    except Exception:
        AW.MyAlertWindow(g.app.window, "Error parsing demo")
        button.text.set("Download DEMO")
        return
    g.demo_stats = my.STATS
    g.demo_nrplayers = g.demo_stats["otherdata"]["nrplayers"]
    rounds_list = [None] * (len(g.demo_stats) - 1)
    for i2 in range(1, len(g.demo_stats)):
        rounds_list[i2 - 1] = "Round " + str(i2)
    g.app.btn6_round.update(rounds_list, cmd=g.app.update_stats)
    # g.app.btn6_round.text.set("Round " + str(len(g.demo_stats) - 2))
    g.app.update_stats(len(g.demo_stats) - 1)
    button.text.set("Download DEMO")
Example #5
0
 def _open_watchlist(self):
     if g.thread_check_vac.is_alive():
         AW.MyAlertWindow(
             self.window,
             "VAC checking in progress, please wait!\n1 player / sec")
         return
     WW.WatchListWindow(self.window)
Example #6
0
def export_wl_csv(iscsv=False):
    try:
        file = open(g.path_exec_folder + "watchlist", "r", encoding="utf-8")
        file_csv = open(g.path_exec_folder + "watchlist.temp", "w", encoding="utf-8", newline="")
    except:
        return
    csv_writer = csv.writer(file_csv)
    csv_writer.writerow(g.csv_header)
    if iscsv:
        rdr = csv.reader(file)
        for line in rdr:
            player = WP.MyWatchPlayer(line)
            csv_writer.writerow(player.ret_csv())
    else:
        for line in file:
            player = WP.MyWatchPlayer(line, old=True)
            csv_writer.writerow(player.ret_csv())
    file.close()
    file_csv.close()
    try:
        os.remove(g.path_exec_folder + "watchlist")
        os.rename(g.path_exec_folder + "watchlist.temp", g.path_exec_folder + "watchlist")
    except PermissionError:
        AW.MyAlertWindow(g.app.window, "Cannot replace watchlist!\nwatchlist.temp was created as the newer "
                                       "version\nRestart the app or replace it manually")
Example #7
0
 def _check_int(self, var, offset=0):
     try:
         var = int(var)
     except Exception:
         AW.MyAlertWindow(self.window, "Page is not a number")
         return None
     return var + offset
Example #8
0
 def close_and_update(self):
     self._check_comm()
     if not len(self.to_remove) and not len(self.to_ban) and not len(
             self.to_comm):
         self.window.destroy()
         return
     self.rfile.seek(0, 0)
     self.findex = 1
     try:
         wfile = open(g.exec_path + "watchlist.temp", "w", encoding="utf-8")
     except Exception:
         AW.MyAlertWindow(self.window, "Cannot update WatchList")
         return
     for line in self.rfile:
         if self.findex in self.to_remove:
             self.findex += 1
             continue
         to_change = False
         if self.findex in self.to_ban or self.findex in self.to_comm:
             player = WP.MyWatchPlayer(line)
             to_change = True
         if self.findex in self.to_ban:
             player.banned = "Y" if player.banned == "N" else "N"
         if self.findex in self.to_comm:
             player.comm = self.comm_dict[self.findex]
         if to_change:
             line = player.ret_string()
         wfile.write(line)
         self.findex += 1
     wfile.close()
     self.rfile.close()
     os.remove(g.exec_path + "watchlist")
     os.rename(g.exec_path + "watchlist.temp", g.exec_path + "watchlist")
     self.window.destroy()
Example #9
0
def check_vac(window):
    # global g.thread_check_vac
    window.close_and_update()
    g.thread_check_vac = t.Thread(target=actual_check_vac, daemon=True)
    g.thread_check_vac.start()
    AW.MyAlertWindow(g.app.window,
                     "Started checking for new VAC bans\n1 player / sec")
Example #10
0
 def close_and_update(self):
     self._check_comm()
     if not len(self.to_remove) and not len(self.to_ban) and not len(
             self.to_comm):
         self.window.destroy()
         return
     self.csvfile.reset()
     self.findex = 1
     try:
         wfile = open(g.path_exec_folder + "watchlist.temp",
                      "w",
                      encoding="utf-8",
                      newline="")
         csvwr = csv.writer(wfile)
         csvwr.writerow(g.csv_header)
     except Exception:
         AW.MyAlertWindow(self.window, "Cannot update WatchList")
         return
     for line in self.csvfile.reader:
         if self.findex in self.to_remove:
             self.findex += 1
             continue
         to_change = False
         if self.findex in self.to_ban or self.findex in self.to_comm:
             player = WP.MyWatchPlayer(line)
             to_change = True
         if self.findex in self.to_ban:
             player.banned = "Y" if player.banned == "N" else "N"
         if self.findex in self.to_comm:
             player.comm = self.comm_dict[self.findex]
         if to_change:
             line = player.ret_csv()
         csvwr.writerow(line)
         self.findex += 1
     wfile.close()
     self.rfile.close()
     try:
         os.remove(g.path_exec_folder + "watchlist")
         os.rename(g.path_exec_folder + "watchlist.temp",
                   g.path_exec_folder + "watchlist")
     except PermissionError:
         AW.MyAlertWindow(
             self.window,
             "Cannot replace watchlist!\nwatchlist.temp was created as the newer "
             "version\nRestart the app or replace it manually")
     self.window.destroy()
Example #11
0
 def _check_more_stats(self):
     try:
         rfile = open(g.path_exec_folder + "watchlist",
                      "r",
                      encoding="utf-8")
         rdr = mycsv.myCSV(rfile)
         rdr.get_next()
     except:
         AW.MyAlertWindow(self.window, "Cannot read Watchlist")
         return
     for line in rdr.reader:
         player = WP.MyWatchPlayer(line)
         if player.banned == "Y":
             self.map_dict_b[player.map] = self.map_dict_b[
                 player.map] + 1 if self.map_dict_b.get(player.map) else 1
             self.rank_dict_b[player.rank] = self.rank_dict_b[
                 player.rank] + 1 if self.rank_dict_b.get(
                     player.rank) else 1
             self.server_dict_b[player.server] = self.server_dict_b[
                 player.server] + 1 if self.server_dict_b.get(
                     player.server) else 1
             self.mode_dict_b[player.mode] = self.mode_dict_b[
                 player.mode] + 1 if self.mode_dict_b.get(
                     player.mode) else 1
         self.map_dict[player.map] = self.map_dict[
             player.map] + 1 if self.map_dict.get(player.map) else 1
         self.rank_dict[player.rank] = self.rank_dict[
             player.rank] + 1 if self.rank_dict.get(player.rank) else 1
         self.server_dict[player.server] = self.server_dict[
             player.server] + 1 if self.server_dict.get(
                 player.server) else 1
         self.mode_dict[player.mode] = self.mode_dict[
             player.mode] + 1 if self.mode_dict.get(player.mode) else 1
     rfile.close()
     self.map_dict = sorted(self.map_dict.items(),
                            key=lambda item: item[1],
                            reverse=True)
     self.rank_dict = sorted(self.rank_dict.items(),
                             key=lambda item: item[1],
                             reverse=True)
     self.server_dict = sorted(self.server_dict.items(),
                               key=lambda item: item[1],
                               reverse=True)
     self.mode_dict = sorted(self.mode_dict.items(),
                             key=lambda item: item[1],
                             reverse=True)
     self.map_dict_b = sorted(self.map_dict_b.items(),
                              key=lambda item: item[1],
                              reverse=True)
     self.rank_dict_b = sorted(self.rank_dict_b.items(),
                               key=lambda item: item[1],
                               reverse=True)
     self.server_dict_b = sorted(self.server_dict_b.items(),
                                 key=lambda item: item[1],
                                 reverse=True)
     self.mode_dict_b = sorted(self.mode_dict_b.items(),
                               key=lambda item: item[1],
                               reverse=True)
Example #12
0
def check_npcap(window):
    try:
        scpa.sniff(count=1, iface=None, store=False)
        return True
    except RuntimeError:
        AW.MyAlertWindow(window.window,
                         "Can't find npcap. Get it from: " + g.npcap_link +
                         "\nPress the DOWNLOAD button to go to the link")
        window.entry1_url.text.set(g.npcap_link)
        window.label3_time.text.set("npcap error")
        return False
    except:
        AW.MyAlertWindow(window.window,
                         "Unknown npcap error. Try to reinstall or get the latest version from: \n" + g.npcap_link +
                         "\nPress the DOWNLOAD button to go to the link")
        window.entry1_url.text.set(g.npcap_link)
        window.label3_time.text.set("npcap error")
        return False
Example #13
0
def save_settings():
    # global g.settings_dict, g.exec_path
    try:
        file = open(g.exec_path + "ow_config", "w")
    except Exception:
        AW.MyAlertWindow(g.app.window, "Error saving settings to file")
        return
    for x in g.settings_dict.items():
        file.write(str(x) + "\n")
    file.close()
Example #14
0
def save_settings():
    try:
        file = open(g.path_exec_folder + "ow_config", "w")
    except Exception:
        AW.MyAlertWindow(g.app.window, "Error saving settings to file")
        return
    g.settings_dict.update({"scaling": g.windows_scaling})
    j.dump(g.settings_dict, file, ensure_ascii=False, indent=4)
    file.close()
    g.settings_dict.update({"scaling": round(100 / g.settings_dict["scaling"], 3)})
Example #15
0
def check_vac(window, delay, count):
    g.vac_delay = delay
    g.vac_players = count
    window.close_and_update()
    g.thread_check_vac = t.Thread(target=actual_check_vac, daemon=True)
    g.thread_check_vac.start()
    keyornot = "Using Steam Web API Key" if g.settings_dict["steam_api_key"] != "" else "No Steam API Key found"
    howmany = "All players" if count == 0 else "Last 30 players"
    AW.MyAlertWindow(g.app.window,
                     "Started checking for new VAC bans\n{}\n{}\n1 player / {} sec".format(keyornot, howmany,
                                                                                           g.vac_delay), "VAC check")
Example #16
0
 def _analyze_demo(self):
     # global g.settings_dict, g.thread_analyze
     path = tkfd.askopenfilename()
     if path == "":
         return
     if g.thread_download.is_alive() or g.thread_analyze.is_alive():
         AW.MyAlertWindow(g.app.window, "A demo is already being analyzed, please wait!")
         return
     g.app.update_stats()
     g.thread_analyze = t.Thread(target=lambda: f.analyze_demo(path, g.app.btn3_download), daemon=True)
     g.thread_analyze.start()
     self._destroy_checkname()
Example #17
0
 def checkk(self, root, count):
     if g.thread_export.is_alive():
         AW.MyAlertWindow(self.window,
                          "Exporting WatchList in progress, please wait!")
         return self.window.destroy()
     delay = self.entry_speed.text.get()
     try:
         delay = int(delay)
     except ValueError:
         delay = 1000
     g.settings_dict["vac_delay"] = delay
     delay = round(delay / 1000, 3)
     f.check_vac(root, delay, count)
Example #18
0
def open_link(link, button):
    # global g.browser_path, g.thread_download
    if link == "":
        return
    link = "http://" + link
    if g.thread_download.is_alive() or g.thread_analyze.is_alive():
        AW.MyAlertWindow(g.app.window,
                         "Download or analyze in progress, please wait!")
        return
    if g.settings_dict["browser_dl"] is True:
        if g.browser_path is None:
            web.open_new_tab(link)
        else:
            sp.Popen(g.browser_path + " " + link)
    else:
        g.thread_download = t.Thread(
            target=lambda: download_from_link(link, button), daemon=True)
        g.thread_download.start()
Example #19
0
 def start_stop(self):
     # global g.thread_sniff
     if f.check_npcap(self) is False:
         return
     if self.btn1_interfaces.text.get() == "Select one interface":
         AW.MyAlertWindow(self.window,
                          "You need to select one network interface")
         return
     if self.btn2_start.text.get() == "Start":
         g.thread_sniff = scpa.AsyncSniffer(
             iface=f.return_interface(self),
             lfilter=lambda y: y.haslayer(scplh.HTTPRequest),
             prn=f.process_packet(self),
             store=False)
         g.thread_sniff.start()
         self.label1_dynamic.text.set("Looking for OW DEMO link")
         self.label1_dynamic.frame.config(fg="green")
         self.btn2_start.text.set("Stop")
         self.entry1_url.frame.delete(0, tk.END)
     else:
         g.thread_sniff.stop(join=False)
         self.label1_dynamic.text.set("Not looking for anything")
         self.label1_dynamic.frame.config(fg="red")
         self.btn2_start.text.set("Start")
Example #20
0
def analyze_demo(path, button):
    # global g.demo_stats, g.demo_nrplayers
    button.text.set("analyzing...")
    g.demo_stats = dp.DemoParser(path, ent="STATS")
    g.demo_stats.subscribe_to_event("parser_start", my.new_demo)
    g.demo_stats.subscribe_to_event("parser_new_tick", my.get_game_mode)
    g.demo_stats.subscribe_to_event("gevent_player_team", my.player_team)
    g.demo_stats.subscribe_to_event("gevent_player_death", my.player_death)
    g.demo_stats.subscribe_to_event("gevent_player_spawn", my.player_spawn)
    g.demo_stats.subscribe_to_event("gevent_bot_takeover", my.bot_takeover)
    g.demo_stats.subscribe_to_event("gevent_begin_new_match", my.begin_new_match)
    g.demo_stats.subscribe_to_event("gevent_round_end", my.round_end)
    g.demo_stats.subscribe_to_event("gevent_round_officially_ended", my.round_officially_ended)
    g.demo_stats.subscribe_to_event("parser_update_pinfo", my.update_pinfo)
    g.demo_stats.subscribe_to_event("cmd_dem_stop", my.cmd_dem_stop)
    # g.demo_stats.subscribe_to_event("parser_new_tick", analyze_progress(button))
    try:
        g.demo_stats.parse()
    except Exception as err:
        AW.MyAlertWindow(g.app.window,
                         f"Error parsing demo!\n{err}\nPlease open a new issue with the download link for the demo")
        button.text.set("Download DEMO")
        return
    g.demo_ranks = dp.DemoParser(path, ent="STATS")
    g.demo_ranks.subscribe_to_event("parser_start", my.new_demo_ranks)
    g.demo_ranks.subscribe_to_event("parser_new_tick", my.get_ranks)
    try:
        g.demo_ranks.parse()
    except Exception:
        AW.MyAlertWindow(g.app.window, "Error parsing demo ranks\nStats are OK")
        for player in my.PLAYERS.values():
            player.rank = 0
    g.last_server = g.demo_ranks.header.server_name[:g.demo_ranks.header.server_name.find("(") - 1]
    if g.last_server.find("Valve CS:GO ") != -1:
        g.last_server = g.last_server[12:]
    stringsearch = g.last_server.find(" Server")
    if stringsearch != -1:
        g.last_server = g.last_server[:stringsearch]
    g.demo_ranks = my.RANK_STATS
    for xuid, rank in g.demo_ranks.items():
        for player in my.PLAYERS.values():
            if xuid == player.userinfo.xuid:
                player.rank = rank
                break

    g.demo_stats = my.STATS
    g.demo_mode = my.game_mode
    # if g.demo_mode == 7:
    #     g.expected_players = 4
    # elif g.demo_mode == 6:
    #     g.expected_players = 10
    g.demo_nrplayers = g.demo_stats["otherdata"]["nrplayers"]
    rounds_list = [None] * (len(g.demo_stats) - 1)
    for i2 in range(1, len(g.demo_stats)):
        rounds_list[i2 - 1] = "Round " + str(i2)
    g.app.btn6_round.update(rounds_list, cmd=g.app.update_stats)
    # g.app.btn6_round.text.set("Round " + str(len(g.demo_stats) - 2))
    tempmap = g.demo_stats["otherdata"]["header"].map_name
    tempmapidx = tempmap.find("_scrimmagemap")
    if tempmapidx != -1:
        tempmap = tempmap[:tempmapidx]
    g.app.label4_map.text.set(tempmap)
    g.app.label5_server.text.set(g.last_server)
    if len(tempmap) > g.TEXT_CUTOUT_MAPSERV:
        g.app.label4_map.frame.config(anchor=tk.W)
    if len(g.last_server) > g.TEXT_CUTOUT_MAPSERV:
        g.app.label5_server.frame.config(anchor=tk.W)
    # swapping player names for the one they used on first join
    for xuid, pfname in g.demo_stats["otherdata"]["PFN"].items():
        for player in my.PLAYERS.values():
            if xuid == str(player.userinfo.xuid):
                # print(f"{player.name} <=> {pfname}")
                player.name = pfname
                break
    g.app.btn6_round.text.set(f"Round {len(g.demo_stats) - 1}")
    g.app.update_stats(len(g.demo_stats) - 1)
    button.text.set("Download DEMO")
Example #21
0
def actual_check_vac():
    newbans = 0
    newpb = ""
    failed = 0
    failedpb = ""
    pnumber = 0
    try:
        rfile = open(g.path_exec_folder + "watchlist", "r", encoding="utf-8")
        crdr = mycsv.myCSV(rfile)
        wfile = open(g.path_exec_folder + "watchlist.temp", "w", encoding="utf-8", newline="")
        cwr = csv.writer(wfile)
    except Exception:
        AW.MyAlertWindow(g.app.window, "Error4 opening WatchList")
        return
    cwr.writerow(g.csv_header)
    crdr.get_next()
    for line in crdr.reader:
        player = WP.MyWatchPlayer(line)
        pnumber += 1
        if g.vac_players != 0 and pnumber < g.wl_players - g.vac_players:
            cwr.writerow(player.ret_csv())
            continue
        text = "Checking VAC {}/{}".format(pnumber, g.wl_players)
        g.app.btn8_watchlist.text.set(text)
        if player.banned == "Y":
            if player.ban_speed != -1:
                cwr.writerow(player.ret_csv())
                continue
        if g.settings_dict["steam_api_key"] == "":
            r = req.get(player.link + "?l=english")
            if r.status_code == req.codes.ok:
                i3 = r.text.find(" day(s) since last ban")
                if i3 == -1:
                    cwr.writerow(player.ret_csv())
                    continue
                data = r.text[:i3]
                days = data[data.rfind("\t") + 1:i3]
                delta = dt.datetime.now().astimezone() - player.dtt
                delta = delta.days
                try:
                    days = int(days)
                    delta = int(delta)
                except Exception:
                    delta = 0
                if days in (0, 1) or days <= delta:
                    delta_speed = dt.datetime.now().astimezone(dt.timezone.utc) - dt.timedelta(days=days)
                    delta_speed = delta_speed - player.dtt
                    player.ban_speed = delta_speed.days
                    newbans += 1
                    player.banned = "Y"
                    newpbtemp = f"{' ' * 5}#{str(pnumber)}: {player.name}{' ' * 5}"
                    newpb += newpbtemp + "\n"
                cwr.writerow(player.ret_csv())
            else:
                failed += 1
                failedpb += f"#{str(pnumber)} / "
                cwr.writerow(player.ret_csv())
        else:
            psteam64 = re.search(".*steamcommunity[.]com/profiles/(\d+)", player.link)
            psteam64 = psteam64.groups()[0]
            r = req.get(g.steam_bans_api + g.settings_dict["steam_api_key"] + "&steamids=" + psteam64)
            if r.status_code == req.codes.ok:
                data = r.json()
                if data["players"][0]["NumberOfVACBans"] + data["players"][0]["NumberOfGameBans"] > 0:
                    days = data["players"][0]["DaysSinceLastBan"]
                    delta = dt.datetime.now().astimezone() - player.dtt
                    delta = delta.days
                    if days in (0, 1) or days <= delta:
                        delta_speed = dt.datetime.now().astimezone(dt.timezone.utc) - dt.timedelta(days=days)
                        delta_speed = delta_speed - player.dtt
                        player.ban_speed = delta_speed.days
                        newbans += 1
                        player.banned = "Y"
                        newpbtemp = f"{' ' * 5}#{str(pnumber)}: {player.name}{' ' * 5}"
                        newpb += newpbtemp + "\n"
                else:
                    cwr.writerow(player.ret_csv())
                    continue
                cwr.writerow(player.ret_csv())
            else:
                failed += 1
                failedpb += f"#{str(pnumber)} / "
                cwr.writerow(player.ret_csv())
        if g.vac_delay > 0:
            g.event_check_vac.wait(g.vac_delay)
    wfile.close()
    rfile.close()
    g.event_check_vac.wait(3)
    os.remove(g.path_exec_folder + "watchlist")
    os.rename(g.path_exec_folder + "watchlist.temp", g.path_exec_folder + "watchlist")
    text = "{} new bans.\n".format(newbans)
    text += newpb
    if failed > 0:
        text += f"Failed to check {failed} players: {failedpb}"
    g.app.btn8_watchlist.text.set("WatchList")
    AW.MyAlertWindow(g.app.window, text, "VAC check")
Example #22
0
 def update_stats(self, stats=None):
     # self.btn6_round.update([])
     self._reset_chekcs()
     if stats:
         # self.label_map.text.set(g.demo_stats["map"])
         indext = 0
         indexct = 0
         if (g.demo_nrplayers == 10
                 and stats <= 15) or (g.demo_nrplayers == 4 and stats <= 8):
             self.label_scorect.text.set(g.demo_stats[stats].score_team3)
             self.label_scoret.text.set(g.demo_stats[stats].score_team2)
             indext = 6
             indexct = 1
         else:
             self.label_scorect.text.set(g.demo_stats[stats].score_team2)
             self.label_scoret.text.set(g.demo_stats[stats].score_team3)
             indext = 1
             indexct = 6
         if indext == 0:
             AW.MyAlertWindow(
                 g.app.window,
                 "error reading players, max= {}".format(g.demo_nrplayers))
             return
         for p in range(g.demo_nrplayers):
             pname = g.demo_stats[stats].pscore[p].player.name
             # pname = "alongassstringtoseehowplayerswithlongnameslook"
             kda = "{} / {} / {}".format(g.demo_stats[stats].pscore[p].k,
                                         g.demo_stats[stats].pscore[p].a,
                                         g.demo_stats[stats].pscore[p].d)
             if g.demo_stats[stats].pscore[p].player.start_team == 2:
                 if (g.demo_nrplayers == 10
                         and stats <= 15) or (g.demo_nrplayers == 4
                                              and stats <= 8):
                     if len(pname) >= 19:
                         getattr(self, "label_player" +
                                 str(indext)).frame.config(anchor=tk.W)
                     else:
                         getattr(self, "label_player" +
                                 str(indext)).frame.config(anchor=tk.E)
                 getattr(self, "label_player" + str(indext)).text.set(pname)
                 g.profile_links.update({
                     getattr(self, "label_player" + str(indext)).frame:
                     g.demo_stats[stats].pscore[p].player.profile
                 })
                 getattr(self, "label_scorep" + str(indext)).text.set(kda)
                 indext += 1
             elif g.demo_stats[stats].pscore[p].player.start_team == 3:
                 if (g.demo_nrplayers == 10
                         and stats > 15) or (g.demo_nrplayers == 4
                                             and stats > 8):
                     if len(pname) >= 19:
                         getattr(self, "label_player" +
                                 str(indexct)).frame.config(anchor=tk.W)
                     else:
                         getattr(self, "label_player" +
                                 str(indexct)).frame.config(anchor=tk.E)
                 getattr(self,
                         "label_player" + str(indexct)).text.set(pname)
                 g.profile_links.update({
                     getattr(self, "label_player" + str(indexct)).frame:
                     g.demo_stats[stats].pscore[p].player.profile
                 })
                 getattr(self, "label_scorep" + str(indexct)).text.set(kda)
                 indexct += 1
         if g.demo_nrplayers == 4:
             for p in range(3):
                 getattr(self, "label_player" + str(indext)).text.set("")
                 getattr(self, "label_scorep" + str(indext)).text.set("")
                 getattr(self, "label_player" + str(indexct)).text.set("")
                 getattr(self, "label_scorep" + str(indexct)).text.set("")
                 getattr(self, "btn_rad" + str(indext)).btn.grid_remove()
                 getattr(self, "btn_rad" + str(indexct)).btn.grid_remove()
                 indext += 1
                 indexct += 1
     else:
         self.btn6_round.update([])
         self.btn6_round.text.set("Select a round")
         # self.label_map.text.set("-")
         self.label_scorect.text.set(0)
         self.label_scoret.text.set(0)
         for p in range(1, 11):
             g.profile_links.update(
                 {getattr(self, "label_player" + str(p)).frame: ""})
             getattr(self, "label_player" + str(p)).text.set("???")
             getattr(self, "label_scorep" + str(p)).text.set("0 / 0 / 0")
             getattr(self, "btn_rad" + str(p)).btn.grid()
             if p > 5:
                 getattr(self,
                         "label_player" + str(p)).frame.config(anchor=tk.E)
     self.window.update_idletasks()