Added basic resource-pack response handling, fixed sounds, broadcast sounds received from client

There are still a lot of sounds which do not work, these are supposed to be sent by the server and will be fixed at a later date.
This commit is contained in:
Dylan K. Taylor 2017-02-28 11:51:00 +00:00
parent 6676029319
commit 425686755b
2 changed files with 39 additions and 39 deletions

View File

@ -897,9 +897,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$pk->z = $pos->z;
$this->dataPacket($pk);
$pk = new PlayStatusPacket();
$pk->status = PlayStatusPacket::PLAYER_SPAWN;
$this->dataPacket($pk);
$this->sendPlayStatus(PlayStatusPacket::PLAYER_SPAWN);
$this->server->getPluginManager()->callEvent($ev = new PlayerJoinEvent($this,
new TranslationContainer(TextFormat::YELLOW . "%multiplayer.player.joined", [
@ -1721,29 +1719,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return ($dot1 - $dot) >= -$maxDiff;
}
public function onPlayerPreLogin(){
//TODO: implement auth
$this->tryAuthenticate();
}
public function tryAuthenticate(){
$pk = new PlayStatusPacket();
$pk->status = PlayStatusPacket::LOGIN_SUCCESS;
$this->dataPacket($pk);
//TODO: implement authentication after it is available
$this->authenticateCallback(true);
}
public function authenticateCallback($valid){
//TODO add more stuff after authentication is available
if(!$valid){
$this->close("", "disconnectionScreen.invalidSession");
return;
}
$this->processLogin();
}
protected function processLogin(){
if(!$this->server->isWhitelisted(strtolower($this->getName()))){
@ -1837,8 +1813,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->inventory->setHeldItemSlot($this->inventory->getHotbarSlotIndex(0));
}
$this->dataPacket(new ResourcePacksInfoPacket());
if(!$this->hasValidSpawnPosition() and isset($this->namedtag->SpawnLevel) and ($level = $this->server->getLevelByName($this->namedtag["SpawnLevel"])) instanceof Level){
$this->spawnPosition = new WeakPosition($this->namedtag["SpawnX"], $this->namedtag["SpawnY"], $this->namedtag["SpawnZ"], $level);
}
@ -1920,16 +1894,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
if($packet->protocol !== ProtocolInfo::CURRENT_PROTOCOL){
if($packet->protocol < ProtocolInfo::CURRENT_PROTOCOL){
$message = "disconnectionScreen.outdatedClient";
$pk = new PlayStatusPacket();
$pk->status = PlayStatusPacket::LOGIN_FAILED_CLIENT;
$this->directDataPacket($pk);
$this->sendPlayStatus(PlayStatusPacket::LOGIN_FAILED_CLIENT, true);
}else{
$message = "disconnectionScreen.outdatedServer";
$pk = new PlayStatusPacket();
$pk->status = PlayStatusPacket::LOGIN_FAILED_SERVER;
$this->directDataPacket($pk);
$this->sendPlayStatus(PlayStatusPacket::LOGIN_FAILED_SERVER, true);
}
$this->close("", $message, false);
@ -1960,7 +1928,12 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true;
}
$this->onPlayerPreLogin();
//TODO: add JWT verification, add encryption
$this->sendPlayStatus(PlayStatusPacket::LOGIN_SUCCESS);
$pk = new ResourcePacksInfoPacket();
$this->dataPacket($pk); //TODO: add resource packs stuff
return true;
}
@ -1969,6 +1942,16 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return false;
}
public function sendPlayStatus(int $status, bool $immediate = false){
$pk = new PlayStatusPacket();
$pk->status = $status;
if($immediate){
$this->directDataPacket($pk);
}else{
$this->dataPacket($pk);
}
}
public function handleServerToClientHandshake(ServerToClientHandshakePacket $packet) : bool{
return false;
}
@ -1995,7 +1978,22 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
}
public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{
// TODO: Implement resource packs
switch($packet->status){
case ResourcePackClientResponsePacket::STATUS_REFUSED:
$this->close("", "must accept resource packs to join", true);
break;
case ResourcePackClientResponsePacket::STATUS_SEND_PACKS:
//TODO
break;
case ResourcePackClientResponsePacket::STATUS_HAVE_ALL_PACKS:
$pk = new ResourcePackStackPacket();
$this->dataPacket($pk); //TODO: send resource stack
break;
case ResourcePackClientResponsePacket::STATUS_COMPLETED:
$this->processLogin();
break;
}
return true;
}
@ -2169,7 +2167,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
}
public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{
return false;
//TODO: add events so plugins can change this
$this->getLevel()->addChunkPacket($this->chunk->getX(), $this->chunk->getZ(), $packet);
return true;
}
public function handleLevelEvent(LevelEventPacket $packet) : bool{

View File

@ -40,7 +40,7 @@ class LoginPacket extends DataPacket{
public $serverAddress;
public $skinId;
public $skin = null;
public $skin = "";
public $clientData = [];