mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-17 11:18:52 +00:00
New packet writing done
This commit is contained in:
parent
415c9f16f4
commit
0af197a0f7
@ -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;
|
||||
}
|
||||
|
||||
|
27
src/network/Packet.php
Normal file
27
src/network/Packet.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class Packet extends stdClass{
|
||||
public $ip;
|
||||
public $port;
|
||||
public $buffer;
|
||||
|
||||
}
|
@ -19,11 +19,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
class RakNetPacket extends stdClass{
|
||||
public $id;
|
||||
class RakNetPacket extends Packet{
|
||||
private $packetID;
|
||||
|
||||
public function __construct($packetID){
|
||||
$this->id = (int) $packetID;
|
||||
$this->packetID = (int) $packetID;
|
||||
}
|
||||
|
||||
public function pid(){
|
||||
return $this->packetID;
|
||||
}
|
||||
|
||||
public function __destruct(){}
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user