View server info in a php web page [starnet]

    Joined
    Aug 29, 2015
    Messages
    27
    Reaction score
    7
    • Purchased!
    After a long search on the web to find this kind of script, the only solution proposed always brings back to this site "starmade-servers.com".
    And if I do not want to register on this site who want to keep the monopoly how I do?
    Well, there is an alternative, thanks to starnet, it is possible, I have searched for a long time because I am not a developer and my knowledge in coding is quite limited so if like me you are not at the " ease to do this kind of thing I hope this script will help you.
    Note that a copy of starnet.jar must be placed for the following case in the same directory as the page.php of the script and that the lines of the server.cfg must be filled:
    SUPER_ADMIN_PASSWORD_USE = true
    SUPER_ADMIN_PASSWORD = yourpassword

    Example for the command "/ status", 000.000.000.000 must be replaced by the IP address of the server.

    Code:
    <?php
    exec("java -jar StarNet.jar 000.000.000.000:4242 yourpassword /status 2>&1", $output);
    preg_match("/RETURN: \[SERVER, Players: ([0-9]+) \/ ([0-9]+), 0\]/", $output, $matches);
    var_dump ($output);
    ?>

    Now, if I want to refine and display only string 4:

    Code:
    <?php
    exec("java -jar StarNet.jar 000.000.000.000:4242 yourpassword /status 2>&1", $output);
    preg_match("/RETURN: \[SERVER, Players: ([0-9]+) \/ ([0-9]+), 0\]/", $output[4], $matches);
    var_dump ($output[4]);
    ?>

    To format:

    Code:
    <?php
    exec("java -jar StarNet.jar 000.000.000.000:4242 yourpassword /status 2>&1", $output);
    preg_match("/RETURN: \[SERVER, Players: ([0-9]+) \/ ([0-9]+), 0\]/", $output[4], $matches);
    $nbrplayer = $matches[1]; $maxplayer = $matches[2];
    print_r ("$nbrplayer / $maxplayer");
    if ($nbrplayer == $maxplayer) { echo "Server off"; }
    ?>
    This opens up other possibilities for the imagination and the needs.
     
    Joined
    Jun 29, 2013
    Messages
    144
    Reaction score
    64
    • Modder
    • Legacy Citizen 4
    • Purchased!
    Hello there, sorry to reply after all this time but there's already a similare function in SMTools and this function return an array with more info about the server and doesn't require any login
    Code:
    <?php
        include_once 'PATH_OF_FILE/SMUtils.php';
        $SMU = new SMUtils();
        $SrvData = $SMU->checkServ('SERVER_ADDRESS', PORT);
        var_dump($SrvData);
    ?>
    
    print result:
        unk Long
        unk Short
        current timestamp
        server version
        server name
        server description
        server start time (timestamp)
        connected player
        server capacity
    I hope this informations could help you
     
    • Like
    Reactions: Toshiro
    Joined
    Aug 29, 2015
    Messages
    27
    Reaction score
    7
    • Purchased!
    Thank you for this information, I will test when I have more time, I am very busy with my work now, but I think it can be very useful.
     
    Joined
    Jun 29, 2013
    Messages
    144
    Reaction score
    64
    • Modder
    • Legacy Citizen 4
    • Purchased!
    You are welcome, if you have any questions i'll be happy to help you