mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
command to show the online players
This commit is contained in:
parent
22af8cb9d5
commit
7182257214
@ -98,6 +98,12 @@ lazy_static! {
|
||||
"/spawn <alignment> <entity> [amount] : Spawn a test entity",
|
||||
handle_spawn,
|
||||
),
|
||||
ChatCommand::new(
|
||||
"who",
|
||||
"{}",
|
||||
"/who : Show the online players list",
|
||||
handle_who
|
||||
),
|
||||
ChatCommand::new(
|
||||
"help", "", "/help: Display this message", handle_help)
|
||||
];
|
||||
@ -285,6 +291,31 @@ fn handle_spawn(server: &mut Server, entity: EcsEntity, args: String, action: &C
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_who(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) {
|
||||
let ecs = server.state.ecs();
|
||||
let players = ecs.read_storage::<comp::Player>();
|
||||
let count = players.join().count();
|
||||
let mut str: String = format!("Online players ({})", count);
|
||||
if count > 0 {
|
||||
str += ": ";
|
||||
let mut player_list: String = players
|
||||
.join()
|
||||
.fold(String::new(), |mut s, player| {
|
||||
s += &player.alias;
|
||||
s += ",";
|
||||
s
|
||||
});
|
||||
player_list.pop();
|
||||
server
|
||||
.clients
|
||||
.notify(entity, ServerMsg::Chat(str + &player_list));
|
||||
} else {
|
||||
server
|
||||
.clients
|
||||
.notify(entity, ServerMsg::Chat(str));
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_help(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) {
|
||||
for cmd in CHAT_COMMANDS.iter() {
|
||||
server
|
||||
|
Loading…
Reference in New Issue
Block a user