game_receive_url_response: Content of registers is not as expected [Solved]

Users who are viewing this thread

shokkueibu

Knight
Hey there!
It's my first time working with URL messages in the module system. I believe I've managed to set up everything just fine outside Warband.

The problem seems to be when the Warband server receives a response. The registers, string or not, seem to be prefixed with characters that shouldn't be there. It tested okay through Chrome so I assume Warband is getting the messages in the correct format though I know of no way to confirm that.
I've also noticed the messages about players joining the game sometimes got omitted while the one about receiving the URL response is there. They should appear more often throughout the log since the code only runs after someone joins.


Code:
 16:47:01 - SERVER has joined the game with ID: 0 and has administrator rights. 
 16:47:22 - Achilles has joined the game with ID: ****
 16:47:23 - Sent *****/test.php?int=6&str=Achilles 
 16:47:26 - Got 0 integers and 2 strings 
 16:47:26 - Int: 100, 0, 0, 0, 0, 0 
 16:47:26 - Str: "a

6", "Achilles

0



", "", "", "", "" 
 16:48:13 - sHocK_of_Sarrdak has joined the game with ID: ****
 16:48:17 - Sent *****/test.php?int=4&str=sHocK_of_Sarrdak 
 16:48:20 - Got 1 integers and 1 strings 
 16:48:20 - Int: 124, 0, 0, 0, 0, 0 
 16:48:20 - Str: "sHocK_of_Sarrdak

0



", "Achilles

0



", "", "", "", "" 
 16:54:11 -  <img=ico_headshot> Achilles 
 16:54:38 - Achilles has joined the game with ID: ****
 16:54:40 - Sent *****/test.php?int=30&str=Achilles 
 16:54:43 - Got 0 integers and 2 strings 
 16:54:43 - Int: 100, 0, 0, 0, 0, 0 
 16:54:43 - Str: "b

30", "Achilles

0



", "", "", "", "" 
 17:02:06 - hibik has joined the game with ID: ****
 17:02:10 - Sent *****/test.php?int=1&str=hibik 
 17:02:13 - Got 1 integers and 1 strings 
 17:02:13 - Int: 71, 0, 0, 0, 0, 0 
 17:02:13 - Str: "hibik

0



", "Achilles

0



", "", "", "", "" 
 17:17:30 - Sent *****/test.php?int=30&str=Achilles 
 17:17:31 - Sent *****/test.php?int=4&str=sHocK_of_Sarrdak 
 17:17:33 - Got 0 integers and 2 strings 
 17:17:33 - Int: 100, 0, 0, 0, 0, 0 
 17:17:33 - Str: "b

30", "Achilles

0



", "", "", "", "" 
 17:17:34 - Got 1 integers and 1 strings 
 17:17:34 - Int: 124, 0, 0, 0, 0, 0 
 17:17:34 - Str: "sHocK_of_Sarrdak

0



", "Achilles

0



", "", "", "", "" 
 17:47:37 - Sent *****/test.php?int=30&str=Achilles 
 17:47:38 - Sent *****/test.php?int=4&str=sHocK_of_Sarrdak 
 17:47:40 - Got 0 integers and 2 strings 
 17:47:40 - Int: 100, 0, 0, 0, 0, 0 
 17:47:40 - Str: "b

30", "Achilles

0



", "", "", "", "" 
 17:47:41 - Got 1 integers and 1 strings 
 17:47:41 - Int: 124, 0, 0, 0, 0, 0 
 17:47:41 - Str: "sHocK_of_Sarrdak

0



", "Achilles

0



", "", "", "", ""

Code:
("game_receive_url_response",[
     (store_script_param, ":num_integers", 1),
     (store_script_param, ":num_strings", 2),
     (try_begin),
       (assign, reg60, ":num_integers"),
       (assign, reg61, ":num_strings"),
       (server_add_message_to_log, "@Got {reg60} integers and {reg61} strings"),
       
       (server_add_message_to_log, "@Int: {reg0}, {reg1}, {reg2}, {reg3}, {reg4}, {reg5}"),
       (server_add_message_to_log, "@Str: \"{s0}\", \"{s1}\", \"{s2}\", \"{s3}\", \"{s4}\", \"{s5}\""),
     (try_end),
  ]),
