diff --git a/src/network/MinecraftInterface.php b/src/network/MinecraftInterface.php index efa28e8f0..3be2af4f9 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -61,22 +61,17 @@ class MinecraftInterface{ $pid = ord($buffer{0}); if(RakNetInfo::isValid($pid)){ $parser = new RakNetParser($buffer); - if($parser->packet !== false){ - $this->packets[] = array( - "pid" => $pid, - "packet" => $packet, - "ip" => $source, - "port" => $port - ); + if($parser->packet !== false){ + $parser->packet->ip = $source; + $parser->packet->port = $port; + $this->packets[] = $parser->packet; } }else{ - if(ServerAPI::request()->api->dhandle("server.unknownpacket", array( - "pid" => $pid, - "data" => array(), - "raw" => $buffer, - "ip" => $source, - "port" => $port - )) !== true){ + $packet = new Packet(); + $packet->ip = $source; + $packet->port = $port; + $packet->buffer = $buffer; + if(ServerAPI::request()->api->dhandle("server.unknownpacket.$pid", $packet) !== true){ console("[ERROR] Unknown Packet ID 0x".Utils::strToHex(chr($pid)), true, true, 2); } return false; @@ -92,19 +87,13 @@ class MinecraftInterface{ } return false; } - - public function writePacket($pid, $data = array(), $raw = false, $dest = false, $port = false, $force = false){ - $CID = PocketMinecraftServer::clientID($dest, $port); - if($raw === false){ - $packet = new Packet($pid, $this->getStruct($pid)); - $packet->data = $data; - @$packet->create(); - $write = $this->socket->write($packet->raw, $dest, $port); - $this->bandwidth[1] += $write; - }else{ - $write = $this->socket->write($data, $dest, $port); - $this->bandwidth[1] += $write; + + public function writePacket(Packet $packet){ + if($packet instanceof RakNetPacket){ + $codec = new RakNetCodec($packet); } + $write = $this->socket->write($packet->buffer, $packet->ip, $packet->port); + $this->bandwidth[1] += $write; return $write; } diff --git a/src/network/Packet.php b/src/network/Packet.php new file mode 100644 index 000000000..abfa75f9b --- /dev/null +++ b/src/network/Packet.php @@ -0,0 +1,27 @@ +id = (int) $packetID; + $this->packetID = (int) $packetID; + } + + public function pid(){ + return $this->packetID; } public function __destruct(){} diff --git a/src/network/raknet/RakNetParser.php b/src/network/raknet/RakNetParser.php index e33633f07..df05211e4 100644 --- a/src/network/raknet/RakNetParser.php +++ b/src/network/raknet/RakNetParser.php @@ -23,10 +23,10 @@ class RakNetParser{ private $id = -1; private $buffer; private $offset; - private $packet; + public $packet; - public function __construct($buffer){ - $this->buffer = $buffer; + public function __construct(&$buffer){ + $this->buffer =& $buffer; $this->offset = 0; if(strlen($this->buffer) > 0){ $this->id = ord($this->get(1)); @@ -78,6 +78,7 @@ class RakNetParser{ private function parse(){ $this->packet = new RakNetPacket($this->pid()); + $this->packet->buffer =& $this->buffer; $this->packet->length = strlen($this->buffer); switch($this->pid()){ case RakNetInfo::UNCONNECTED_PING: