HTML user login

I have a running HTML game built using Phaser. I am close to moving over to Defold, but I haven’t figured out how to know which user/player that is currently playing. I need to know that for the server communication to function properly.

It is a game for kids, so a parent/teacher logs in using their account, then chooses who will play. I have a server set up already, so I was wondering how to get who is logged in (parent) and who the current player (child) is?
Is it possible for the game engine to send http request together with my browser cookies?
If not, is there any way for me to pass id tokens and other data into the game engine (so I can attach that to my http requests)?

Yes, you can pass things such as session tokens and other launch parameters to the emscripten container and into the HTML game when it launches and then at runtime pick them up and use them in your Lua code.

You pass in additional arguments when you call Module.runApp("name_of_your_div", params) from HTML (bundle to HTML5 and take a look at index.html). By default params looks like this:

var extra_params = {
	archive_location_filter: function( path ) {
		return ("archive" + path + "");
	},
	splash_image: "splash_image.png",
	custom_heap_size: 268435456
}

If you take a look at dmengine.js and find the runApp function you can see that one of the available extra_params is engine_arguments. Example:

var extra_params = {
	archive_location_filter: function( path ) {
		return ("archive" + path + "");
	},
	splash_image: "splash_image.png",
	custom_heap_size: 268435456,
	engine_arguments : [
		"--config=mygame.session_token=XYZABC123",
		"--config=physics.debug=1"
	]
}

This will create a new custom config value named mygame.session_token. (It will also change an existing value in game.project, in this case the physics debug option, which can be quite handy sometimes).

Now, in your game you pick up mygame.session_token using sys.get_config():

local session_token = sys.get_config("mygame.session_token")
3 Likes

Thanks for the extensive reply!
I’ll try it out :slight_smile:

2 Likes