launcher: the game's made-up name can be rolled for a new one

The game's own name (horizon-player.txt) isn't a kept offline name, so
Forget never applied to it and there was no way to be rid of it. Settings
> Account shows it with "New name", which writes a fresh PlayerNNNNN to
every existing game home — the default and each instance's — so the
player stays the same (new) player in its worlds, as PLAYER_FILES' copies
do.

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
socksprox
2026-10-27 18:13:55 +01:00
parent 8cfc13fe2c
commit 9b6faeb8cf
4 changed files with 88 additions and 1 deletions
+28
View File
@@ -491,6 +491,34 @@ fn follow_player(game_home: &Path, home: &Path) {
}
}
/// A fresh made-up name everywhere the game keeps one: `horizon-player.txt` is per game
/// folder (`PLAYER_FILES`), so the same new name goes to the default home and every
/// instance's — the player stays one player in its worlds. The file's `name:` line and the
/// `Player` + five digits scheme are horizon-client's (`offline_name.rs`).
pub fn new_player_name() -> Result<String, String> {
new_player_name_in(&backend::game_home(), &backend::data_dir())
}
fn new_player_name_in(game_home: &Path, data: &Path) -> Result<String, String> {
let nanos = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map_or(0, |d| d.as_nanos() as u64);
let name = format!(
"Player{:05}",
(nanos ^ u64::from(std::process::id()).rotate_left(32)) % 100_000
);
for instance in list_in(game_home, data) {
if instance.home.is_dir() {
fs::write(
instance.home.join("horizon-player.txt"),
format!("name:{name}\n"),
)
.map_err(|e| format!("{}: {e}", instance.home.display()))?;
}
}
Ok(name)
}
#[cfg(test)]
#[path = "instances/tests.rs"]
mod tests;