diff --git a/plugins/utilities/advanced_party_window.py b/plugins/utilities/advanced_party_window.py index d349642..d40b718 100644 --- a/plugins/utilities/advanced_party_window.py +++ b/plugins/utilities/advanced_party_window.py @@ -42,14 +42,15 @@ import ba import _ba from typing import TYPE_CHECKING, cast import urllib.request +import urllib.parse from _thread import start_new_thread import threading version_str = "7" - +BCSSERVER = 'api2.bombsquad.ga' cache_chat = [] -connect = _ba.connect_to_party -disconnect = _ba.disconnect_from_host +connect = ba.internal.connect_to_party +disconnect = ba.internal.disconnect_from_host unmuted_names = [] smo_mode = 3 f_chat = False @@ -66,6 +67,7 @@ ssl._create_default_https_context = ssl._create_unverified_context def newconnect_to_party(address, port=43210, print_progress=False): global ip_add global p_port + dd = _ba.get_connection_to_host_info() if (dd != {}): _ba.disconnect_from_host() @@ -543,7 +545,7 @@ class ModifiedPartyWindow(bastd_party.PartyWindow): size=(20, 5), color=(0.45, 0.63, 0.15), position=(self._width/2 - 20, 50), - text='', + text="Ping:"+str(current_ping)+" ms", selectable=True, autoselect=False, v_align='center') @@ -934,8 +936,8 @@ class ModifiedPartyWindow(bastd_party.PartyWindow): _ba.chatmessage("script version "+s_v+"- build "+str(s_build)) ba.textwidget(edit=self._text_field, text="") return - elif sendtext == ".ping disabled": - PingThread(ip_add, p_port).start() + elif sendtext == ".ping": + _ba.chatmessage("My ping:"+str(current_ping)) ba.textwidget(edit=self._text_field, text="") return elif sendtext == ".save": @@ -1721,8 +1723,9 @@ def fetchAccountInfo(account, loading_widget): fdata = json.load(f) if account in fdata: servers = fdata[account] - data = urllib.request.urlopen( - f'https://api.bombsquad.ga/player?key={base64.b64encode(account.encode("utf-8")).decode("utf-8")}&base64=true') + url = f'https://{BCSSERVER}/player?key={base64.b64encode(account.encode("utf-8")).decode("utf-8")}&base64=true' + + data = urllib.request.urlopen(url) account_data = json.loads(data.read().decode('utf-8'))[0] pbid = account_data["pbid"] @@ -2172,12 +2175,10 @@ class CustomAccountViewerWindow(viewer.AccountViewerWindow): ba.print_exception('Error displaying account info.') # ba_meta export plugin - - class bySmoothy(ba.Plugin): def __init__(self): if _ba.env().get("build_number", 0) >= 20577: - _ba.connect_to_party = newconnect_to_party + ba.internal.connect_to_party = newconnect_to_party bastd_party.PartyWindow = ModifiedPartyWindow else: print("AdvancePartyWindow only runs with BombSquad version equal or higher than 1.7") diff --git a/plugins/utilities/easy_connect.py b/plugins/utilities/easy_connect.py index e55f101..3b3a26e 100644 --- a/plugins/utilities/easy_connect.py +++ b/plugins/utilities/easy_connect.py @@ -45,8 +45,24 @@ from enum import Enum from bastd.ui.popup import PopupMenuWindow, PopupWindow from typing import Any, Optional, Dict, List, Tuple, Type, Union, Callable from bastd.ui.gather.publictab import PublicGatherTab +import json +import urllib.request +import time +ENABLE_SERVER_BANNING = True +DEBUG_SERVER_COMMUNICATION = False +DEBUG_PROCESSING = False +""" +This banned servers list is maintained by commmunity , its not official. +Reason for ban can be (not limited to) using abusive server names , using server name of a reputed server/community +without necessary permissions. +Report such case on community discord channels +https://discord.gg/ucyaesh +https://ballistica.net/discord +""" +BCSURL = 'https://bcsserver.bombsquad.ga/bannedservers' + def is_game_version_lower_than(version): """ Returns a boolean value indicating whether the current game @@ -63,6 +79,23 @@ if is_game_version_lower_than("1.7.7"): else: ba_internal = ba.internal +def updateBannedServersCache(): + response = None + config = ba.app.config + if not isinstance(config.get('Banned Servers'), list): + config['Banned Servers'] = [] + try: + response = urllib.request.urlopen(BCSURL).read() + data = json.loads(response.decode('utf-8')) + bannedlist = [] + for server in data["servers"]: + bannedlist.append(server["ip"]) + config['Banned Servers'] = bannedlist + config.commit() + print("updated cache") + except Exception as e: + print(e) + class _HostLookupThread(threading.Thread): """Thread to fetch an addr.""" @@ -453,7 +486,6 @@ def popup_menu_selected_choice(self, window: popup.PopupMenu, 'UNKNOWN')) ba.open_url(url) elif choice == 'connect': - PartyQuickConnect(_party.address, _party.port) elif choice == 'save': config = ba.app.config @@ -475,6 +507,63 @@ def popup_menu_selected_choice(self, window: popup.PopupMenu, ba.playsound(ba.getsound('gunCocking')) +def _update_party_lists(self) -> None: + if not self._party_lists_dirty: + return + starttime = time.time() + config = ba.app.config + bannedservers = config.get('Banned Servers',[]) + assert len(self._parties_sorted) == len(self._parties) + + self._parties_sorted.sort( + key=lambda p: ( + p[1].ping if p[1].ping is not None else 999999.0, + p[1].index, + ) + ) + + # If signed out or errored, show no parties. + if ( + ba.internal.get_v1_account_state() != 'signed_in' + or not self._have_valid_server_list + ): + self._parties_displayed = {} + else: + if self._filter_value: + filterval = self._filter_value.lower() + self._parties_displayed = { + k: v + for k, v in self._parties_sorted + if (filterval in v.name.lower() or filterval in v.address) and (v.address not in bannedservers if ENABLE_SERVER_BANNING else True) + } + else: + self._parties_displayed = { + k: v + for k, v in self._parties_sorted + if (v.address not in bannedservers if ENABLE_SERVER_BANNING else True) + } + + # Any time our selection disappears from the displayed list, go back to + # auto-selecting the top entry. + if ( + self._selection is not None + and self._selection.entry_key not in self._parties_displayed + ): + self._have_user_selected_row = False + + # Whenever the user hasn't selected something, keep the first visible + # row selected. + if not self._have_user_selected_row and self._parties_displayed: + firstpartykey = next(iter(self._parties_displayed)) + self._selection = Selection(firstpartykey, SelectionComponent.NAME) + + self._party_lists_dirty = False + if DEBUG_PROCESSING: + print( + f'Sorted {len(self._parties_sorted)} parties in' + f' {time.time()-starttime:.5f}s.' + ) + def replace(): manualtab.ManualGatherTab._build_favorites_tab = new_build_favorites_tab manualtab.ManualGatherTab._on_favorites_connect_press = new_on_favorites_connect_press @@ -485,6 +574,7 @@ def replace(): publictab.UIRow.on_stats_click = on_stats_click publictab.UIRow.popup_menu_closing = popup_menu_closing publictab.UIRow.popup_menu_selected_choice = popup_menu_selected_choice + publictab.PublicGatherTab._update_party_lists = _update_party_lists class PartyQuickConnect(ba.Window): @@ -601,9 +691,11 @@ class PartyQuickConnect(ba.Window): self.closed = True ba.containerwidget(edit=self._root_widget, transition='out_scale') + # ba_meta export plugin - - class InitalRun(ba.Plugin): def __init__(self): replace() + config = ba.app.config + if config["launchCount"]% 5 ==0: + updateBannedServersCache() diff --git a/plugins/utilities/server_switch.py b/plugins/utilities/server_switch.py index 66b90bd..ecd3c39 100644 --- a/plugins/utilities/server_switch.py +++ b/plugins/utilities/server_switch.py @@ -22,8 +22,8 @@ from bastd.ui.confirm import ConfirmWindow import bastd.ui.mainmenu as bastd_ui_mainmenu -connect = _ba.connect_to_party -disconnect = _ba.disconnect_from_host +connect = ba.internal.connect_to_party +disconnect = ba.internal.disconnect_from_host server = [] @@ -566,7 +566,7 @@ class bySmoothy(ba.Plugin): def __init__(self): if _ba.env().get("build_number", 0) >= 20577: bastd_ui_mainmenu.MainMenuWindow._refresh_in_game = new_refresh_in_game - _ba.connect_to_party = newconnect_to_party - _ba.disconnect_from_host = newdisconnect_from_host + ba.internal.connect_to_party = newconnect_to_party + ba.internal.disconnect_from_host = newdisconnect_from_host else: print("Server Switch only works on bs 1.7 and above")