update from origin

This commit is contained in:
Ayush Saini 2023-09-30 17:21:33 +05:30
parent 8beb334d64
commit bf2f252ee5
91 changed files with 1839 additions and 1281 deletions

View file

@ -42,7 +42,7 @@ class AccountV1Subsystem:
if babase.app.plus is None:
return
if (
babase.app.headless_mode
babase.app.env.headless
or babase.app.config.get('Auto Account State') == 'Local'
):
babase.app.plus.sign_in_v1('Local')

View file

@ -31,27 +31,6 @@ def get_input_device_mapped_value(
subplatform = app.classic.subplatform
appconfig = babase.app.config
# iiRcade: hard-code for a/b/c/x for now...
if babase.app.iircade_mode:
return {
'triggerRun2': 19,
'unassignedButtonsRun': False,
'buttonPickUp': 100,
'buttonBomb': 98,
'buttonJump': 97,
'buttonStart': 83,
'buttonStart2': 109,
'buttonPunch': 99,
'buttonRun2': 102,
'buttonRun1': 101,
'triggerRun1': 18,
'buttonLeft': 22,
'buttonRight': 23,
'buttonUp': 20,
'buttonDown': 21,
'buttonVRReorient': 110,
}.get(name, -1)
# If there's an entry in our config for this controller, use it.
if 'Controllers' in appconfig:
ccfgs = appconfig['Controllers']

View file

@ -4,13 +4,12 @@
from __future__ import annotations
import copy
import threading
import weakref
import threading
from enum import Enum
from typing import TYPE_CHECKING
import babase
from babase import DEFAULT_REQUEST_TIMEOUT_SECONDS
import bascenev1
if TYPE_CHECKING:
@ -36,7 +35,9 @@ class MasterServerV1CallThread(threading.Thread):
callback: MasterServerCallback | None,
response_type: MasterServerResponseType,
):
super().__init__()
# Set daemon=True so long-running requests don't keep us from
# quitting the app.
super().__init__(daemon=True)
self._request = request
self._request_type = request_type
if not isinstance(response_type, MasterServerResponseType):
@ -69,6 +70,7 @@ class MasterServerV1CallThread(threading.Thread):
def run(self) -> None:
# pylint: disable=consider-using-with
# pylint: disable=too-many-branches
import urllib.request
import urllib.parse
import urllib.error
@ -80,6 +82,13 @@ class MasterServerV1CallThread(threading.Thread):
assert plus is not None
response_data: Any = None
url: str | None = None
# Tearing the app down while this is running can lead to
# rare crashes in LibSSL, so avoid that if at all possible.
if not babase.shutdown_suppress_begin():
# App is already shutting down, so we're a no-op.
return
try:
classic = babase.app.classic
assert classic is not None
@ -101,7 +110,7 @@ class MasterServerV1CallThread(threading.Thread):
{'User-Agent': classic.legacy_user_agent_string},
),
context=babase.app.net.sslcontext,
timeout=DEFAULT_REQUEST_TIMEOUT_SECONDS,
timeout=babase.DEFAULT_REQUEST_TIMEOUT_SECONDS,
)
elif self._request_type == 'post':
url = plus.get_master_server_address() + '/' + self._request
@ -113,7 +122,7 @@ class MasterServerV1CallThread(threading.Thread):
{'User-Agent': classic.legacy_user_agent_string},
),
context=babase.app.net.sslcontext,
timeout=DEFAULT_REQUEST_TIMEOUT_SECONDS,
timeout=babase.DEFAULT_REQUEST_TIMEOUT_SECONDS,
)
else:
raise TypeError('Invalid request_type: ' + self._request_type)
@ -147,6 +156,9 @@ class MasterServerV1CallThread(threading.Thread):
response_data = None
finally:
babase.shutdown_suppress_end()
if self._callback is not None:
babase.pushcall(
babase.Call(self._run_callback, response_data),

View file

@ -214,7 +214,10 @@ class ServerController:
babase.app.classic.master_server_v1_get(
'bsAccessCheck',
{'port': bascenev1.get_game_port(), 'b': babase.app.build_number},
{
'port': bascenev1.get_game_port(),
'b': babase.app.env.build_number,
},
callback=self._access_check_response,
)
@ -379,8 +382,8 @@ class ServerController:
if self._first_run:
curtimestr = time.strftime('%c')
startupmsg = (
f'{Clr.BLD}{Clr.BLU}{babase.appnameupper()} {app.version}'
f' ({app.build_number})'
f'{Clr.BLD}{Clr.BLU}{babase.appnameupper()} {app.env.version}'
f' ({app.env.build_number})'
f' entering server-mode {curtimestr}{Clr.RST}'
)
logging.info(startupmsg)

View file

@ -545,7 +545,7 @@ class StoreSubsystem:
"""
plus = babase.app.plus
unowned_maps: set[str] = set()
if not babase.app.headless_mode:
if babase.app.env.gui:
for map_section in self.get_store_layout()['maps']:
for mapitem in map_section['items']:
if plus is None or not plus.get_purchased(mapitem):
@ -558,7 +558,7 @@ class StoreSubsystem:
try:
plus = babase.app.plus
unowned_games: set[type[bascenev1.GameActivity]] = set()
if not babase.app.headless_mode:
if babase.app.env.gui:
for section in self.get_store_layout()['minigames']:
for mname in section['items']:
if plus is None or not plus.get_purchased(mname):

View file

@ -73,7 +73,7 @@ class ClassicSubsystem(babase.AppSubsystem):
self.value_test_defaults: dict = {}
self.special_offer: dict | None = None
self.ping_thread_count = 0
self.allow_ticket_purchases: bool = not babase.app.iircade_mode
self.allow_ticket_purchases: bool = True
# Main Menu.
self.main_menu_did_initial_transition = False
@ -128,6 +128,10 @@ class ClassicSubsystem(babase.AppSubsystem):
assert isinstance(self._env['platform'], str)
return self._env['platform']
def scene_v1_protocol_version(self) -> int:
"""(internal)"""
return bascenev1.protocol_version()
@property
def subplatform(self) -> str:
"""String for subplatform.
@ -153,6 +157,7 @@ class ClassicSubsystem(babase.AppSubsystem):
plus = babase.app.plus
assert plus is not None
env = babase.app.env
cfg = babase.app.config
self.music.on_app_loading()
@ -161,11 +166,7 @@ class ClassicSubsystem(babase.AppSubsystem):
# Non-test, non-debug builds should generally be blessed; warn if not.
# (so I don't accidentally release a build that can't play tourneys)
if (
not babase.app.debug_build
and not babase.app.test_build
and not plus.is_blessed()
):
if not env.debug and not env.test and not plus.is_blessed():
babase.screenmessage('WARNING: NON-BLESSED BUILD', color=(1, 0, 0))
# FIXME: This should not be hard-coded.
@ -219,7 +220,7 @@ class ClassicSubsystem(babase.AppSubsystem):
self.special_offer = cfg['pendingSpecialOffer']['o']
show_offer()
if not babase.app.headless_mode:
if babase.app.env.gui:
babase.apptimer(3.0, check_special_offer)
# If there's a leftover log file, attempt to upload it to the
@ -465,6 +466,37 @@ class ClassicSubsystem(babase.AppSubsystem):
_analytics.game_begin_analytics()
@classmethod
def json_prep(cls, data: Any) -> Any:
"""Return a json-friendly version of the provided data.
This converts any tuples to lists and any bytes to strings
(interpreted as utf-8, ignoring errors). Logs errors (just once)
if any data is modified/discarded/unsupported.
"""
if isinstance(data, dict):
return dict(
(cls.json_prep(key), cls.json_prep(value))
for key, value in list(data.items())
)
if isinstance(data, list):
return [cls.json_prep(element) for element in data]
if isinstance(data, tuple):
logging.exception('json_prep encountered tuple')
return [cls.json_prep(element) for element in data]
if isinstance(data, bytes):
try:
return data.decode(errors='ignore')
except Exception:
logging.exception('json_prep encountered utf-8 decode error')
return data.decode(errors='ignore')
if not isinstance(data, (str, float, bool, type(None), int)):
logging.exception(
'got unsupported type in json_prep: %s', type(data)
)
return data
def master_server_v1_get(
self,
request: str,
@ -750,7 +782,7 @@ class ClassicSubsystem(babase.AppSubsystem):
from bauiv1lib.party import PartyWindow
from babase import app
assert not app.headless_mode
assert app.env.gui
bauiv1.getsound('swish').play()
@ -773,7 +805,7 @@ class ClassicSubsystem(babase.AppSubsystem):
if not in_main_menu:
set_ui_input_device(device_id)
if not babase.app.headless_mode:
if babase.app.env.gui:
bauiv1.getsound('swish').play()
babase.app.ui_v1.set_main_menu_window(

View file

@ -106,16 +106,14 @@ def get_all_tips() -> list[str]:
),
]
app = babase.app
if not app.iircade_mode:
tips += [
'If your framerate is choppy, try turning down resolution\nor '
'visuals in the game\'s graphics settings.'
]
tips += [
'If your framerate is choppy, try turning down resolution\nor '
'visuals in the game\'s graphics settings.'
]
if (
app.classic is not None
and app.classic.platform in ('android', 'ios')
and not app.on_tv
and not app.iircade_mode
and not app.env.tv
):
tips += [
(
@ -124,11 +122,7 @@ def get_all_tips() -> list[str]:
'in Settings->Graphics'
),
]
if (
app.classic is not None
and app.classic.platform in ['mac', 'android']
and not app.iircade_mode
):
if app.classic is not None and app.classic.platform in ['mac', 'android']:
tips += [
'Tired of the soundtrack? Replace it with your own!'
'\nSee Settings->Audio->Soundtrack'
@ -136,11 +130,11 @@ def get_all_tips() -> list[str]:
# Hot-plugging is currently only on some platforms.
# FIXME: Should add a platform entry for this so don't forget to update it.
if (
app.classic is not None
and app.classic.platform in ['mac', 'android', 'windows']
and not app.iircade_mode
):
if app.classic is not None and app.classic.platform in [
'mac',
'android',
'windows',
]:
tips += [
'Players can join and leave in the middle of most games,\n'
'and you can also plug and unplug controllers on the fly.',