From 8ddd701d762c383ff92c9e167d019a1929b45dc1 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 12 Mar 2015 10:35:39 +0100 Subject: [PATCH] Renamed LoginStatusPacket to PlayStatusPacket, added spawn status, new colors --- src/pocketmine/Player.php | 22 +++++++----- src/pocketmine/network/RakLibInterface.php | 4 +-- src/pocketmine/network/protocol/Info.php | 2 +- ...nStatusPacket.php => PlayStatusPacket.php} | 12 +++++-- src/pocketmine/utils/TextFormat.php | 35 ++++++++++--------- 5 files changed, 43 insertions(+), 32 deletions(-) rename src/pocketmine/network/protocol/{LoginStatusPacket.php => PlayStatusPacket.php} (83%) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 4e0add586..052103ee2 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -92,7 +92,7 @@ use pocketmine\network\protocol\DisconnectPacket; 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\PlayStatusPacket; use pocketmine\network\protocol\MessagePacket; use pocketmine\network\protocol\MoveEntityPacket; use pocketmine\network\protocol\MovePlayerPacket; @@ -637,7 +637,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->level->requestChunk($X, $Z, $this, LevelProvider::ORDER_ZXY); } - if(count($this->usedChunks) >= 56 and $this->spawned === false){ + if(count($this->usedChunks) >= 16 and $this->spawned === false){ $spawned = 0; foreach($this->usedChunks as $d){ if($d === true){ @@ -645,11 +645,15 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } } - if($spawned < 56){ + if($spawned < 16){ return; } $this->spawned = true; + + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::PLAYER_SPAWN; + $this->dataPacket($pk); $pk = new SetTimePacket(); $pk->time = $this->level->getTime(); @@ -1420,12 +1424,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){ if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){ - $pk = new LoginStatusPacket(); - $pk->status = 1; + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::LOGIN_FAILED_CLIENT; $this->dataPacket($pk); }else{ - $pk = new LoginStatusPacket(); - $pk->status = 2; + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::LOGIN_FAILED_SERVER; $this->dataPacket($pk); } $this->close("", "Incorrect protocol #" . $packet->protocol1, false); @@ -1526,8 +1530,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->inventory->setHeldItemSlot(0); } - $pk = new LoginStatusPacket(); - $pk->status = 0; + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::LOGIN_SUCCESS; $this->dataPacket($pk); if($this->spawnPosition === null and isset($this->namedtag->SpawnLevel) and ($level = $this->server->getLevelByName($this->namedtag["SpawnLevel"])) instanceof Level){ diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index 84b0e03ae..a9384f470 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -49,7 +49,7 @@ use pocketmine\network\protocol\InteractPacket; use pocketmine\network\protocol\LevelEventPacket; use pocketmine\network\protocol\DisconnectPacket; use pocketmine\network\protocol\LoginPacket; -use pocketmine\network\protocol\LoginStatusPacket; +use pocketmine\network\protocol\PlayStatusPacket; use pocketmine\network\protocol\MessagePacket; use pocketmine\network\protocol\MoveEntityPacket; use pocketmine\network\protocol\MovePlayerPacket; @@ -306,7 +306,7 @@ class RakLibInterface implements ServerInstance, SourceInterface{ $this->packetPool = new \SplFixedArray(256); $this->registerPacket(ProtocolInfo::LOGIN_PACKET, LoginPacket::class); - $this->registerPacket(ProtocolInfo::LOGIN_STATUS_PACKET, LoginStatusPacket::class); + $this->registerPacket(ProtocolInfo::PLAY_STATUS_PACKET, PlayStatusPacket::class); $this->registerPacket(ProtocolInfo::DISCONNECT_PACKET, DisconnectPacket::class); $this->registerPacket(ProtocolInfo::MESSAGE_PACKET, MessagePacket::class); $this->registerPacket(ProtocolInfo::SET_TIME_PACKET, SetTimePacket::class); diff --git a/src/pocketmine/network/protocol/Info.php b/src/pocketmine/network/protocol/Info.php index 8fea7506c..5b6973835 100644 --- a/src/pocketmine/network/protocol/Info.php +++ b/src/pocketmine/network/protocol/Info.php @@ -33,7 +33,7 @@ interface Info{ const CURRENT_PROTOCOL = 21; const LOGIN_PACKET = 0x82; - const LOGIN_STATUS_PACKET = 0x83; + const PLAY_STATUS_PACKET = 0x83; const DISCONNECT_PACKET = 0x84; diff --git a/src/pocketmine/network/protocol/LoginStatusPacket.php b/src/pocketmine/network/protocol/PlayStatusPacket.php similarity index 83% rename from src/pocketmine/network/protocol/LoginStatusPacket.php rename to src/pocketmine/network/protocol/PlayStatusPacket.php index e3e92d3e9..ca9ec3c0d 100644 --- a/src/pocketmine/network/protocol/LoginStatusPacket.php +++ b/src/pocketmine/network/protocol/PlayStatusPacket.php @@ -24,14 +24,20 @@ namespace pocketmine\network\protocol; #include -class LoginStatusPacket extends DataPacket{ +class PlayStatusPacket extends DataPacket{ + + const LOGIN_SUCCESS = 0; + const LOGIN_FAILED_CLIENT = 1; + const LOGIN_FAILED_SERVER = 2; + const PLAYER_SPAWN = 3; + public static $pool = []; public static $next = 0; public $status; public function pid(){ - return Info::LOGIN_STATUS_PACKET; + return Info::PLAY_STATUS_PACKET; } public function decode(){ @@ -43,4 +49,4 @@ class LoginStatusPacket extends DataPacket{ $this->putInt($this->status); } -} \ No newline at end of file +} diff --git a/src/pocketmine/utils/TextFormat.php b/src/pocketmine/utils/TextFormat.php index 185569d74..25c83624a 100644 --- a/src/pocketmine/utils/TextFormat.php +++ b/src/pocketmine/utils/TextFormat.php @@ -390,6 +390,7 @@ abstract class TextFormat{ foreach($string as $token){ switch($token){ case TextFormat::BOLD: + $newString .= "\x1b[1m"; break; case TextFormat::OBFUSCATED: $newString .= "\x1b[8m"; @@ -409,52 +410,52 @@ abstract class TextFormat{ //Colors case TextFormat::BLACK: - $newString .= "\x1b[0;30m"; + $newString .= "\x1b[38;2;0;0;0m"; break; case TextFormat::DARK_BLUE: - $newString .= "\x1b[0;34m"; + $newString .= "\x1b[38;2;0;0;170m"; break; case TextFormat::DARK_GREEN: - $newString .= "\x1b[0;32m"; + $newString .= "\x1b[38;2;0;170;0m"; break; case TextFormat::DARK_AQUA: - $newString .= "\x1b[0;36m"; + $newString .= "\x1b[38;2;0;170;170m"; break; case TextFormat::DARK_RED: - $newString .= "\x1b[0;31m"; + $newString .= "\x1b[38;2;170;0;0m"; break; case TextFormat::DARK_PURPLE: - $newString .= "\x1b[0;35m"; + $newString .= "\x1b[38;2;170;0;170m"; break; case TextFormat::GOLD: - $newString .= "\x1b[0;33m"; + $newString .= "\x1b[38;2;255;170;0m"; break; case TextFormat::GRAY: - $newString .= "\x1b[0;37m"; + $newString .= "\x1b[38;2;170;170;170m"; break; case TextFormat::DARK_GRAY: - $newString .= "\x1b[30;1m"; + $newString .= "\x1b[38;2;85;85;85m"; break; case TextFormat::BLUE: - $newString .= "\x1b[34;1m"; + $newString .= "\x1b[38;2;85;85;255m"; break; case TextFormat::GREEN: - $newString .= "\x1b[32;1m"; + $newString .= "\x1b[38;2;85;255;85m"; break; case TextFormat::AQUA: - $newString .= "\x1b[36;1m"; + $newString .= "\x1b[38;2;85;255;255m"; break; case TextFormat::RED: - $newString .= "\x1b[31;1m"; + $newString .= "\x1b[38;2;255;85;85m"; break; case TextFormat::LIGHT_PURPLE: - $newString .= "\x1b[35;1m"; + $newString .= "\x1b[38;2;255;85;255m"; break; case TextFormat::YELLOW: - $newString .= "\x1b[33;1m"; + $newString .= "\x1b[38;2;255;255;85m"; break; case TextFormat::WHITE: - $newString .= "\x1b[37;1m"; + $newString .= "\x1b[38;2;255;255;255m"; break; default: $newString .= $token; @@ -465,4 +466,4 @@ abstract class TextFormat{ return $newString; } -} \ No newline at end of file +}