Merge commit '5356557f7b0009d43d7f437ada1a0c564a53dcc5'
# Conflicts: # src/game.rs
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use crate::{page::new, random_names::get_name_by_uuid, Backend};
|
use crate::{page::new, Backend};
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{Path, State},
|
extract::{Path, State},
|
||||||
response::{IntoResponse, Redirect, Response},
|
response::{IntoResponse, Redirect, Response},
|
||||||
@@ -50,9 +50,7 @@ async fn index(State(backend): State<Arc<Backend>>, cookies: CookieJar) -> Respo
|
|||||||
(rank.rank)"."
|
(rank.rank)"."
|
||||||
}
|
}
|
||||||
@if rank.uuid == client.uuid { (PreEscaped("<mark>")) }
|
@if rank.uuid == client.uuid { (PreEscaped("<mark>")) }
|
||||||
@if let Some(name) = rank.name { (name) } @else {
|
(rank.name)
|
||||||
"Anonymous "
|
|
||||||
(get_name_by_uuid(&rank.uuid))}
|
|
||||||
@if rank.uuid == client.uuid { (PreEscaped("</mark>")) }
|
@if rank.uuid == client.uuid { (PreEscaped("</mark>")) }
|
||||||
}
|
}
|
||||||
span.font-headline.cam {
|
span.font-headline.cam {
|
||||||
|
@@ -1,17 +1,40 @@
|
|||||||
use crate::Backend;
|
use crate::{random_names::get_name_by_uuid, Backend};
|
||||||
|
|
||||||
pub(crate) struct Rank {
|
struct RankDb {
|
||||||
pub(crate) rank: i64,
|
pub(crate) rank: i64,
|
||||||
pub(crate) name: Option<String>,
|
pub(crate) name: Option<String>,
|
||||||
pub(crate) uuid: String,
|
pub(crate) uuid: String,
|
||||||
pub(crate) amount: i64,
|
pub(crate) amount: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) struct Rank {
|
||||||
|
pub(crate) rank: i64,
|
||||||
|
pub(crate) name: String,
|
||||||
|
pub(crate) uuid: String,
|
||||||
|
pub(crate) amount: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<RankDb> for Rank {
|
||||||
|
fn from(value: RankDb) -> Self {
|
||||||
|
let name = match value.name {
|
||||||
|
Some(name) => name,
|
||||||
|
None => get_name_by_uuid(&value.uuid).to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
Self {
|
||||||
|
rank: value.rank,
|
||||||
|
name,
|
||||||
|
uuid: value.uuid,
|
||||||
|
amount: value.amount,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Backend {
|
impl Backend {
|
||||||
pub(crate) async fn highscore(&self) -> Vec<Rank> {
|
pub(crate) async fn highscore(&self) -> Vec<Rank> {
|
||||||
match self {
|
match self {
|
||||||
Backend::Sqlite(db) => sqlx::query_as!(
|
Backend::Sqlite(db) => sqlx::query_as!(
|
||||||
Rank,
|
RankDb,
|
||||||
"SELECT
|
"SELECT
|
||||||
RANK() OVER (ORDER BY COUNT(s.client_uuid) DESC) as rank,
|
RANK() OVER (ORDER BY COUNT(s.client_uuid) DESC) as rank,
|
||||||
c.name,
|
c.name,
|
||||||
@@ -24,7 +47,10 @@ impl Backend {
|
|||||||
)
|
)
|
||||||
.fetch_all(db)
|
.fetch_all(db)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default()
|
||||||
|
.into_iter()
|
||||||
|
.map(|r| r.into())
|
||||||
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -470,11 +470,11 @@ const NAMES: [&str; 467] = [
|
|||||||
"Yellow",
|
"Yellow",
|
||||||
];
|
];
|
||||||
|
|
||||||
pub(crate) fn get_name_by_uuid(uuid: &str) -> &str {
|
pub(crate) fn get_name_by_uuid(uuid: &str) -> String {
|
||||||
let mut hasher = DefaultHasher::new();
|
let mut hasher = DefaultHasher::new();
|
||||||
uuid.hash(&mut hasher);
|
uuid.hash(&mut hasher);
|
||||||
let hash = hasher.finish();
|
let hash = hasher.finish();
|
||||||
|
|
||||||
let index = (hash % NAMES.len() as u64) as usize;
|
let index = (hash % NAMES.len() as u64) as usize;
|
||||||
NAMES[index]
|
format!("Anonymous {}", NAMES[index])
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user