0 votes

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:
# 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: */*"]
    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())]
# Make sure all is OK
assert(RESPONSE == OK)
# Keep polling until the request is going on
while (HTTP.get_status() == HTTPClient.STATUS_REQUESTING):
# 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:
        CHUNK = HTTP.read_response_body_chunk()
        if(CHUNK.size() == 0):
            RB = RB + CHUNK
        RESULT = RB.get_string_from_ascii()
asked Oct 4, 2017 in Engine by stubbsy345 (282 points)

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.

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?

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.