[DEV/WEB] WebSend v2.4 - Use PHP and other web-languages for bukkit! [1.4.7-R1.0]

Discussion in 'Archived: Plugin Releases' started by Waterflames, Jul 21, 2011.

  1. Offline

    Waterflames

    websend-icon-text-smaller.png

    WebSend - Use PHP for Bukkit!:
    Version: v2.3
    BukkitDev: http://dev.bukkit.org/server-mods/websend/
    What does this plugin do?
    A scheme:
    Ingame command -> Your php-enabled server
    -> Your PHP file does stuff and provides output/commands -> Plugin executes commands and prints output.
    Or:
    Webpage command -> bukkit server -> Plugin executes commands and prints output.

    Example scripts are provided in the files.
    !!! IMPORTANT NOTE !!!
    Use the bukkitDev forum for bugs, questions and other stuff. I will no longer respond here!

    A few of the possibilities:
    • Online adminstration screen
    • Online console
    • Membership system (become VIP with a donation)
    • Paypal donation system
    • ...
    Features:
    • Seperate thread (no server lag because of the wait.)
    • Commands (ingame or console emulation)
    • Command to color output send from php.
    • Secure connection (protected with password hash)
    • Permissions support (just "websend")
    • Both ways enabled (PHP -> bukkit | bukkit -> php (-> bukkit))
    Installation: (more detailed instructions can be found on bukkitdev):
    1. Put the plugin in the plugin folder.
    2. Start/reload server to allow the config file to be generated.
    3. Open the example php file and fill in your password.
    4. Upload the example php file to your server.
    5. Open the config file and fill in the settings.
    6. Reload server and test with "/ws timeset".
    7. Go to the bukkitDev page to find instructions to get started.
    Download on bukkitdev.

    Changelog:
    Show Spoiler

    For more changelog, visit the bukkitdev "files" section.
    Version 0.9:
    • Fixes false error reporting
    • A debug feature was added.
    Version 0.8.1:
    • Couple of small bugfixes for 1240
    Version 0.8:
    • Added error report on invalid /Command/
    • Added warning if the first line doesn't contain the password.
    • Added proper disabling code for ServerSocket.
    • Tweaked the variable checking.
    Version 0.7.1:
    • Added extra POST data. (Info)
    Version 0.7:
    • Enabled input from console
    • Implemented a config line to use a custom port.
    Version 0.6:
    • Added extra POST data. (Info)
    Version 0.5:
    • Added the other way (PHP -> bukkit) Port 4445 needs to be forwarded.
    • Improved config file reading
    • Optimized code structure.
    Version 0.4:
    • Added option to use port 4444 opposed to the default
    Version 0.3:
    • Added color feature. (examples in supplied zip.)
    • Added Console command option (Use /Command/ExecuteConsoleCommand)
    Version 0.2
    • Fixed permissions plugin absence error.
    Version 0.1
    • Plugin released
     

    Attached Files:

  2. Offline

    Ycros

    I get that exception on reload - but it still seems to work fine. Are you sure you're not running anything on port 4445 already?

    Try implementing low-level logging of everything you send to the socket, or perhaps even use a packet logger (tcpdump/ngrep/wireshark) to make sure you're sending correctly formatted things.

    I've just extracted and made public the API code I wrote to use Websend from my PHP app, it's up at https://bitbucket.org/Ycros/websendphpapi/ under an LGPLv3 license.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 17, 2016
  3. Offline

    darker9999

    Hi. I'm getting a permissionsEx error :
    Show Spoiler

    2011-09-22 08:21:58 [INFO] Websend: ServerSocket: activated.
    2011-09-22 08:21:58 [SEVERE] null
    java.net.BindException: Address already in use
    at java.net.PlainSocketImpl.socketBind(Native Method)
    at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383)
    at java.net.ServerSocket.bind(ServerSocket.java:328)
    at java.net.ServerSocket.<init>(ServerSocket.java:194)
    at java.net.ServerSocket.<init>(ServerSocket.java:106)
    at websend.PHPSktSrvrThread.run(Main.java:305)
    2011-09-22 08:21:58 [SEVERE] Error occurred while enabling PermissionsEx v1.13 (Is it up to date?): org.bukkit.plugin.PluginDescriptionFile.getPermissions()Ljava/util/ArrayList;
    java.lang.NoSuchMethodError: org.bukkit.plugin.PluginDescriptionFile.getPermissions()Ljava/util/ArrayList;
    at ru.tehkode.permissions.bukkit.BukkitPermissions.collectPermissions(BukkitPermissions.java:105)
    at ru.tehkode.permissions.bukkit.BukkitPermissions.<init>(BukkitPermissions.java:73)
    at ru.tehkode.permissions.bukkit.PermissionsEx.onEnable(PermissionsEx.java:103)
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:126)
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:920)
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:278)
    at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:173)
    at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:156)
    at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:410)
    at org.bukkit.Bukkit.reload(Bukkit.java:173)
    at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:22)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:163)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:353)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:349)
    at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:499)
    at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:478)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:374)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
     
  4. Offline

    nax_hh

    pretty sure.

    i format yesterday.. hard to be using this port for something ugh?
     
  5. Offline

    Ycros

    That's a bug in PermissionsEx caused by the new Bukkit build (they broke the getPermissions API), you'll need to grab the latest development version of PermissionsEx (1.14).
     
  6. Offline

    Waterflames

    That is pretty damn great! I'm putting this in the main post.
     
  7. Offline

    darker9999

    Thanks for your reply, i'm getting error now :
    Show Spoiler

    2011-09-22 07:54:56 [SEVERE] java.io.IOException: Bad packet id 100
    2011-09-22 07:54:56 [SEVERE] at net.minecraft.server.Packet.a(Packet.java:73)
    2011-09-22 07:54:56 [SEVERE] at net.minecraft.server.NetworkManager.h(NetworkManager.java:149)
    2011-09-22 07:54:56 [SEVERE] at net.minecraft.server.NetworkManager.c(NetworkManager.java:263)
    2011-09-22 07:54:56 [SEVERE] at net.minecraft.server.NetworkReaderThread.run(SourceFile:77)
    2011-09-22 07:54:56 [INFO] /109.235.70.20:50916 lost connection

    I get it once i call php file.
     
  8. Offline

    nax_hh

    what about the error code i upload?
     
  9. Offline

    Waterflames

    I'm guessing a config error. Try some different combinations in the URL.
    Also, is the port forwarded on both sides?
     
  10. Offline

    nax_hh

    it's localhost so yes...

    i gonna try to test modifications and i tell something...
     
  11. Offline

    istealth

    i get this error when i run it from the php website

    Code:
    19:45:29 [SEVERE] java.io.IOException: Bad packet id 49
    19:45:29 [SEVERE]       at net.minecraft.server.Packet.a(Packet.java:73)
    19:45:29 [SEVERE]       at net.minecraft.server.NetworkManager.h(NetworkManager.java:149)
    19:45:29 [SEVERE]       at net.minecraft.server.NetworkManager.c(NetworkManager.java:263)
    19:45:29 [SEVERE]       at net.minecraft.server.NetworkReaderThread.run(SourceFile:77)
    19:45:29 [INFO] /199.168.138.30:49022 lost connection
    
    websend config.txt
    Code:
    #Configuration and settings file!
    #Help: URL: set to the full path of your server php file (see example).
    #Help: PASS: change the password to one of your choice (set the same in the server php file).
    URL=http://********.net/minecraft/minecraft.php
    PASS=*********
    #Optional settings. Remove the '#' to use.
    #FORCEPORT=false
    #FILE=
    WEBLISTENER_ACTIVE=true
    #ALTPROTECTION=
    
    timeday.php
    Code:
    <?php
    $PORT = 4445;
    $HOST = "199.168.138.30"; //the ip of the bukkit server (in this case it's the same machine)
    $password = "*********";
    
    //Can't touch this:
    $sock = socket_create(AF_INET, SOCK_STREAM, 0) //Creating a TCP socket
    or die("error: could not create socket\n");
    $succ = socket_connect($sock, $HOST, $PORT) //Connecting to to server using that socket
    or die("error: could not connect to host\n");
    
    //Begin custom code here.
    socket_write($sock, $command = md5($password).";", strlen($command) + 1) //Put md5(password) first to let the server accept the next commands.
    or die("error: failed to write to socket\n");
    
    socket_write($sock, $command = "/Command/ExecuteConsoleCommand:time day;", strlen($command) + 1) //Writing text/command we want to send to the server
    or die("error: failed to write to socket\n");
    
    socket_write($sock, $command = "Time set to day;", strlen($command) + 1)
    or die("error: failed to write to socket\n");
    ?>
    when typing /ws timeset it works fine

    and yes port 4445 is open on tcp, udp
     
  12. Offline

    Waterflames

    This indicates a problem with your minecraft server. Websend should not be the problem.
    What other plugins are you running, and what type of webserver?
     
  13. Offline

    Ycros

    Are you talking to the Websend port? That looks like you're trying to use the main Minecraft server port.
     
  14. Offline

    istealth

    for some reason it wont saving the file correctly and wont listening on port 4445 which it is now.

    when i run the php file now i have no errors in my minecraft console but the time didnt change

    is there away you can connect to my pc over teamviewer and have a look at it.
     
  15. Offline

    Snaipe

    Ok, it stopped to work at all. Whenever I restart it or not, it still does not work, throwing nothing in the console.
    It seems to work when I change port, but that is quite a random issue...
     
  16. Offline

    Waterflames

    Have you tried using a clean install, with a minimal amount of plugins? You've got a considerably large amount of plugins so the chance that there is a conflict is pretty big. The plugin can't just stop working.
     
  17. Offline

    peachpit580

    Ok so im using this for a server, no errors, but how would i echo the people online?
     
  18. Offline

    kidovate

    Hi!

    I'm having a hell of a time getting this working -_-

    Basically since no PHP host is available I want to use c# to send commands to the MC server.

    My config file looks like this:

    Code:
    #Configuration and settings file!
    #Help: URL: set to the full path of your server php file (see example).
    #Help: PASS: change the password to one of your choice (set the same in the server php file).
    URL=http://www.example.com/minecraftPHPcom.php
    PASS=test
    #Optional settings. Remove the '#' to use.
    #FORCEPORT=false
    #FILE=
    WEBLISTENER_ACTIVE=true
    #ALTPROTECTION=
    I have no need for bukkit -> php, only socket -> bukkit, so I left URL default

    Here's the c# code, I've tried every string encoding method possible, what do you think is wrong here? Also I tried some strange method to NOT encode but that didn't do anything either
    Code:
            private byte[] fromStringToByte(string input)
            {
                return Encoding.ASCII.GetBytes(input);
                /*
                BinaryFormatter bf = new BinaryFormatter();
                byte[] bytes;
                MemoryStream ms = new MemoryStream();
    
                bf.Serialize(ms, input);
                ms.Seek(0, 0);
                bytes = ms.ToArray();
                return bytes;
                 * */
            }
            private void SendRefreshCommand()
            {
    
                TcpClient client = new TcpClient("127.0.0.1", 4445);
                if (!client.Connected) client.Connect("127.0.0.1", 4445);
                string md5Pass = CalculateMD5Hash("test");
                Console.WriteLine("Calculated MD5: " + md5Pass + " Connected: " + client.Connected);
                string message =  md5Pass+";";
                byte[] finalMessage = fromStringToByte(message);
                Console.WriteLine(message);
                client.GetStream().Write(finalMessage, 0, message.Length);
                client.GetStream().Flush();
                System.Threading.Thread.Sleep(10);
                finalMessage = fromStringToByte("/Command/ExecuteConsoleCommand:permissions -refresh all;/Command/ExecuteConsoleCommand:reload;");
                client.GetStream().Write(finalMessage, 0, "/Command/ExecuteConsoleCommand:permissions -refresh all;/Command/ExecuteConsoleCommand:reload;".Length);
                client.GetStream().Flush();
                System.Threading.Thread.Sleep(10);
                client.Close();
            }
                public string CalculateMD5Hash(string input)
                {
                    // step 1, calculate MD5 hash from input
                    MD5 md5 = System.Security.Cryptography.MD5.Create();
                    byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
                    byte[] hash = md5.ComputeHash(inputBytes);
    
                    // step 2, convert byte array to hex string
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < hash.Length; i++)
                    {
                        sb.Append(hash[i].ToString("X2"));
                    }
                    return sb.ToString();
                }
    
    Absolutely nothing appears in the minecraft console when these are run O_O. I know its connecting properly because client.connected is true.

    WTF? Thanks. Any help appreciated :)
     
  19. Offline

    Ycros

    From looking at the code, it looks like you're doing authentication incorrectly. It needs to be md5Pass+"<Password>";

    Waterflames: Can I suggest maybe printing out something in the console in the event of an incorrect login/invalid data?
     
  20. Offline

    Waterflames

    Probably a good idea, I'll see what I can do.

    A new version is ready!

    Websend 0.8:
    Changelog:
    • Added errorreport on invalid /Command/
    • Added warning if the first line doesn't contain the password.
    • Added proper disabling code for ServerSocket.
    • Tweaked the variable checking.
    Download in the main post!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 17, 2016
  21. Offline

    Snaipe

    Ha-ha ! Now I have an error :


    Code:
    2011-09-25 10:38:46 [SEVERE] Exception in thread "Thread-15"
    2011-09-25 10:38:46 [SEVERE] java.lang.ArrayIndexOutOfBoundsException: 1
    2011-09-25 10:38:46 [SEVERE]     at websend.PHPSktSrvrThread.run(Main.java:319)
    Using this :


    Code:
       socket_write($sock, $command = "/Command/ExecuteConsoleCommand:say test;", strlen($command) + 1)
         or die("error: failed to write to socket\n");
    And with those plugins :

    Show Spoiler
    AuthDB 2.3.2.220
    CommandBook "1.5.2"
    HeroChat 4.10.3
    BukkitCompat r15A
    Multiverse-Core 2.0-b228
    PermissionsBukkit 1.2
    Spout 1.0.6.381
    TGM '1.0'
    Towny 0.74.0
    VoxelSniper 5.019
    Websend 0.5
    WorldEdit 4.6
    WorldGuard "5.2.2"
    godPowers 2.2
    iConomy 5.01
     
  22. Offline

    Waterflames

    I think I know what the problem is, can you give me your full php source?
     
  23. Offline

    Snaipe

    Sure, but the php code is ran through eval, in a forum wrapper (IPB).

    Here it is anyways :

    PHP:
    $HOST "127.0.0.1";
    $password "my-password";

    $sock socket_create(AF_INETSOCK_STREAM0) or die("error: could not create socket\n");
    $succ socket_connect($sock$HOST25564) or die("Erreur: Connexion impossible, le serveur a besoin d'un restart !\n");

    socket_write($sock$command md5($password)."<Password>"strlen($command) + 1) or die("Erreur: Connexion impossible, le serveur a besoin d'un restart !\n");


    if (
    $_GET['action'] == "buy") {
        if (isset(
    $_GET['id'])){
            if (
    $_GET['id'] == 1) {
            
    // Some HTML Code goes here
              
    }
         }
         else
         {
            
    // Some HTML Code goes here
         
    }
    }
    if (
    $_GET['action'] == "check")
    {
        
    $RECALL $_GET["RECALL"];
        if( 
    trim($RECALL) == "" )
        {
            
    // The RECALL variable is empty
            
    echo "Une erreur est survenue. Veuillez contacter un administrateur.";
            exit(
    1);
        }
        
    // $RECALL contains the access code

        
    $RECALL urlencode$RECALL );

        if (
    $_GET['id'] == 1){
            
    $AUTH urlencode"some ID here" );
        }

        
    $r = @file"http://payment.allopass.com/api/checkcode.apu?code=$RECALL&auth=$AUTH);


        if( 
    substr$r[0],0,) != "OK" )
        {
            
    // The server answered ERR or NOK : access is denied

            
    echo "Le code que vous avez entré est invalide.";
            exit(
    1);
        }

        
    // Valid !

        
    if ($_GET['id'] == 1){
            
    socket_write($sock$command "/Command/ExecuteConsoleCommand:say test;"strlen($command) + 1)
            or die(
    "error: failed to write to socket\n");
        }

        echo 
    "Merci de votre achat ! Vous pouvez dès maintenant en profiter en jeu. A bientôt sur MineKingdom !";
    }
     
  24. Offline

    Waterflames

    Could you update again?
     
  25. Offline

    Snaipe

    OK, updated, seems to work atm.

    I'll post if there's an error.

    Thanks a lot :)

    Seems to work, but There's this message in console when I execute a command :

    Code:
    2011-09-25 19:18:30 [INFO] /Command/ExecuteConsoleCommand:money grant Snaipe_S 5000
    2011-09-25 19:18:30 [INFO] Player Snaipe_S's account had 5,000.00 Gold Coins grant to it.
    2011-09-25 19:18:30 [INFO] ERROR: While parsing php output, websend found
    2011-09-25 19:18:30 [INFO] an error on line 1: Invalid command.
    
    with :

    PHP:
       socket_write($sock$command "/Command/ExecuteConsoleCommand:money grant " $this->memberData['members_display_name'] . " 5000;"strlen($command) + 1)
         or die(
    "error: failed to write to socket\n");
    The command is executed, but it prints that there's an error.

    EDIT :

    I had an error :

    Code:
    2011-09-25 19:24:23 [SEVERE] Exception in thread "Thread-17"
    2011-09-25 19:24:24 [SEVERE] java.lang.ArrayIndexOutOfBoundsException: 1
    2011-09-25 19:24:24 [SEVERE] at websend.PHPSktSrvrThread.run(Main.java:341)
    
    When using this :

    PHP:
       socket_write($sock$command "/Command/ExecuteConsoleCommand:permissions addgroup " $this->memberData['members_display_name'] . " VIP;"strlen($command) + 1)
         or die(
    "error: failed to write to socket\n");
    The plugin stops afterwards.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 17, 2016
  26. Offline

    peachpit580

    How can i use ingame commands from other plugins?
     
  27. Offline

    Waterflames

    @Snaipe
    Those 2 bugs should be fixed. Download from main post.

    @peachpit580
    Like any other:
    /Command/ExecuteBukkitCommand:OtherPluginCommandHere
     
  28. Offline

    peachpit580

    It doesnt work for me, do we need the new version?
     
  29. Offline

    Waterflames

    Have you followed the tutorial? To answer your question: always use the latest version.
     
  30. Offline

    Snaipe

    Still got this :

    Code:
    2011-09-25 23:32:32 [SEVERE] Exception in thread "Thread-17"
    2011-09-25 23:32:32 [SEVERE] java.lang.ArrayIndexOutOfBoundsException: 1
    2011-09-25 23:32:32 [SEVERE] at websend.PHPSktSrvrThread.run(Main.java:359)
    
    with the same code :

    PHP:
       socket_write($sock$command =  "/Command/ExecuteConsoleCommand:permissions addgroup " .  $this->memberData['members_display_name'] . " VIP;"strlen($command)  + 1)
         or die(
    "error: failed to write to socket\n");
    Even after updating.
     
  31. Offline

    sourcemaker

    Hi Waterflames,

    it would be fantastic, if websend could do a simple (public chat).
    For example:
    [...some code...]
    echo "/Command/ExecuteConsoleCommand:perm player setgroup $param Member;";
    echo "/Command/Chat:Hey everyone, $param is now member;";

    Not a "say", because it should be used only for announcements, but a simple chat message.

    Is it possible?
    Thanks!
     

Share This Page