mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
Thanks to @Gameherobrine at NostalgiaCore-BackPort at commit #48c317a
This commit is contained in:
parent
1b25bd4694
commit
dcb8732335
7 changed files with 97 additions and 35 deletions
|
|
@ -45,7 +45,7 @@ class Player{
|
|||
public $CID;
|
||||
public $MTU;
|
||||
public $spawned = false;
|
||||
public $PROTOCOL = ProtocolInfo::CURRENT_PROTOCOL;
|
||||
public $PROTOCOL = ProtocolInfo::CURRENT_PROTOCOL;
|
||||
/**
|
||||
* Stores player inventory. Should not be accessed directly: use Player::addItem/Player::removeItem/Player::setSlot for setting and Player::getSlot for getting.
|
||||
* @var array
|
||||
|
|
@ -482,7 +482,7 @@ class Player{
|
|||
if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY) return [];
|
||||
if(!$this->convertToLocalEIDPacket($packet)) return false;
|
||||
|
||||
$packet->PROTOCOL = $this->PROTOCOL;
|
||||
$packet->PROTOCOL = $this->PROTOCOL;
|
||||
$packet->encode();
|
||||
$pk = new RakNetPacket(RakNetInfo::DATA_PACKET_0);
|
||||
$pk->data[] = $packet;
|
||||
|
|
@ -505,11 +505,11 @@ class Player{
|
|||
if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY) return;
|
||||
if(!$this->convertToLocalEIDPacket($packet)) return false;
|
||||
|
||||
if(PacketPool::isPacketExist($packet->pid(), $this->PROTOCOL) != true){
|
||||
return;
|
||||
}
|
||||
if(PacketPool::isPacketExist($packet->pid(), $this->PROTOCOL) != true){
|
||||
return;
|
||||
}
|
||||
|
||||
$packet->PROTOCOL = $this->PROTOCOL;
|
||||
$packet->PROTOCOL = $this->PROTOCOL;
|
||||
$packet->encode();
|
||||
$len = strlen($packet->buffer) + 1;
|
||||
$MTU = $this->MTU - 24;
|
||||
|
|
@ -542,7 +542,7 @@ class Player{
|
|||
$pk->seqNumber = $this->counter[0]++;
|
||||
$pk->sendtime = microtime(true);
|
||||
|
||||
$packet->PROTOCOL = $this->PROTOCOL;
|
||||
$packet->PROTOCOL = $this->PROTOCOL;
|
||||
$packet->encode();
|
||||
$len = strlen($packet->buffer) + 1;
|
||||
$MTU = $this->MTU - 24;
|
||||
|
|
@ -572,7 +572,7 @@ class Player{
|
|||
$cnts[] = $count = $this->counter[0]++;
|
||||
|
||||
$pk = new UnknownPacket;
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->packetID = $pk->pid();
|
||||
$pk->reliability = RakNetInfo::RELIABILITY_RELIABLE_ORDERED;
|
||||
|
||||
|
|
@ -610,7 +610,7 @@ class Player{
|
|||
$cnts[] = $count = $this->counter[0]++;
|
||||
|
||||
$pk = new UnknownPacket;
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->packetID = $pk->pid();
|
||||
$pk->reliability = RakNetInfo::RELIABILITY_RELIABLE_ORDERED;
|
||||
|
||||
|
|
@ -649,7 +649,7 @@ class Player{
|
|||
$cnts[] = $count = $this->counter[0]++;
|
||||
|
||||
$pk = new UnknownPacket;
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->packetID = $pk->pid();
|
||||
$pk->reliability = RakNetInfo::RELIABILITY_RELIABLE_ORDERED;
|
||||
|
||||
|
|
@ -677,7 +677,7 @@ class Player{
|
|||
if($this->connected === false) return false;
|
||||
if(EventHandler::callEvent(new DataPacketSendEvent($this, $pk)) === BaseEvent::DENY) return;
|
||||
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->encode();
|
||||
$sendtime = microtime(true);
|
||||
$size = $this->MTU - 34;
|
||||
|
|
@ -691,7 +691,7 @@ class Player{
|
|||
$cnts[] = $count = $this->counter[0]++;
|
||||
|
||||
$pk = new UnknownPacket;
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->packetID = $pk->pid();
|
||||
$pk->reliability = RakNetInfo::RELIABILITY_RELIABLE;
|
||||
$pk->hasSplit = true;
|
||||
|
|
@ -729,7 +729,7 @@ class Player{
|
|||
$cnts[] = $count = $this->counter[0]++;
|
||||
|
||||
$pk = new UnknownPacket;
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->packetID = $packet->pid();
|
||||
$pk->reliability = RakNetInfo::RELIABILITY_RELIABLE;
|
||||
$pk->hasSplit = true;
|
||||
|
|
@ -751,7 +751,7 @@ class Player{
|
|||
|
||||
public function send(RakNetPacket $packet){
|
||||
if($this->connected === true){
|
||||
$packet->PROTOCOL = $this->PROTOCOL;
|
||||
$packet->PROTOCOL = $this->PROTOCOL;
|
||||
$packet->packetID = $packet->pid();
|
||||
$packet->ip = $this->ip;
|
||||
$packet->port = $this->port;
|
||||
|
|
@ -1106,9 +1106,9 @@ class Player{
|
|||
public function eventHandler($data, $event){
|
||||
switch($event){
|
||||
case "entity.link":
|
||||
if($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){
|
||||
break;
|
||||
}
|
||||
if($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){
|
||||
break;
|
||||
}
|
||||
$pk = new SetEntityLinkPacket();
|
||||
$pk->rider = $data["rider"];
|
||||
$pk->riding = $data["riding"];
|
||||
|
|
@ -1801,7 +1801,7 @@ class Player{
|
|||
if(EventHandler::callEvent(new DataPacketSendEvent($this, $pk)) === BaseEvent::DENY) return;
|
||||
if(!$this->convertToLocalEIDPacket($pk)) return false;
|
||||
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->encode();
|
||||
|
||||
$len = 1 + strlen($pk->buffer);
|
||||
|
|
@ -1845,7 +1845,7 @@ class Player{
|
|||
if($this->connected === false) return false;
|
||||
if(EventHandler::callEvent(new DataPacketSendEvent($this, $pk)) === BaseEvent::DENY) return;
|
||||
if(!$this->convertToLocalEIDPacket($pk)) return false;
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->PROTOCOL = $this->PROTOCOL;
|
||||
$pk->encode();
|
||||
$len = 1 + strlen($pk->buffer);
|
||||
$MTU = $this->MTU - 24;
|
||||
|
|
@ -2101,7 +2101,7 @@ class Player{
|
|||
if(EventHandler::callEvent(new DataPacketSendEvent($this, $packet)) === BaseEvent::DENY) return false;
|
||||
if(!$this->convertToLocalEIDPacket($packet)) return false;
|
||||
|
||||
$packet->PROTOCOL = $this->PROTOCOL;
|
||||
$packet->PROTOCOL = $this->PROTOCOL;
|
||||
$packet->encode();
|
||||
$len = strlen($packet->buffer) + 1;
|
||||
$MTU = $this->MTU - 24;
|
||||
|
|
@ -2165,12 +2165,12 @@ class Player{
|
|||
$this->username = $packet->username;
|
||||
$this->iusername = strtolower($this->username);
|
||||
$this->loginData = ["clientId" => $packet->clientId, "loginData" => $packet->loginData];
|
||||
$this->PROTOCOL = $packet->PROTOCOL;
|
||||
$this->PROTOCOL = $packet->PROTOCOL;
|
||||
if(count($this->server->clients) > $this->server->maxClients and !$this->server->api->ban->isOp($this->iusername)){
|
||||
$this->close("server is full!", false);
|
||||
return;
|
||||
}
|
||||
if($packet->protocol1 < ProtocolInfo3::CURRENT_PROTOCOL_3 && $packet->protocol1 > ProtocolInfo::CURRENT_PROTOCOL){
|
||||
if($packet->protocol1 < ProtocolInfo3::CURRENT_PROTOCOL_3 && $packet->protocol1 > ProtocolInfo::CURRENT_PROTOCOL){
|
||||
if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){
|
||||
$pk = new LoginStatusPacket;
|
||||
$pk->status = 1;
|
||||
|
|
@ -2397,7 +2397,7 @@ class Player{
|
|||
$this->username = $packet->username;
|
||||
$this->iusername = strtolower($this->username);
|
||||
$this->loginData = ["clientId" => $packet->clientId, "loginData" => $packet->loginData];
|
||||
$this->PROTOCOL = $packet->PROTOCOL;
|
||||
$this->PROTOCOL = $packet->PROTOCOL;
|
||||
if(count($this->server->clients) > $this->server->maxClients and !$this->server->api->ban->isOp($this->iusername)){
|
||||
$this->close("server is full!", false);
|
||||
return;
|
||||
|
|
@ -3535,6 +3535,10 @@ class Player{
|
|||
$t->spawn($this);
|
||||
}else{
|
||||
$nbt = new NBT();
|
||||
if($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12) {
|
||||
$t->setText($packet->line1, $packet->line2, $packet->line3, $packet->line4);
|
||||
break;
|
||||
}
|
||||
$nbt->load($packet->namedtag);
|
||||
$d = array_shift($nbt->tree);
|
||||
if($d["id"] !== TILE_SIGN){
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ abstract class ProtocolInfo9{
|
|||
const CONTAINER_SET_CONTENT_PACKET = 0xb2;
|
||||
const CONTAINER_ACK_PACKET = 0xb3;
|
||||
const CHAT_PACKET = 0xb4;
|
||||
const ENTITY_DATA_PACKET = 0xb5;
|
||||
const ENTITY_DATA_PACKET = 0xb5;
|
||||
const ADVENTURE_SETTINGS_PACKET = 0xb6;
|
||||
}
|
||||
abstract class ProtocolInfo8{
|
||||
|
|
@ -276,7 +276,7 @@ abstract class ProtocolInfo8{
|
|||
const CONTAINER_SET_CONTENT_PACKET = 0xaf;
|
||||
const CONTAINER_ACK_PACKET = 0xb;
|
||||
const CHAT_PACKET = 0xb1;
|
||||
const ENTITY_DATA_PACKET = 0xb2;
|
||||
const ENTITY_DATA_PACKET = 0xb2;
|
||||
const ADVENTURE_SETTINGS_PACKET = 0xb3;
|
||||
}
|
||||
abstract class ProtocolInfo6{
|
||||
|
|
@ -342,7 +342,7 @@ abstract class ProtocolInfo6{
|
|||
const CONTAINER_SET_CONTENT_PACKET = 0xad;
|
||||
const CONTAINER_ACK_PACKET = 0xae;
|
||||
const CHAT_PACKET = 0xaf;
|
||||
const ENTITY_DATA_PACKET = 0xb0;
|
||||
const ENTITY_DATA_PACKET = 0xb0;
|
||||
//const ADVENTURE_SETTINGS_PACKET = 0xb3;
|
||||
}
|
||||
abstract class ProtocolInfo4{
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class ChatPacket extends RakNetDataPacket{
|
|||
}
|
||||
|
||||
public function decode(){
|
||||
|
||||
console($this->getString());
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
|
|
|||
|
|
@ -5,15 +5,19 @@ class EntityDataPacket extends RakNetDataPacket{
|
|||
public $y;
|
||||
public $z;
|
||||
public $namedtag;
|
||||
public $line1;
|
||||
public $line2;
|
||||
public $line3;
|
||||
public $line4;
|
||||
|
||||
public function pid(){
|
||||
if($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){
|
||||
return ProtocolInfo6::ENTITY_DATA_PACKET;
|
||||
}elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9) {
|
||||
return ProtocolInfo8::ENTITY_DATA_PACKET;
|
||||
}elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12) {
|
||||
return ProtocolInfo9::ENTITY_DATA_PACKET;
|
||||
}elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){
|
||||
if($this->PROTOCOL < ProtocolInfo8::CURRENT_PROTOCOL_8){
|
||||
return ProtocolInfo6::ENTITY_DATA_PACKET;
|
||||
}elseif($this->PROTOCOL < ProtocolInfo9::CURRENT_PROTOCOL_9) {
|
||||
return ProtocolInfo8::ENTITY_DATA_PACKET;
|
||||
}elseif($this->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12) {
|
||||
return ProtocolInfo9::ENTITY_DATA_PACKET;
|
||||
}elseif($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL){
|
||||
return ProtocolInfo12::ENTITY_DATA_PACKET;
|
||||
}
|
||||
return ProtocolInfo::ENTITY_DATA_PACKET;
|
||||
|
|
@ -23,6 +27,19 @@ class EntityDataPacket extends RakNetDataPacket{
|
|||
$this->x = $this->getShort();
|
||||
$this->y = $this->getByte();
|
||||
$this->z = $this->getShort();
|
||||
if($this->PROTOCOL < 11){
|
||||
$this->line1 = $this->get(Utils::readLShort($this->get(2), false));
|
||||
$this->line2 = $this->get(Utils::readLShort($this->get(2), false));
|
||||
$this->line3 = $this->get(Utils::readLShort($this->get(2), false));
|
||||
$this->line4 = $this->get(Utils::readLShort($this->get(2), false));
|
||||
return;
|
||||
}elseif($this->PROTOCOL === 11){
|
||||
$this->line1 = $this->getString();
|
||||
$this->line2 = $this->getString();
|
||||
$this->line3 = $this->getString();
|
||||
$this->line4 = $this->getString();
|
||||
return;
|
||||
}
|
||||
$this->namedtag = $this->get(true);
|
||||
}
|
||||
|
||||
|
|
@ -31,8 +48,23 @@ class EntityDataPacket extends RakNetDataPacket{
|
|||
$this->putShort($this->x);
|
||||
$this->putByte($this->y);
|
||||
$this->putShort($this->z);
|
||||
if($this->PROTOCOL < 11){
|
||||
$this->putLShort(strlen($this->line1));
|
||||
$this->put($this->line1);
|
||||
$this->putLShort(strlen($this->line2));
|
||||
$this->put($this->line2);
|
||||
$this->putLShort(strlen($this->line3));
|
||||
$this->put($this->line3);
|
||||
$this->putLShort(strlen($this->line4));
|
||||
$this->put($this->line4);
|
||||
}elseif($this->PROTOCOL === 11){
|
||||
$this->putString($this->line1);
|
||||
$this->putString($this->line2);
|
||||
$this->putString($this->line3);
|
||||
$this->putString($this->line4);
|
||||
return;
|
||||
}
|
||||
$this->put($this->namedtag);
|
||||
console($this->namedtag);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -11,6 +11,8 @@ class MessagePacket extends RakNetDataPacket{
|
|||
public function decode(){
|
||||
if($this->PROTOCOL > ProtocolInfo9::CURRENT_PROTOCOL_9){ //0.6.1 and below From NostalgiaCore-BackPort Author:Gameherobrine
|
||||
$this->source = $this->getString();
|
||||
}else {
|
||||
$this->source = "";
|
||||
}
|
||||
$this->message = $this->getString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,6 +162,10 @@ abstract class RakNetDataPacket extends stdClass{
|
|||
$this->buffer .= Utils::writeShort($v);
|
||||
}
|
||||
|
||||
protected function putLShort($v){
|
||||
$this->buffer .= Utils::writeLShort($v);
|
||||
}
|
||||
|
||||
protected function putByte($v){
|
||||
$this->buffer .= chr((int)$v);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -412,6 +412,26 @@ class Tile extends Position{
|
|||
|
||||
$nbt->write(chr(NBT::TAG_END));
|
||||
|
||||
if($player->PROTOCOL < ProtocolInfo12::CURRENT_PROTOCOL_12){
|
||||
$line1 = mb_substr($this->data["Text1"], 0, 15);
|
||||
$line2 = mb_substr($this->data["Text2"], 0, 15);
|
||||
$line3 = mb_substr($this->data["Text3"], 0, 15);
|
||||
$line4 = mb_substr($this->data["Text4"], 0, 15);
|
||||
|
||||
$pk = new EntityDataPacket;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
|
||||
$pk->line1 = $line1;
|
||||
$pk->line2 = $line2;
|
||||
$pk->line3 = $line3;
|
||||
$pk->line4 = $line4;
|
||||
|
||||
$player->blockQueueDataPacket($pk);
|
||||
break;
|
||||
}
|
||||
|
||||
$pk = new EntityDataPacket;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue