Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tap = "1.0.1"
config = "0.13.4"
dot_vox = "5.1.1"
rand = "0.8.5"
ping-rs = "0.1.2"

[lints]
workspace = true
1 change: 1 addition & 0 deletions server/src/addon/command_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl CommandManager {
manager.register(Who);
manager.register(WhoIp);
manager.register(Player);
manager.register(Ping);
manager.register(Xp);
manager.register(Level);
manager.register(Countdown);
Expand Down
3 changes: 3 additions & 0 deletions server/src/addon/command_manager/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ mod test;
mod team;
mod act;
mod heal;
mod ping;

#[derive(Debug, PartialEq, Eq, Hash, Clone, Default)]
pub struct Who;
#[derive(Debug, PartialEq, Eq, Hash, Clone, Default)]
pub struct WhoIp;
#[derive(Debug, PartialEq, Eq, Hash, Clone, Default)]
pub struct Player;
#[derive(Debug, PartialEq, Eq, Hash, Clone, Default)]
pub struct Ping;

#[derive(Debug, PartialEq, Eq, Hash, Clone, Default)]
pub struct Xp;
Expand Down
28 changes: 28 additions & 0 deletions server/src/addon/command_manager/commands/ping.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::str::SplitWhitespace;
use std::sync::Arc;
use std::time::Duration;

use crate::addon::command_manager::{Command, CommandResult};
use crate::addon::command_manager::commands::Ping;
use crate::server::player::Player;
use crate::server::Server;
use ping_rs::*;

impl Command for Ping {
const LITERAL: &'static str = "ping";
const ADMIN_ONLY: bool = false;

#[expect(clippy::significant_drop_in_scrutinee, clippy::significant_drop_tightening, reason = "cannot drop any earlier")]
async fn execute<'fut>(&'fut self, server: &'fut Server, caller: Option<&'fut Player>, params: &'fut mut SplitWhitespace<'fut>) -> CommandResult {
let target = server
.find_player(params.next().ok_or("no target specified")?).await
.ok_or("target not found")?;
let target_ip = target.address.ip();

let ping_reply = send_ping_async(&target_ip, Duration::from_secs(5), Arc::new(&[]), None)
.await.map_err(|_|"ping TimedOut or was ignored by the firewall")?;
let display = format!("{} round trip latency: {}ms", target.character.read().await.name, ping_reply.rtt);

Ok(Some(display))
}
}