From 852aa8acc466be4a2d06712835bb7fed40a4a208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Wolf?= Date: Mon, 26 Feb 2024 21:58:22 +0100 Subject: [PATCH 1/2] add configuration options for mcosu clients --- .env.example | 3 +++ app/api/domains/cho.py | 15 ++++++++++++++- app/settings.py | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 85846fc0..175b56a8 100644 --- a/.env.example +++ b/.env.example @@ -51,6 +51,9 @@ REDIRECT_OSU_URLS=True PP_CACHED_ACCS=90,95,98,99,100 +ALLOW_MCOSU_CLIENTS=True +ALLOW_MCOSU_SCORES=False + DISALLOWED_NAMES=mrekk,vaxei,btmc,cookiezi DISALLOWED_PASSWORDS=password,abc123 DISALLOW_OLD_CLIENTS=True diff --git a/app/api/domains/cho.py b/app/api/domains/cho.py index 29790114..076cc431 100644 --- a/app/api/domains/cho.py +++ b/app/api/domains/cho.py @@ -186,9 +186,19 @@ async def bancho_handler( request: Request, osu_token: str | None = Header(None), user_agent: Literal["osu!"] = Header(...), + x_mcosu_ver: str | None = Header(None), ) -> Response: ip = app.state.services.ip_resolver.get_ip(request.headers) + if x_mcosu_ver is not None and app.settings.ALLOW_MCOSU_CLIENTS is False: + return Response( + headers={"cho-token": "no"}, + content=( + app.packets.login_reply(LoginFailureReason.AUTHENTICATION_FAILED) + + app.packets.notification("McOsu clients are not allowed on this server.") + ), + ) + if osu_token is None: # the client is performing a login login_data = await handle_osu_login_request( @@ -199,7 +209,10 @@ async def bancho_handler( return Response( content=login_data["response_body"], - headers={"cho-token": login_data["osu_token"]}, + headers={ + "cho-token": login_data["osu_token"], + "x-mcosu-features": f"submit={1 if app.settings.ALLOW_MCOSU_SCORES else 0}", + }, ) # get the player from the specified osu token. diff --git a/app/settings.py b/app/settings.py index aa292197..bb381bd9 100644 --- a/app/settings.py +++ b/app/settings.py @@ -50,6 +50,9 @@ PP_CACHED_ACCURACIES = [int(acc) for acc in read_list(os.environ["PP_CACHED_ACCS"])] +ALLOW_MCOSU_CLIENTS = read_bool(os.environ["ALLOW_MCOSU_CLIENTS"]) +ALLOW_MCOSU_SCORES = read_bool(os.environ["ALLOW_MCOSU_SCORES"]) + DISALLOWED_NAMES = read_list(os.environ["DISALLOWED_NAMES"]) DISALLOWED_PASSWORDS = read_list(os.environ["DISALLOWED_PASSWORDS"]) DISALLOW_OLD_CLIENTS = read_bool(os.environ["DISALLOW_OLD_CLIENTS"]) From d9ab9d8d3549b9c1bb6af2bce6132939bbe8aa99 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 26 Feb 2024 21:27:42 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- app/api/domains/cho.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/api/domains/cho.py b/app/api/domains/cho.py index 076cc431..24bceda3 100644 --- a/app/api/domains/cho.py +++ b/app/api/domains/cho.py @@ -195,7 +195,9 @@ async def bancho_handler( headers={"cho-token": "no"}, content=( app.packets.login_reply(LoginFailureReason.AUTHENTICATION_FAILED) - + app.packets.notification("McOsu clients are not allowed on this server.") + + app.packets.notification( + "McOsu clients are not allowed on this server.", + ) ), )