Added colors, Disconnect Packet, protocol 21

This commit is contained in:
Shoghi Cervantes 2015-02-01 13:56:39 +01:00
parent 2cd757d80a
commit 8679ad5b86
4 changed files with 76 additions and 66 deletions

View File

@ -88,6 +88,7 @@ use pocketmine\nbt\tag\String;
use pocketmine\network\protocol\AdventureSettingsPacket; use pocketmine\network\protocol\AdventureSettingsPacket;
use pocketmine\network\protocol\AnimatePacket; use pocketmine\network\protocol\AnimatePacket;
use pocketmine\network\protocol\DataPacket; use pocketmine\network\protocol\DataPacket;
use pocketmine\network\protocol\DisconnectPacket;
use pocketmine\network\protocol\EntityEventPacket; use pocketmine\network\protocol\EntityEventPacket;
use pocketmine\network\protocol\FullChunkDataPacket; use pocketmine\network\protocol\FullChunkDataPacket;
use pocketmine\network\protocol\Info as ProtocolInfo; use pocketmine\network\protocol\Info as ProtocolInfo;
@ -164,7 +165,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
protected $forceMovement = null; protected $forceMovement = null;
protected $connected = true; protected $connected = true;
protected $ip; protected $ip;
protected $removeFormat = true; protected $removeFormat = false;
protected $port; protected $port;
protected $username; protected $username;
protected $iusername; protected $iusername;
@ -2399,7 +2400,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, TextFormat::YELLOW . $this->username . " has left the game")); $this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, TextFormat::YELLOW . $this->username . " has left the game"));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : ""); $message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : "");
$this->sendMessage($message);
$this->close($ev->getQuitMessage(), $message); $this->close($ev->getQuitMessage(), $message);
return true; return true;
@ -2440,6 +2440,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
$this->tasks = []; $this->tasks = [];
if($this->connected and !$this->closed){ if($this->connected and !$this->closed){
if($message != ""){
$pk = new DisconnectPacket;
$pk->message = $reason;
$this->directDataPacket($pk);
}
$this->connected = false; $this->connected = false;
if($this->username != ""){ if($this->username != ""){
$this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message)); $this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message));

View File

