mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
review fixes
This commit is contained in:
parent
56cc33ec55
commit
d814296676
@ -790,7 +790,7 @@ fn handle_motd(
|
||||
server
|
||||
.editable_settings()
|
||||
.server_description
|
||||
.get(locale.as_ref())
|
||||
.get(locale.as_deref())
|
||||
.map_or("", |d| &d.motd)
|
||||
.to_string(),
|
||||
),
|
||||
|
@ -32,6 +32,8 @@ use std::{
|
||||
use tracing::{error, warn};
|
||||
use world::sim::FileOpts;
|
||||
|
||||
use self::server_description::ServerDescription;
|
||||
|
||||
const DEFAULT_WORLD_SEED: u32 = 230;
|
||||
const CONFIG_DIR: &str = "server_config";
|
||||
const SETTINGS_FILENAME: &str = "settings.ron";
|
||||
@ -382,9 +384,9 @@ impl EditableSettings {
|
||||
let mut server_description = ServerDescriptions::default();
|
||||
server_description
|
||||
.descriptions
|
||||
.values_mut()
|
||||
.for_each(|entry| {
|
||||
entry.motd = "Who needs friends anyway?".into();
|
||||
.insert("en".to_string(), ServerDescription {
|
||||
motd: "Who needs friends anyway?".to_string(),
|
||||
rules: None,
|
||||
});
|
||||
|
||||
let mut admins = Admins::default();
|
||||
|
@ -219,16 +219,32 @@ mod v2 {
|
||||
}
|
||||
|
||||
impl ServerDescriptions {
|
||||
pub fn get(&self, locale: Option<&String>) -> Option<&ServerDescription> {
|
||||
let locale = locale.map_or(&self.default_locale, |locale| {
|
||||
fn unwrap_locale_or_default<'a, 'b: 'a>(&'b self, locale: Option<&'a str>) -> &'a str {
|
||||
locale.map_or(&self.default_locale, |locale| {
|
||||
if self.descriptions.contains_key(locale) {
|
||||
locale
|
||||
} else {
|
||||
&self.default_locale
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
self.descriptions.get(locale)
|
||||
pub fn get(&self, locale: Option<&str>) -> Option<&ServerDescription> {
|
||||
self.descriptions.get(self.unwrap_locale_or_default(locale))
|
||||
}
|
||||
|
||||
/// Attempts to get the rules in the specified locale, falls back to
|
||||
/// `default_locale` if no rules were specified in this locale
|
||||
pub fn get_rules(&self, locale: Option<&str>) -> Option<&str> {
|
||||
self.descriptions
|
||||
.get(self.unwrap_locale_or_default(locale))
|
||||
.and_then(|d| d.rules.as_deref())
|
||||
.or_else(|| {
|
||||
self.descriptions
|
||||
.get(&self.default_locale)?
|
||||
.rules
|
||||
.as_deref()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ impl Sys {
|
||||
// Give the player a welcome message
|
||||
let localized_description = editable_settings
|
||||
.server_description
|
||||
.get(client.locale.as_ref());
|
||||
.get(client.locale.as_deref());
|
||||
if !localized_description.map_or(true, |d| d.motd.is_empty()) {
|
||||
client.send(ServerGeneral::server_msg(
|
||||
ChatType::CommandInfo,
|
||||
|
@ -329,17 +329,11 @@ impl<'a> System<'a> for Sys {
|
||||
client.send(Ok(()))?;
|
||||
|
||||
|
||||
let description = read_data
|
||||
.editable_settings
|
||||
.server_description
|
||||
.get(client.locale.as_ref())
|
||||
.map(|description|
|
||||
ServerDescription {
|
||||
motd: description.motd.clone(),
|
||||
rules: description.rules.clone()
|
||||
}
|
||||
)
|
||||
.unwrap_or_default();
|
||||
let server_descriptions = &read_data.editable_settings.server_description;
|
||||
let description = ServerDescription {
|
||||
motd: server_descriptions.get(client.locale.as_deref()).map(|d| d.motd.clone()).unwrap_or_default(),
|
||||
rules: server_descriptions.get_rules(client.locale.as_deref()).map(str::to_string),
|
||||
};
|
||||
|
||||
// Send client all the tracked components currently attached to its entity
|
||||
// as well as synced resources (currently only `TimeOfDay`)
|
||||
|
Loading…
Reference in New Issue
Block a user