4

What I am trying to do is add support for Votifier plugin on my website.

I have forwarded the correct ports for the Minecraft server, tested and confirmed that they are open. Also used Minestatus to confirm that the Votifier plugin is working correctly.

However, when I try and use a PHP script I found for connecting to the server, all I get is a connection refused.

<?php

error_reporting(E_ALL);

// Details of the vote.
$str = "VOTE\n" .
       "TopHCSMP\n" .
       "SlickTheNick666\n" .
       "50.98.149.40\n" .
       time()."\n";

// Fill in empty space to make the encrypted block 256 bytes.
$leftover = (256 - strlen($str)) / 2;

while ($leftover > 0) {
    $str .= "\x0";
    $leftover--;
}

// The public key, this is an example.
$key =             "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkFywgrx2fPXL/CPS1Gi5/a7zoTfWV9fqrhsJMzPqqC0CnLBBkg8VUiwnBVsMvhJrUT1mLvyHx5H9dobTVlE+aoxcsDRa1Yc9OAUKHspxrPswRW6/Yn85YAghOSBZfgPoXD3Q0Ng5jkJUoBUHOBtFHDUeAHi5av36iJ8dTQTSaOyAXKGdB88TOzre5cpnj5oDi/JSJ0bCJx7cgcBAO1TvOVuFMTXhygDyEVh6 o2nn8+qdDlEPXf+m+dxdkH3zWkkWjY4OittIpaHj2n8ihgPqwMPZFH1CXkoTjoSh4Fo7KtUAaAa4gt5w/thauozG25G    1s2XSigNgCDDvg4S8awmtewIDAQAB";
$key = wordwrap($key, 65, "\n", true);
$key = <<<EOF
-----BEGIN PUBLIC KEY-----
$key
-----END PUBLIC KEY-----
EOF;

// Encrypt the string.
openssl_public_encrypt($str, $encrypted, $key);

// Establish a connection to Votifier.
$socket = fsockopen("50.98.149.40", "8192", $errno, $errstr, 2);

if (!$socket) {
    die("Failed to connect to Votifier.");
}

// Send the contents of the encrypted block to Votifier.
fwrite($socket, $encrypted);
?>

It seems to be that Votifier is dropping the connection, possibly because the encryption isn't right?

spongebob
  • 8,370
  • 15
  • 50
  • 83
SlickTheNick
  • 91
  • 2
  • 7
  • If you are using shared hosting, outbound port 8142 might be blocked. GoDaddy shared hosting, for example, only allows fsockopen on 443 and 80. – Drakes Jul 20 '16 at 12:33

1 Answers1

0

The error you are gettings is a connection refused, this means the either the ip address, or the port is incorrect. These need to be confirmed for correctness. Since you stated that you forwarded the ports, another reason for the code not working can be that you are running the script and the minecraft server behind the same router, and your router doesn't support NAT Loopback, this is not an indication that there is something wrong with your script, but that your router is lacking a feature.

There are more errors in your code, when calculating the leftover, you should NOT divide the amount by 2, instead calculate it as $leftover = (256 - strlen($str)); to prevent the output block being smaller than 256 and bugging some implementations of the Votifer protocol, the default Votifer plugin doesn't check all protocol restrictions on its input.

Ferrybig
  • 18,194
  • 6
  • 57
  • 79