PW 4.4 Assigning Gold Var from URL

Users who are viewing this thread

Slowly getting through getting this thing to work for me but I am having dificulty assigning a gold value to a player who joins using the fetched data from my db.

game_receive_url_response

Code:
  ("game_receive_url_response", # called by the game when a response is received from a web server, if used
   [
    (store_script_param, ":integer_count", 1),
    (store_script_param, ":string_count", 2),
	
	(display_message, "@PASSED 1 | {reg0} {reg1} {s1}"),
						# gold|unique_id|player_id|
	(try_begin),
	(eq, ":integer_count", 2),
	(eq, ":string_count", 1),
	(assign, ":gold", reg0),
	(assign, ":unique_id", reg1),
	(assign, ":player_id", s0),
	dbg.vars_display(":player_id", ":gold"),
	(display_message, "@PASSED 2 | {reg0} {reg1} {s1} "),
	 # check if player is still online
	(player_is_active, ":player_id"),
	# unique id checksum
	(player_get_unique_id, ":player_unique_id", ":player_id"),
	(eq, ":player_unique_id", ":unique_id"),
	(call_script, "script_player_adjust_gold", ":player_id", ":gold"),
	dbg.vars_display(":player_id", ":gold"),
	(display_message, "@PASSED 3 | {reg0} {reg1} {s1} "),
	(try_end),
	
	]),

*fetch / receive script
Code:
	("test_script", # grab player's database values
   [(store_script_param, ":player_id", 1), # must be valid
     (player_get_unique_id, ":unique_id", ":player_id"),
	 (str_store_string, s0, "@WELCOME TO GGS_PW (EXPORTED INFORMATION) "),
	 (multiplayer_send_string_to_player, ":player_id", server_event_local_chat, s0),
	  (assign, reg1, ":unique_id"),
	  (str_store_player_username, s1, ":player_id"),
         # gold|unique_id|player_id|
      (send_message_to_url, "@http://127.0.0.1/dicks/index.php?player_id={s1}&unique_id={reg1}"),
	  (display_message, "@SENDING URL"),

    ]),

My web server is receiving the information and exporting the correct values, warband recognises the values being received but I am unable to assign the values to players. It seems game_receive_url is only  reaching PASSED 1 then stopping.


https://dl.dropboxusercontent.com/u/5493561/dicks%20script.png

Any suggestions would be great :smile:


 
A player id and a player username are totally different things: you can't assign a local variable to a string register. The operation (assign, ":player_id", s0) will always set ":player_id" to 0 (since s0 happens to be assigned to 0, as an implementation detail), which as a player id will always be reserved for a client hosted server, which are not possible to start with PW (replaced by the edit scene mode). You need to send the player id as an integer to your web server, then send it back in the reply (without storing in the database, since it is only unique to the player as long as they stay connected to the Warband server, reused after that); see the PW "nameserver" for an example.

You should also use the first integer as a "return code" or "message type", otherwise your code will not integrate with any other web server features, and you will run into trouble when trying to do more things with the database. It is a very common and standardized practice to have a "header" at the start of a network message to identify what type it is, and what code must handle it.

I also suggest you indent your code based on the try_ blocks, so control flow is easily understandable with larger scripts - as is common practice in many programming languages.
 
Game_Recevive_URL
Code:
  ("game_receive_url_response", # called by the game when a response is received from a web server, if used
   [
    (store_script_param, ":integer_count", 1),
    (store_script_param, ":string_count", 2),
	
	(display_message, "@PASSED 1 | {reg0} {reg1} {reg2}"),
							# gold|unique_id|player_id|
	(try_begin),
	(eq, ":integer_count", 3),
	(eq, ":string_count", 1),

	(assign, ":gold", reg0),
	(assign, ":unique_id", reg1),
	(assign, ":player_id", reg2),
	dbg.vars_display(":player_id", ":gold"),
	(display_message, "@PASSED 2 | {reg0} {reg1} {reg2} "),
	 # check if player is still online
	(player_is_active, ":player_id"),
	# unique id checksum
	(player_get_unique_id, ":player_unique_id", ":player_id"),
	(eq, ":player_unique_id", ":unique_id"),
	(call_script, "script_player_adjust_gold", ":player_id", ":gold"),
	dbg.vars_display(":player_id", ":gold"),
	(display_message, "@PASSED 3 | {reg0} {reg1} {reg2} "),
	(try_end),
	
	]),

