From 90572f7b5d408078f58d0531181eff1b3f837b21 Mon Sep 17 00:00:00 2001 From: Ayush Saini <36878972+imayushsaini@users.noreply.github.com> Date: Sun, 18 Dec 2022 16:52:31 +0530 Subject: [PATCH 1/4] server ip fix in APW,server switch, server banning in easy connect, search by ip --- plugins/utilities/advanced_party_window.py | 23 ++--- plugins/utilities/easy_connect.py | 98 +++++++++++++++++++++- plugins/utilities/server_switch.py | 8 +- 3 files changed, 111 insertions(+), 18 deletions(-) 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") From f86623a09ad4c5935ed0f7e85d12374b50f29431 Mon Sep 17 00:00:00 2001 From: imayushsaini Date: Sun, 18 Dec 2022 11:24:08 +0000 Subject: [PATCH 2/4] [ci] auto-format --- plugins/utilities/advanced_party_window.py | 6 +- plugins/utilities/easy_connect.py | 109 +++++++++++---------- 2 files changed, 60 insertions(+), 55 deletions(-) diff --git a/plugins/utilities/advanced_party_window.py b/plugins/utilities/advanced_party_window.py index d40b718..8f36b02 100644 --- a/plugins/utilities/advanced_party_window.py +++ b/plugins/utilities/advanced_party_window.py @@ -67,7 +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() @@ -1724,7 +1724,7 @@ def fetchAccountInfo(account, loading_widget): if account in fdata: servers = fdata[account] 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"] @@ -2175,6 +2175,8 @@ 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: diff --git a/plugins/utilities/easy_connect.py b/plugins/utilities/easy_connect.py index 3b3a26e..d14745c 100644 --- a/plugins/utilities/easy_connect.py +++ b/plugins/utilities/easy_connect.py @@ -63,6 +63,7 @@ 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 @@ -79,6 +80,7 @@ if is_game_version_lower_than("1.7.7"): else: ba_internal = ba.internal + def updateBannedServersCache(): response = None config = ba.app.config @@ -508,61 +510,62 @@ def popup_menu_selected_choice(self, window: popup.PopupMenu, 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) + 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, - ) + 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.' ) - # 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 @@ -697,5 +700,5 @@ class InitalRun(ba.Plugin): def __init__(self): replace() config = ba.app.config - if config["launchCount"]% 5 ==0: + if config["launchCount"] % 5 == 0: updateBannedServersCache() From 64e8a5c629ed7b4c21ca213c3486ea0d5c6e722c Mon Sep 17 00:00:00 2001 From: Rikko Date: Mon, 19 Dec 2022 01:45:20 +0530 Subject: [PATCH 3/4] Create metadata entry --- plugins/utilities.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/utilities.json b/plugins/utilities.json index 8737a94..f9d2b2c 100644 --- a/plugins/utilities.json +++ b/plugins/utilities.json @@ -299,6 +299,7 @@ } ], "versions": { + "1.2.1": null, "1.2.0": { "api_version": 7, "commit_sha": "b7036af", @@ -324,6 +325,7 @@ } ], "versions": { + "1.0.1": null, "1.0.0": { "api_version": 7, "commit_sha": "e994af5", @@ -362,6 +364,7 @@ } ], "versions": { + "1.0.1": null, "1.0.0": { "api_version": 7, "commit_sha": "e994af5", @@ -567,4 +570,4 @@ } } } -} \ No newline at end of file +} From edaf26311b9ebc3dfd0b6d35f737131d458e5f07 Mon Sep 17 00:00:00 2001 From: rikkolovescats Date: Sun, 18 Dec 2022 20:16:09 +0000 Subject: [PATCH 4/4] [ci] apply-version-metadata --- plugins/utilities.json | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/plugins/utilities.json b/plugins/utilities.json index f9d2b2c..80af302 100644 --- a/plugins/utilities.json +++ b/plugins/utilities.json @@ -299,7 +299,12 @@ } ], "versions": { - "1.2.1": null, + "1.2.1": { + "api_version": 7, + "commit_sha": "64e8a5c", + "released_on": "18-12-2022", + "md5sum": "5237713243bd3ba5dd20a5efc568f40d" + }, "1.2.0": { "api_version": 7, "commit_sha": "b7036af", @@ -325,7 +330,12 @@ } ], "versions": { - "1.0.1": null, + "1.0.1": { + "api_version": 7, + "commit_sha": "64e8a5c", + "released_on": "18-12-2022", + "md5sum": "7807b532802d17b77a0017c46ac1cbfb" + }, "1.0.0": { "api_version": 7, "commit_sha": "e994af5", @@ -364,7 +374,12 @@ } ], "versions": { - "1.0.1": null, + "1.0.1": { + "api_version": 7, + "commit_sha": "64e8a5c", + "released_on": "18-12-2022", + "md5sum": "8efcf38604e5519d66a858cc38868641" + }, "1.0.0": { "api_version": 7, "commit_sha": "e994af5", @@ -570,4 +585,4 @@ } } } -} +} \ No newline at end of file