Types of communication.

Note: This information is outdated. Use the documentation found here for version 2.5 and higher.

Bukkit to PHP to bukkit

Note: to use a url different from the one specified in the config, use -wp:url in your command (ex: /ws -wp:http://example.com/websend.php timeset) This requires you to be op.

Using the communication in this kind of connection works using the print(); function. Basic on-request command scripts are fairly to create:

  • Make a new PHP file
  • Paste this in:
<?php
//variables
/*********************************** Variables ***********************************/
/**/  $checkpass = "PutYourPasswordHere";
/*********************************************************************************/
/**/  $receivedMD5 = $_POST['authKey'];
/**/  $player = $_POST["player"];
/**/  $args = $_POST["args"]; //each argument is stored in an array called "args"
/*********************************************************************************/
 
 
//Do not edit!
if($receivedMD5 != "" && $args[0] != "")
{
    if($receivedMD5 == md5($checkpass))
    {
        //Begin your code here.
        if($args[0] == "checkcolors") //script 1
        {
            print('/Output/PrintToPlayer:Example script from php.;');
            print('/Output/PrintToPlayer:This command will show all possible colors;');
            // use minecraft color codes to color the text
            print("&aThis is green;");
            print("&bThis is light blue;");
            print("&cThis is red;");
            print("&dThis is pink;");
            print("&eThis is yellow;");
            print("&fThis is white;");
            print("&1This is dark blue;");
            print("&2This is dark green;");
            print("&3This is aqua;");
            print("&4This is dark red;");
            print("&5This is purple;");
            print("&6This is gold;");
            print("&7This is grey;");
            print("&8This is dark grey;");
            print("&9This is blue;");
            print("&0This is black;");
            print("&7These are &1multiple colors &cin one &5sentence;");
        }
        elseif($args[0] == "timeset") //script 2
        {
            print('/Output/PrintToPlayer:Success;');
            print('/Output/PrintToPlayer:Example script from php.;');
            print('/Output/PrintToPlayer:This will set the time of players world to day.;');
            // use /Command/ExecuteBukkitCommand: to indicate a command sent by $player.
            // Behind that line you can put any player chat command.
            print("/Command/ExecuteBukkitCommand:time day;");
            print("/Output/PrintToPlayer:Player = ".$player.";");
            print("/Output/PrintToPlayer:Argument 1 = ".$args[0].";");
        }
        elseif($args[0] == "weatherset") //script 3
        {
            print('/Output/PrintToPlayer:Success;');
            print('/Output/PrintToPlayer:Example script from php.;');
            print('/Output/PrintToPlayer:This will set the weather of players world to sun.;');
            // use /Command/ExecuteBukkitCommand: to indicate a command sent by $player.
            // Behind that line you can put any player chat command.
            print("/Command/ExecuteBukkitCommand:weather sun;");
            print("/Output/PrintToPlayer:Player = ".$player.";");
            print("/Output/PrintToPlayer:Argument 1 = ".$args[0].";");
        }
        elseif($args[0] == "consoleCommand") //script 4
        {
            print('/Output/PrintToPlayer:Example script from php.;');
            print('/Output/PrintToPlayer:This command will send a command to the console.;');
            if($player == 'console')
            {
                print('/Output/PrintToConsole:Error: Only in-game players can use this command.;');
            }
            else
            {
                print('/Output/PrintToPlayer:Proof it is send to console:;');
                // use /Command/ExecuteConsoleCommand: to indicate a command from console.
                print("/Command/ExecuteConsoleCommand:say Hello World;");
            }
        }
        else
        {
            print('/Output/PrintToPlayer:Websend: Unknown command.;');
        }
        //Stop editing here.
    }
    else
    {
        print('/Output/PrintToConsole:Authorization Failed;');
    }
}
else
{
    print("/Output/PrintToConsole:No (enough) data provided.;");
}
?>
  • Fill in the password.
  • Upload this file to your website.
  • Go to your plugin configuration file.
  • Set the "URL=" tag to the url of your php file.

PHP to bukkit

Scripts like the supplied "ExternalTimeSet.php" can be used to send a command to the server, without needing an event from the server first. This is useful for applications like registration forms (whitelisting), online server setting adjustment (time set), ect... Communicating here is done via the API in the supplied Websend.php file. To use this, follow these steps:

  • Forward port 4445 on the minecraft server side.
  • Go to the plugin settings and uncomment (remove the #) the #WEBLISTENER_ACTIVE=true line. (If you can't find it, paste it in.)
  • Make a new php file and paste this in:
<?php
    include_once 'Websend.php';

    //Replace with bukkit server IP. To use a different port, change the constructor to new Websend(ip, port)
    $ws = new Websend("123.456.789.123"); 

    //Replace with password specified in Websend config file
    $ws->connect("password");

    $ws->doCommandAsConsole("time set 6000");
    $ws->disconnect();
?>
  • Upload this and Websend.php (download in files section) to your website.
  • Try it out. The time should be set to day.

More information on this can be found here.


Comments

  • To post a comment, please or register a new account.
Posts Quoted:
Reply
Clear All Quotes