Getting user specific data from online server.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By stubbsy345
:warning: Old Version Published before Godot 3 was released.

I am using HTTPClient to GET and POST files from and to a server. Basically files such as a saved game and data about how they are playing. All are JSON files. I have the protocol successfully working in that I am able to receive the files and post them. My question is now how to assign this to a specific user.

Players don’t log into the game. They are able to log into my website and then have access to the game. With the HTTP client how do I ensure the file is delivered or retrieved from the players specific data. Is there a way of passing some variable from the website (after they have logged in and on launch of the game) that can then be used to access the player specific info.

I am just beginning with HTTPClient so sorry if this is a noob question. The code I am using is below.

func talkToServer(url, mode, data):
# Connect to host/port
HTTP = HTTPClient.new()
RESPONSE = HTTP.connect("http://posttestserver.com", 80)
# Wait until resolved and connected
while HTTP.get_status() == HTTPClient.STATUS_CONNECTING or HTTP.get_status() == HTTPClient.STATUS_RESOLVING:
	HTTP.poll()
	OS.delay_msec(300)
# Error catch: Could not connect
assert(HTTP.get_status() == HTTPClient.STATUS_CONNECTED)
# Check for a GET or POST command
if data == "":
	HEADERS =["User-Agent: Pirulo/1.0 (Godot)", "Accept: */*"]
	RESPONSE = HTTP.request(HTTPClient.METHOD_GET, url, HEADERS)
else:
	QUERY = HTTP.query_string_from_dict(data)
	HEADERS = ["User-Agent: Pirulo/1.0 (Godot)", "Content-Type: application/x-www-form-urlencoded", "Content-Length: " + str(QUERY.length())]
	RESPONSE = HTTP.request(HTTPClient.METHOD_POST, url, HEADERS, QUERY)
# Make sure all is OK
assert(RESPONSE == OK)
# Keep polling until the request is going on
while (HTTP.get_status() == HTTPClient.STATUS_REQUESTING):
	HTTP.poll()
	OS.delay_msec(300)
# Make sure request finished
assert(HTTP.get_status() == HTTPClient.STATUS_BODY or HTTP.get_status() == HTTPClient.STATUS_CONNECTED)
# Set up some variables
var RB = RawArray()
var CHUNK = 0
var RESULT = 0
# Raw data array
if HTTP.has_response():
	# Get response headers
	var headers = HTTP.get_response_headers_as_dictionary()
	while HTTP.get_status() == HTTPClient.STATUS_BODY:
		HTTP.poll()
		CHUNK = HTTP.read_response_body_chunk()
		if(CHUNK.size() == 0):
			OS.delay_usec(100)
		else:
			RB = RB + CHUNK
		HTTP.close()
		RESULT = RB.get_string_from_ascii()

You would need to identify your users somehow. One way you could achieve that is by saving some sort of identifier to a file, which you send as a parameter to your server whenever you make a request. This will only work if the user is playing on a single device though, and not deleting that file. If you need more persistent tracking, you’d need to make the player log in.

Also, some users are probably going to want to know that you’re tracking them, and some are going to want a way to opt out.

flesk | 2017-10-04 19:30

Yeah, that is all in place to let the users know what we use and why. It’s nothing personal, just to allow us to improve the game. What I am think though is a system like kongregate. You log into the website and can then save any game you play, without having to log into each game individually. There must be a way of passing data from the website log in. Or perhaps generic calls are made from the game. And then perhaps who is actually sending that save game request is handled on the server side?

stubbsy345 | 2017-10-05 09:29