Regenerate corrupt player data if invalid data is found

This commit is contained in:
Shoghi Cervantes 2014-11-20 21:58:27 +01:00
parent 05679c7872
commit 7b7bbe9105

View File

@ -681,7 +681,19 @@ class Server{
public function getOfflinePlayerData($name){ public function getOfflinePlayerData($name){
$name = strtolower($name); $name = strtolower($name);
$path = $this->getDataPath() . "players/"; $path = $this->getDataPath() . "players/";
if(!file_exists($path . "$name.dat")){ if(file_exists($path . "$name.dat")){
try{
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->readCompressed(file_get_contents($path . "$name.dat"));
return $nbt->getData();
}catch(\Exception $e){ //zlib decode error / corrupt data
rename($path . "$name.dat", $path . "$name.dat.bak");
$this->logger->warning("Corrupted data found for \"" . $name . "\", creating new profile");
}
}else{
$this->logger->notice("Player data not found for \"" . $name . "\", creating new profile");
}
$spawn = $this->getDefaultLevel()->getSafeSpawn(); $spawn = $this->getDefaultLevel()->getSafeSpawn();
$nbt = new Compound(false, [ $nbt = new Compound(false, [
new Long("firstPlayed", floor(microtime(true) * 1000)), new Long("firstPlayed", floor(microtime(true) * 1000)),
@ -770,18 +782,11 @@ class Server{
$nbt->Achievements[$achievement] = new Byte($achievement, $status == true ? 1 : 0); $nbt->Achievements[$achievement] = new Byte($achievement, $status == true ? 1 : 0);
} }
unlink($path . "$name.yml"); unlink($path . "$name.yml");
}else{
$this->logger->notice("Player data not found for \"" . $name . "\", creating new profile");
} }
$this->saveOfflinePlayerData($name, $nbt); $this->saveOfflinePlayerData($name, $nbt);
return $nbt; return $nbt;
}else{
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->readCompressed(file_get_contents($path . "$name.dat"));
return $nbt->getData();
}
} }
/** /**