function ascii2hex($ascii) {
$hex = '';
for ($i = 0; $i < strlen($ascii); $i++) {
$byte = strtoupper(dechex(ord($ascii{$i})));
$byte = str_repeat('0', 2 - strlen($byte)).$byte;
$hex.=$byte." ";
}
$hex=str_replace(" ", "", $hex);
return $hex;
}
function hex2ascii($hex){
$ascii='';
$hex=str_replace(" ", "", $hex);
for($i=0; $i<strlen($hex); $i=$i+2) {
$ascii.=chr(hexdec(substr($hex, $i, 2)));
}
return($ascii);
}
function int_int_divide($x, $y) {
if ($x == 0) return 0;
if ($y == 0) return FALSE;
return ($x % $y >= $y / 2) ?
(($x - ($x % $y)) / $y) + 1 : ($x - ($x % $y)) / $y;
}
function send_msg($host, $port, $msg)
{
$header = "C144A10024000000";
$msglength = strlen($msg);
if ($msglength < 34 && $msglength != 0){
$divisor = (34 - $msglength);
$start_space = int_int_divide($divisor , 2);
for ($i=0;$i<=$start_space;$i++){
$header .= "20";
}
$header .= ascii2hex($msg);
for ($j=0;$j<=($divisor-$start_space);$j++){
$header .= "20";
}
}else{
$header .= ascii2hex($msg);
}
$header .= "00BED3410000F8BBB90400000000FCBBB904A4FF1A06F8F04100FFFFFFFF";
$packet = hex2ascii($header);
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (!$x = @socket_connect($socket, $host, $port))
{
echo "No access to the Joinserver or Server is down.";
}
else
{
socket_write($socket, $packet , strlen($packet));
socket_close($socket);
}
}
send_msg("127.0.0.1", "55970", "Insert your text here. It can fit in one message up to here.");