From 3fce4584064966c9863b0390f6e4e798c8ad62aa Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sun, 25 Nov 2012 19:27:38 +0100 Subject: [PATCH] Fixes --- classes/MinecraftInterface.class.php | 4 ++-- classes/SerializedPacketHandler.class.php | 6 +++--- classes/{Socket.class.php => UDPSocket.class.php} | 2 +- classes/Utils.class.php | 4 ++++ common/dependencies.php | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) rename classes/{Socket.class.php => UDPSocket.class.php} (99%) diff --git a/classes/MinecraftInterface.class.php b/classes/MinecraftInterface.class.php index afaea47f1e..a4345c860c 100644 --- a/classes/MinecraftInterface.class.php +++ b/classes/MinecraftInterface.class.php @@ -29,7 +29,7 @@ class MinecraftInterface{ var $pstruct, $name, $server, $protocol, $client, $buffer, $dataName; function __construct($server, $protocol = CURRENT_PROTOCOL, $port = 25565, $listen = false, $client = true){ - $this->server = new Socket($server, $port, (bool) $listen); + $this->server = new UDPSocket($server, $port, (bool) $listen); $this->protocol = (int) $protocol; require("pstruct/RakNet.php"); require("pstruct/packetName.php"); @@ -59,7 +59,7 @@ class MinecraftInterface{ $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]."(\"".serialize($d)."\")").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):Utils::printable($d)).")":$this->pstruct[$pid][$i]."(\"".serialize(array_map("Utils::printable", $d))."\")").PHP_EOL; } } $p .= PHP_EOL; diff --git a/classes/SerializedPacketHandler.class.php b/classes/SerializedPacketHandler.class.php index 7a742250eb..cba7ae7cce 100644 --- a/classes/SerializedPacketHandler.class.php +++ b/classes/SerializedPacketHandler.class.php @@ -72,17 +72,17 @@ class SerializedPacketHandler{ $pk = new CustomPacketHandler($id, $raw); $pk->data["length"] = $len; $pk->data["id"] = $id; - if($pid !== 0x00 and $i === 0){ + if($pid !== 0x00){ $pk->data["counter"] = $c; } $pk->data["packetName"] = $pk->name; $this->data["packets"][] = array($pid, $pk->data, $raw); - if($pid === 0x60 and $i === 0){ + /*if($pid === 0x60 and $i === 0){ $l = $this->get(3); if(strlen($l) === 3){ $this->data["unknown2"] = $this->get(Utils::readTriad($l)); } - } + }*/ ++$i; } } diff --git a/classes/Socket.class.php b/classes/UDPSocket.class.php similarity index 99% rename from classes/Socket.class.php rename to classes/UDPSocket.class.php index c7e5b1d54b..9d3ffce754 100644 --- a/classes/Socket.class.php +++ b/classes/UDPSocket.class.php @@ -27,7 +27,7 @@ the Free Software Foundation, either version 3 of the License, or -class Socket{ +class UDPSocket{ private $encrypt; var $buffer, $connected, $errors, $sock, $server; diff --git a/classes/Utils.class.php b/classes/Utils.class.php index c6c024cac9..5a486bc5c9 100644 --- a/classes/Utils.class.php +++ b/classes/Utils.class.php @@ -143,6 +143,10 @@ class Utils{ return $output; } + public static function printable($str){ + return preg_replace('#([^\x20-\x7E])#', '.', $str); + } + public static function microtime(){ return microtime(true); } diff --git a/common/dependencies.php b/common/dependencies.php index b8cb3a2ddf..b7ed7b43f7 100644 --- a/common/dependencies.php +++ b/common/dependencies.php @@ -70,7 +70,7 @@ if($errors > 0){ } require_once("classes/Utils.class.php"); -require_once("classes/Socket.class.php"); +require_once("classes/UDPSocket.class.php"); require_once("classes/Packet.class.php"); require_once("classes/SerializedPacketHandler.class.php"); require_once("classes/CustomPacketHandler.class.php");