mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-05 09:26:06 +00:00
New packets, general Improvement
This commit is contained in:
@ -111,70 +111,4 @@ function logg($message, $name, $EOL = true, $level = 2, $close = false){
|
||||
unset($fpointers[$name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user