<?php// This is a sample PHP code snipet to connect to a Minecraft Server running// the SocketCraft Plugin. You may use this as a starting point to write// PHP for your website to be able to communicate to your server.//// Author: LexLaiden// Permission is granted to anyone to use and or modify this code // and distribute it to anyone.try{$HOST="your.server.com";// The IP or Address of your bukkit server.$PORT=12671;// The port number to use$login="LexLaiden";// Set this to your login Case Sensitive$password="YourPassword";// Set this to your password Case Sensitive// Don't touch this section if you don't know what your doing: //$sock=@socket_create(AF_INET,SOCK_STREAM,0)//ordie("error: could not create socket");//$succ=@socket_connect($sock,$HOST,$PORT)//ordie("error: could not connect to host");////////////////////////////////////////////////////////////////////Authentication$command="login=".$login.";";$command.="password=".$password.";";/////////////////////////////////////////////// // Commands that can be sent to SocketCraft. /////////////////////////////////////////////////// CmdConsole= Send a console command. You may use any command that can be typed// in the consol. Returns OK in the result on success.// SpecialCmd= Send a Special SocketCraft Command.// @ONLINECOUNT Send request for online player count.// The count is returned in the results.// @ONLINELIST Send request for a list of online players.// The result is a coma separated list of names// Begin custom code here.// Writing commands we want to send to the server in a string.// Separate each command with a semicolon ;$command.="CmdConsole=time day;";// a console command /time day$command.="fakecmd=Fake;";// This will return UNKNOWN fakecmd=Fake$command.="SpecialCmd=@ONLINECOUNT;";// a special SocketCraft command$command.="SpecialCmd=@ONLINELIST;";// a special SocketCraft command $command.="CmdConsole=manuadd LexLaiden Mod;";// a consol command /manuadd Lexlaiden Mod$command.="\n";// end with a newline THIS IS A MUST.// send all commands@socket_write($sock,$command)ordie("error: failed to write to socket");// Now loop and get results of your commands Until we get "endSocketCraftSession\n"// Possible return values are// LOGINERROR// UNKNOWN <error info>// ERROR <error info>// OK// <depends on SpecialCmd used>// $count=0;while(($result=socket_read($sock,32767,PHP_NORMAL_READ))!="endSocketCraftSession\n"){// Lets get rid of the \n at the end of the result$result=substr($result,0,strlen($result)-1);// Add each result to an array so we may access them as needed.$results[$count++]=$result;}// Lets make sure we logged in ok if not index zero will = "LOGINERROR"if($results[0]=="LOGINERROR"){//Wrong Loginecho"Wrong login or Password!";}else{// We can check out results with a zero based index// Lets get the Online Player Count. This was the third command we sent so// on a zero base 0, 1, 2 : 2 is the index of the third command so...// First make sure we did not get and error for this command.if(stripos($result[2],"ERROR")!=0&&stripos($result[2],"UNKNOWN")!=0){//Here you could handle what to do if you got an error or unknown returnd on this command}else{//No Error or Unknown so get the value.echo"There are ".$results[2]." Players online.<br>";}}// We are done!socket_close($sock);}catch(Exception$e){echo$e->getMessage();}?>