aboutsummaryrefslogtreecommitdiff
path: root/src/world.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2021-11-07 01:42:13 +0100
committerDaniel Schadt <kingdread@gmx.de>2021-11-07 01:42:13 +0100
commit5ce6fcc59bb988bda9a1bb9725a2fbcf2270b3c2 (patch)
tree92e5192ffb0c2df09d70ae04c309c83ea6943bcb /src/world.rs
parentbe5879eaaa4000891b1e5369250fec48433b806b (diff)
downloadmodderbaas-5ce6fcc59bb988bda9a1bb9725a2fbcf2270b3c2.tar.gz
modderbaas-5ce6fcc59bb988bda9a1bb9725a2fbcf2270b3c2.tar.bz2
modderbaas-5ce6fcc59bb988bda9a1bb9725a2fbcf2270b3c2.zip
use fallback world name
Apparently, the default world of minetest-server does not have a name set (which is kind of okay because it is the only existing world anyway). But ModderBaas needs to deal with this situation properly. In this case, we simply take the directory name, similar to games.
Diffstat (limited to 'src/world.rs')
-rw-r--r--src/world.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/world.rs b/src/world.rs
index 42a41a4..79ba3f9 100644
--- a/src/world.rs
+++ b/src/world.rs
@@ -37,8 +37,14 @@ impl World {
/// Returns the name of the world.
pub fn world_name(&self) -> Result<String> {
+ let fallback = self.path
+ .file_name()
+ .map(|s| s.to_str().expect("Non-UTF8 directory encountered"));
+
let conf = self.conf()?;
conf.get("world_name")
+ .map(String::as_str)
+ .or(fallback)
.ok_or_else(|| Error::InvalidWorldDir(self.path.clone()))
.map(Into::into)
}