mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Adds a command that allows a username to be added or removed from the whitelist
This commit is contained in:
parent
de1f970088
commit
44203ab817
@ -70,6 +70,7 @@ pub enum ChatCommand {
|
|||||||
Tp,
|
Tp,
|
||||||
Version,
|
Version,
|
||||||
Waypoint,
|
Waypoint,
|
||||||
|
Whitelist,
|
||||||
World,
|
World,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,6 +111,7 @@ pub static CHAT_COMMANDS: &[ChatCommand] = &[
|
|||||||
ChatCommand::Tp,
|
ChatCommand::Tp,
|
||||||
ChatCommand::Version,
|
ChatCommand::Version,
|
||||||
ChatCommand::Waypoint,
|
ChatCommand::Waypoint,
|
||||||
|
ChatCommand::Whitelist,
|
||||||
ChatCommand::World,
|
ChatCommand::World,
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -347,6 +349,11 @@ impl ChatCommand {
|
|||||||
ChatCommand::Waypoint => {
|
ChatCommand::Waypoint => {
|
||||||
cmd(vec![], "Set your waypoint to your current position", Admin)
|
cmd(vec![], "Set your waypoint to your current position", Admin)
|
||||||
},
|
},
|
||||||
|
ChatCommand::Whitelist => cmd(
|
||||||
|
vec![Any("add/remove", Required), Any("username", Required)],
|
||||||
|
"Adds/removes username to whitelist",
|
||||||
|
Admin,
|
||||||
|
),
|
||||||
ChatCommand::World => cmd(
|
ChatCommand::World => cmd(
|
||||||
vec![Message(Optional)],
|
vec![Message(Optional)],
|
||||||
"Send messages to everyone on the server",
|
"Send messages to everyone on the server",
|
||||||
@ -393,6 +400,7 @@ impl ChatCommand {
|
|||||||
ChatCommand::Tp => "tp",
|
ChatCommand::Tp => "tp",
|
||||||
ChatCommand::Version => "version",
|
ChatCommand::Version => "version",
|
||||||
ChatCommand::Waypoint => "waypoint",
|
ChatCommand::Waypoint => "waypoint",
|
||||||
|
ChatCommand::Whitelist => "whitelist",
|
||||||
ChatCommand::World => "world",
|
ChatCommand::World => "world",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,7 @@ fn get_handler(cmd: &ChatCommand) -> CommandHandler {
|
|||||||
ChatCommand::Tp => handle_tp,
|
ChatCommand::Tp => handle_tp,
|
||||||
ChatCommand::Version => handle_version,
|
ChatCommand::Version => handle_version,
|
||||||
ChatCommand::Waypoint => handle_waypoint,
|
ChatCommand::Waypoint => handle_waypoint,
|
||||||
|
ChatCommand::Whitelist => handle_whitelist,
|
||||||
ChatCommand::World => handle_world,
|
ChatCommand::World => handle_world,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1679,3 +1680,43 @@ fn handle_version(
|
|||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_whitelist(
|
||||||
|
server: &mut Server,
|
||||||
|
client: EcsEntity,
|
||||||
|
_target: EcsEntity,
|
||||||
|
args: String,
|
||||||
|
action: &ChatCommand,
|
||||||
|
) {
|
||||||
|
if let Ok((whitelist_action, username)) = scan_fmt!(&args, &action.arg_fmt(), String, String) {
|
||||||
|
if whitelist_action.eq_ignore_ascii_case("add") {
|
||||||
|
server
|
||||||
|
.settings_mut()
|
||||||
|
.edit(|s| s.whitelist.push(username.clone()));
|
||||||
|
server.notify_client(
|
||||||
|
client,
|
||||||
|
ChatType::CommandInfo.server_msg(format!("\"{}\" added to whitelist", username)),
|
||||||
|
);
|
||||||
|
} else if whitelist_action.eq_ignore_ascii_case("remove") {
|
||||||
|
server.settings_mut().edit(|s| {
|
||||||
|
s.whitelist
|
||||||
|
.retain(|x| !x.eq_ignore_ascii_case(&username.clone()))
|
||||||
|
});
|
||||||
|
server.notify_client(
|
||||||
|
client,
|
||||||
|
ChatType::CommandInfo
|
||||||
|
.server_msg(format!("\"{}\" removed from whitelist", username)),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
server.notify_client(
|
||||||
|
client,
|
||||||
|
ChatType::CommandError.server_msg(action.help_string()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
server.notify_client(
|
||||||
|
client,
|
||||||
|
ChatType::CommandError.server_msg(action.help_string()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user