From b183138ecdfabd8c6ecae1773a13d30f22d94cf8 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 16 Jun 2023 19:44:15 -0700 Subject: [PATCH] tidying --- .efrocachemap | 88 +++++++++---------- .idea/dictionaries/ericf.xml | 1 + CHANGELOG.md | 9 +- .../.idea/dictionaries/ericf.xml | 1 + src/assets/ba_data/python/babase/__init__.py | 2 + src/assets/ba_data/python/babase/_apputils.py | 12 ++- .../ba_data/python/babase/_assetmanager.py | 6 +- src/assets/ba_data/python/baclassic/_input.py | 2 +- src/assets/ba_data/python/baclassic/_music.py | 2 +- src/assets/ba_data/python/baclassic/_net.py | 7 +- .../ba_data/python/baclassic/_subsystem.py | 6 +- src/assets/ba_data/python/baenv.py | 2 +- .../ba_data/python/bauiv1lib/mainmenu.py | 2 +- .../python/bauiv1lib/settings/gamepad.py | 2 +- .../python/bauiv1lib/settings/keyboard.py | 2 +- .../python/bauiv1lib/settings/nettesting.py | 4 +- src/ballistica/base/app/app.cc | 3 +- .../base/python/methods/python_methods_app.cc | 28 +++++- src/ballistica/core/core.h | 11 ++- src/ballistica/core/platform/core_platform.cc | 2 +- src/ballistica/core/platform/core_platform.h | 5 +- .../python/methods/python_methods_input.cc | 16 ++-- src/ballistica/shared/ballistica.cc | 2 +- 23 files changed, 135 insertions(+), 80 deletions(-) diff --git a/.efrocachemap b/.efrocachemap index b30cc6d2..5d348136 100644 --- a/.efrocachemap +++ b/.efrocachemap @@ -4072,50 +4072,50 @@ "build/assets/workspace/ninjafightplug.py": "https://files.ballistica.net/cache/ba1/18/4b/787a9267e17be3c49966072581a5", "build/assets/workspace/onslaughtplug.py": "https://files.ballistica.net/cache/ba1/20/f6/4ce9bc3c1f3732f6adf8237fbe9b", "build/assets/workspace/runaroundplug.py": "https://files.ballistica.net/cache/ba1/a5/30/9058181df0b1255bf6950cbc7813", - "build/prefab/full/linux_arm64_gui/debug/ballisticakit": "https://files.ballistica.net/cache/ba1/88/5a/046584c2f9bb1dfaf2cc7305811a", - "build/prefab/full/linux_arm64_gui/release/ballisticakit": "https://files.ballistica.net/cache/ba1/04/21/578917394a42afdaa94a6d0c2af1", - "build/prefab/full/linux_arm64_server/debug/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/9c/cc/b1456d7f585078f0b5116e16ca5b", - "build/prefab/full/linux_arm64_server/release/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/6a/4c/8eefc8bca27698731ae4eb385b31", - "build/prefab/full/linux_x86_64_gui/debug/ballisticakit": "https://files.ballistica.net/cache/ba1/ba/e7/14a5244c9740a6a3ca510a17d9d2", - "build/prefab/full/linux_x86_64_gui/release/ballisticakit": "https://files.ballistica.net/cache/ba1/c5/23/55a127747393ea1bdb45d52f8ef3", - "build/prefab/full/linux_x86_64_server/debug/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/62/39/db07ddb660c23869885b6dfeb2bd", - "build/prefab/full/linux_x86_64_server/release/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/f9/88/89c742f5d6d2d03858edc409107c", - "build/prefab/full/mac_arm64_gui/debug/ballisticakit": "https://files.ballistica.net/cache/ba1/23/9e/2c6f955ad9ee17fd0fd0d132127e", - "build/prefab/full/mac_arm64_gui/release/ballisticakit": "https://files.ballistica.net/cache/ba1/36/f1/cf87abc5c2d38e21f31d17783c64", - "build/prefab/full/mac_arm64_server/debug/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/96/94/b9ca75a69e7c2fe122d1af08684e", - "build/prefab/full/mac_arm64_server/release/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/f5/0b/0bf0d0d9722df1c2bd4a9566166f", - "build/prefab/full/mac_x86_64_gui/debug/ballisticakit": "https://files.ballistica.net/cache/ba1/a0/83/b185f5ee357b4730bd96df784bf5", - "build/prefab/full/mac_x86_64_gui/release/ballisticakit": "https://files.ballistica.net/cache/ba1/40/2e/291910a12f2e637d585a23732e39", - "build/prefab/full/mac_x86_64_server/debug/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/b5/97/fdf687c944dff99145350594fbd6", - "build/prefab/full/mac_x86_64_server/release/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/bc/e6/acb2fa1eebb0c8219919fc7bd904", - "build/prefab/full/windows_x86_gui/debug/BallisticaKit.exe": "https://files.ballistica.net/cache/ba1/43/1d/1e30712c0f7bbed6bc4c4d19d9be", - "build/prefab/full/windows_x86_gui/release/BallisticaKit.exe": "https://files.ballistica.net/cache/ba1/b9/03/9f180b240019437ebdad1d2450b3", - "build/prefab/full/windows_x86_server/debug/dist/BallisticaKitHeadless.exe": "https://files.ballistica.net/cache/ba1/ee/1c/c2f9d7571fa7123305727345c493", - "build/prefab/full/windows_x86_server/release/dist/BallisticaKitHeadless.exe": "https://files.ballistica.net/cache/ba1/13/66/5f85708aab5186b5c2cc7dad5628", - "build/prefab/lib/linux_arm64_gui/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/f6/e4/1fc7d7c6701ca9d1a4fc104c11a0", - "build/prefab/lib/linux_arm64_gui/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/d2/40/7b8787a2a20b2bf5b853762abf82", - "build/prefab/lib/linux_arm64_server/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/3d/a9/4d58c1ba26c71020600f16212c59", - "build/prefab/lib/linux_arm64_server/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/a1/81/6700b345f65181be591b999bd0ba", - "build/prefab/lib/linux_x86_64_gui/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/9b/f3/3e6848d3d51e45f2bc892ba866fe", - "build/prefab/lib/linux_x86_64_gui/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/71/26/3e4f7d23518f3d4dd719223c7bd5", - "build/prefab/lib/linux_x86_64_server/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/41/30/ebf7264a7846b7e17d2ccee1e68e", - "build/prefab/lib/linux_x86_64_server/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/b7/36/7b5926a3f526c4f53beeb85e0f28", - "build/prefab/lib/mac_arm64_gui/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/bb/df/26fd523b58edf61c230e0d8c29a9", - "build/prefab/lib/mac_arm64_gui/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/60/d6/d24629a9c4cc8d53034b166533fc", - "build/prefab/lib/mac_arm64_server/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/ae/74/add4f1b22a9d870deab498a78150", - "build/prefab/lib/mac_arm64_server/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/60/cc/efd87e8316e57e6060c0f8c1c3b5", - "build/prefab/lib/mac_x86_64_gui/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/06/a5/b9dc8830177144edccc3361f2380", - "build/prefab/lib/mac_x86_64_gui/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/d6/55/0ed426d7d9718e6c7cfa25ed45fa", - "build/prefab/lib/mac_x86_64_server/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/36/d9/1bac79e3118546083de075c591eb", - "build/prefab/lib/mac_x86_64_server/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/0d/51/6431fa180fe6ca7a4f5e755deb13", - "build/prefab/lib/windows/Debug_Win32/BallisticaKitGenericPlus.lib": "https://files.ballistica.net/cache/ba1/88/27/5acc5bf12db2eeafad941cb4983c", - "build/prefab/lib/windows/Debug_Win32/BallisticaKitGenericPlus.pdb": "https://files.ballistica.net/cache/ba1/b5/17/999fb8864717791fdb549e8d27ee", - "build/prefab/lib/windows/Debug_Win32/BallisticaKitHeadlessPlus.lib": "https://files.ballistica.net/cache/ba1/75/a7/8a9faed3b33c85ed48becd57b96e", - "build/prefab/lib/windows/Debug_Win32/BallisticaKitHeadlessPlus.pdb": "https://files.ballistica.net/cache/ba1/7c/a5/7e049cf1b1974b1dafa6a5a5c651", - "build/prefab/lib/windows/Release_Win32/BallisticaKitGenericPlus.lib": "https://files.ballistica.net/cache/ba1/e0/2e/0fb1dcf86dc106e610cdf85d9904", - "build/prefab/lib/windows/Release_Win32/BallisticaKitGenericPlus.pdb": "https://files.ballistica.net/cache/ba1/f1/4f/6d693934819c9fa3b46f5796d040", - "build/prefab/lib/windows/Release_Win32/BallisticaKitHeadlessPlus.lib": "https://files.ballistica.net/cache/ba1/a2/98/1149701221912567fed626f41262", - "build/prefab/lib/windows/Release_Win32/BallisticaKitHeadlessPlus.pdb": "https://files.ballistica.net/cache/ba1/9c/51/6659783ad53b29633d8962fa6463", + "build/prefab/full/linux_arm64_gui/debug/ballisticakit": "https://files.ballistica.net/cache/ba1/cb/2b/b20e3667a76de438a96f0afc0305", + "build/prefab/full/linux_arm64_gui/release/ballisticakit": "https://files.ballistica.net/cache/ba1/46/7d/7d4757c004be2572c77b06b77bee", + "build/prefab/full/linux_arm64_server/debug/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/e7/f1/a546a5af991fe6ca8cad30151c45", + "build/prefab/full/linux_arm64_server/release/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/0a/6a/ee6c62dfc7df0ee2649b4259859f", + "build/prefab/full/linux_x86_64_gui/debug/ballisticakit": "https://files.ballistica.net/cache/ba1/5c/72/34434953e56f2dc38a38ebc06c8c", + "build/prefab/full/linux_x86_64_gui/release/ballisticakit": "https://files.ballistica.net/cache/ba1/81/13/a5095e89d11645df552e952934b2", + "build/prefab/full/linux_x86_64_server/debug/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/e1/5d/2284e87c1eb013e2f9719f3af758", + "build/prefab/full/linux_x86_64_server/release/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/be/ed/d03bd1603588c5ee3941dcb098b0", + "build/prefab/full/mac_arm64_gui/debug/ballisticakit": "https://files.ballistica.net/cache/ba1/b5/46/2ff94d2fd35975f6a78333811fce", + "build/prefab/full/mac_arm64_gui/release/ballisticakit": "https://files.ballistica.net/cache/ba1/84/56/c0a936571bf54f90b4f63d2044df", + "build/prefab/full/mac_arm64_server/debug/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/26/27/18a284bc01bc00d58b0547a6e6cc", + "build/prefab/full/mac_arm64_server/release/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/36/ac/9001c8d1bd457b7345bfc41d78e9", + "build/prefab/full/mac_x86_64_gui/debug/ballisticakit": "https://files.ballistica.net/cache/ba1/b0/8f/ae5bfba34e6c8652825165e1a91d", + "build/prefab/full/mac_x86_64_gui/release/ballisticakit": "https://files.ballistica.net/cache/ba1/3c/29/3a0fb2e030569a1e72e26d19b79e", + "build/prefab/full/mac_x86_64_server/debug/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/aa/8c/baa3f85599add12b5fb9c6d36a25", + "build/prefab/full/mac_x86_64_server/release/dist/ballisticakit_headless": "https://files.ballistica.net/cache/ba1/7c/99/ee5199e38af7e9e26018bd8e53bf", + "build/prefab/full/windows_x86_gui/debug/BallisticaKit.exe": "https://files.ballistica.net/cache/ba1/54/9c/4e83da01264024628839375ee954", + "build/prefab/full/windows_x86_gui/release/BallisticaKit.exe": "https://files.ballistica.net/cache/ba1/b5/8a/3c7f11a2b165425faeab02b6854b", + "build/prefab/full/windows_x86_server/debug/dist/BallisticaKitHeadless.exe": "https://files.ballistica.net/cache/ba1/ae/90/e625b0ef976e7a4d101f184ca70e", + "build/prefab/full/windows_x86_server/release/dist/BallisticaKitHeadless.exe": "https://files.ballistica.net/cache/ba1/fb/1e/94322715fea49e0450bfc38cd2eb", + "build/prefab/lib/linux_arm64_gui/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/e1/36/4336b37f86fd4a4870133803fab7", + "build/prefab/lib/linux_arm64_gui/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/19/e8/69f3145d1a635ff682323d5122a7", + "build/prefab/lib/linux_arm64_server/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/62/12/fc103a5a8e2e6a607499b8887c65", + "build/prefab/lib/linux_arm64_server/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/75/d5/4fc5951cf8408dc074a523ec0ecc", + "build/prefab/lib/linux_x86_64_gui/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/e6/35/64ef9eb0aa12b25a35ec4cf94d73", + "build/prefab/lib/linux_x86_64_gui/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/f6/9f/96526d08d8d151381b999206a22c", + "build/prefab/lib/linux_x86_64_server/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/cf/ac/6b205f3ec382b27a63835723f062", + "build/prefab/lib/linux_x86_64_server/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/14/09/738e56ba494bfbd25b4d0fd20439", + "build/prefab/lib/mac_arm64_gui/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/5e/15/de8816c5b0978d58a5a97b5dc96b", + "build/prefab/lib/mac_arm64_gui/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/cf/05/4b089f20f8673bbeaff43ad22316", + "build/prefab/lib/mac_arm64_server/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/8c/ea/d02addfdff12637679eb84fc0c76", + "build/prefab/lib/mac_arm64_server/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/3b/3d/cb40316b8f1bcf2be6726e7caa02", + "build/prefab/lib/mac_x86_64_gui/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/cc/50/4e046e25f8aa45acf1dec45a3ac8", + "build/prefab/lib/mac_x86_64_gui/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/0b/0b/3df53fda69cf1bbde139a737155d", + "build/prefab/lib/mac_x86_64_server/debug/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/48/72/2bb9986c42cb3f830622bba48b84", + "build/prefab/lib/mac_x86_64_server/release/libballistica_plus.a": "https://files.ballistica.net/cache/ba1/cf/55/0266ad6c51ea654700d6e5401942", + "build/prefab/lib/windows/Debug_Win32/BallisticaKitGenericPlus.lib": "https://files.ballistica.net/cache/ba1/69/cb/33e310a3a4088fd8d01a791a4101", + "build/prefab/lib/windows/Debug_Win32/BallisticaKitGenericPlus.pdb": "https://files.ballistica.net/cache/ba1/29/14/0c633d4d62106e27fad7e93bd1ee", + "build/prefab/lib/windows/Debug_Win32/BallisticaKitHeadlessPlus.lib": "https://files.ballistica.net/cache/ba1/f9/6a/02d03767f94811eec30204d75317", + "build/prefab/lib/windows/Debug_Win32/BallisticaKitHeadlessPlus.pdb": "https://files.ballistica.net/cache/ba1/90/2e/9a54913813513c1d3a44af34bd8a", + "build/prefab/lib/windows/Release_Win32/BallisticaKitGenericPlus.lib": "https://files.ballistica.net/cache/ba1/bc/20/abfd0ae02083fd0ee86b6d784df7", + "build/prefab/lib/windows/Release_Win32/BallisticaKitGenericPlus.pdb": "https://files.ballistica.net/cache/ba1/87/bc/b7cc546fda6955c72db6cabc055b", + "build/prefab/lib/windows/Release_Win32/BallisticaKitHeadlessPlus.lib": "https://files.ballistica.net/cache/ba1/db/d6/6111b49e4ea15032002dea192c53", + "build/prefab/lib/windows/Release_Win32/BallisticaKitHeadlessPlus.pdb": "https://files.ballistica.net/cache/ba1/2d/dd/e753ae37c3c6fdc50c36174d0815", "src/assets/ba_data/python/babase/_mgen/__init__.py": "https://files.ballistica.net/cache/ba1/52/c6/c11130af7b10d6c0321add5518fa", "src/assets/ba_data/python/babase/_mgen/enums.py": "https://files.ballistica.net/cache/ba1/38/c3/1dedd5e74f2508efc5974c8815a1", "src/ballistica/base/mgen/pyembed/binding_base.inc": "https://files.ballistica.net/cache/ba1/ea/6a/6a4721b144e5e297b542d2a0eea2", diff --git a/.idea/dictionaries/ericf.xml b/.idea/dictionaries/ericf.xml index 76bd39a7..a7892d12 100644 --- a/.idea/dictionaries/ericf.xml +++ b/.idea/dictionaries/ericf.xml @@ -130,6 +130,7 @@ apprun appspot appstate + appstatedata appstore appsubsystem apptime diff --git a/CHANGELOG.md b/CHANGELOG.md index 8369d64a..592b1bf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -### 1.7.20 (build 21121, api 8, 2023-06-16) +### 1.7.20 (build 21122, api 8, 2023-06-16) - This seems like a good time for a `refactoring` release in anticipation of changes coming in 1.8. Basically this means that a lot of things will be @@ -340,13 +340,18 @@ its working. - (build 21118) Fixed an issue where certain messages such as player-left weren't being send to clients. -- (build 21118) renamed `bascenev1.screenmessage()` to +- (build 21118) Renamed `bascenev1.screenmessage()` to `bascenev1.broadcastmessage()` to make it more clear that it behaves differently (sending messages to all connected clients instead of just the local screen). There is still a `bascenev1.screenmessage()` but that is now the same local-only version available in babase. Added a temporary warning if calling screenmessage() in a situation that in previous versions would have done a broadcast. +- (build 21121) The old app `user_agent_string` which was very ugly and + cluttered and nonstandard has been renamed to `legacy_user_agent_string`. A + newer simpler one is now available from `babase.user_agent_string()`. It looks + like `Ballistica/1.7.20`. If OS version or platform or whatever else needs to + be communicated to a server, it should be passed explicitly as extra data. ### 1.7.19 (build 20997, api 7, 2023-01-19) diff --git a/ballisticakit-cmake/.idea/dictionaries/ericf.xml b/ballisticakit-cmake/.idea/dictionaries/ericf.xml index 4334c9da..18f52ad4 100644 --- a/ballisticakit-cmake/.idea/dictionaries/ericf.xml +++ b/ballisticakit-cmake/.idea/dictionaries/ericf.xml @@ -88,6 +88,7 @@ apprun appspot appstate + appstatedata appsubsystem apptime apptimer diff --git a/src/assets/ba_data/python/babase/__init__.py b/src/assets/ba_data/python/babase/__init__.py index f6baced4..5a871a74 100644 --- a/src/assets/ba_data/python/babase/__init__.py +++ b/src/assets/ba_data/python/babase/__init__.py @@ -81,6 +81,7 @@ from _babase import ( show_progress_bar, SimpleSound, unlock_all_input, + user_agent_string, Vec3, workspaces_in_use, ) @@ -275,6 +276,7 @@ __all__ = [ 'timestring', 'UIScale', 'unlock_all_input', + 'user_agent_string', 'utf8_all', 'Vec3', 'vec3validate', diff --git a/src/assets/ba_data/python/babase/_apputils.py b/src/assets/ba_data/python/babase/_apputils.py index a692584c..e35756a4 100644 --- a/src/assets/ba_data/python/babase/_apputils.py +++ b/src/assets/ba_data/python/babase/_apputils.py @@ -103,7 +103,7 @@ def handle_v1_cloud_log() -> None: 'log': _babase.get_v1_cloud_log(), 'version': app.version, 'build': app.build_number, - 'userAgentString': app.classic.user_agent_string, + 'userAgentString': app.classic.legacy_user_agent_string, 'session': sessionname, 'activity': activityname, 'fatal': 0, @@ -339,10 +339,14 @@ def log_dumped_app_state() -> None: _tb_held_files.clear() with open(mdpath, 'r', encoding='utf-8') as infile: - metadata = dataclass_from_json( - DumpedAppStateMetadata, infile.read() - ) + appstatedata = infile.read() + + # Kill the file first in case we can't parse the data; don't + # want to get stuck doing this repeatedly. os.unlink(mdpath) + + metadata = dataclass_from_json(DumpedAppStateMetadata, appstatedata) + out += ( f'App state dump:\nReason: {metadata.reason}\n' f'Time: {metadata.app_time:.2f}' diff --git a/src/assets/ba_data/python/babase/_assetmanager.py b/src/assets/ba_data/python/babase/_assetmanager.py index 035c57c2..b7db7305 100644 --- a/src/assets/ba_data/python/babase/_assetmanager.py +++ b/src/assets/ba_data/python/babase/_assetmanager.py @@ -185,7 +185,11 @@ def fetch_url(url: str, filename: Path, asset_gather: AssetGather) -> None: # Pass a very short timeout to urllib so we have opportunities # to cancel even with network blockage. req = urllib.request.urlopen( - url, context=_babase.app.net.sslcontext, timeout=1 + urllib.request.Request( + url, None, {'User-Agent': _babase.user_agent_string()} + ), + context=_babase.app.net.sslcontext, + timeout=1, ) file_size = int(req.headers['Content-Length']) print(f'\nDownloading: {filename} Bytes: {file_size:,}') diff --git a/src/assets/ba_data/python/baclassic/_input.py b/src/assets/ba_data/python/baclassic/_input.py index edde385b..35a7e6f4 100644 --- a/src/assets/ba_data/python/baclassic/_input.py +++ b/src/assets/ba_data/python/baclassic/_input.py @@ -26,7 +26,7 @@ def get_input_device_mapped_value( app = babase.app assert app.classic is not None - useragentstring = app.classic.user_agent_string + useragentstring = app.classic.legacy_user_agent_string platform = app.classic.platform subplatform = app.classic.subplatform appconfig = babase.app.config diff --git a/src/assets/ba_data/python/baclassic/_music.py b/src/assets/ba_data/python/baclassic/_music.py index efe0adc8..6e6c4aec 100644 --- a/src/assets/ba_data/python/baclassic/_music.py +++ b/src/assets/ba_data/python/baclassic/_music.py @@ -165,7 +165,7 @@ class MusicSubsystem: def supports_soundtrack_entry_type(self, entry_type: str) -> bool: """Return whether provided soundtrack entry type is supported here.""" - uas = babase.env()['user_agent_string'] + uas = babase.env()['legacy_user_agent_string'] assert isinstance(uas, str) # FIXME: Generalize this. diff --git a/src/assets/ba_data/python/baclassic/_net.py b/src/assets/ba_data/python/baclassic/_net.py index 4d339075..d109acdc 100644 --- a/src/assets/ba_data/python/baclassic/_net.py +++ b/src/assets/ba_data/python/baclassic/_net.py @@ -81,7 +81,8 @@ class MasterServerV1CallThread(threading.Thread): response_data: Any = None url: str | None = None try: - assert babase.app.classic is not None + classic = babase.app.classic + assert classic is not None self._data = babase.utf8_all(self._data) babase.set_thread_name('BA_ServerCallThread') if self._request_type == 'get': @@ -97,7 +98,7 @@ class MasterServerV1CallThread(threading.Thread): urllib.request.Request( url, None, - {'User-Agent': babase.app.classic.user_agent_string}, + {'User-Agent': classic.legacy_user_agent_string}, ), context=babase.app.net.sslcontext, timeout=DEFAULT_REQUEST_TIMEOUT_SECONDS, @@ -109,7 +110,7 @@ class MasterServerV1CallThread(threading.Thread): urllib.request.Request( url, urllib.parse.urlencode(self._data).encode(), - {'User-Agent': babase.app.classic.user_agent_string}, + {'User-Agent': classic.legacy_user_agent_string}, ), context=babase.app.net.sslcontext, timeout=DEFAULT_REQUEST_TIMEOUT_SECONDS, diff --git a/src/assets/ba_data/python/baclassic/_subsystem.py b/src/assets/ba_data/python/baclassic/_subsystem.py index 19096c07..3cd637b7 100644 --- a/src/assets/ba_data/python/baclassic/_subsystem.py +++ b/src/assets/ba_data/python/baclassic/_subsystem.py @@ -139,10 +139,10 @@ class ClassicSubsystem(babase.AppSubsystem): return self._env['subplatform'] @property - def user_agent_string(self) -> str: + def legacy_user_agent_string(self) -> str: """String containing various bits of info about OS/device/etc.""" - assert isinstance(self._env['user_agent_string'], str) - return self._env['user_agent_string'] + assert isinstance(self._env['legacy_user_agent_string'], str) + return self._env['legacy_user_agent_string'] def on_app_loading(self) -> None: from bascenev1lib.actor import spazappearance diff --git a/src/assets/ba_data/python/baenv.py b/src/assets/ba_data/python/baenv.py index a648c5a8..896ebfcb 100644 --- a/src/assets/ba_data/python/baenv.py +++ b/src/assets/ba_data/python/baenv.py @@ -28,7 +28,7 @@ if TYPE_CHECKING: # Build number and version of the ballistica binary we expect to be # using. -TARGET_BALLISTICA_BUILD = 21121 +TARGET_BALLISTICA_BUILD = 21122 TARGET_BALLISTICA_VERSION = '1.7.20' _g_env_config: EnvConfig | None = None diff --git a/src/assets/ba_data/python/bauiv1lib/mainmenu.py b/src/assets/ba_data/python/bauiv1lib/mainmenu.py index 3f82c276..cc262fd8 100644 --- a/src/assets/ba_data/python/bauiv1lib/mainmenu.py +++ b/src/assets/ba_data/python/bauiv1lib/mainmenu.py @@ -381,7 +381,7 @@ class MainMenuWindow(bui.Window): resource=self._r + ( '.quitText' - if 'Mac' in app.classic.user_agent_string + if 'Mac' in app.classic.legacy_user_agent_string else '.exitGameText' ) ), diff --git a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py index 22a993ba..d708551c 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/gamepad.py @@ -828,7 +828,7 @@ class GamepadSettingsWindow(bui.Window): classic.master_server_v1_post( 'controllerConfig', { - 'ua': classic.user_agent_string, + 'ua': classic.legacy_user_agent_string, 'b': bui.app.build_number, 'name': self._name, 'inputMapHash': inputhash, diff --git a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py index 9835aebf..47403ceb 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/keyboard.py @@ -299,7 +299,7 @@ class ConfigKeyboardWindow(bui.Window): bui.app.classic.master_server_v1_post( 'controllerConfig', { - 'ua': bui.app.classic.user_agent_string, + 'ua': bui.app.classic.legacy_user_agent_string, 'name': self._name, 'b': bui.app.build_number, 'config': dst2, diff --git a/src/assets/ba_data/python/bauiv1lib/settings/nettesting.py b/src/assets/ba_data/python/bauiv1lib/settings/nettesting.py index faa7e55b..dd295108 100644 --- a/src/assets/ba_data/python/bauiv1lib/settings/nettesting.py +++ b/src/assets/ba_data/python/bauiv1lib/settings/nettesting.py @@ -200,7 +200,7 @@ def _run_diagnostics(weakwin: weakref.ref[NetTestingWindow]) -> None: _print( f'Running network diagnostics...\n' - f'ua: {bui.app.classic.user_agent_string}\n' + f'ua: {bui.app.classic.legacy_user_agent_string}\n' f'time: {utc_now()}.' ) @@ -414,7 +414,7 @@ def _test_fetch(baseaddr: str) -> None: urllib.request.Request( f'{baseaddr}/ping', None, - {'User-Agent': bui.app.classic.user_agent_string}, + {'User-Agent': bui.app.classic.legacy_user_agent_string}, ), context=bui.app.net.sslcontext, timeout=MAX_TEST_SECONDS, diff --git a/src/ballistica/base/app/app.cc b/src/ballistica/base/app/app.cc index ac9aec2a..60f3414f 100644 --- a/src/ballistica/base/app/app.cc +++ b/src/ballistica/base/app/app.cc @@ -36,7 +36,8 @@ void App::PostInit() { assert(true); #endif // !BA_DEBUG_BUILD - g_core->user_agent_string = g_core->platform->GetUserAgentString(); + g_core->set_legacy_user_agent_string( + g_core->platform->GetLegacyUserAgentString()); } void App::LogicThreadApplyAppConfig() { diff --git a/src/ballistica/base/python/methods/python_methods_app.cc b/src/ballistica/base/python/methods/python_methods_app.cc index 3d7b58d3..143a6861 100644 --- a/src/ballistica/base/python/methods/python_methods_app.cc +++ b/src/ballistica/base/python/methods/python_methods_app.cc @@ -648,7 +648,7 @@ static PyMethodDef PyCommitConfigDef = { "(internal)", }; -// --------------------------------- env --------------------------------------- +// ------------------------------- pre_env ------------------------------------- static auto PyPreEnv(PyObject* self) -> PyObject* { BA_PYTHON_TRY; @@ -726,7 +726,7 @@ static auto PyEnv(PyObject* self) -> PyObject* { "si" // build_number "ss" // config_file_path "ss" // locale - "ss" // user_agent_string + "ss" // legacy_user_agent_string "ss" // version "sO" // debug_build "sO" // test_build @@ -750,7 +750,7 @@ static auto PyEnv(PyObject* self) -> PyObject* { "build_number", kEngineBuildNumber, "config_file_path", g_core->platform->GetConfigFilePath().c_str(), "locale", g_core->platform->GetLocale().c_str(), - "user_agent_string", g_core->user_agent_string.c_str(), + "legacy_user_agent_string", g_core->legacy_user_agent_string().c_str(), "version", kEngineVersion, "debug_build", g_buildconfig.debug_build() ? Py_True : Py_False, "test_build", g_buildconfig.test_build() ? Py_True : Py_False, @@ -1330,6 +1330,27 @@ static PyMethodDef PyReachedEndOfBaBaseDef = { "reached_end_of_babase() -> None\n" "\n" + "A simple user-agent-string that should be used in any web requests made\n" + "on behalf of the engine.", +}; + +// --------------------------- user_agent_string ------------------------------- + +static auto PyUserAgentString(PyObject* self) -> PyObject* { + BA_PYTHON_TRY; + char buffer[64]; + snprintf(buffer, sizeof(buffer), "Ballistica/%s", kEngineVersion); + return PyUnicode_FromString(buffer); + BA_PYTHON_CATCH; +} + +static PyMethodDef PyUserAgentStringDef = { + "user_agent_string", // name + (PyCFunction)PyUserAgentString, // method + METH_NOARGS, // flags + + "user_agent_string() -> str\n" + "\n" "(internal)\n", }; @@ -1375,6 +1396,7 @@ auto PythonMethodsApp::GetMethods() -> std::vector { PyOnAppRunningDef, PyOnInitialAppModeSetDef, PyReachedEndOfBaBaseDef, + PyUserAgentStringDef, }; } diff --git a/src/ballistica/core/core.h b/src/ballistica/core/core.h index 2a8bbbf4..5e727163 100644 --- a/src/ballistica/core/core.h +++ b/src/ballistica/core/core.h @@ -100,6 +100,14 @@ class CoreFeatureSet { /// any source file paths we print. auto build_src_dir() const { return build_src_dir_; } + const auto& legacy_user_agent_string() const { + return legacy_user_agent_string_; + } + + void set_legacy_user_agent_string(const std::string& val) { + legacy_user_agent_string_ = val; + } + // Subsystems. CorePython* const python; CorePlatform* const platform; @@ -121,7 +129,6 @@ class CoreFeatureSet { bool should_pause{}; bool reset_vr_orientation{}; bool user_ran_commands{}; - std::string user_agent_string{"BA_USER_AGENT_UNSET (" BA_PLATFORM_STRING ")"}; int return_value{}; bool debug_timing{}; std::thread::id main_thread_id{}; @@ -149,6 +156,8 @@ class CoreFeatureSet { microsecs_t app_time_microsecs_{}; microsecs_t last_app_time_measure_microsecs_; std::mutex app_time_mutex_; + std::string legacy_user_agent_string_{ + "BA_USER_AGENT_UNSET (" BA_PLATFORM_STRING ")"}; }; } // namespace ballistica::core diff --git a/src/ballistica/core/platform/core_platform.cc b/src/ballistica/core/platform/core_platform.cc index 28c1c0a8..2b15b7e0 100644 --- a/src/ballistica/core/platform/core_platform.cc +++ b/src/ballistica/core/platform/core_platform.cc @@ -573,7 +573,7 @@ auto CorePlatform::GetIsStdinATerminal() -> bool { auto CorePlatform::GetOSVersionString() -> std::string { return ""; } -auto CorePlatform::GetUserAgentString() -> std::string { +auto CorePlatform::GetLegacyUserAgentString() -> std::string { std::string device = GetDeviceName(); std::string version = GetOSVersionString(); if (!version.empty()) { diff --git a/src/ballistica/core/platform/core_platform.h b/src/ballistica/core/platform/core_platform.h index d9f812cc..391ad81d 100644 --- a/src/ballistica/core/platform/core_platform.h +++ b/src/ballistica/core/platform/core_platform.h @@ -187,7 +187,10 @@ class CorePlatform { /// Return en_US or whatnot. virtual auto GetLocale() -> std::string; - virtual auto GetUserAgentString() -> std::string; + /// Get the older more complex user-agent-string, used for communication + /// with v1 servers/etc. This can go away eventually. + auto GetLegacyUserAgentString() -> std::string; + virtual auto GetOSVersionString() -> std::string; /// Set an environment variable as utf8, overwriting if it already exists. diff --git a/src/ballistica/scene_v1/python/methods/python_methods_input.cc b/src/ballistica/scene_v1/python/methods/python_methods_input.cc index fd0c6058..55700a64 100644 --- a/src/ballistica/scene_v1/python/methods/python_methods_input.cc +++ b/src/ballistica/scene_v1/python/methods/python_methods_input.cc @@ -222,12 +222,14 @@ static auto PyGetUIInputDevice(PyObject* self, PyObject* args, PyObject* keywds) dynamic_cast(delegate)) { return c_delegate->NewPyRef(); } else { - // Perhaps will want to return None in this case once we've got - // newer versions of InputDevice; we'll see... - throw Exception( - "Unexpected delegate " - + (delegate ? delegate->GetObjectDescription() : "(nullptr)") - + " for ui-input-device " + d->GetObjectDescription() + "."); + // Assuming this would be due to getting called in another app-mode. + // Wonder if it would be wise to error in that case... + BA_LOG_ONCE( + LogLevel::kWarning, + "scene_v1: Found unexpected delegate " + + (delegate ? delegate->GetObjectDescription() : "(nullptr)") + + " for ui-input-device " + d->GetObjectDescription() + "."); + Py_RETURN_NONE; } } else { Py_RETURN_NONE; @@ -240,7 +242,7 @@ static PyMethodDef PyGetUIInputDeviceDef = { (PyCFunction)PyGetUIInputDevice, // method METH_VARARGS | METH_KEYWORDS, // flags - "get_ui_input_device() -> bascenev1.InputDevice\n" + "get_ui_input_device() -> bascenev1.InputDevice | None\n" "\n" "(internal)\n" "\n" diff --git a/src/ballistica/shared/ballistica.cc b/src/ballistica/shared/ballistica.cc index 5759e41e..171388c1 100644 --- a/src/ballistica/shared/ballistica.cc +++ b/src/ballistica/shared/ballistica.cc @@ -39,7 +39,7 @@ auto main(int argc, char** argv) -> int { namespace ballistica { // These are set automatically via script; don't modify them here. -const int kEngineBuildNumber = 21121; +const int kEngineBuildNumber = 21122; const char* kEngineVersion = "1.7.20"; auto MonolithicMain(const core::CoreConfig& core_config) -> int {