mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Converted banlist from vector of tuples to HashMap
This commit is contained in:
parent
b64f3fa8a9
commit
4653eb63c4
@ -1868,14 +1868,14 @@ fn handle_ban(
|
||||
|
||||
let banlist = server.settings().banlist.clone();
|
||||
|
||||
if let Some(_) = banlist.iter().find(|x| x.0 == target_alias) {
|
||||
if banlist.contains_key(&target_alias) {
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandError.server_msg(format!("{} is already on the banlist", target_alias))
|
||||
)
|
||||
} else {
|
||||
server.settings_mut().edit(|s| {
|
||||
s.banlist.push((target_alias.clone(), reason.clone()))
|
||||
s.banlist.insert(target_alias.clone(), reason.clone());
|
||||
});
|
||||
server.notify_client(
|
||||
client,
|
||||
@ -1913,7 +1913,7 @@ fn handle_unban(
|
||||
) {
|
||||
if let Ok(username) = scan_fmt!(&args, &action.arg_fmt(), String) {
|
||||
server.settings_mut().edit(|s| {
|
||||
s.banlist.retain(|x| !(x.0).eq_ignore_ascii_case(&username))
|
||||
s.banlist.remove(&username);
|
||||
});
|
||||
server.notify_client(
|
||||
client,
|
||||
|
@ -53,7 +53,7 @@ impl LoginProvider {
|
||||
&mut self,
|
||||
username_or_token: &str,
|
||||
whitelist: &[String],
|
||||
banlist: &[(String, String)]
|
||||
banlist: &HashMap<String, String>
|
||||
) -> Result<(String, Uuid), RegisterError> {
|
||||
self
|
||||
// resolve user information
|
||||
@ -61,9 +61,9 @@ impl LoginProvider {
|
||||
// if found, check name against whitelist or if user is admin
|
||||
.and_then(|(username, uuid)| {
|
||||
// user cannot join if they are listed on the banlist
|
||||
if let Some(ban_record) = banlist.iter().find(|x| x.0.eq_ignore_ascii_case(&username)) {
|
||||
if let Some(ban_record) = banlist.get(&username) {
|
||||
// Pull reason string out of ban record and send a copy of it
|
||||
return Err(RegisterError::Banned(ban_record.1.clone()));
|
||||
return Err(RegisterError::Banned(ban_record.clone()));
|
||||
}
|
||||
|
||||
// user can only join if he is admin, the whitelist is empty (everyone can join)
|
||||
|
@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::{fs, io::prelude::*, net::SocketAddr, path::PathBuf, time::Duration};
|
||||
use tracing::{error, warn};
|
||||
use world::sim::FileOpts;
|
||||
use hashbrown::HashMap;
|
||||
|
||||
const DEFAULT_WORLD_SEED: u32 = 59686;
|
||||
|
||||
@ -20,7 +21,7 @@ pub struct ServerSettings {
|
||||
pub start_time: f64,
|
||||
pub admins: Vec<String>,
|
||||
pub whitelist: Vec<String>,
|
||||
pub banlist: Vec<(String, String)>,
|
||||
pub banlist: HashMap<String, String>,
|
||||
/// When set to None, loads the default map file (if available); otherwise,
|
||||
/// uses the value of the file options to decide how to proceed.
|
||||
pub map_file: Option<FileOpts>,
|
||||
@ -45,7 +46,7 @@ impl Default for ServerSettings {
|
||||
map_file: None,
|
||||
admins: Vec::new(),
|
||||
whitelist: Vec::new(),
|
||||
banlist: Vec::new(),
|
||||
banlist: HashMap::new(),
|
||||
persistence_db_dir: "saves".to_owned(),
|
||||
max_view_distance: Some(30),
|
||||
banned_words_files: Vec::new(),
|
||||
|
Loading…
Reference in New Issue
Block a user