mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-13 15:05:33 +00:00
New packets, general Improvement
This commit is contained in:
parent
9c4abf49f5
commit
5425dfa5dc
@ -52,7 +52,7 @@ class MinecraftInterface{
|
|||||||
protected function writeDump($pid, $raw, $data, $origin = "client", $ip = "", $port = 0){
|
protected function writeDump($pid, $raw, $data, $origin = "client", $ip = "", $port = 0){
|
||||||
if(LOG === true and DEBUG >= 2){
|
if(LOG === true and DEBUG >= 2){
|
||||||
$p = "[".microtime(true)."] [".((($origin === "client" and $this->client === true) or ($origin === "server" and $this->client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: ".$this->name[$pid]." (0x".Utils::strTohex(chr($pid)).") [lenght ".strlen($raw)."]".PHP_EOL;
|
$p = "[".microtime(true)."] [".((($origin === "client" and $this->client === true) or ($origin === "server" and $this->client === false)) ? "CLIENT->SERVER":"SERVER->CLIENT")." ".$ip.":".$port."]: ".$this->name[$pid]." (0x".Utils::strTohex(chr($pid)).") [lenght ".strlen($raw)."]".PHP_EOL;
|
||||||
$p .= hexdump($raw, false, false, true);
|
$p .= Utils::hexdump($raw);
|
||||||
if(is_array($data)){
|
if(is_array($data)){
|
||||||
foreach($data as $i => $d){
|
foreach($data as $i => $d){
|
||||||
$p .= $i ." => ".(!is_array($d) ? $this->pstruct[$pid][$i]."(".(($this->pstruct[$pid][$i] === "magic" or substr($this->pstruct[$pid][$i], 0, 7) === "special" or is_int($this->pstruct[$pid][$i])) ? Utils::strToHex($d):$d).")":$this->pstruct[$pid][$i]."(***)").PHP_EOL;
|
$p .= $i ." => ".(!is_array($d) ? $this->pstruct[$pid][$i]."(".(($this->pstruct[$pid][$i] === "magic" or substr($this->pstruct[$pid][$i], 0, 7) === "special" or is_int($this->pstruct[$pid][$i])) ? Utils::strToHex($d):$d).")":$this->pstruct[$pid][$i]."(***)").PHP_EOL;
|
||||||
@ -80,7 +80,7 @@ class MinecraftInterface{
|
|||||||
$struct = $this->getStruct($pid);
|
$struct = $this->getStruct($pid);
|
||||||
if($struct === false){
|
if($struct === false){
|
||||||
$p = "[".microtime(true)."] [SERVER->CLIENT]: Error, bad packet id 0x".Utils::strToHex(chr($pid)).PHP_EOL;
|
$p = "[".microtime(true)."] [SERVER->CLIENT]: Error, bad packet id 0x".Utils::strToHex(chr($pid)).PHP_EOL;
|
||||||
$p .= hexdump($data[0], false, false, true);
|
$p .= Utils::hexdump($data[0]);
|
||||||
$p .= PHP_EOL;
|
$p .= PHP_EOL;
|
||||||
logg($p, "packets", true, 2);
|
logg($p, "packets", true, 2);
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ class Packet{
|
|||||||
$this->offset = 1;
|
$this->offset = 1;
|
||||||
$this->raw = $data;
|
$this->raw = $data;
|
||||||
$this->data = array();
|
$this->data = array();
|
||||||
if($pid !== false){
|
if($data === ""){
|
||||||
$this->addRaw(chr($pid));
|
$this->addRaw(chr($pid));
|
||||||
}
|
}
|
||||||
$this->struct = $struct;
|
$this->struct = $struct;
|
||||||
@ -61,6 +61,7 @@ class Packet{
|
|||||||
switch($this->pid){
|
switch($this->pid){
|
||||||
case 0x05:
|
case 0x05:
|
||||||
case 0x84:
|
case 0x84:
|
||||||
|
case 0x8c:
|
||||||
$this->addRaw($this->data[$field]);
|
$this->addRaw($this->data[$field]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -140,6 +141,7 @@ class Packet{
|
|||||||
switch($this->pid){
|
switch($this->pid){
|
||||||
case 0x05:
|
case 0x05:
|
||||||
case 0x84:
|
case 0x84:
|
||||||
|
case 0x8c:
|
||||||
$this->data[] = $this->get(true);
|
$this->data[] = $this->get(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,11 @@ the Free Software Foundation, either version 3 of the License, or
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class PocketMinecraftClient{
|
class PocketMinecraftClient{
|
||||||
protected $interface, $protocol, $entities, $player, $cnt, $events, $username, $version, $clientID, $connected, $serverID;
|
protected $interface, $protocol, $entities, $player, $cnt, $events, $username, $version, $clientID, $connected, $serverID, $start;
|
||||||
var $serverList = array();
|
var $serverList = array();
|
||||||
function __construct($username, $protocol = CURRENT_PROTOCOL, $version = CURRENT_VERSION){
|
function __construct($username, $protocol = CURRENT_PROTOCOL, $version = CURRENT_VERSION){
|
||||||
//$this->player = new Player($username);
|
//$this->player = new Player($username);
|
||||||
|
$this->start = microtime(true);
|
||||||
$this->version = (int) $version;
|
$this->version = (int) $version;
|
||||||
$this->username = $username;
|
$this->username = $username;
|
||||||
$this->connected = false;
|
$this->connected = false;
|
||||||
@ -77,7 +78,7 @@ class PocketMinecraftClient{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getServerList(){
|
public function getServerList(){
|
||||||
$this->action(1000000, '$this->send(0x02, array((microtime(true) * 1000)));');
|
$this->action(1000000, '$this->send(0x02, array(((microtime(true) - $this->start) * 1000)));');
|
||||||
$this->action(5000000, '$this->actions = array();$this->stop = true;');
|
$this->action(5000000, '$this->actions = array();$this->stop = true;');
|
||||||
$this->process();
|
$this->process();
|
||||||
$list = array();
|
$list = array();
|
||||||
@ -111,7 +112,8 @@ class PocketMinecraftClient{
|
|||||||
case 0x08:
|
case 0x08:
|
||||||
$serverID = $data[1];
|
$serverID = $data[1];
|
||||||
$this->send(0x84, array(
|
$this->send(0x84, array(
|
||||||
"\x00\x00\x00\x40\x00\x90\x00\x00\x00\x09".$this->serverID.Utils::writeDouble(microtime(true) * 1000).chr(0x00),
|
0,
|
||||||
|
"\x00\x00\x40\x00\x90\x00\x00\x00\x09".$this->serverID.Utils::writeDouble((microtime(true) - $this->start) * 1000).chr(0x00),
|
||||||
/*"\x00\x00\x00\x40\x00\x90\x00\x00\x00\x09",
|
/*"\x00\x00\x00\x40\x00\x90\x00\x00\x00\x09",
|
||||||
$this->serverID,
|
$this->serverID,
|
||||||
(microtime(true) * 1000),
|
(microtime(true) * 1000),
|
||||||
|
@ -132,6 +132,17 @@ class Utils{
|
|||||||
return ($negative === true ? "-":"").str_replace("x", "", $hash);
|
return ($negative === true ? "-":"").str_replace("x", "", $hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function hexdump($bin){
|
||||||
|
$output = "";
|
||||||
|
$bin = str_split($bin, 16);
|
||||||
|
foreach($bin as $counter => $line){
|
||||||
|
$hex = chunk_split(chunk_split(str_pad(bin2hex($line), 32, " ", STR_PAD_RIGHT), 2, " "), 24, " ");
|
||||||
|
$ascii = preg_replace('#([^\x20-\x7E])#', '.', $line);
|
||||||
|
$output .= str_pad(dechex($counter << 4), 4, "0", STR_PAD_LEFT). " " . $hex . " " . $ascii . PHP_EOL;
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
public static function microtime(){
|
public static function microtime(){
|
||||||
return microtime(true);
|
return microtime(true);
|
||||||
}
|
}
|
||||||
|
@ -112,69 +112,3 @@ function logg($message, $name, $EOL = true, $level = 2, $close = false){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hexdump($data, $htmloutput = true, $uppercase = false, $return = false)
|
|
||||||
{
|
|
||||||
// Init
|
|
||||||
$hexi = '';
|
|
||||||
$ascii = '';
|
|
||||||
$dump = ($htmloutput === true) ? '<pre>' : '';
|
|
||||||
$offset = 0;
|
|
||||||
$len = strlen($data);
|
|
||||||
|
|
||||||
// Upper or lower case hexadecimal
|
|
||||||
$x = ($uppercase === false) ? 'x' : 'X';
|
|
||||||
|
|
||||||
// Iterate string
|
|
||||||
for ($i = $j = 0; $i < $len; $i++)
|
|
||||||
{
|
|
||||||
// Convert to hexidecimal
|
|
||||||
$hexi .= Utils::strToHex($data[$i]);
|
|
||||||
|
|
||||||
// Replace non-viewable bytes with '.'
|
|
||||||
if (ord($data[$i]) >= 0x20 and ord($data[$i]) < 0x80) {
|
|
||||||
$ascii .= ($htmloutput === true) ?
|
|
||||||
htmlentities($data[$i]) :
|
|
||||||
$data[$i];
|
|
||||||
} else {
|
|
||||||
$ascii .= '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add extra column spacing
|
|
||||||
if ($j === 7) {
|
|
||||||
$hexi .= ' ';
|
|
||||||
$ascii .= ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add row
|
|
||||||
if (++$j === 16 || $i === $len - 1) {
|
|
||||||
// Join the hexi / ascii output
|
|
||||||
$dump .= sprintf("%04$x %-49s %s", $offset, $hexi, $ascii);
|
|
||||||
|
|
||||||
// Reset vars
|
|
||||||
$hexi = $ascii = '';
|
|
||||||
$offset += 16;
|
|
||||||
$j = 0;
|
|
||||||
|
|
||||||
// Add newline
|
|
||||||
if ($i !== $len - 1) {
|
|
||||||
$dump .= "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finish dump
|
|
||||||
$dump .= $htmloutput === true ?
|
|
||||||
'</pre>' :
|
|
||||||
'';
|
|
||||||
$dump .= "\n";
|
|
||||||
|
|
||||||
$dump = preg_replace("/[^[:print:]\\r\\n]/", ".", $dump);
|
|
||||||
|
|
||||||
// Output method
|
|
||||||
if ($return === false) {
|
|
||||||
echo $dump;
|
|
||||||
} else {
|
|
||||||
return $dump;
|
|
||||||
}
|
|
||||||
}
|
|
@ -81,6 +81,7 @@ $pstruct = array(
|
|||||||
),
|
),
|
||||||
|
|
||||||
0x84 => array(
|
0x84 => array(
|
||||||
|
"ubyte",
|
||||||
"special1",
|
"special1",
|
||||||
/*10,
|
/*10,
|
||||||
8,
|
8,
|
||||||
@ -88,6 +89,11 @@ $pstruct = array(
|
|||||||
"byte", */
|
"byte", */
|
||||||
),
|
),
|
||||||
|
|
||||||
|
0x8c => array(
|
||||||
|
"ubyte",
|
||||||
|
"special1",
|
||||||
|
),
|
||||||
|
|
||||||
0xc0 => array(
|
0xc0 => array(
|
||||||
6,
|
6,
|
||||||
),
|
),
|
||||||
|
@ -35,5 +35,6 @@ $packetName = array(
|
|||||||
0x1c => "ID_UNCONNECTED_PONG", //RakNet
|
0x1c => "ID_UNCONNECTED_PONG", //RakNet
|
||||||
0x1d => "ID_ADVERTISE_SYSTEM", //RakNet
|
0x1d => "ID_ADVERTISE_SYSTEM", //RakNet
|
||||||
0x84 => "ID_RESERVED_7", //Minecraft Implementation
|
0x84 => "ID_RESERVED_7", //Minecraft Implementation
|
||||||
|
0x8c => "Unknown", //Minecraft Implementation
|
||||||
0xc0 => "Unknown", //Minecraft Implementation
|
0xc0 => "Unknown", //Minecraft Implementation
|
||||||
);
|
);
|
Loading…
x
Reference in New Issue
Block a user