aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Queseth <eskilq@kth.se>2021-05-21 15:47:53 +0200
committerEskil Queseth <eskilq@kth.se>2021-05-21 15:47:53 +0200
commitaac27b02754e2d8b8152a062c112842d9f22478a (patch)
tree484a19225cdeaeb349881f0f2dba7084a4fbde0d
parent1a0a0cc5796bebf32e50465abb68b06044aac2e7 (diff)
downloadmum-aac27b02754e2d8b8152a062c112842d9f22478a.tar.gz
fix potential panic when getting usernames while disconnected
-rw-r--r--mumd/src/state.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/mumd/src/state.rs b/mumd/src/state.rs
index 87a5a0e..ce915ac 100644
--- a/mumd/src/state.rs
+++ b/mumd/src/state.rs
@@ -300,12 +300,15 @@ impl State {
.1
.channel()
}
- fn get_user_name(&self, user: u32) -> String {
+
+ /// Gets the username of a user with id `user` connected to the same server that we are connected to.
+ /// If we are connected to the server but the user with the id doesn't exist, the string "Unknown user {id}"
+ /// is returned instead. If we aren't connected to a server, None is returned instead.
+ fn get_user_name(&self, user: u32) -> Option<String> {
self.server()
- .unwrap()
- .users()
- .get(&user).map(|e| e.name().to_string())
- .unwrap_or(format!("Unknown user {}", user))
+ .map(|e| e.users()
+ .get(&user).map(|e| e.name().to_string())
+ .unwrap_or(format!("Unknown user {}", user)))
}
}