@ -47,6 +47,7 @@ use pocketmine\network\protocol\HurtArmorPacket;
use pocketmine\network\protocol\Info as ProtocolInfo; use pocketmine\network\protocol\Info as ProtocolInfo;
use pocketmine\network\protocol\InteractPacket; use pocketmine\network\protocol\InteractPacket;
use pocketmine\network\protocol\LevelEventPacket; use pocketmine\network\protocol\LevelEventPacket;
use pocketmine\network\protocol\DisconnectPacket;
use pocketmine\network\protocol\LoginPacket; use pocketmine\network\protocol\LoginPacket;
use pocketmine\network\protocol\LoginStatusPacket; use pocketmine\network\protocol\LoginStatusPacket;
use pocketmine\network\protocol\MessagePacket; use pocketmine\network\protocol\MessagePacket;
@ -71,7 +72,6 @@ use pocketmine\network\protocol\StartGamePacket;
use pocketmine\network\protocol\TakeItemEntityPacket; use pocketmine\network\protocol\TakeItemEntityPacket;
use pocketmine\network\protocol\TileEventPacket; use pocketmine\network\protocol\TileEventPacket;
use pocketmine\network\protocol\UnknownPacket; use pocketmine\network\protocol\UnknownPacket;
use pocketmine\network\protocol\UnloadChunkPacket;
use pocketmine\network\protocol\UpdateBlockPacket; use pocketmine\network\protocol\UpdateBlockPacket;
use pocketmine\network\protocol\UseItemPacket; use pocketmine\network\protocol\UseItemPacket;
use pocketmine\Player; use pocketmine\Player;
@ -306,6 +306,7 @@ class RakLibInterface implements ServerInstance, SourceInterface{
private function registerPackets(){ private function registerPackets(){
$this->packetPool = new \SplFixedArray(256); $this->packetPool = new \SplFixedArray(256);
$this->registerPacket(ProtocolInfo::DISCONNECT_PACKET, DisconnectPacket::class);
$this->registerPacket(ProtocolInfo::LOGIN_PACKET, LoginPacket::class); $this->registerPacket(ProtocolInfo::LOGIN_PACKET, LoginPacket::class);
$this->registerPacket(ProtocolInfo::LOGIN_STATUS_PACKET, LoginStatusPacket::class); $this->registerPacket(ProtocolInfo::LOGIN_STATUS_PACKET, LoginStatusPacket::class);
$this->registerPacket(ProtocolInfo::MESSAGE_PACKET, MessagePacket::class); $this->registerPacket(ProtocolInfo::MESSAGE_PACKET, MessagePacket::class);
@ -350,7 +351,6 @@ class RakLibInterface implements ServerInstance, SourceInterface{
$this->registerPacket(ProtocolInfo::CHAT_PACKET, ChatPacket::class); $this->registerPacket(ProtocolInfo::CHAT_PACKET, ChatPacket::class);
$this->registerPacket(ProtocolInfo::ADVENTURE_SETTINGS_PACKET, AdventureSettingsPacket::class); $this->registerPacket(ProtocolInfo::ADVENTURE_SETTINGS_PACKET, AdventureSettingsPacket::class);
$this->registerPacket(ProtocolInfo::ENTITY_DATA_PACKET, EntityDataPacket::class); $this->registerPacket(ProtocolInfo::ENTITY_DATA_PACKET, EntityDataPacket::class);
$this->registerPacket(ProtocolInfo::UNLOAD_CHUNK_PACKET, UnloadChunkPacket::class);
$this->registerPacket(ProtocolInfo::SET_DIFFICULTY_PACKET, SetDifficultyPacket::class); $this->registerPacket(ProtocolInfo::SET_DIFFICULTY_PACKET, SetDifficultyPacket::class);
} }

View File

@ -24,25 +24,23 @@ namespace pocketmine\network\protocol;
#include <rules/DataPacket.h> #include <rules/DataPacket.h>
class UnloadChunkPacket extends DataPacket{ class DisconnectPacket extends DataPacket{
public static $pool = []; public static $pool = [];
public static $next = 0; public static $next = 0;
public $chunkX; public $message;
public $chunkZ;
public function pid(){ public function pid(){
return Info::UNLOAD_CHUNK_PACKET; return Info::DISCONNECT_PACKET;
} }
public function decode(){ public function decode(){
$this->message = $this->getString();
} }
public function encode(){ public function encode(){
$this->reset(); $this->reset();
$this->putInt($this->chunkX); $this->putString($this->message);
$this->putInt($this->chunkZ);
} }
} }

View File

@ -30,64 +30,70 @@ interface Info{
/** /**
* Actual Minecraft: PE protocol version * Actual Minecraft: PE protocol version
*/ */
const CURRENT_PROTOCOL = 20; const CURRENT_PROTOCOL = 21;
const LOGIN_PACKET = 0x82; const DISCONNECT_PACKET = 0x82;
const LOGIN_STATUS_PACKET = 0x83;
const LOGIN_PACKET = 0x83;
const LOGIN_STATUS_PACKET = 0x84;
const MESSAGE_PACKET = 0x85; const MESSAGE_PACKET = 0x85;
const SET_TIME_PACKET = 0x86; const SET_TIME_PACKET = 0x86;
const START_GAME_PACKET = 0x87; const START_GAME_PACKET = 0x87;
const ADD_MOB_PACKET = 0x88; const ADD_MOB_PACKET = 0x88;
const ADD_PLAYER_PACKET = 0x89; const ADD_PLAYER_PACKET = 0x89;
const REMOVE_PLAYER_PACKET = 0x8a; const REMOVE_PLAYER_PACKET = 0x8a;
const ADD_ENTITY_PACKET = 0x8c; const ADD_ENTITY_PACKET = 0x8b;
const REMOVE_ENTITY_PACKET = 0x8d; const REMOVE_ENTITY_PACKET = 0x8c;
const ADD_ITEM_ENTITY_PACKET = 0x8e; const ADD_ITEM_ENTITY_PACKET = 0x8d;
const TAKE_ITEM_ENTITY_PACKET = 0x8f; const TAKE_ITEM_ENTITY_PACKET = 0x8e;
const MOVE_ENTITY_PACKET = 0x90;
const ROTATE_HEAD_PACKET = 0x94; const MOVE_ENTITY_PACKET = 0x8f;
const MOVE_PLAYER_PACKET = 0x95; const ROTATE_HEAD_PACKET = 0x90;
//const PLACE_BLOCK_PACKET = 0x96; const MOVE_PLAYER_PACKET = 0x91;
const REMOVE_BLOCK_PACKET = 0x97;
const UPDATE_BLOCK_PACKET = 0x98;
const ADD_PAINTING_PACKET = 0x99;
const EXPLODE_PACKET = 0x9a;
const LEVEL_EVENT_PACKET = 0x9b;
const TILE_EVENT_PACKET = 0x9c;
const ENTITY_EVENT_PACKET = 0x9d;
const PLAYER_EQUIPMENT_PACKET = 0xa0; const REMOVE_BLOCK_PACKET = 0x92;
const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa1; const UPDATE_BLOCK_PACKET = 0x93;
const INTERACT_PACKET = 0xa2;
const USE_ITEM_PACKET = 0xa3;
const PLAYER_ACTION_PACKET = 0xa4;
const HURT_ARMOR_PACKET = 0xa6; const ADD_PAINTING_PACKET = 0x94;
const SET_ENTITY_DATA_PACKET = 0xa7;
const SET_ENTITY_MOTION_PACKET = 0xa8; const EXPLODE_PACKET = 0x95;
//const SET_ENTITY_LINK_PACKET = 0xa9;
const SET_HEALTH_PACKET = 0xaa; const LEVEL_EVENT_PACKET = 0x96;
const SET_SPAWN_POSITION_PACKET = 0xab; const TILE_EVENT_PACKET = 0x97;
const ANIMATE_PACKET = 0xac; const ENTITY_EVENT_PACKET = 0x98;
const RESPAWN_PACKET = 0xad; //const MOB_EFFECT_paCKET = 0x99;
const SEND_INVENTORY_PACKET = 0xae;
const DROP_ITEM_PACKET = 0xaf; const PLAYER_EQUIPMENT_PACKET = 0x9a;
const CONTAINER_OPEN_PACKET = 0xb0; const PLAYER_ARMOR_EQUIPMENT_PACKET = 0x9b;
const CONTAINER_CLOSE_PACKET = 0xb1; const INTERACT_PACKET = 0x9c;
const CONTAINER_SET_SLOT_PACKET = 0xb2; const USE_ITEM_PACKET = 0x9d;
const CONTAINER_SET_DATA_PACKET = 0xb3; const PLAYER_ACTION_PACKET = 0x9e;
const CONTAINER_SET_CONTENT_PACKET = 0xb4; const HURT_ARMOR_PACKET = 0x9f;
//const CONTAINER_ACK_PACKET = 0xb5; const SET_ENTITY_DATA_PACKET = 0xa0;
const CHAT_PACKET = 0xb6; const SET_ENTITY_MOTION_PACKET = 0xa1;
const ADVENTURE_SETTINGS_PACKET = 0xb7; //const SET_ENTITY_LINK_PACKET = 0xa2;
const ENTITY_DATA_PACKET = 0xb8; const SET_HEALTH_PACKET = 0xa3;
//const PLAYER_INPUT_PACKET = 0xb9; const SET_SPAWN_POSITION_PACKET = 0xa4;
const FULL_CHUNK_DATA_PACKET = 0xba; const ANIMATE_PACKET = 0xa5;
const UNLOAD_CHUNK_PACKET = 0xbb; const RESPAWN_PACKET = 0xa6;
const SET_DIFFICULTY_PACKET = 0xbc; const SEND_INVENTORY_PACKET = 0xa7;
const DROP_ITEM_PACKET = 0xa8;
const CONTAINER_OPEN_PACKET = 0xa9;
const CONTAINER_CLOSE_PACKET = 0xaa;
const CONTAINER_SET_SLOT_PACKET = 0xab;
const CONTAINER_SET_DATA_PACKET = 0xac;
const CONTAINER_SET_CONTENT_PACKET = 0xad;
//const CONTAINER_ACK_PACKET = 0xae;
const CHAT_PACKET = 0xaf;
const ADVENTURE_SETTINGS_PACKET = 0xb0;
const ENTITY_DATA_PACKET = 0xb1;
//const PLAYER_INPUT_PACKET = 0xb2;
const FULL_CHUNK_DATA_PACKET = 0xb3;
const SET_DIFFICULTY_PACKET = 0xb4;
} }