Faster player login

This commit is contained in:
Shoghi Cervantes 2015-06-06 17:38:32 +02:00
parent 7f6704f761
commit 6ee61cce7b
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89

View File

@ -92,6 +92,7 @@ use pocketmine\nbt\tag\Double;
use pocketmine\nbt\tag\Enum; use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Float; use pocketmine\nbt\tag\Float;
use pocketmine\nbt\tag\Int; use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\Long;
use pocketmine\nbt\tag\Short; use pocketmine\nbt\tag\Short;
use pocketmine\nbt\tag\String; use pocketmine\nbt\tag\String;
use pocketmine\network\Network; use pocketmine\network\Network;
@ -1620,13 +1621,31 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
break; break;
} }
if(strpos($packet->username, "\x00") !== false or preg_match('#^[a-zA-Z0-9_]{3,16}$#', $packet->username) == 0 or $this->username === "" or $this->iusername === "rcon" or $this->iusername === "console" or strlen($packet->username) > 16 or strlen($packet->username) < 3){ $valid = true;
$len = strlen($packet->username);
if($len > 16 or $len < 3){
$valid = false;
}
for($i = 0; $i < $len and $valid; ++$i){
$c = ord($packet->username{$i});
if(($c >= ord("a") and $c <= ord("z")) or
($c >= ord("Z") and $c <= ord("Z")) or
($c >= ord("0") and $c <= ord("9")) or $c === "_"
){
continue;
}
$valid = false;
break;
}
if(!$valid or $this->iusername === "rcon" or $this->iusername === "console"){
$this->close("", "disconnectionScreen.invalidName"); $this->close("", "disconnectionScreen.invalidName");
break; break;
} }
if(strlen($packet->skin) < 64 * 32 * 4){ if(strlen($packet->skin) !== 64 * 32 * 4 and strlen($packet->skin) !== 64 * 64 * 4){
$this->close("", "disconnectionScreen.invalidSkin"); $this->close("", "disconnectionScreen.invalidSkin");
break; break;
} }
@ -1684,13 +1703,13 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
if(($level = $this->server->getLevelByName($nbt["Level"])) === null){ if(($level = $this->server->getLevelByName($nbt["Level"])) === null){
$this->setLevel($this->server->getDefaultLevel(), true); $this->setLevel($this->server->getDefaultLevel());
$nbt["Level"] = $this->level->getName(); $nbt["Level"] = $this->level->getName();
$nbt["Pos"][0] = $this->level->getSpawnLocation()->x; $nbt["Pos"][0] = $this->level->getSpawnLocation()->x;
$nbt["Pos"][1] = $this->level->getSpawnLocation()->y; $nbt["Pos"][1] = $this->level->getSpawnLocation()->y;
$nbt["Pos"][2] = $this->level->getSpawnLocation()->z; $nbt["Pos"][2] = $this->level->getSpawnLocation()->z;
}else{ }else{
$this->setLevel($level, true); $this->setLevel($level);
} }
if(!($nbt instanceof Compound)){ if(!($nbt instanceof Compound)){
@ -1706,8 +1725,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->achievements[$achievement->getName()] = $achievement->getValue() > 0 ? true : false; $this->achievements[$achievement->getName()] = $achievement->getValue() > 0 ? true : false;
} }
$nbt["lastPlayed"] = floor(microtime(true) * 1000); $nbt->lastPlayed = new Long(floor(microtime(true) * 1000));
$this->server->saveOfflinePlayerData($this->username, $nbt); $this->server->saveOfflinePlayerData($this->username, $nbt, true);
parent::__construct($this->level->getChunk($nbt["Pos"][0] >> 4, $nbt["Pos"][2] >> 4, true), $nbt); parent::__construct($this->level->getChunk($nbt["Pos"][0] >> 4, $nbt["Pos"][2] >> 4, true), $nbt);
$this->loggedIn = true; $this->loggedIn = true;
@ -1796,9 +1815,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->forceMovement = $this->teleportPosition = $this->getPosition(); $this->forceMovement = $this->teleportPosition = $this->getPosition();
$this->orderChunks();
$this->sendNextChunk();
$this->server->onPlayerLogin($this); $this->server->onPlayerLogin($this);
break; break;