[REQ] Communication FROM craftbukkit TO webserver

Discussion in 'Archived: Plugin Requests' started by MariuszT, Jun 10, 2011.

  1. Offline

    MariuszT

    Your PHP script works?
     
  2. Offline

    Waterflames

    Yeah...

    PHP:
    if (isset($_POST['args'][0]) AND $_POST['args'][0] == 'day') {

      echo 
    'Success\n';
      echo 
    'Example script from PHP\n';
      echo 
    'This will set the time of players world to day\n';
      
    // Use /Command/ExecuteBukkitCommand: to indicate a command.
      // Behind that you can put any player chat command. Example:
      
    echo '/Command/ExecuteBukkitCommand:time day\n';
      echo 
    'Player = '$player;
      echo 
    'Argument 1 = '$_POST['args'][0];

    }
     
  3. Offline

    MariuszT

    It's working because you have a single quotes. Difference in PHP between single and double quotes:
    '\n' - doesn't recognize a new line, treat as normal text
    "\n" - recognize a new line

    I think we should use double quotes. Otherwise it would be difficult to understand for PHP developers.
     
  4. Offline

    Waterflames

    That is a build in function of PHP, I can't just disable it. Either we use ' or we go back to /n or something similair.
    (I could try using the result value of "\n" but that could give conflicts and be another block of code, just to change "/" to "\".)
     
  5. Offline

    MariuszT

    Why we need to do anything with this\n? PHP sends to Java lines of text with new lines characters. Why it's a problem?

    Can you show your source code that is responsible for receiving text from PHP?
     
  6. Offline

    Waterflames

    Now there is the problem. I don't know whether php does or not, the new line characters are lost when the data is read from the URL. I'm sure, the javadocs prove it.
    Link sais it stops at "a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed".

    It doesn't stop at the end of the php line.
     
  7. Offline

    MariuszT

    There is no such thing as "php line". PHP sends to Java normal text but with \n. This \n for PHP is the same \n for Java.

    You read the text sent with PHP in the loop with readLine()? So look at this:

    Show me a piece of your source code please.

    Tried with double quotes in PHP file?

    PHP:
      echo "Success\n";
      echo 
    "Example script from PHP\n";
      echo 
    "This will set the weather of players world to sun\n";
      echo 
    "/Command/ExecuteBukkitCommand:weather sun\n";
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 16, 2016
  8. Offline

    Waterflames

    Even if that would be true, fact remains the java contains() and split() method can't find any \n characters.

    When I do readLine(), I should get the string from the previous position to a \n, not including the \n.
    That is a good thing, because the line-termination character isn't used for anything else than the detection of the split position. (A new line in output is generated by executing a new command, rather than using that character.)

    Yes.

    Look, why is this so important? You (or even me, if you want to) can easely write a function to echo a string plus the "\n" piece.
     
  9. Offline

    MariuszT

    Of course it is not so important. I just wanted to find a solution, I'm sure one exists. Any PHP programmer knows that he must use double quotes to get a new line. He does not understand why he needs to do differently here.

    Do you want in the future to share the source code? I don't know Java but I have very extensive experience in programming. Two heads are better than one :)
     
  10. Offline

    Waterflames

    Sure.
    So what now, do I change it back to /n or something completely different?
     
  11. Offline

    MariuszT

    I think there are two options:
    - back to /n or \n with single quotes
    - show the source and think how to solve the problem

    Your choice :)
     
  12. Offline

    Waterflames

    I experimented a bit more and I found a theoretical way to get the line seperator.
    However, that would involve reading the text byte by byte which I don't think is a very good idea.

    I would go with the /n solution.
     
  13. Offline

    MariuszT

    I'm sure I could solve this problem but it's your plugin. If you want you can release it.
     
  14. Offline

    cisco211

    I could solve that problem too. I think the easiest way will be with regexp.

    For example with that regex replacer:

    Code:
    match: ^.*(\/n).*$
    replace: \n
    
    This should work in both languages, and you dont need to read byte by byte.
     

Share This Page