StarMade Server Information [PHP]

    Joined
    Jun 21, 2013
    Messages
    2
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    Hey,

    Just wondering if there was a way to get StarMade Server Information (Online Player Count, etc.) using PHP? Not limited to PHP of course, but PHP to be used as the front-end, fetching the information.

    Any help is appreciated!
     
    Joined
    Jun 29, 2013
    Messages
    144
    Reaction score
    64
    • Modder
    • Legacy Citizen 4
    • Purchased!
    hi, you can use the stream_socket_client or fsockopen to get the status online and I think the fputs or fwrite function can be used to obtain other information, but I do not find the argument to send. if someone has a track
     
    Joined
    Jun 30, 2013
    Messages
    19
    Reaction score
    0
    • Legacy Citizen 2
    • Legacy Citizen
    I wish I could help you on this, I\'m liking the sound of what you\'re doing!
     
    Joined
    Jun 29, 2013
    Messages
    144
    Reaction score
    64
    • Modder
    • Legacy Citizen 4
    • Purchased!
    After some try and consultation of starmade, the only data that i\'ve obtain are this entry:



    [11 août 2013 15:08:25] STDERR: [ERR] connection made. starting new processor 57563, /127.0.0.1; local: 4242, /127.0.0.1, keepalive false
    [11 août 2013 15:08:25] STDOUT: [OUT] [SERVER] connection registered
    [11 août 2013 15:08:25] STDOUT: [OUT] [SERVER][PROCESSOR] client setup completed. listening for input
    [11 août 2013 15:08:25] STDERR: [ERR] Client null and not first try
    [11 août 2013 15:08:26] STDERR: [ERR] Client null and not first try
    [11 août 2013 15:08:27] STDERR: [ERR] [SERVER] client has not send any login information: 2000 / 10000
    [11 août 2013 15:08:28] STDERR: [ERR] [SERVER] client has not send any login information: 3000 / 10000
    [11 août 2013 15:08:29] STDERR: [ERR] [SERVER] client has not send any login information: 4000 / 10000
    [11 août 2013 15:08:30] STDERR: [ERR] [SERVER] client has not send any login information: 5000 / 10000
    [11 août 2013 15:08:31] STDERR: [ERR] [SERVER] client has not send any login information: 6000 / 10000
    [11 août 2013 15:08:32] STDERR: [ERR] [SERVER] client has not send any login information: 7000 / 10000
    [11 août 2013 15:08:33] STDERR: [ERR] [SERVER] client has not send any login information: 8000 / 10000
    [11 août 2013 15:08:34] STDERR: [ERR] [SERVER] client has not send any login information: 9000 / 10000
    [11 août 2013 15:08:35] STDERR: [ERR] [SERVER] client has not send any login information: 10001 / 10000
    [11 août 2013 15:08:35] STDERR: [ERR] [SERVER] NULL CLIENT TIMED OUT: DISCONENCTING
    [11 août 2013 15:08:35] STDERR: [ERR] java.net.SocketException: Socket Closed
    [11 août 2013 15:08:35] STDERR: [ERR] at java.net.SocketInputStream.socketRead0(Native Method)
    [11 août 2013 15:08:35] STDERR: [ERR] at java.net.SocketInputStream.read(Unknown Source)
    [11 août 2013 15:08:35] STDERR: [ERR] at java.net.SocketInputStream.read(Unknown Source)
    [11 août 2013 15:08:35] STDERR: [ERR] at java.net.SocketInputStream.read(Unknown Source)
    [11 août 2013 15:08:35] STDERR: [ERR] at java.io.DataInputStream.readInt(Unknown Source)
    [11 août 2013 15:08:35] STDERR: [ERR] at org.schema.schine.network.server.ServerProcessor.run(SourceFile:800)
    [11 août 2013 15:08:35] STDERR: [ERR] at java.lang.Thread.run(Unknown Source)
    [11 août 2013 15:08:35] STDERR: [ERR] [SERVER] Client \'null\' HAS BEEN DISCONNECTED . PROBE: false
    [11 août 2013 15:08:35] STDERR: [ERR] [SERVER] COULD NOT UNREGISTER CLIENT null
    [11 août 2013 15:08:35] STDERR: [ERR] [SERVER] COULD NOT UNREGISTER CLIENT null
    [11 août 2013 15:08:35] STDERR: [ERR] [SERVER] SERVER PROCESSOR STOPPED FOR null



    I\'m in impasse, the function try to connect me like a player but return nothing
     
    Joined
    Jun 29, 2013
    Messages
    144
    Reaction score
    64
    • Modder
    • Legacy Citizen 4
    • Purchased!
    here is a function for the server status checker and get the info.

    function getServerInfo($host, $port){
    $buffer = \'\';
    $packet = pack(\"N\", 9).pack(\"c\", 42).pack(\"n\", -1).pack(\"c\", 1).pack(\"c\", 111).pack(\"N\", 0);

    $octet = 8;
    $intSize = 32;
    $longSize = $floatSize = 64;

    $socket = socket_create(AF_INET, SOCK_STREAM,SOL_TCP);
    if(socket_connect($socket, $host, $port)){
    socket_sendto($socket, $packet, strlen($packet), 0 , $host, $port);
    socket_recvfrom($socket, $buffer, 8190, 0 , $host, $port);

    $byteBuffer = null;
    for ($i = 0; $i < strlen($buffer); $i++){
    $byteBuffer .= sprintf(\'%08b\', ord($buffer[$i]));
    }

    $bufferPos = $intSize;
    $diffBuffer = strlen($byteBuffer) - $intSize - $longSize;
    $arr[\'Timestamp\'] = bindec(substr(substr($byteBuffer, $bufferPos),0, - $diffBuffer));

    $bufferPos = $intSize + $longSize + 96;
    $diffBuffer = strlen($byteBuffer) - $bufferPos - $intSize;
    $arr[\'Version\'] = round(bin2Float(substr(substr($byteBuffer, $bufferPos),0, - $diffBuffer)),5);

    $bufferPos = strlen($byteBuffer) - $intSize;
    $arr[\'MaxPlayer\'] = bin2Int(substr($byteBuffer, $bufferPos));

    $oldBufferPos = $bufferPos;
    $bufferPos = $bufferPos - $intSize - $octet;
    $diffBuffer = $oldBufferPos - $bufferPos;
    $arr[\'Connected\'] = bin2Int(substr(substr($byteBuffer, $bufferPos),0 , - $diffBuffer));

    $oldBufferPos = $bufferPos + $octet;
    $bufferPos = $bufferPos - $longSize - $octet;
    $diffBuffer = $oldBufferPos - $bufferPos;
    $arr[\'StartTime\'] = bindec(substr(substr($byteBuffer, $bufferPos),0, - $diffBuffer));

    return $arr;
    }else{
    return false;
    }
    }

    this function return false if server is offline or return array with version info, current timestamp, server start timestamp, max player and connected player.
     
    Joined
    Aug 11, 2013
    Messages
    86
    Reaction score
    9
    Ei @blackcancer, can you show the implementation of bin2Float and bin2Int, I\'ve replaced them for bindec and it seems to work with the int, but not with the floats.

    Many thanks for the function anyways ^^
     
    Joined
    Jun 29, 2013
    Messages
    144
    Reaction score
    64
    • Modder
    • Legacy Citizen 4
    • Purchased!
    sorry for this mistak, i\'m working on SMDecoder class for entity file and this tow function have been made for this.Functions hexReverse and hexify are used by bin2Float.

    function bin2Int($data){
    if(strlen($data) != 32){
    return -1;
    } else {
    if($data[0] == \"1\"){
    $bin_replace = str_replace(\"1\",\"x\",$data);
    $bin_replace = str_replace(\"0\",\"1\",$bin_replace);
    $bin_replace = str_replace(\"x\",\"0\",$bin_replace);
    if($bin_replace[31] === \"0\"){
    $bin_replace[31] = 1;
    }else{
    $i=31;
    $loop = true;
    while($loop == true){
    if($bin_replace[$i-1] == \"0\" && $i == 31){
    $loop = false;
    }else if($bin_replace[$i-1] == \"0\"){
    $bin_replace[$i] = 0;
    $bin_replace[$i-1] = 1;
    $loop = false;
    }
    $i--;
    }
    }
    return bindec($bin_replace) *-1;
    }
    else{
    return bindec($data);
    }
    }
    }

    function bin2Float($data){
    if(strlen($data) != 32){
    return -1;
    } else {
    if($data === $null32){
    return $nullFloat;
    } else {
    $hex = substr(chunk_split(base_convert($data, 2, 16), 2, \" \"), 0, -1);
    $hexRev = hexReverse($hex);
    $hexi = hexify($hexRev);
    if($hexi === false) die(\"Invalid input\\n\");
    $decode = unpack(\"f\", $hexi);
    return $decode[1];
    }
    }
    }

    function hexReverse($hex){
    $r = \'\';
    $hexArray = explode(\' \', $hex);
    foreach ($hexArray as $z) {
    $r = $z . \' \' . $r;
    }
    return substr($r, 0, -1);
    }

    function hexify($hex){
    static $hexVal = array(
    \'0\'=>0, \'1\'=>1, \'2\'=>2, \'3\'=>3,
    \'4\'=>4, \'5\'=>5, \'6\'=>6, \'7\'=>7,
    \'8\'=>8, \'9\'=>9, \'A\'=>10, \'B\'=>11,
    \'C\'=>12, \'D\'=>13, \'E\'=>14, \'F\'=>15,
    \'a\'=>10, \'b\'=>11, \'c\'=>12, \'d\'=>13, \'e\'=>14, \'f\'=>15,
    );
    $r = \'\';
    $hexArray = explode(\' \', $hex);
    foreach ($hexArray as $z) {
    if (!ctype_xdigit($z)) return false;
    $tmp = $hexVal[$z{0}] * 16 + $hexVal[$z{1}];
    $r .= chr($tmp);
    }
    return $r;
    }

    You\'ll need to replace function getServInfo() (i\'ve replaced functions used for convertion)