Question Detecting expired session

tcamps

Non-stop Poster
Reaction score
109
I have a script that does a bunch of webpage scraping that is typically ran in the background as the player goes about their business. In some cases the player may be logged out by a co, and the script starts throwing errors since the session expired. The player thinks the script is broken because of the errors.

I'd like to detect when the user's session has expired, though I haven't found a "good" method for doing this.

Any webpage requests will be redirected to TW home page with HTTP 302, but this response isn't fully captured as the AJAX data only shows generic "error" text with status code 0. An alternative is to poke some AJAX API ie /game.php?screen=overview&ajax=map_info&village=0 and checking if the response object shows a session expiration error. I'd rather avoid this since TW would be seeing a lot of errors on their end since I'll likely be querying a nonexistent village or some other nonexistent data depending on the endpoint.

Is there any consistent API that I can query to check session status?
 

Ibra Gonza II

Non-stop Poster
Reaction score
140
As far as I know there is not, but why would you query a non existent village?

If it's a script that runs in the background of a tw window, you would still have a village id of an actual village present in the game_data object. Use that one to query the API and no error will be present? Or what am I not getting? :D I feel like I'm missing something
 

tcamps

Non-stop Poster
Reaction score
109
I didn’t realize current village was available as a local object - that’ll do the trick, thanks!
 
Top