From 56ac2f25ac1fdc23dbab04e83e41bffb48d410e1 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 4 Sep 2024 21:13:18 +0200 Subject: top5 command --- server/src/commands.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'server/src') diff --git a/server/src/commands.rs b/server/src/commands.rs index e2d40f05..5354c266 100644 --- a/server/src/commands.rs +++ b/server/src/commands.rs @@ -20,7 +20,7 @@ use anyhow::{anyhow, bail, Result}; use clap::{Parser, ValueEnum}; use hurrycurry_bot::algos::ALGO_CONSTRUCTORS; use hurrycurry_protocol::{Message, PacketC, PlayerID}; -use std::time::Duration; +use std::{fmt::Write, time::Duration}; #[derive(Parser)] #[clap(multicall = true)] @@ -34,6 +34,12 @@ enum Command { #[arg(default_value = "420")] timer: u64, }, + /// Shows the best entries of the scoreboard for this map. + #[clap(alias = "top5")] + Top { + /// Name of the map, default: current + map: Option, + }, /// Abort the current game End, /// Download recipe/map's source declaration @@ -162,6 +168,22 @@ impl Server { algo, ))); } + Command::Top { map } => { + let mapname = map.as_ref().unwrap_or(&self.game.data.current_map); + if let Some(board) = self.scoreboard.get(mapname) { + let mut o = format!("Scoreboard for {}:\n", mapname); + for (i, entry) in board.best.iter().take(5).enumerate() { + writeln!( + o, + " {i}. {} points by {}", + entry.score.points, + entry.players.clone().join(", ") + ) + .unwrap(); + } + bail!("{o}"); + } + } } Ok(()) } -- cgit v1.2.3-70-g09d2