FireTime Posted August 12, 2016 Share Posted August 12, 2016 Here is a simple script I made a while back that I figured I should share. I wanted to make a very basic script that would just let people on a website know how many users were in mumble. At the time I was on windows server running x64 IIS7 so I couldn't use ICE. I did a little snooping and I was able to capture and decode the packet the client uses to populate the hover data on the server list http://i.imgur.com/vU7Qfdu.pngUsing PHP the script sends a UDP packet to request the data and then receives a response. The script parses the data and returns an associative array that you can use to display the host name, server version, current users, max users, and bandwidth. (Really only want the number of users but might as well make the rest available as I'm collecting it.Upload mumble.php to your server and include it on a webpage you want to display the data. Look to DISPLAY.php for a very basic example. If the server you call is offline it can cause the php script execution to hang until timing out. To circumvent this I recommend running the script asynchronously (either ajax or go super oldschool and use an iframe).MUMBLE.php<?php function mumbleStatus($host = '127.0.0.1', $port = 64738) { //set up return $serverdata = array( "hostname" => $host, "version" => false, "userCount" => false, "maxUsers" => false, "bandwidth" => false, ); //Get IP from URL if (substr_count($host , '.') != 4) $host = gethostbyname($host); //Make a new UDP socket $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); //Check for socket creation if (!is_resource($socket)) { return false; } //Set socket timeout if(!socket_set_option($socket,SOL_SOCKET, SO_RCVTIMEO, array("sec"=>3, "usec"=>0))) { return false; } //Connect to server if (!@socket_connect($socket, $host, $port)) { socket_close($socket); return false; } //Send handshake //Should send a microsecond based hash to properly identify each packet but works fine without it. // " 0 0 0 0 Microseconds based hash 0 0" socket_send($socket, "\x00\x00\x00\x00\x17\x6b\x06\x5b\xe7\x6d\x00\x00", 12, 0); //Read data $data = bin2hex(@socket_read($socket, 24, PHP_BINARY_READ)); if(!$data) { return false; } if($socket != null) { socket_close($socket); } //Response data format //'00 '01 '02 '06 '7a 'cf 'c7 '1b '6b '11 '00 '00 '00 '00 '00 '03 '00 '00 '00 '19 '00 '01 '19 '40 // | v1.2.6 | Microsecond packet ID | | 3 users online| 25 Max users |72000bps(72kbps) $serverdata['version'] = implode(".",array_map('hexdec', str_split(substr($data,2,6), 2))); $serverdata['userCount'] = hexdec(substr($data,24,8)); $serverdata['maxUsers'] = hexdec(substr($data,32,8)); $serverdata['bandwidth'] = hexdec(substr($data,40,8)); $serverdata['kbps'] = $serverdata['bandwidth'] / 1000 . " kbps"; return $serverdata; } ?> DISPLAY.php<?php include_once 'MUMBLE.php'; $response = mumbleStatus('216.127.64.199', 6406); ?> <?php var_dump($response); if(!$response) { echo"<p>Mumble: Server Offline</p>"; echo"<p>You try turning it off and on again?</p>"; } elseif((int) $response['userCount'] == 0) { echo"<p>Mumble: Server Online</p>"; echo"<p>Quiet, too quiet.</p>"; } else { echo"<p>Mumble: " . $response['userCount'] . " Users(s) Online</p>"; echo"<p>Mumbling commences!</p>"; } ?>Script outputAs this script is just simulating the client it does not need to be run on the same server as mumble. If your mumble is publicly accessible this script can reside on any server on the web with php.So that's my quick and dirty Super Simple Server Status ... Script.I should also add that much of the code was inspired by Julian Spravil's Minecraft Server Status Query Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now