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()