Skip to content
Open
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
77 changes: 41 additions & 36 deletions app/api/domains/cho.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ async def bancho_handler(
return Response(
content=(
app.packets.notification("Server has restarted.")
+ app.packets.restart_server(0) # ms until reconnection
),
+ app.packets.restart_server(0)
), # ms until reconnection
)

if player.restricted:
Expand Down Expand Up @@ -564,29 +564,35 @@ async def get_allowed_client_versions(osu_stream: OsuStream) -> set[date] | None

Returns None if the connection to the osu! api fails.
"""
osu_stream_str = osu_stream.value
if osu_stream in (OsuStream.STABLE, OsuStream.BETA):
osu_stream_str += "40" # i wonder why this exists

response = await services.http_client.get(
OSU_API_V2_CHANGELOG_URL,
params={"stream": osu_stream_str},
)
if not response.is_success:
return None

osu_stream_strs = []
allowed_client_versions: set[date] = set()
for build in response.json()["builds"]:
version = date(
int(build["version"][0:4]),
int(build["version"][4:6]),
int(build["version"][6:8]),

if osu_stream == OsuStream.STABLE:
osu_stream_strs.append(osu_stream.value + "40") # i wonder why this exists
elif osu_stream == OsuStream.TOURNEY:
# osu!tourney clients are allowed to connect with any version
osu_stream_strs.append("stable40")
osu_stream_strs.append("cuttingedge")

for osu_stream_str in osu_stream_strs:
Copy link
Member

Choose a reason for hiding this comment

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

i very much disagree with doing a request in a for loop here, why are we not just requesting OSU_API_V2_CHANGELOG_URL, iterating over the streams and getting dates from the latest_build?

Copy link
Member

Choose a reason for hiding this comment

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

also, looking at the current response i can't seem to see anything about major versions anymore

response = await services.http_client.get(
OSU_API_V2_CHANGELOG_URL,
params={"stream": osu_stream_str},
)
allowed_client_versions.add(version)
if any(entry["major"] for entry in build["changelog_entries"]):
# this build is a major iteration to the client
# don't allow anything older than this
break
if not response.is_success:
return None

for build in response.json()["builds"]:
version = date(
int(build["version"][0:4]),
int(build["version"][4:6]),
int(build["version"][6:8]),
)
allowed_client_versions.add(version)
if any(entry["major"] for entry in build["changelog_entries"]):
# this build is a major iteration to the client
# don't allow anything older than this
break

return allowed_client_versions

Expand Down Expand Up @@ -722,17 +728,16 @@ async def handle_osu_login_request(
),
}

if osu_version.stream is OsuStream.TOURNEY and not (
user_info["priv"] & Privileges.DONATOR
and user_info["priv"] & Privileges.UNRESTRICTED
):
# trying to use tourney client with insufficient privileges.
return {
"osu_token": "no",
"response_body": app.packets.login_reply(
LoginFailureReason.AUTHENTICATION_FAILED,
),
}
if osu_version.stream is OsuStream.TOURNEY:
allowed_priv = Privileges.DONATOR | Privileges.TOURNEY_MANAGER | Privileges.UNRESTRICTED
if user_info["priv"] & allowed_priv <= Privileges.UNRESTRICTED:
# trying to use tourney client with insufficient privileges.
return {
"osu_token": "no",
"response_body": app.packets.login_reply(
LoginFailureReason.AUTHENTICATION_FAILED,
),
}

""" login credentials verified """

Expand Down Expand Up @@ -884,8 +889,8 @@ async def handle_osu_login_request(
if (
not channel.auto_join
or not channel.can_read(player.priv)
or channel.real_name == "#lobby" # (can't be in mp lobby @ login)
):
or channel.real_name == "#lobby"
): # (can't be in mp lobby @ login)
continue

# send chan info to all players who can see
Expand Down