Last active
February 13, 2018 01:22
-
-
Save Wampa842/d14620cdc699a8c01c9c2662c217ea4b to your computer and use it in GitHub Desktop.
A function to pull the Cetus bounty reset timestamp from the world state file, then pass it to a callback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The first parameter defines the platform (1: PC, 2: PS4, 3: XBO). If it's 0 or undefined, the function won't fetch anything - it'll instead use a static timestamp. | |
//I don't think there's any major difference between the platforms' times, you can probably safely use the PC data and remove the unnecessary lines. | |
//On success, the time is passed to the callback function. On any error, the callback will receive the static timestamp. | |
function getCetusTime(platform, callback) | |
{ | |
var timestamp = 1510884902; //Static timestamp to be returned in case of an error. Correct as of 2018-02-13, for PC version 22.12.2. Might not be accurate in the future. | |
if(!platform || (platform > 3)) | |
{ | |
callback(timestamp); | |
return; | |
} | |
var worldStateUrls = | |
[ | |
"http://content.warframe.com/dynamic/worldState.php", | |
"http://content.ps4.warframe.com/dynamic/worldState.php", | |
"http://content.xb1.warframe.com/dynamic/worldState.php" | |
]; | |
var worldStateUrl = "http://www.whateverorigin.org/get?url=" + encodeURIComponent(worldStateUrls[platform-1]) + "&callback=?"; | |
$.ajax( | |
{ | |
url: worldStateUrl, | |
dataType: "json", | |
mimeType: "application/json", | |
success: function(data) | |
{ | |
var worldStateData; | |
try | |
{ | |
worldStateData = JSON.parse(data.contents); //The data is returned as a string inside a JSON response and has to be parsed. | |
} | |
catch(e) | |
{ | |
console.warn("Could not fetch Cetus time (", e.message, "). Using static timestamp. Accuracy not guaranteed."); | |
callback(timestamp); | |
return; | |
} | |
var syndicate = worldStateData["SyndicateMissions"].find(element => (element["Tag"] == "CetusSyndicate")); | |
timestamp = Math.floor(syndicate["Activation"]["$date"]["$numberLong"] / 1000); //The activation time, converted to whole seconds | |
console.log("Fetched Cetus time: ", timestamp); | |
callback(timestamp); | |
}, | |
failure: function(xhr, status, error) | |
{ | |
console.warn("Cound not fetch Cetus time:", status, error, ". Using static timestamp. Accuracy not guaranteed."); | |
callback(timestamp); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment