Is there any way I can request e.g. play count through an HTTP request from PHP, I can do the code to count the players, but I don't know how to respond to a request from a website. Any help ? Thanks =)
http://forums.bukkit.org/threads/admin-dev-tcp-interface-for-bukkit.746/ You can use the playercount command without sending the password. PHP: <?php$bukkit_host = "localhost";$bukkit_port = 6790;$bukkit_password = "password";$errn = "";$errs = "";$timeout = 10;$sock = fsockopen($bukkit_host, $bukkit_port, $errn, $errs, $timeout);$expectplayercount = false;if($sock){ while(!feof($sock)){ fgetc($sock); fgetc($sock); //remove the first two chars $line = trim(mb_convert_encoding(fgets($sock, 4096), "ASCII")); if($line != ""){ if($expectplayercount == true){ if($line != "1"){ echo $line." players online.\r\n"; } else{ echo "1 player online.\r\n"; } fclose($sock); exit; } if($line == "Welcome to Bukkit, please authenticate."){ fwrite($sock, "playercount\r\n"); $expectplayercount = true; } } }}else{ echo "Error: Could not connect to Bukkit! ".$errn." (".$errs.")";}?>
I want to create a plugin that will return an array of players when I use http://<serverip>:<port>/players or submit the players to a website (every 5 mins) so I can use $_GET
PHP: <?php$bukkit_host = "localhost";$bukkit_port = 6790;$bukkit_password = "password";$errn = "";$errs = "";$timeout = 10;$sock = fsockopen($bukkit_host, $bukkit_port, $errn, $errs, $timeout);$expectplayers = false;$players = array();if($sock){ while(!feof($sock)){ fgetc($sock); fgetc($sock); //remove the first two chars $line = trim(mb_convert_encoding(fgets($sock, 4096), "ASCII")); if($line != ""){ if($line == "Welcome to Bukkit, please authenticate."){ fwrite($sock, "getplayers\r\n"); fgetc($sock); fgetc($sock); $line = fgets($sock, 4096); while(preg_match("/player name=/",$line)){ array_push($players, trim(substr($line, 12))); fgetc($sock); fgetc($sock); $line = fgets($sock, 4096); } echo json_encode($players); fwrite($sock, "quit\r\n"); fclose($sock); exit; } } }}else{ echo "Error: Could not connect to Bukkit! ".$errn." (".$errs.")";}?>
Well uh, you can take code from my plugin and remove everything that's not needed. Password isn't needed for the getplayers, playercount, port, or maxplayers commands. Edit: K.
Thanks for help, I have implemented this into the new server status checker I am currently working on, Gotta redesign layout now ^^