Code:
(ti_server_player_joined, 0, 0, [],[
        (store_trigger_param_1, ":player_no"),
        (call_script, "script_multiplayer_server_player_joined_common", ":player_no"),
         
        (assign, reg0, ":player_no"),
        (str_store_player_username, s0, ":player_no"),
        (send_message_to_url, "@http://127.0.0.1/*****/test.php?int={reg0}&str={s0}"),
        (server_add_message_to_log, "@Sent *****/test.php?int={reg0}&str={s0}"),
      ]),


The requests are getting to the server just fine, as far as I can tell:
Code:
127.0.0.1 - - [17/Sep/2011:16:47:23 +0100] "GET /*****/test.php?int=6&str=Achilles HTTP/1.1" 200 20 "-" "Mozilla/4.0"
127.0.0.1 - - [17/Sep/2011:16:48:17 +0100] "GET /*****/test.php?int=4&str=sHocK_of_Sarrdak HTTP/1.1" 200 29 "-" "Mozilla/4.0"
127.0.0.1 - - [17/Sep/2011:16:54:40 +0100] "GET /*****/test.php?int=30&str=Achilles HTTP/1.1" 200 21 "-" "Mozilla/4.0"
127.0.0.1 - - [17/Sep/2011:17:02:10 +0100] "GET /*****/test.php?int=1&str=hibik HTTP/1.1" 200 17 "-" "Mozilla/4.0"
127.0.0.1 - - [17/Sep/2011:17:17:30 +0100] "GET /*****/test.php?int=30&str=Achilles HTTP/1.1" 200 21 "-" "Mozilla/4.0"
127.0.0.1 - - [17/Sep/2011:17:17:31 +0100] "GET /*****/test.php?int=4&str=sHocK_of_Sarrdak HTTP/1.1" 200 29 "-" "Mozilla/4.0"
127.0.0.1 - - [17/Sep/2011:17:47:37 +0100] "GET /*****/test.php?int=30&str=Achilles HTTP/1.1" 200 21 "-" "Mozilla/4.0"
127.0.0.1 - - [17/Sep/2011:17:47:38 +0100] "GET /*****/test.php?int=4&str=sHocK_of_Sarrdak HTTP/1.1" 200 29 "-" "Mozilla/4.0"

This is my first time dealing with PHP but it works as expected when I access it on the browser.
Code:
<?php
	$int = $_GET["int"];
	$str = $_GET["str"];
	$count = 0;
	
	if($int != null){
		$count++;
		echo $int;
	}
	if($count == 1){
		echo "|";
	}
	if($str != null){
		$count++;
		echo $str;
	}
	if($count == 0){
		echo "0";
	}
?>

This [font=consolas,fixedsys]test.php?int=30&str=Achilles[/font] displays the following in my browser:
Code:
30|Achilles
as expected.

Any ideas on what could be wrong?



EDIT:
Solved:
Vornne said:
I asked chadz through cmpxchg8b about this problem (developers of cRPG), who said it is a problem with warband reading part of the headers; their fix is to add this code to the very start of the php script, before any data is output:
Code:
header_remove();
function set_content_length($output)
{
  header("Content-Length: ".strlen($output));
  return $output;
}
ob_start("set_content_length");
 
I suspect that is related with the UNIX encoding? and the game parsing only ANSI based charset.
Also, I'm glad about you using nginx, way better than A patchy Web Server*:wink: *pun intended*
 
I see what you mean. Unfortunately, I've never worked with nginx before this, so I need a little help.
It seems pretty hard to get noob-friendly info for nginx too :/

Here's what I tried (as shown here):
Code:
http {    
    (...)
    server {
        (...)
        charset    windows-1251;
    }
}

To no avail. It's still the
127.0.0.1 - - [18/Sep/2011:23:14:42 +0100] "GET /****/test.php?int=18&str=Achilles HTTP/1.1" 200 21 "-" "Mozilla/4.0"

