Skip to content

Commit f857d19

Browse files
authored
feat(backend): remove server play analytics fallback (#5884)
Remove server play analytics fallback
1 parent 5b59e39 commit f857d19

1 file changed

Lines changed: 28 additions & 37 deletions

File tree

apps/labrinth/src/routes/analytics.rs

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,8 @@ struct MinecraftProfile {
252252
#[derive(Deserialize)]
253253
pub struct MinecraftJavaServerPlayInput {
254254
project_id: ProjectId,
255-
username: Option<String>,
256-
server_id: Option<String>,
257-
minecraft_uuid: Option<Uuid>,
255+
username: String,
256+
server_id: String,
258257
}
259258

260259
pub const MINECRAFT_SERVER_PLAYS: &str = "minecraft_server_plays";
@@ -292,44 +291,36 @@ async fn minecraft_server_play_ingest(
292291
)));
293292
}
294293

295-
let minecraft_uuid = if let (Some(username), Some(server_id)) =
296-
(&play_input.username, &play_input.server_id)
294+
let has_joined = http
295+
.get("https://sessionserver.mojang.com/session/minecraft/hasJoined")
296+
.query(&[
297+
("username", play_input.username.as_str()),
298+
("serverId", play_input.server_id.as_str()),
299+
])
300+
.send()
301+
.await
302+
.wrap_internal_err("failed to contact Mojang session server")?;
303+
304+
if has_joined.status() == reqwest::StatusCode::NO_CONTENT
305+
|| !has_joined.status().is_success()
297306
{
298-
let has_joined = http
299-
.get("https://sessionserver.mojang.com/session/minecraft/hasJoined")
300-
.query(&[
301-
("username", username.as_str()),
302-
("serverId", server_id.as_str()),
303-
])
304-
.send()
305-
.await
306-
.wrap_internal_err("failed to contact Mojang session server")?;
307-
308-
if has_joined.status() == reqwest::StatusCode::NO_CONTENT
309-
|| !has_joined.status().is_success()
310-
{
311-
return Err(ApiError::Request(eyre!(
312-
"Minecraft session verification failed"
313-
)));
314-
}
307+
return Err(ApiError::Request(eyre!(
308+
"Minecraft session verification failed"
309+
)));
310+
}
315311

316-
let profile = has_joined
317-
.json::<MinecraftProfile>()
318-
.await
319-
.wrap_internal_err("invalid Mojang session response")?;
312+
let profile = has_joined
313+
.json::<MinecraftProfile>()
314+
.await
315+
.wrap_internal_err("invalid Mojang session response")?;
320316

321-
if profile.name != *username {
322-
return Err(ApiError::Request(eyre!(
323-
"returned Mojang profile name does not match username"
324-
)));
325-
}
317+
if profile.name != play_input.username {
318+
return Err(ApiError::Request(eyre!(
319+
"returned Mojang profile name does not match username"
320+
)));
321+
}
326322

327-
profile.id
328-
} else {
329-
play_input
330-
.minecraft_uuid
331-
.wrap_request_err("missing `minecraft_uuid`")?
332-
};
323+
let minecraft_uuid = profile.id;
333324

334325
let conn_info = req.connection_info().peer_addr().map(|x| x.to_string());
335326
let headers = req

0 commit comments

Comments
 (0)