server ip fix in APW,server switch, server banning in easy connect, search by ip

This commit is contained in:
Ayush Saini 2022-12-18 16:52:31 +05:30
parent 763c1fdb61
commit 90572f7b5d
3 changed files with 111 additions and 18 deletions

View file

@ -42,14 +42,15 @@ import ba
import _ba import _ba
from typing import TYPE_CHECKING, cast from typing import TYPE_CHECKING, cast
import urllib.request import urllib.request
import urllib.parse
from _thread import start_new_thread from _thread import start_new_thread
import threading import threading
version_str = "7" version_str = "7"
BCSSERVER = 'api2.bombsquad.ga'
cache_chat = [] cache_chat = []
connect = _ba.connect_to_party connect = ba.internal.connect_to_party
disconnect = _ba.disconnect_from_host disconnect = ba.internal.disconnect_from_host
unmuted_names = [] unmuted_names = []
smo_mode = 3 smo_mode = 3
f_chat = False 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): def newconnect_to_party(address, port=43210, print_progress=False):
global ip_add global ip_add
global p_port global p_port
dd = _ba.get_connection_to_host_info() dd = _ba.get_connection_to_host_info()
if (dd != {}): if (dd != {}):
_ba.disconnect_from_host() _ba.disconnect_from_host()
@ -543,7 +545,7 @@ class ModifiedPartyWindow(bastd_party.PartyWindow):
size=(20, 5), size=(20, 5),
color=(0.45, 0.63, 0.15), color=(0.45, 0.63, 0.15),
position=(self._width/2 - 20, 50), position=(self._width/2 - 20, 50),
text='', text="Ping:"+str(current_ping)+" ms",
selectable=True, selectable=True,
autoselect=False, autoselect=False,
v_align='center') v_align='center')
@ -934,8 +936,8 @@ class ModifiedPartyWindow(bastd_party.PartyWindow):
_ba.chatmessage("script version "+s_v+"- build "+str(s_build)) _ba.chatmessage("script version "+s_v+"- build "+str(s_build))
ba.textwidget(edit=self._text_field, text="") ba.textwidget(edit=self._text_field, text="")
return return
elif sendtext == ".ping disabled": elif sendtext == ".ping":
PingThread(ip_add, p_port).start() _ba.chatmessage("My ping:"+str(current_ping))
ba.textwidget(edit=self._text_field, text="") ba.textwidget(edit=self._text_field, text="")
return return
elif sendtext == ".save": elif sendtext == ".save":
@ -1721,8 +1723,9 @@ def fetchAccountInfo(account, loading_widget):
fdata = json.load(f) fdata = json.load(f)
if account in fdata: if account in fdata:
servers = fdata[account] servers = fdata[account]
data = urllib.request.urlopen( url = f'https://{BCSSERVER}/player?key={base64.b64encode(account.encode("utf-8")).decode("utf-8")}&base64=true'
f'https://api.bombsquad.ga/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] account_data = json.loads(data.read().decode('utf-8'))[0]
pbid = account_data["pbid"] pbid = account_data["pbid"]
@ -2172,12 +2175,10 @@ class CustomAccountViewerWindow(viewer.AccountViewerWindow):
ba.print_exception('Error displaying account info.') ba.print_exception('Error displaying account info.')
# ba_meta export plugin # ba_meta export plugin
class bySmoothy(ba.Plugin): class bySmoothy(ba.Plugin):
def __init__(self): def __init__(self):
if _ba.env().get("build_number", 0) >= 20577: 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 bastd_party.PartyWindow = ModifiedPartyWindow
else: else:
print("AdvancePartyWindow only runs with BombSquad version equal or higher than 1.7") print("AdvancePartyWindow only runs with BombSquad version equal or higher than 1.7")

View file

@ -45,8 +45,24 @@ from enum import Enum
from bastd.ui.popup import PopupMenuWindow, PopupWindow from bastd.ui.popup import PopupMenuWindow, PopupWindow
from typing import Any, Optional, Dict, List, Tuple, Type, Union, Callable from typing import Any, Optional, Dict, List, Tuple, Type, Union, Callable
from bastd.ui.gather.publictab import PublicGatherTab 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): def is_game_version_lower_than(version):
""" """
Returns a boolean value indicating whether the current game Returns a boolean value indicating whether the current game
@ -63,6 +79,23 @@ if is_game_version_lower_than("1.7.7"):
else: else:
ba_internal = ba.internal 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): class _HostLookupThread(threading.Thread):
"""Thread to fetch an addr.""" """Thread to fetch an addr."""
@ -453,7 +486,6 @@ def popup_menu_selected_choice(self, window: popup.PopupMenu,
'UNKNOWN')) 'UNKNOWN'))
ba.open_url(url) ba.open_url(url)
elif choice == 'connect': elif choice == 'connect':
PartyQuickConnect(_party.address, _party.port) PartyQuickConnect(_party.address, _party.port)
elif choice == 'save': elif choice == 'save':
config = ba.app.config config = ba.app.config
@ -475,6 +507,63 @@ def popup_menu_selected_choice(self, window: popup.PopupMenu,
ba.playsound(ba.getsound('gunCocking')) 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(): def replace():
manualtab.ManualGatherTab._build_favorites_tab = new_build_favorites_tab manualtab.ManualGatherTab._build_favorites_tab = new_build_favorites_tab
manualtab.ManualGatherTab._on_favorites_connect_press = new_on_favorites_connect_press 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.on_stats_click = on_stats_click
publictab.UIRow.popup_menu_closing = popup_menu_closing publictab.UIRow.popup_menu_closing = popup_menu_closing
publictab.UIRow.popup_menu_selected_choice = popup_menu_selected_choice publictab.UIRow.popup_menu_selected_choice = popup_menu_selected_choice
publictab.PublicGatherTab._update_party_lists = _update_party_lists
class PartyQuickConnect(ba.Window): class PartyQuickConnect(ba.Window):
@ -601,9 +691,11 @@ class PartyQuickConnect(ba.Window):
self.closed = True self.closed = True
ba.containerwidget(edit=self._root_widget, transition='out_scale') ba.containerwidget(edit=self._root_widget, transition='out_scale')
# ba_meta export plugin # ba_meta export plugin
class InitalRun(ba.Plugin): class InitalRun(ba.Plugin):
def __init__(self): def __init__(self):
replace() replace()
config = ba.app.config
if config["launchCount"]% 5 ==0:
updateBannedServersCache()

View file

@ -22,8 +22,8 @@ from bastd.ui.confirm import ConfirmWindow
import bastd.ui.mainmenu as bastd_ui_mainmenu import bastd.ui.mainmenu as bastd_ui_mainmenu
connect = _ba.connect_to_party connect = ba.internal.connect_to_party
disconnect = _ba.disconnect_from_host disconnect = ba.internal.disconnect_from_host
server = [] server = []
@ -566,7 +566,7 @@ class bySmoothy(ba.Plugin):
def __init__(self): def __init__(self):
if _ba.env().get("build_number", 0) >= 20577: if _ba.env().get("build_number", 0) >= 20577:
bastd_ui_mainmenu.MainMenuWindow._refresh_in_game = new_refresh_in_game bastd_ui_mainmenu.MainMenuWindow._refresh_in_game = new_refresh_in_game
_ba.connect_to_party = newconnect_to_party ba.internal.connect_to_party = newconnect_to_party
_ba.disconnect_from_host = newdisconnect_from_host ba.internal.disconnect_from_host = newdisconnect_from_host
else: else:
print("Server Switch only works on bs 1.7 and above") print("Server Switch only works on bs 1.7 and above")