Skip to content

Commit

Permalink
feat: include sb features
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueRou authored and arily committed Dec 7, 2023
1 parent 47cb538 commit 0612528
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 134 deletions.
187 changes: 124 additions & 63 deletions app/api/domains/cho.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@

BEATMAPS_PATH = Path.cwd() / ".data/osu"

PPYSB_CLIENT_VERSION = "b20210125.1 SB Edition.x01" # (ppysb feature)

BASE_DOMAIN = app.settings.DOMAIN

NOW_PLAYING_RGX = re.compile(
Expand Down Expand Up @@ -544,75 +546,133 @@ async def login(
-8: requires verification
other: valid id, logged in
"""


# parse login data
# parse login data (ppysb feature)
login_data = parse_login_data(body)
bypass = login_data["osu_version"] == PPYSB_CLIENT_VERSION

# perform some validation & further parsing on the data (ppysb feature)

if bypass:
osu_version = OsuVersion(
date=date(
year=2021,
month=1,
day=25,
),
revision=None,
stream=OsuStream("ppysb"),
)
running_under_wine = login_data["adapters_str"] == "runningunderwine"
adapters = [a for a in login_data["adapters_str"][:-1].split(".")]
if not bypass:
# perform some validation & further parsing on the data

# perform some validation & further parsing on the data

match = regexes.OSU_VERSION.match(login_data["osu_version"])
if match is None:
return {
"osu_token": "invalid-request",
"response_body": b"",
}
match = regexes.OSU_VERSION.match(login_data["osu_version"])
if match is None:
return {
"osu_token": "invalid-request",
"response_body": b"",
}

osu_version = OsuVersion(
date=date(
year=int(match["date"][0:4]),
month=int(match["date"][4:6]),
day=int(match["date"][6:8]),
),
revision=int(match["revision"]) if match["revision"] else None,
stream=OsuStream(match["stream"] or "stable"),
)
osu_version = OsuVersion(
date=date(
year=int(match["date"][0:4]),
month=int(match["date"][4:6]),
day=int(match["date"][6:8]),
),
revision=int(match["revision"]) if match["revision"] else None,
stream=OsuStream(match["stream"] or "stable"),
)

if app.settings.DISALLOW_OLD_CLIENTS:
osu_client_stream = osu_version.stream.value
if osu_client_stream in ("stable", "beta"):
osu_client_stream += "40" # TODO: why?
if app.settings.DISALLOW_OLD_CLIENTS:
osu_client_stream = osu_version.stream.value
if osu_client_stream in ("stable", "beta"):
osu_client_stream += "40" # TODO: why?

allowed_client_versions = set()
allowed_client_versions = set()

# TODO: put this behind a layer of abstraction
# for better handling of the error cases
response = await services.http_client.get(
OSU_API_V2_CHANGELOG_URL,
params={"stream": osu_client_stream},
)
response.raise_for_status()
for build in response.json()["builds"]:
version = date(
int(build["version"][0:4]),
int(build["version"][4:6]),
int(build["version"][6:8]),
# TODO: put this behind a layer of abstraction
# for better handling of the error cases
response = await services.http_client.get(
OSU_API_V2_CHANGELOG_URL,
params={"stream": osu_client_stream},
)
allowed_client_versions.add(version)
response.raise_for_status()
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
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 osu_version.date not in allowed_client_versions:
return {
"osu_token": "client-too-old",
"response_body": (
app.packets.version_update() + app.packets.user_id(-2)
if osu_version.date not in allowed_client_versions:
return {
"osu_token": "invalid-request",
"response_body": b"",
}

osu_version = OsuVersion(
date=date(
year=int(match["date"][0:4]),
month=int(match["date"][4:6]),
day=int(match["date"][6:8]),
),
}
revision=int(match["revision"]) if match["revision"] else None,
stream=OsuStream(match["stream"] or "stable"),
)

running_under_wine = login_data["adapters_str"] == "runningunderwine"
adapters = [a for a in login_data["adapters_str"][:-1].split(".")]
if app.settings.DISALLOW_OLD_CLIENTS:
osu_client_stream = osu_version.stream.value
if osu_client_stream in ("stable", "beta"):
osu_client_stream += "40" # TODO: why?

if not (running_under_wine or any(adapters)):
return {
"osu_token": "empty-adapters",
"response_body": (
app.packets.user_id(-1)
+ app.packets.notification("Please restart your osu! and try again.")
),
}
allowed_client_versions = set()

resp = await services.http_client.get(
OSU_API_V2_CHANGELOG_URL,
params={"stream": osu_client_stream},
)

for build in (resp.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

if osu_version.date not in allowed_client_versions:
return {
"osu_token": "client-too-old",
"response_body": (
app.packets.version_update() + app.packets.user_id(-2)
),
}

running_under_wine = login_data["adapters_str"] == "runningunderwine"
adapters = [a for a in login_data["adapters_str"][:-1].split(".")]

if not (running_under_wine or any(adapters)):
return {
"osu_token": "empty-adapters",
"response_body": (
app.packets.user_id(-1)
+ app.packets.notification("Please restart your osu! and try again.")
),
}

## parsing successful

Expand Down Expand Up @@ -905,13 +965,14 @@ async def login(

# the player may have been sent mail while offline,
# enqueue any messages from their respective authors.
mail_rows = await db_conn.fetch_all(
"SELECT m.`msg`, m.`time`, m.`from_id`, "
"(SELECT name FROM users WHERE id = m.`from_id`) AS `from`, "
"(SELECT name FROM users WHERE id = m.`to_id`) AS `to` "
"FROM `mail` m WHERE m.`to_id` = :to AND m.`read` = 0",
{"to": player.id},
)
# mail_rows = await db_conn.fetch_all(
# "SELECT m.`msg`, m.`time`, m.`from_id`, "
# "(SELECT name FROM users WHERE id = m.`from_id`) AS `from`, "
# "(SELECT name FROM users WHERE id = m.`to_id`) AS `to` "
# "FROM `mail` m WHERE m.`to_id` = :to AND m.`read` = 0",
# {"to": player.id},
# )
mail_rows = None

if mail_rows:
sent_to = set() # ids
Expand Down
Loading

0 comments on commit 0612528

Please sign in to comment.