我正在尽我最大的努力让这件事正常工作,但我不知道为什么我的世界服务器控制台给了我:05.04 01:40:29 [Server] INFO /212.1.212.1:58215 lost connection
我的代码php函数:
function Votifier($public_key, $server_ip, $server_port, $username)
{
//pharse the public key
$public_key2 = wordwrap($public_key, 65, "\n", true);
$public_key = <<<EOF
-----BEGIN PUBLIC KEY-----
$public_key2
-----END PUBLIC KEY-----
EOF;
//get user IP
$address = $_SERVER['REMOTE_ADDR'];
//set voting time
$timeStamp = time();
//create basic required string for Votifier
$string = "VOTE\nTest\n$username\n$address\n$timeStamp\n";
//fill blanks to make packet lenght 256
$leftover = (256 - strlen($string)) / 2;
while ($leftover > 0) {
$string.= "\x0";
$leftover--;
}
//encrypt string before send
openssl_public_encrypt($string,$crypted,$public_key);
//try to connect to server
$socket = fsockopen($server_ip, $server_port, $errno, $errstr, 3);
if ($socket)
{
var_dump(fwrite($socket, $crypted)); //on success send encrypted packet to server
}
else
return false; //on fail return false
}