added PBs to userscores
This commit is contained in:
Binary file not shown.
+9
-5
@@ -5,10 +5,13 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hiscores</h1>
|
||||
<p>Highest achieved numbers before returning to 0</p>
|
||||
<div id="hiscore-table"></div>
|
||||
<h1>Loscores</h1>
|
||||
<p>Highest number of consecutive resets to 0</p>
|
||||
<div id="loscore-table"></div>
|
||||
<h1>Pingscores</h1>
|
||||
<h1>Userscores</h1>
|
||||
<p>Total number of resets and personal bests of each username</p>
|
||||
<div id="pingscore-table"></div>
|
||||
</body>
|
||||
<style>
|
||||
@@ -57,14 +60,15 @@
|
||||
tableDiv2.appendChild(table2);
|
||||
const tableDiv3 = document.getElementById("pingscore-table");
|
||||
const table3 = document.createElement("table");
|
||||
table3.innerHTML = `<tr><th>Rank</th><th>Score</th><th>Name</th></tr>`;
|
||||
table3.innerHTML = `<tr><th>Rank</th><th>Name</th><th>Reset count</th><th>PB</th></tr>`;
|
||||
let pingscores = data.pingscores;
|
||||
let sorted = Object.entries(pingscores).sort(([,a],[,b]) => b - a)
|
||||
sorted.forEach(([person,score],index) => {
|
||||
let sorted = Object.entries(pingscores).sort(([,[a,]],[,[b,]]) => b - a)
|
||||
sorted.forEach(([person,scores],index) => {
|
||||
table3.innerHTML += `<tr>
|
||||
<td>#${index + 1}</td>
|
||||
<td>${validate_data(person)}</td>
|
||||
<td>${validate_data(score)}</td>
|
||||
<td>${validate_data(scores[0])}</td>
|
||||
<td>${validate_data(scores[1])}</td>
|
||||
</tr>`;
|
||||
});
|
||||
tableDiv3.appendChild(table3);
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"anon":15,"deadvey":58,"error":0}
|
||||
{"error":[0,60],"anon":[15,10],"deadvey":[1129258,0]}
|
||||
|
||||
Binary file not shown.
+21
-13
@@ -36,7 +36,7 @@ struct AppState {
|
||||
tx: mpsc::Sender<(Entry,Leaderboard)>,
|
||||
hiscores: Arc<Mutex<Vec<Entry>>>,
|
||||
loscores: Arc<Mutex<Vec<Entry>>>,
|
||||
pingscores: Arc<Mutex<HashMap<String,u64>>>,
|
||||
pingscores: Arc<Mutex<HashMap<String,(u64,u32)>>>, // u64 is reset count and u32 is PB
|
||||
}
|
||||
|
||||
static CHANCE: f64 = 1.0/3.0;
|
||||
@@ -48,7 +48,7 @@ async fn main() {
|
||||
let file_contents: String = fs::read_to_string("loscores.json").unwrap();
|
||||
let loscores: Arc<Mutex<Vec<Entry>>> = Arc::new(Mutex::new(serde_json::from_str(&file_contents).unwrap()));
|
||||
let file_contents: String = fs::read_to_string("pingscores.json").unwrap();
|
||||
let pingscores: Arc<Mutex<HashMap<String,u64>>> = Arc::new(Mutex::new(serde_json::from_str(&file_contents).unwrap()));
|
||||
let pingscores: Arc<Mutex<HashMap<String,(u64,u32)>>> = Arc::new(Mutex::new(serde_json::from_str(&file_contents).unwrap()));
|
||||
let hiscore_clone1 = Arc::clone(&hiscores);
|
||||
let loscore_clone1 = Arc::clone(&loscores);
|
||||
let pingscore_clone1 = Arc::clone(&pingscores);
|
||||
@@ -100,7 +100,7 @@ async fn leaderboard() -> Html<&'static str> {
|
||||
Html(include_str!("../leaderboard.html"))
|
||||
}
|
||||
// receiver: 0 for hiscore, 1 for loscore, 2 for pingscore
|
||||
fn handle_hiscores(rx: mpsc::Receiver<(Entry, Leaderboard)>, hiscores_arc: Arc<Mutex<Vec<Entry>>>, loscores_arc: Arc<Mutex<Vec<Entry>>>,pingscores_arc: Arc<Mutex<HashMap<String,u64>>>,)
|
||||
fn handle_hiscores(rx: mpsc::Receiver<(Entry, Leaderboard)>, hiscores_arc: Arc<Mutex<Vec<Entry>>>, loscores_arc: Arc<Mutex<Vec<Entry>>>,pingscores_arc: Arc<Mutex<HashMap<String,(u64,u32)>>>,)
|
||||
{
|
||||
// Panic galore
|
||||
let mut hiscores = hiscores_arc.lock().unwrap();
|
||||
@@ -151,7 +151,12 @@ fn handle_hiscores(rx: mpsc::Receiver<(Entry, Leaderboard)>, hiscores_arc: Arc<M
|
||||
{
|
||||
let name = new_entry.person;
|
||||
let mut pingscores = pingscores_arc.lock().unwrap();
|
||||
*pingscores.entry(name).or_insert(0) += 1;
|
||||
if new_entry.score > pingscores.get(&name).unwrap_or(&(0,0)).1 // pb
|
||||
{
|
||||
pingscores.entry(name.clone()).or_insert((0,0)).1 = new_entry.score;
|
||||
println!("{name} new PB: {}",new_entry.score);
|
||||
};
|
||||
pingscores.entry(name.clone()).or_insert((0,0)).0 += 1; // reset count
|
||||
drop(pingscores);
|
||||
}
|
||||
Err(error) => println!("{error}"),
|
||||
@@ -180,7 +185,7 @@ async fn handle_socket
|
||||
tx: mpsc::Sender<(Entry,Leaderboard)>,
|
||||
hiscores_arc: Arc<Mutex<Vec<Entry>>>,
|
||||
loscores_arc: Arc<Mutex<Vec<Entry>>>,
|
||||
pingscores_arc: Arc<Mutex<HashMap<String, u64>>>,
|
||||
pingscores_arc: Arc<Mutex<HashMap<String,(u64,u32)>>>,
|
||||
) {
|
||||
let mut value: u32 = 0;
|
||||
let msg =
|
||||
@@ -198,6 +203,7 @@ async fn handle_socket
|
||||
};
|
||||
println!("Client connected: {name}");
|
||||
let mut resets: u32 = 0;
|
||||
let mut prev: u32 = 0;
|
||||
|
||||
let _ = socket
|
||||
.send(Message::Text(msg.into()))
|
||||
@@ -206,19 +212,21 @@ async fn handle_socket
|
||||
while let Some(msg) = socket.next().await {
|
||||
match msg {
|
||||
Ok(Message::Text(_)) => {
|
||||
if random_bool(CHANCE) {
|
||||
if random_bool(CHANCE) { // reset
|
||||
let _ = tx.send((Entry{ person: name.clone(), score: value },Leaderboard::Hiscores)); //hiscores
|
||||
let _ = tx.send((Entry{ person: name.clone(), score: 0 },Leaderboard::Pingscores)); //pingscores
|
||||
if value == 0
|
||||
{
|
||||
let _ = tx.send((Entry{ person: name.clone(), score: value },Leaderboard::Pingscores)); //pingscores
|
||||
resets += 1;
|
||||
let _ = tx.send((Entry{ person: name.clone(), score: resets },Leaderboard::Loscores));//loscores
|
||||
}
|
||||
else { resets = 0 };
|
||||
value = 0
|
||||
} // 1/3 chance of failing
|
||||
else { value += 1; }
|
||||
else {
|
||||
value += 1;
|
||||
if prev == 0 {
|
||||
let _ = tx.send((Entry{ person: name.clone(), score: resets },Leaderboard::Loscores));//loscores
|
||||
resets = 0;
|
||||
}
|
||||
}
|
||||
let _ = socket.send(Message::Text(value.to_string().into())).await;
|
||||
prev = value;
|
||||
}
|
||||
|
||||
Ok(Message::Close(_)) => {
|
||||
|
||||
Reference in New Issue
Block a user