*fetch / receive script
Code:
	("test_script", # grab player's database values
   [(store_script_param, ":player_id", 1), # must be valid
      #(player_is_active, ":player_id"),
      # assign player_id to reg1 integer register
     (player_get_unique_id, ":unique_id", ":player_id"),
	 (str_store_string, s0, "@WELCOME TO GGS_PW (EXPORTED INFORMATION) "),
	 (multiplayer_send_string_to_player, ":player_id", server_event_local_chat, s0),
	 # |unique_id|player_id|gold|
	  (assign, reg1, ":unique_id"),
	  (assign, reg2, ":player_id"), 
	  (str_store_player_username, s1, ":player_id"),
	  # |unique_id|player_id|gold|
      (send_message_to_url, "@http://127.0.0.1/dicks/index.php?player_id={reg2}&unique_id={reg1}"),
	  (display_message, "@SENDING URL"),

    ]),

https://dl.dropboxusercontent.com/u/5493561/more%20dicks.png

So player_id is actually the assigning number to the player who has connected to the server. If this is so then what more have I done wrong Vornne?
 
You are still checking that there is 1 string recieved as well as the 3 integers, but your web server probably doesn't send the name back (since you don't send it there in the request, any more). You should probably also avoid using underscores in the strings sent to the web server, since they are converted to spaces by the game engine when reading the module .txt files.
 
Code:
<?php
*Removed*
?>

This is what I send all data to. It responds with the correct vars in corresponding order which it is formatted in the database.
gold|unique_id|player_id|

Whenever a unique_id and player_id are sent to this address, it responds with the appropriate gold|unique_id|player_id| from the database.
Unless you have a better idea.
 
There is no point in ever storing a player id in your database, since that number is only valid for a player while they are still connected, as said before: when joining, a player is assigned a number between 1 and 250 as their "player id" used by all module system operations dealing with players, but if they disconnect (or crash) that id number will probably be reused by another player. The only permanent number that should identify a player in long term storage in a database is the player unique id, but that number is not easily linked to a connected player in game, since you would have to loop over all players, comparing their unique ids to find the correct player.

So, as done in the official "name server", you should send the player id and the unique id to the web server (along with the name, and whatever other information necessary), where the unique id is used as a table index for storing the name, gold, or any other data, but the player id is only temporarily stored in the PHP code for immediately sending back with the reply, to save the Warband server from having to loop over all connected players to find the appropriate player id (wasteful of server CPU when repetitive).

It doesn't make sense you are taking time to write the web server code thoroughly, but are still using a simplistic format for the reply, entirely taking over the web server connection feature by not identifying with some sort of return code or message type.

I would suggest not automatically expanding all columns in your table into the reply, since if you decided to store something else in the database, the Warband code would stop working or have bugs, whether the added columns were relevant to every other message type or not. I suggest explicitly fetching and including only the relevant values in each reply, along with a "return code" type identifier at the start, so you can cleanly develop other features later.
 
My assumption when I was exporting the player_id via string was it was the players username.
So, if it is actually some sort of player join id, why am I still unable to assign the gold when I use the correct format (both exported and called).

What do you mean return code? Am I required to assign codes in the export for warband to recognize?
I thought warband reads left to right reg1|reg2|reg3|s1|s2|s3|
 
Because you are still checking that 3 integers and a string are recieved, when your latest PHP script only returns the integers:
Heavy_Bob said:
Code:
   (eq, ":integer_count", 3),
   (eq, ":string_count", 1),
Passed from the section in the PHP code that dumps all database fields, as opposed to explicitly specifying the fields / columns that will be recognised:
Heavy_Bob said:
Code:
         print( "" . implode( "|", $player_data ) . "|" );
You don't need the trailing "|" seperator, either; it could confuse the integer or string counts.
Heavy_Bob said:
What do you mean return code? Am I required to assign codes in the export for warband to recognize?
I mean deciding that reg0 / the first integer is always the "return code", for any message; for example you might choose 1 = player gold reply, 2 = admin permissions reply, 3 = server time of day, 4 = whatever... and in your player gold PHP code, format the response to start with the appropriate return code, such as "1|$player_id|$player_unique_id|$player_name|$gold", and the fake admin permissions example in a different PHP file like "2|$player_id|$player_unique_id|$kick_permitted|$ban_permitted". Since all replies from any web server queried by Warband code are only passed to the same game_recieve_url_response script, this allows multiple different features to coexist without interfering with each other. See the PW nameserver code for a more complete example: the "return codes" / "message types" are listed in the private/config.php file as constants. This is a very standard practice for network messages for all sorts of games or applications.
 
Back
Top Bottom