23:14:40 - Achilles has joined the game with ID: ***** and has administrator rights.
23:14:42 - Sent ****/test.php?int=18&str=Achilles
23:14:45 - Got 0 integers and 2 strings
23:14:45 - Int: 100, 0, 0, 0, 0, 0
23:14:45 - Str: "b

18", "Achilles

0



", "", "", "", ""

Oh, and I tried Apache but couldn't get the Windows service working and the PHP install wasn't cooperating. :/

EDIT: I've managed to figure something out:

The 0 at the end of all responses received by the server seems to be a null character missing the backslash.


<?php
  echo "6|9|43|stuff|12|test|50";
?>



10:23:51 - Got 5 integers and 2 strings
10:23:51 - Int: 176, 9, 43, 12, 500, 0
10:23:51 - Str: "stuff", "test", "", "", "", ""



<?php
  echo "6|9|43|stuff|12|50|test";
?>



10:25:54 - Got 5 integers and 2 strings
10:25:54 - Int: 176, 9, 43, 12, 50, 0
10:25:54 - Str: "stuff", "test

0



", "", "", "", ""


<?php
  echo "6|9|43|stuff|12|50|test";
  echo "\0";
?>


10:29:00 - Got 5 integers and 2 strings
10:29:00 - Int: 186, 9, 43, 12, 50, 0
10:29:00 - Str: "stuff", "test", "", "", "", ""


It seems I now have a workaround to fixing whatever is in the last register, any ideas on why it isn't dealing with that?
Also, what could the number getting appended at the first register be and how to get rid of it?

I feel really stupid in that this whole thing feels like it should be a lot easier and I don't see anyone else complaining about it.
 
I tried that but there are two unused integers on the beginning and end. At least it stops garbling the text.

|morestuff|6|9|43|stuff|12|test|

16:33:25 - Got 6 integers and 3 strings    <-- The PHP script only outputs 4 integers
16:33:25 - Int: 20, 6, 9, 43, 12, 0
16:33:25 - Str: "morestuff", "stuff", "test", "", "", ""

I'll have to discard the first and last registers as a workaround until someone can shed some light on this.
 
shokkueibu said:
I tried that but there are two unused integers on the beginning and end. At least it stops garbling the text.
...
I'll have to discard the first and last registers as a workaround until someone can shed some light on this.

Okay, it might be due the Unicode's Byte Order Mask, try this.
Open your PHP script into a Notepad++ tab and do the following:
Code:
Encoding > Convert to UTF-8 without BOM

This is an old misconception.
 
Thanks for the tip but sadly it didn't work. The output is exactly the same:

17:49:14 - Got 6 integers and 3 strings
17:49:14 - Int: 20, 6, 9, 43, 12, 0
17:49:14 - Str: "morestuff", "stuff", "test", "", "", ""

PHP script output: |morestuff|6|9|43|stuff|12|test|

I think the two unused integers are there because of the leading and trailing pipes, at least it'd be consistent with TW's comment on top of the script:
Code:
  #script_game_receive_url_response
  #response format should be like this:
  #  [a number or a string]|[another number or a string]|[yet another number or a string] ...
  # here is an example response:
  # 12|Player|100|another string|142|323542|34454|yet another string

Without them however, I go back to the first problem:

17:48:17 - Got 4 integers and 3 strings
17:48:17 - Int: 6, 9, 43, 12, 0, 0
17:48:17 - Str: "1e

morestuff", "stuff", "test

0



", "", "", ""
 
I asked chadz through cmpxchg8b about this problem (developers of cRPG), who said it is a problem with warband reading part of the headers; their fix is to add this code to the very start of the php script, before any data is output:
Code:
header_remove();
function set_content_length($output)
{
  header("Content-Length: ".strlen($output));
  return $output;
}
ob_start("set_content_length");
 
Awesome! That does the trick :smile:

I doubt I'd get there by myself and if I did it'd take ages.
Many thanks to all of you for your time and help!
 
Back
Top Bottom