Jump to content

fetchRemote taking awhile to fetch


Recommended Posts

I have a simple script that gets a .txt from my website, it fetches correctly the said key but takes awhile, making resources that uses that key fail to start as thats what the protection does, cancels onResourcesStart if it can't fetch the key or if it is wrong.

I've tried onResourcePreStart but no success, also download priority on meta.xml.

Is there a way to delay every other resource startup or dont make any of them load before it fetches?

Or another way to solve this? 

 

 

Code below.

Credits to Lord Henry for 98% of the code, I just edited to make it fetch a file not an ip from web, and some other stuff, but pretty much all the code is from him.

P.s: if there is something wrong its my addition and my fault ok xD

 

 
function startIPChecking ()
	fetchRemote ("http://***.com/key.txt", myCallback, "", false)
end
addEventHandler ("onResourceStart", resourceRoot, startIPChecking)
 
 
 
function myCallback (responseData, errors)
    if (errors == 0) then
        KEY = tostring(responseData)
        print("server authorized")
    else
        KEY = "error"
        print("server not authorized")
    end
end

function getKey()
    return KEY
end

 

Protected script

addEventHandler("onResourceStart", resourceRoot, function()

    local keyy = exports["secur"]:getKey ()
    if not keyy then
        return cancelEvent()
    end

    if keyy ~= "****" then
        return cancelEvent()
    else
        ---- code if verification OK
	...

 

 

Edited by sirrjohn
Link to comment

You can prioritize the resources which means two ways. The first way is to prioritize their download, so you can kinda line them up, which should be downloaded first and things like that.

But I think you mean, you need to start the other resources first, then I recommend you create a serverside resourcestarter script, which basically will use timers and predefined args to make your own way of loading the needed resources.

  • Like 1
Link to comment
Posted (edited)

 

1 hour ago, Flashmyname said:

You can prioritize the resources which means two ways. The first way is to prioritize their download, so you can kinda line them up, which should be downloaded first and things like that.

But I think you mean, you need to start the other resources first, then I recommend you create a serverside resourcestarter script, which basically will use timers and predefined args to make your own way of loading the needed resources.

oh that sounds like a good idea, a resource starter script!! Tyvm for the heads up i wasn't thinking about that.

I can find out how to do it myself, to not bother you guys much more! Was a nice tip. Ty!

Edited by sirrjohn
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...