Skip to content

Commit

Permalink
disallow double login of normal clients when tourney session exists
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed Sep 24, 2023
1 parent d61e5fb commit 3b2e9b4
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions app/api/domains/cho.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,27 +622,23 @@ async def login(

login_time = time.time()

# TODO: improve tournament client support
# disallow multiple sessions from a single user
# with the exception of tourney spectator clients
player = app.state.sessions.players.get(name=login_data["username"])
if player:
# player is already logged in - allow this only for tournament clients

if not (osu_version.stream == "tourney" or player.tourney_client):
# neither session is a tournament client, disallow

if (login_time - player.last_recv_time) > 10:
# let this session overrule the existing one
# (this is made to help prevent user ghosting)
player.logout()
else:
# current session is still active, disallow
return {
"osu_token": "user-ghosted",
"response_body": (
app.packets.user_id(-1)
+ app.packets.notification("User already logged in.")
),
}
if player and osu_version.stream != "tourney":
# check if the existing session is still active
if (login_time - player.last_recv_time) < 10:
return {
"osu_token": "user-already-logged-in",
"response_body": (
app.packets.user_id(-1)
+ app.packets.notification("User already logged in.")
),
}
else:
# session is not active; replace it
player.logout()
del player

user_info = await players_repo.fetch_one(
name=login_data["username"],
Expand Down

0 comments on commit 3b2e9b4

Please sign in to comment.