New packets, general Improvement

This commit is contained in:
Shoghi Cervantes Pueyo
2012-10-21 23:58:16 +02:00
parent 9c4abf49f5
commit 5425dfa5dc
7 changed files with 28 additions and 72 deletions

View File

@ -52,7 +52,7 @@ class MinecraftInterface{
protected function writeDump($pid, $raw, $data, $origin = "client", $ip = "", $port = 0){
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 .= hexdump($raw, false, false, true);
$p .= Utils::hexdump($raw);
if(is_array($data)){
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;
@ -80,7 +80,7 @@ class MinecraftInterface{
$struct = $this->getStruct($pid);
if($struct === false){
$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;
logg($p, "packets", true, 2);

View File

@ -36,7 +36,7 @@ class Packet{
$this->offset = 1;
$this->raw = $data;
$this->data = array();
if($pid !== false){
if($data === ""){
$this->addRaw(chr($pid));
}
$this->struct = $struct;
@ -61,6 +61,7 @@ class Packet{
switch($this->pid){
case 0x05:
case 0x84:
case 0x8c:
$this->addRaw($this->data[$field]);
break;
}
@ -140,6 +141,7 @@ class Packet{
switch($this->pid){
case 0x05:
case 0x84:
case 0x8c:
$this->data[] = $this->get(true);
break;
}

View File

@ -26,10 +26,11 @@ the Free Software Foundation, either version 3 of the License, or
*/
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();
function __construct($username, $protocol = CURRENT_PROTOCOL, $version = CURRENT_VERSION){
//$this->player = new Player($username);
$this->start = microtime(true);
$this->version = (int) $version;
$this->username = $username;
$this->connected = false;
@ -77,7 +78,7 @@ class PocketMinecraftClient{
}
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->process();
$list = array();
@ -111,7 +112,8 @@ class PocketMinecraftClient{
case 0x08:
$serverID = $data[1];
$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",
$this->serverID,
(microtime(true) * 1000),

View File

@ -131,6 +131,17 @@ class Utils{
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(){
return microtime(true);