Changed all Player packets to new network

This commit is contained in:
Shoghi Cervantes 2014-02-07 16:44:10 +01:00
parent eb375be550
commit 95bff304e4
15 changed files with 548 additions and 474 deletions

View File

@ -317,7 +317,7 @@ class BlockAPI{
}
private function cancelAction(Block $block, Player $player, $send = true){
$player->dataPacket(MC_UPDATE_BLOCK, array(
$player->dataPacket(ProtocolInfo::UPDATE_BLOCK_PACKET, array(
"x" => $block->x,
"y" => $block->y,
"z" => $block->z,

View File

@ -157,12 +157,12 @@ class EntityAPI{
$entity->closed = true;
$this->server->query("DELETE FROM entities WHERE EID = ".$eid.";");
if($entity->class === ENTITY_PLAYER){
$this->server->api->player->broadcastPacket($this->server->api->player->getAll(), MC_REMOVE_PLAYER, array(
$this->server->api->player->broadcastPacket($this->server->api->player->getAll(), ProtocolInfo::REMOVE_PLAYER_PACKET, array(
"clientID" => 0,
"eid" => $entity->eid,
));
}else{
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($entity->level), MC_REMOVE_ENTITY, array(
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($entity->level), ProtocolInfo::REMOVE_ENTITY_PACKET, array(
"eid" => $entity->eid,
));
}

View File

@ -402,7 +402,7 @@ class PlayerAPI{
if($p !== $player and ($p->entity instanceof Entity)){
$p->entity->spawn($player);
if($p->level !== $player->level){
$player->dataPacket(MC_MOVE_ENTITY_POSROT, array(
$player->dataPacket(ProtocolInfo::MOVE_ENTITY_POSROT_PACKET, array(
"eid" => $p->entity->eid,
"x" => -256,
"y" => 128,
@ -420,7 +420,7 @@ class PlayerAPI{
if($p !== $player and ($p->entity instanceof Entity) and ($player->entity instanceof Entity)){
$player->entity->spawn($p);
if($p->level !== $player->level){
$p->dataPacket(MC_MOVE_ENTITY_POSROT, array(
$p->dataPacket(ProtocolInfo::MOVE_ENTITY_POSROT_PACKET, array(
"eid" => $player->entity->eid,
"x" => -256,
"y" => 128,

View File

@ -256,7 +256,7 @@ class ServerAPI{
"memory_usage" => memory_get_usage(true),
"php_version" => PHP_VERSION,
"version" => MAJOR_VERSION,
"mc_version" => CURRENT_MINECRAFT_VERSION,
"ProtocolInfo::version_PACKET" => CURRENT_MINECRAFT_VERSION,
"protocol" => ProtocolInfo::CURRENT_PROTOCOL,
"online" => count($this->server->clients),
"max" => $this->server->maxClients,

File diff suppressed because it is too large Load Diff

View File

@ -474,7 +474,7 @@ class PocketMinecraftServer{
public static function clientID($ip, $port){
//return crc32($ip . $port) ^ crc32($port . $ip . BOOTUP_RANDOM);
return md5($ip . ":" . $port . BOOTUP_RANDOM, true);
return $ip . ":" . $port;
}
public function packetHandler(Packet $packet){

View File

@ -125,7 +125,7 @@ class DoorBlock extends TransparentBlock{
$this->level->setBlock($down, BlockAPI::get($this->id, $meta), true, false, true);
$players = ServerAPI::request()->api->player->getAll($this->level);
unset($players[$player->CID]);
ServerAPI::request()->api->player->broadcastPacket($players, MC_LEVEL_EVENT, array(
ServerAPI::request()->api->player->broadcastPacket($players, ProtocolInfo::LEVEL_EVENT_PACKET, array(
"x" => $this->x,
"y" => $this->y,
"z" => $this->z,
@ -140,7 +140,7 @@ class DoorBlock extends TransparentBlock{
$this->level->setBlock($this, $this, true, false, true);
$players = ServerAPI::request()->api->player->getAll($this->level);
unset($players[$player->CID]);
ServerAPI::request()->api->player->broadcastPacket($players, MC_LEVEL_EVENT, array(
ServerAPI::request()->api->player->broadcastPacket($players, ProtocolInfo::LEVEL_EVENT_PACKET, array(
"x" => $this->x,
"y" => $this->y,
"z" => $this->z,

View File

@ -29,7 +29,7 @@ class BedBlock extends TransparentBlock{
public function onActivate(Item $item, Player $player){
if(ServerAPI::request()->api->time->getPhase($player->level) !== "night"){
$player->dataPacket(MC_CLIENT_MESSAGE, array(
$player->dataPacket(ProtocolInfo::CHAT_PACKET, array(
"message" => "You can only sleep at night"
));
return true;
@ -51,7 +51,7 @@ class BedBlock extends TransparentBlock{
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$b = $blockWest;
}else{
$player->dataPacket(MC_CLIENT_MESSAGE, array(
$player->dataPacket(ProtocolInfo::CHAT_PACKET, array(
"message" => "The bed is incomplete"
));
return true;
@ -59,7 +59,7 @@ class BedBlock extends TransparentBlock{
}
if($player->sleepOn($b) === false){
$player->dataPacket(MC_CLIENT_MESSAGE, array(
$player->dataPacket(ProtocolInfo::CHAT_PACKET, array(
"message" => "This bed is occupied"
));
}

View File

@ -39,6 +39,7 @@ class PlayerEquipmentPacket extends RakNetDataPacket{
public function encode(){
$this->reset();
$this->putInt($this->eid);
$this->putShort($this->item);
$this->putShort($this->meta);
$this->putByte($this->slot);
}

View File

@ -36,9 +36,9 @@ class SetEntityMotionPacket extends RakNetDataPacket{
public function encode(){
$this->reset();
$this->putInt($this->eid);
$this->putShort($this->speedX);
$this->putShort($this->speedY);
$this->putShort($this->speedZ);
$this->putShort((int) ($this->speedX * 400));
$this->putShort((int) ($this->speedY * 400));
$this->putShort((int) ($this->speedZ * 400));
}
}

View File

@ -151,7 +151,7 @@ class RakNetParser{
or $reliability === 7){
$messageIndex = $this->getLTriad();
}else{
$messageIndex = 0;
$messageIndex = false;
}
if($reliability === 1
@ -161,8 +161,8 @@ class RakNetParser{
$orderIndex = $this->getLTriad();
$orderChannel = $this->getByte();
}else{
$orderIndex = 0;
$orderChannel = 0;
$orderIndex = false;
$orderChannel = false;
}
if($hasSplit == true){
@ -172,14 +172,14 @@ class RakNetParser{
//error! no split packets allowed!
return false;
}else{
$splitCount = 0;
$splitID = 0;
$splitIndex = 0;
$splitCount = false;
$splitID = false;
$splitIndex = false;
}
if($length <= 0
or $orderChannel >= 32
or ($hasSplit === 1 and $splitIndex >= $splitCount)){
or ($hasSplit === true and $splitIndex >= $splitCount)){
return false;
}
@ -191,7 +191,7 @@ class RakNetParser{
$data->packetID = $pid;
}
$data->reliability = $reliability;
$data->hasSplit = $hasSplit == true;
$data->hasSplit = $hasSplit;
$data->messageIndex = $messageIndex;
$data->orderIndex = $orderIndex;
$data->orderChannel = $orderChannel;

View File

@ -572,7 +572,7 @@ class Entity extends Position{
$players = $this->server->api->player->getAll($this->level);
if($this->player instanceof Player){
unset($players[$this->player->CID]);
$this->server->api->player->broadcastPacket($players, MC_MOVE_PLAYER, array(
$this->server->api->player->broadcastPacket($players, ProtocolInfo::MOVE_PLAYER_PACKET, array(
"eid" => $this->eid,
"x" => $this->x,
"y" => $this->y,
@ -582,7 +582,7 @@ class Entity extends Position{
"bodyYaw" => $this->yaw,
));
}else{
$this->server->api->player->broadcastPacket($players, MC_MOVE_ENTITY_POSROT, array(
$this->server->api->player->broadcastPacket($players, ProtocolInfo::MOVE_ENTITY_POSROT_PACKET, array(
"eid" => $this->eid,
"x" => $this->x,
"y" => $this->y,
@ -661,7 +661,7 @@ class Entity extends Position{
if($this->player->connected !== true or $this->player->spawned === false){
return false;
}
$player->dataPacket(MC_ADD_PLAYER, array(
$player->dataPacket(ProtocolInfo::ADD_PLAYER_PACKET, array(
"clientID" => 0,/*$this->player->clientID,*/
"username" => $this->player->username,
"eid" => $this->eid,
@ -674,7 +674,7 @@ class Entity extends Position{
"unknown2" => 0,
"metadata" => $this->getMetadata(),
));
$player->dataPacket(MC_PLAYER_EQUIPMENT, array(
$player->dataPacket(ProtocolInfo::PLAYER_EQUIPMENT_PACKET, array(
"eid" => $this->eid,
"block" => $this->player->getSlot($this->player->slot)->getID(),
"meta" => $this->player->getSlot($this->player->slot)->getMetadata(),
@ -683,7 +683,7 @@ class Entity extends Position{
$this->player->sendArmor($player);
break;
case ENTITY_ITEM:
$player->dataPacket(MC_ADD_ITEM_ENTITY, array(
$player->dataPacket(ProtocolInfo::ADD_ITEM_ENTITY_PACKET, array(
"eid" => $this->eid,
"x" => $this->x,
"y" => $this->y,
@ -695,7 +695,7 @@ class Entity extends Position{
"meta" => $this->meta,
"stack" => $this->stack,
));
$player->dataPacket(MC_SET_ENTITY_MOTION, array(
$player->dataPacket(ProtocolInfo::SET_ENTITY_MOTION_PACKET, array(
"eid" => $this->eid,
"speedX" => (int) ($this->speedX * 400),
"speedY" => (int) ($this->speedY * 400),
@ -703,7 +703,7 @@ class Entity extends Position{
));
break;
case ENTITY_MOB:
$player->dataPacket(MC_ADD_MOB, array(
$player->dataPacket(ProtocolInfo::ADD_MOB_PACKET, array(
"type" => $this->type,
"eid" => $this->eid,
"x" => $this->x,
@ -713,7 +713,7 @@ class Entity extends Position{
"pitch" => 0,
"metadata" => $this->getMetadata(),
));
$player->dataPacket(MC_SET_ENTITY_MOTION, array(
$player->dataPacket(ProtocolInfo::SET_ENTITY_MOTION_PACKET, array(
"eid" => $this->eid,
"speedX" => (int) ($this->speedX * 400),
"speedY" => (int) ($this->speedY * 400),
@ -722,7 +722,7 @@ class Entity extends Position{
break;
case ENTITY_OBJECT:
if($this->type === OBJECT_PAINTING){
$player->dataPacket(MC_ADD_PAINTING, array(
$player->dataPacket(ProtocolInfo::ADD_PAINTING_PACKET, array(
"eid" => $this->eid,
"x" => (int) $this->x,
"y" => (int) $this->y,
@ -731,7 +731,7 @@ class Entity extends Position{
"title" => $this->data["Motive"],
));
}elseif($this->type === OBJECT_PRIMEDTNT){
$player->dataPacket(MC_ADD_ENTITY, array(
$player->dataPacket(ProtocolInfo::ADD_ENTITY_PACKET, array(
"eid" => $this->eid,
"type" => $this->type,
"x" => $this->x,
@ -740,7 +740,7 @@ class Entity extends Position{
"did" => 0,
));
}elseif($this->type === OBJECT_ARROW){
$player->dataPacket(MC_ADD_ENTITY, array(
$player->dataPacket(ProtocolInfo::ADD_ENTITY_PACKET, array(
"eid" => $this->eid,
"type" => $this->type,
"x" => $this->x,
@ -748,7 +748,7 @@ class Entity extends Position{
"z" => $this->z,
"did" => 0,
));
$player->dataPacket(MC_SET_ENTITY_MOTION, array(
$player->dataPacket(ProtocolInfo::SET_ENTITY_MOTION_PACKET, array(
"eid" => $this->eid,
"speedX" => (int) ($this->speedX * 400),
"speedY" => (int) ($this->speedY * 400),
@ -757,7 +757,7 @@ class Entity extends Position{
}
break;
case ENTITY_FALLING:
$player->dataPacket(MC_ADD_ENTITY, array(
$player->dataPacket(ProtocolInfo::ADD_ENTITY_PACKET, array(
"eid" => $this->eid,
"type" => $this->type,
"x" => $this->x,
@ -765,7 +765,7 @@ class Entity extends Position{
"z" => $this->z,
"did" => -$this->data["Tile"],
));
$player->dataPacket(MC_SET_ENTITY_MOTION, array(
$player->dataPacket(ProtocolInfo::SET_ENTITY_MOTION_PACKET, array(
"eid" => $this->eid,
"speedX" => (int) ($this->speedX * 400),
"speedY" => (int) ($this->speedY * 400),
@ -981,7 +981,7 @@ class Entity extends Position{
$this->server->api->dhandle("entity.event", array("entity" => $this, "event" => 2)); //Ouch! sound
}
if($this->player instanceof Player){
$this->player->dataPacket(MC_SET_HEALTH, array(
$this->player->dataPacket(ProtocolInfo::SET_HEALTH_PACKET, array(
"health" => $this->health,
));
}
@ -995,7 +995,7 @@ class Entity extends Position{
$this->updateMetadata();
$this->dead = true;
if($this->player instanceof Player){
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), MC_MOVE_ENTITY_POSROT, array(
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), ProtocolInfo::MOVE_ENTITY_POSROT_PACKET, array(
"eid" => $this->eid,
"x" => -256,
"y" => 128,

View File

@ -114,7 +114,7 @@ class Explosion{
$this->level->level->setBlockID($block->x, $block->y, $block->z, 0);
$send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z);
}
$server->api->player->broadcastPacket($server->api->player->getAll($this->level), MC_EXPLOSION, array(
$server->api->player->broadcastPacket($server->api->player->getAll($this->level), ProtocolInfo::EXPLOSION_PACKET, array(
"x" => $this->source->x,
"y" => $this->source->y,
"z" => $this->source->z,

View File

@ -78,7 +78,7 @@ class Level{
}
if($this->server->api->dhandle("time.change", array("level" => $this, "time" => $time)) !== false){
$this->time = $time;
$this->server->api->player->broadcastPacket($this->players, MC_SET_TIME, array(
$this->server->api->player->broadcastPacket($this->players, ProtocolInfo::SET_TIME_PACKET, array(
"time" => (int) $this->time,
"started" => $this->stopTime == false,
));
@ -109,7 +109,7 @@ class Level{
if(count($this->changedBlocks) > 0){
foreach($this->changedBlocks as $blocks){
foreach($blocks as $b){
$this->server->api->player->broadcastPacket($this->players, MC_UPDATE_BLOCK, array(
$this->server->api->player->broadcastPacket($this->players, ProtocolInfo::UPDATE_BLOCK_PACKET, array(
"x" => $b->x,
"y" => $b->y,
"z" => $b->z,
@ -286,7 +286,7 @@ class Level{
public function setBlockRaw(Vector3 $pos, Block $block, $direct = true, $send = true){
if(($ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata())) === true and $send !== false){
if($direct === true){
$this->server->api->player->broadcastPacket($this->players, MC_UPDATE_BLOCK, array(
$this->server->api->player->broadcastPacket($this->players, ProtocolInfo::UPDATE_BLOCK_PACKET, array(
"x" => $pos->x,
"y" => $pos->y,
"z" => $pos->z,
@ -326,7 +326,7 @@ class Level{
$block->position($pos);
if($direct === true){
$this->server->api->player->broadcastPacket($this->players, MC_UPDATE_BLOCK, array(
$this->server->api->player->broadcastPacket($this->players, ProtocolInfo::UPDATE_BLOCK_PACKET, array(
"x" => $pos->x,
"y" => $pos->y,
"z" => $pos->z,

View File

@ -142,7 +142,7 @@ class Tile extends Position{
}else{
$player->windows[$id] = $this;
}
$player->dataPacket(MC_CONTAINER_OPEN, array(
$player->dataPacket(ProtocolInfo::CONTAINER_OPEN_PACKET, array(
"windowid" => $id,
"type" => WINDOW_CHEST,
"slots" => is_array($player->windows[$id]) ? CHEST_SLOTS << 1:CHEST_SLOTS,
@ -155,7 +155,7 @@ class Tile extends Position{
if(is_array($player->windows[$id])){
$all = $this->server->api->player->getAll($this->level);
foreach($player->windows[$id] as $ob){
$this->server->api->player->broadcastPacket($all, MC_TILE_EVENT, array(
$this->server->api->player->broadcastPacket($all, ProtocolInfo::TILE_EVENT_PACKET, array(
"x" => $ob->x,
"y" => $ob->y,
"z" => $ob->z,
@ -172,7 +172,7 @@ class Tile extends Position{
}
}
}else{
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), MC_TILE_EVENT, array(
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), ProtocolInfo::TILE_EVENT_PACKET, array(
"x" => $this->x,
"y" => $this->y,
"z" => $this->z,
@ -188,7 +188,7 @@ class Tile extends Position{
}
}
}
$player->dataPacket(MC_CONTAINER_SET_CONTENT, array(
$player->dataPacket(ProtocolInfo::CONTAINER_SET_CONTENT_PACKET, array(
"windowid" => $id,
"count" => count($slots),
"slots" => $slots,
@ -198,7 +198,7 @@ class Tile extends Position{
$player->windowCnt++;
$player->windowCnt = $id = max(2, $player->windowCnt % 99);
$player->windows[$id] = $this;
$player->dataPacket(MC_CONTAINER_OPEN, array(
$player->dataPacket(ProtocolInfo::CONTAINER_OPEN_PACKET, array(
"windowid" => $id,
"type" => WINDOW_FURNACE,
"slots" => FURNACE_SLOTS,
@ -215,7 +215,7 @@ class Tile extends Position{
$slots[] = BlockAPI::getItem(AIR, 0, 0);
}
}
$player->dataPacket(MC_CONTAINER_SET_CONTENT, array(
$player->dataPacket(ProtocolInfo::CONTAINER_SET_CONTENT_PACKET, array(
"windowid" => $id,
"count" => count($slots),
"slots" => $slots
@ -383,7 +383,7 @@ class Tile extends Position{
$nbt->write(chr(NBT::TAG_END));
$player->dataPacket(MC_ENTITY_DATA, array(
$player->dataPacket(ProtocolInfo::ENTITY_DATA_PACKET, array(
"x" => $this->x,
"y" => $this->y,
"z" => $this->z,
@ -428,7 +428,7 @@ class Tile extends Position{
$nbt->write(chr(NBT::TAG_END));
$player->dataPacket(MC_ENTITY_DATA, array(
$player->dataPacket(ProtocolInfo::ENTITY_DATA_PACKET, array(
"x" => $this->x,
"y" => $this->y,
"z" => $this->z,