Skip to content

Commit

Permalink
Update the nick if it has been changed
Browse files Browse the repository at this point in the history
The authoritative source for mapping a player's nick
to the id pair is and always will be the auth db.
This db might not be available to people who get
a copy of the map though, e.g. for security reasons.

For them, the map provides a cached version of the nick.
This commit ensures the cached version is updated
and follows nick changes. Currently, there is no
support in the server for changing nicks, but you can
already now edit the db manually.
  • Loading branch information
est31 committed Oct 20, 2020
1 parent fa4a571 commit f5efd04
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion mimas-server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ struct Player<C: NetworkServerConn> {

impl<C: NetworkServerConn> Player<C> {
pub fn from_waiting(waiting :KvWaitingPlayer<C>) -> Self {
let mut slow_states = waiting.slow_states.clone().unwrap();
// The nick field in slow_states is only a map db cache of
// the real nick stored in the auth db, helpful e.g. when
// you only get the map db and want to figure out player nicks.
// Here we update the nick if we notice it has changed,
// but make sure that it's done in a way that the update
// is written to the DB as well (by not updating
// the _last_ser field).
if slow_states.nick != waiting.nick {
slow_states.nick = waiting.nick.clone();
}
Player {
conn : waiting.conn,
ids : waiting.ids,
Expand All @@ -93,7 +104,7 @@ impl<C: NetworkServerConn> Player<C> {
inventory_last_ser : waiting.inv.unwrap(),
craft_inventory : waiting.craft_inv.clone().unwrap(),
craft_inventory_last_ser : waiting.craft_inv.clone().unwrap(),
slow_states : waiting.slow_states.clone().unwrap(),
slow_states,
slow_states_last_ser : waiting.slow_states.clone().unwrap(),
sent_chunks : HashSet::new(),
last_chunk_pos : Vector3::new(0, 0, 0),
Expand Down

0 comments on commit f5efd04

Please sign in to comment.