Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support mcosu clients #641

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion app/api/domains/cho.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,21 @@ 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(
Expand All @@ -199,7 +211,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}",
Copy link
Member

@cmyui cmyui Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would more features be added in the future, and what's the serialization format for these if so?

Could we extract that into a function? e.g.:

def write_mcosu_features_header(allow_submission: bool) -> str:
    ...
headers={"x-mcosu-features": write_mcosu_features_header(allow_submission=True)}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format is x-mcosu-features: foo=0 bar=1.

I don't plan on adding more than submit, but if servers admin request it, you could disable some McOsu features independently, for example:

  • FPS mode, VR mode
  • Multiplayer lobbies
  • Joining/talking in chat
  • Fetching online leaderboards
  • Spectating players (not implemented right now)

You could also use it to signal the server supports custom protocol packets, eg. for experimental mods, but I doubt people are interested in that.

Since right now it's just submit, extracting it in a function is overkill :p

},
)

# get the player from the specified osu token.
Expand Down
3 changes: 3 additions & 0 deletions app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
Loading