00:00
00:00
3p0ch
If you like hard games try my Daxolissian System series

plasmid @3p0ch

Cat

Scientist

Read the manual & try stuff

So Cal

Joined on 2/13/10

Level:
13
Exp Points:
1,650 / 1,880
Exp Rank:
38,330
Vote Power:
5.48 votes
Audio Scouts
1
Rank:
Portal Security
Global Rank:
23,500
Blams:
50
Saves:
375
B/P Bonus:
8%
Whistle:
Normal
Medals:
4,624
Supporter:
3y 3m 13d

Comments

Great work! One of the 3 alternatives that actually functions properly.
Having it be as simple as an autoload is a GODSEND, thank you so much!

Yeah yeah based very cool

Been hoping to port one of my Android games to browser to post here, to Newgrounds. Thanks for this!

This is awesome and I've been using it on most of my games, so thank you! <3

I've taken the liberty of adding a few extra functions though to call Gateway.ping, to keep the session alive. What do you think? Sorry about the (lack of) formatting!

var session_request
var session_timer

func _ready():
if OS.has_feature('JavaScript'):
session_timer = Timer.new()
add_child(session_timer)
session_timer.one_shot = false
session_timer.autostart = false
session_timer.connect("timeout", self, "_on_session_timer_timeout")
session_timer.start(30)


func _on_session_timer_timeout():
session_request = HTTPRequest.new()
add_child(session_request)
session_request.request(
gateway_uri,
["Content-Type: application/x-www-form-urlencoded"],
true,
HTTPClient.METHOD_POST,
"input=" + JSON.print({
"app_id": app_id,
"session_id": str(JavaScript.eval(
'var urlParams = new URLSearchParams(window.location.search);' +
'urlParams.get("ngio_session_id");'
, true)),
"execute": {
"component": "Gateway.ping",
}
}).percent_encode()
)

Hmm, I wasn't even aware there would be any need to ping the server to keep the session alive. I looked at the docs again and in the section on NewGrounds Passport (https://www.newgrounds.io/help/passport/) it talks about sessions being "remembered" or not, where if it's remembered then it's good for 30 days and if it's not remembered then it's good for a few hours.

I tested it out and yeah, even if when I log in I have the "Keep me signed in" option checked, if I call App.checkSession then the Results object has remember:False. So that could potentially foul things up if the player goes AFK for a day and then comes back and keeps playing.

I agree it's probably better to just ping the server periodically instead of calling App.startSession – I always thought it was obnoxious whenever I play a game and it asked me to log in even though I was already logged in to my NewGrounds account when I opened the game's page, but I guess that's probably what they're doing and why. I still think it's unnecessarily obnoxious though :p so yeah ping the server. But the ping rate could probably be decreased and instead of every 30 seconds do a ping every hour (3600 seconds) or so.

But first, I just uploaded a test project that has a button to check the session ID and made sure it works, so I'm going to go take a catnap and come back sometime tomorrow to confirm if it really does forget the session ID, and if so then add a pinger.

Incidentally, while I was checking the newgrounds.io site I saw that @jefvel made an addon for Godot 4 that looks really sophisticated and automates stuff like keeping track of medals and scores that are achieved while not logged in and syncs them when the user does log in. It looks like it's only for Godot 4 and not Godot 3 though, which wouldn't be my preference because AFAIK the Apple incompatibility issue with Godot web exports is still there for the foreseeable future (plz correct me if I'm wrong about that though).

@3p0ch this is comes off the back of a discussion in the newgrounds.io discord (you should join! :) ) where @psychogoldfish said sessions timeout after 30 minutes of inactivity, which I was definitely seeing - some of my harder medals weren’t unlocking for people! The 30 second timer came from the unity implantation of this.

And yeah, AFAIK, web export is largely broken for Godot 4. Not that I’ve tried it myself! I’ve been quite happy with Godot 3.5.

@blit-blat @3p0ch Hello! Yeah, I've been meaning to write up a news post here about that addon. But as you say, Godot 4 is not really viable for the web at the moment. I wrote it mostly in hopes that web support will improve in the future. (There was a PR for fixing the Apple issues though, which I think has been merged but not yet released. Keeping my fingers crossed!)

I could try to port it to Godot 3 at some point, not sure how complicated it would be since I've only used Godot 4.

I think you should ping the server at least every half hour according to somewhere (don't remember where I read it), so maybe every 5 minutes just to be sure?

I noticed the code uses some inline JS for AES encryption, so I modified it a bit. It uses Godot's own AES stuff, this way you can also run it on desktop. It also frees the request node on completion (otherwise every request will remain in the tree): https://hastebin.skyra.pw/wiqixituwo.php

This is amazing, thanks so much. You are, indeed, based.