mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 17:59:41 +00:00
0.9.0 clients can join
This commit is contained in:
parent
fb46faa320
commit
3fbc411e17
@ -62,16 +62,18 @@ use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\String;
|
||||
use pocketmine\network\protocol\AdventureSettingsPacket;
|
||||
use pocketmine\network\protocol\AnimatePacket;
|
||||
use pocketmine\network\protocol\ChunkDataPacket;
|
||||
use pocketmine\network\protocol\DataPacket;
|
||||
use pocketmine\network\protocol\EntityEventPacket;
|
||||
use pocketmine\network\protocol\FullChunkDataPacket;
|
||||
use pocketmine\network\protocol\Info as ProtocolInfo;
|
||||
use pocketmine\network\protocol\LoginStatusPacket;
|
||||
use pocketmine\network\protocol\MessagePacket;
|
||||
use pocketmine\network\protocol\ReadyPacket;
|
||||
use pocketmine\network\protocol\SetSpawnPositionPacket;
|
||||
use pocketmine\network\protocol\SetTimePacket;
|
||||
use pocketmine\network\protocol\StartGamePacket;
|
||||
use pocketmine\network\protocol\TakeItemEntityPacket;
|
||||
use pocketmine\network\protocol\UnloadChunkPacket;
|
||||
use pocketmine\network\protocol\UpdateBlockPacket;
|
||||
use pocketmine\network\SourceInterface;
|
||||
use pocketmine\permission\PermissibleBase;
|
||||
@ -560,7 +562,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$Yndex = $this->chunksLoaded[$index];
|
||||
$this->chunksLoaded[$index] = 0; //Load them all
|
||||
$this->getLevel()->useChunk($X, $Z, $this);
|
||||
$pk = new ChunkDataPacket;
|
||||
$pk = new FullChunkDataPacket;
|
||||
$pk->chunkX = $X;
|
||||
$pk->chunkZ = $Z;
|
||||
$pk->data = $this->getLevel()->getOrderedChunk($X, $Z, $Yndex);
|
||||
@ -569,6 +571,30 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(count($this->chunksLoaded) >= 56 and $this->spawned === false){
|
||||
//TODO
|
||||
//$this->heal($this->data->get("health"), "spawn", true);
|
||||
$this->spawned = true;
|
||||
|
||||
$this->sendSettings();
|
||||
$this->inventory->sendContents($this);
|
||||
$this->inventory->sendArmorContents($this);
|
||||
|
||||
$this->blocked = false;
|
||||
|
||||
$pk = new SetTimePacket;
|
||||
$pk->time = $this->getLevel()->getTime();
|
||||
$pk->started = $this->getLevel()->stopTime == false;
|
||||
$this->dataPacket($pk);
|
||||
|
||||
$pos = new Position($this->x, $this->y, $this->z, $this->getLevel());
|
||||
$pos = $this->getLevel()->getSafeSpawn($pos);
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $pos));
|
||||
|
||||
$this->teleport($ev->getRespawnPosition());
|
||||
$this->spawnToAll();
|
||||
}
|
||||
|
||||
$this->lastChunk = array($X, $Z, $cnt, microtime(true));
|
||||
|
||||
if($this->chunkScheduled === 0 or $force === true){
|
||||
@ -634,6 +660,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$entity->despawnFrom($this);
|
||||
}
|
||||
}
|
||||
$pk = new UnloadChunkPacket();
|
||||
$pk->chunkX = $X;
|
||||
$pk->chunkZ = $Z;
|
||||
$this->dataPacket($pk);
|
||||
}
|
||||
unset($this->chunksLoaded[$index]);
|
||||
}
|
||||
@ -1126,7 +1156,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$pk = new LoginStatusPacket;
|
||||
$pk->status = 0;
|
||||
$this->dataPacket($pk);
|
||||
$this->directDataPacket($pk);
|
||||
|
||||
$pk = new StartGamePacket;
|
||||
$pk->seed = $this->getLevel()->getSeed();
|
||||
@ -1136,7 +1166,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$pk->generator = 0;
|
||||
$pk->gamemode = $this->gamemode & 0x01;
|
||||
$pk->eid = 0; //Always use EntityID as zero for the actual player
|
||||
$this->dataPacket($pk);
|
||||
$this->directDataPacket($pk);
|
||||
|
||||
$pk = new SetTimePacket();
|
||||
$pk->time = $this->getLevel()->getTime();
|
||||
$this->directDataPacket($pk);
|
||||
|
||||
|
||||
if(($level = $this->server->getLevel($this->namedtag["SpawnLevel"])) instanceof Level){
|
||||
@ -1153,39 +1187,25 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$this->server->getPluginManager()->callEvent(new PlayerJoinEvent($this, $this->username . " joined the game"));
|
||||
|
||||
$this->orderChunks();
|
||||
$this->tasks[] = $this->server->getScheduler()->scheduleDelayedTask(new CallbackTask(array($this, "orderChunks")), 30);
|
||||
$this->getNextChunk();
|
||||
|
||||
$pk = new ReadyPacket();
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$this->dataPacket($pk);
|
||||
|
||||
break;
|
||||
case ProtocolInfo::READY_PACKET:
|
||||
|
||||
//TODO: check
|
||||
if($this->loggedIn === false){
|
||||
break;
|
||||
}
|
||||
switch($packet->status){
|
||||
case 1: //Spawn!!
|
||||
if($this->spawned !== false){
|
||||
break;
|
||||
}
|
||||
//TODO
|
||||
//$this->heal($this->data->get("health"), "spawn", true);
|
||||
$this->spawned = true;
|
||||
|
||||
$this->sendSettings();
|
||||
$this->inventory->sendContents($this);
|
||||
$this->inventory->sendArmorContents($this);
|
||||
$this->tasks[] = $this->server->getScheduler()->scheduleDelayedTask(new CallbackTask(array($this, "orderChunks")), 30);
|
||||
|
||||
$this->blocked = false;
|
||||
|
||||
$pk = new SetTimePacket;
|
||||
$pk->time = $this->getLevel()->getTime();
|
||||
$pk->started = $this->getLevel()->stopTime == false;
|
||||
$this->dataPacket($pk);
|
||||
|
||||
$pos = new Position($this->x, $this->y, $this->z, $this->getLevel());
|
||||
$pos = $this->getLevel()->getSafeSpawn($pos);
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $pos));
|
||||
|
||||
$this->teleport($ev->getRespawnPosition());
|
||||
$this->spawnToAll();
|
||||
|
||||
break;
|
||||
case 2: //Chunk loaded?
|
||||
break;
|
||||
|
@ -1283,7 +1283,7 @@ class Server{
|
||||
$this->logger->setLogDebug(\pocketmine\DEBUG > 1);
|
||||
}
|
||||
define("ADVANCED_CACHE", $this->getConfigBoolean("enable-advanced-cache", false));
|
||||
define("MAX_CHUNK_RATE", 20 / $this->getConfigInt("max-chunks-per-second", 7)); //Default rate ~336 kB/s
|
||||
define("MAX_CHUNK_RATE", 20 / $this->getConfigInt("max-chunks-per-second", 20));
|
||||
if(ADVANCED_CACHE == true){
|
||||
$this->logger->info("Advanced cache enabled");
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ use pocketmine\tile\Chest;
|
||||
use pocketmine\tile\Furnace;
|
||||
use pocketmine\tile\Sign;
|
||||
use pocketmine\tile\Tile;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\Cache;
|
||||
use pocketmine\utils\Random;
|
||||
use pocketmine\utils\ReversePriorityQueue;
|
||||
@ -1250,6 +1251,9 @@ class Level{
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
|
||||
$Yndex = 0xff;
|
||||
|
||||
if(ADVANCED_CACHE == true and $Yndex === 0xff){
|
||||
$identifier = "world:{$this->name}:" . LevelFormat::getIndex($X, $Z);
|
||||
if(($cache = Cache::get($identifier)) !== false){
|
||||
@ -1265,14 +1269,23 @@ class Level{
|
||||
}
|
||||
}
|
||||
|
||||
$ordered = "";
|
||||
$orderedIds = "";
|
||||
$orderedData = "";
|
||||
$flag = chr($Yndex);
|
||||
|
||||
for($j = 0; $j < 256; ++$j){
|
||||
$ordered .= $flag;
|
||||
//$ordered .= $flag;
|
||||
foreach($raw as $mini){
|
||||
$ordered .= substr($mini, $j << 5, 24); //16 + 8
|
||||
$orderedIds .= substr($mini, $j << 5, 16); //16
|
||||
$orderedData .= substr($mini, ($j << 5) + 16, 8); //16
|
||||
}
|
||||
}
|
||||
$light = str_repeat("\xff", 2048 * 8);
|
||||
$null = str_repeat("\x00", 2048 * 8);
|
||||
$biomeIDs = str_repeat("\x3f", 256);
|
||||
$grassColor = str_repeat("\x01\x85\xb2\x4a", 256);
|
||||
$ordered = zlib_encode(Binary::writeLInt($X) . Binary::writeLInt($Z) . $orderedIds . $orderedData . $light . $null . $biomeIDs . $grassColor, ZLIB_ENCODING_DEFLATE, 7);
|
||||
|
||||
if(ADVANCED_CACHE == true and $Yndex === 0xff){
|
||||
Cache::add($identifier, $ordered, 60);
|
||||
}
|
||||
|
@ -73,6 +73,7 @@ use pocketmine\network\protocol\StartGamePacket;
|
||||
use pocketmine\network\protocol\TakeItemEntityPacket;
|
||||
use pocketmine\network\protocol\TileEventPacket;
|
||||
use pocketmine\network\protocol\UnknownPacket;
|
||||
use pocketmine\network\protocol\UnloadChunkPacket;
|
||||
use pocketmine\network\protocol\UpdateBlockPacket;
|
||||
use pocketmine\network\protocol\UseItemPacket;
|
||||
use pocketmine\Player;
|
||||
@ -263,9 +264,6 @@ class RakLibInterface implements ServerInstance, SourceInterface{
|
||||
case ProtocolInfo::REQUEST_CHUNK_PACKET:
|
||||
$data = new RequestChunkPacket();
|
||||
break;
|
||||
case ProtocolInfo::CHUNK_DATA_PACKET:
|
||||
$data = new ChunkDataPacket();
|
||||
break;
|
||||
case ProtocolInfo::PLAYER_EQUIPMENT_PACKET:
|
||||
$data = new PlayerEquipmentPacket();
|
||||
break;
|
||||
@ -332,6 +330,9 @@ class RakLibInterface implements ServerInstance, SourceInterface{
|
||||
case ProtocolInfo::ENTITY_DATA_PACKET:
|
||||
$data = new EntityDataPacket();
|
||||
break;
|
||||
case ProtocolInfo::UNLOAD_CHUNK_PACKET:
|
||||
$data = new UnloadChunkPacket();
|
||||
break;
|
||||
default:
|
||||
$data = new UnknownPacket();
|
||||
$data->packetID = $pid;
|
||||
|
43
src/pocketmine/network/protocol/FullChunkDataPacket.php
Normal file
43
src/pocketmine/network/protocol/FullChunkDataPacket.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class FullChunkDataPacket extends DataPacket{
|
||||
public $chunkX;
|
||||
public $chunkZ;
|
||||
public $data;
|
||||
|
||||
public function pid(){
|
||||
return Info::FULL_CHUNK_DATA_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->put($this->data);
|
||||
}
|
||||
|
||||
}
|
@ -30,7 +30,7 @@ interface Info{
|
||||
/**
|
||||
* Actual Minecraft: PE protocol version
|
||||
*/
|
||||
const CURRENT_PROTOCOL = 15;
|
||||
const CURRENT_PROTOCOL = 14; //WTF Mojang
|
||||
|
||||
|
||||
const LOGIN_PACKET = 0x82;
|
||||
@ -61,7 +61,7 @@ interface Info{
|
||||
const TILE_EVENT_PACKET = 0x9c;
|
||||
const ENTITY_EVENT_PACKET = 0x9d;
|
||||
const REQUEST_CHUNK_PACKET = 0x9e;
|
||||
const CHUNK_DATA_PACKET = 0x9f;
|
||||
|
||||
const PLAYER_EQUIPMENT_PACKET = 0xa0;
|
||||
const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa1;
|
||||
const INTERACT_PACKET = 0xa2;
|
||||
@ -88,5 +88,7 @@ interface Info{
|
||||
const ADVENTURE_SETTINGS_PACKET = 0xb7;
|
||||
const ENTITY_DATA_PACKET = 0xb8;
|
||||
//const PLAYER_INPUT_PACKET = 0xb9;
|
||||
const FULL_CHUNK_DATA_PACKET = 0xba;
|
||||
const UNLOAD_CHUNK_PACKET = 0xbb;
|
||||
|
||||
}
|
@ -41,7 +41,7 @@ class LevelEventPacket extends DataPacket{
|
||||
$this->reset();
|
||||
$this->putShort($this->evid);
|
||||
$this->putInt($this->x);
|
||||
$this->putInt($this->y);
|
||||
$this->putShort($this->y);
|
||||
$this->putInt($this->z);
|
||||
$this->putInt($this->data);
|
||||
}
|
||||
|
@ -30,11 +30,15 @@ class ReadyPacket extends DataPacket{
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->status = $this->getByte();
|
||||
$this->x = $this->getFloat();
|
||||
$this->y = $this->getFloat();
|
||||
$this->z = $this->getFloat();
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
||||
$this->putFloat($this->x);
|
||||
$this->putFloat($this->y);
|
||||
$this->putFloat($this->z);
|
||||
}
|
||||
|
||||
}
|
@ -22,13 +22,12 @@
|
||||
namespace pocketmine\network\protocol;
|
||||
|
||||
|
||||
class ChunkDataPacket extends DataPacket{
|
||||
class UnloadChunkPacket extends DataPacket{
|
||||
public $chunkX;
|
||||
public $chunkZ;
|
||||
public $data;
|
||||
|
||||
public function pid(){
|
||||
return Info::CHUNK_DATA_PACKET;
|
||||
return Info::UNLOAD_CHUNK_PACKET;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
@ -39,7 +38,6 @@ class ChunkDataPacket extends DataPacket{
|
||||
$this->reset();
|
||||
$this->putInt($this->chunkX);
|
||||
$this->putInt($this->chunkZ);
|
||||
$this->put($this->data);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user