Jump to content

How can i download a file from web site?


thisdp

Recommended Posts

  • Scripting Moderators

i can't use fetchRemote in client side. And if i use fetchRemote and triggerClientEvent, the server's bandwidth can't hold these files.

Link to comment
  • Scripting Moderators
Use fetchRemote server side and send data to client using triggerLatentClientEvent.

There's no way to let client download files from other website?

Link to comment
  • Scripting Moderators
No, because if clients were able to use fetchRemote and callRemote, a server with a large amount of players could potentially set up a large botnet.

Just download can cause botnet?

Link to comment

Not tested, but I think that you can exploit the CEF to download some files directly (website - > client):

Images:

local webBrowser = createBrowser(Width, Height, false, false) -- Width, Height of the image 
addEventHandler("onClientBrowserCreated", webBrowser, function() 
    loadBrowserURL(webBrowser, "http://direct_hotlink_to_image.png") --note that at this point the user will likely revive a dialog to whitelist the domain, and the rest of the script will fail if he doesn't... 
--also there will be problems if the hosting site contains adds... 
end) 
addEventHandler ( "onClientBrowserDocumentReady" , root , function ( url ) --domain already whitelisted 
    if source == webBrowser then 
        encodeImage() 
    end  
end) 
addEventHandler ( "onClientBrowserWhitelistChange" , root , function( url ) --domain whitelisted by the user 
    if source == webBrowser then 
        encodeImage() 
    end  
end) 
function encodeImage() 
    local data = dxGetTexturePixels(webBrowser) 
    destroyElement(webBrowser) 
    local newImg = fileCreate('img.png') 
    fileWrite(newImg, data) 
    fileClose(newImg) 
end 
  

Small text files (less then 2mb):

local webBrowser = createBrowser(Width, Height, false, false) -- Width, Height do not matter 
addEventHandler("onClientBrowserCreated", webBrowser, function() 
    loadBrowserURL(webBrowser, "http://direct_hotlink_to_file.txt") --note that at this point the user will likely revive a dialog to whitelist the domain, and the rest of the script will fail if he doesn't... 
--also there will be problems if the hosting site contains adds... 
end) 
addEventHandler ( "onClientBrowserDocumentReady" , root , function ( url ) --domain already whitelisted 
    if source == webBrowser then 
        getBrowserSource(webBrowser, encodeFile(code)) 
    end  
end) 
addEventHandler ( "onClientBrowserWhitelistChange" , root , function( url ) --domain whitelisted by the user 
    if source == webBrowser then 
        getBrowserSource(webBrowser, encodeFile(code)) 
    end  
end) 
function encodeFile(code) 
    destroyElement(webBrowser) 
    local newtxt = fileCreate('test.txt') 
    fileWrite(newtxt, data) 
    fileClose(newtxt) 
end 
  

Link to comment
  • Scripting Moderators
Not tested, but I think that you can exploit the CEF to download some files directly (website - > client):

Images:

local webBrowser = createBrowser(Width, Height, false, false) -- Width, Height of the image 
addEventHandler("onClientBrowserCreated", webBrowser, function() 
    loadBrowserURL(webBrowser, "http://direct_hotlink_to_image.png") --note that at this point the user will likely revive a dialog to whitelist the domain, and the rest of the script will fail if he doesn't... 
--also there will be problems if the hosting site contains adds... 
end) 
addEventHandler ( "onClientBrowserDocumentReady" , root , function ( url ) --domain already whitelisted 
    if source == webBrowser then 
        encodeImage() 
    end  
end) 
addEventHandler ( "onClientBrowserWhitelistChange" , root , function( url ) --domain whitelisted by the user 
    if source == webBrowser then 
        encodeImage() 
    end  
end) 
function encodeImage() 
    local data = dxGetTexturePixels(webBrowser) 
    destroyElement(webBrowser) 
    local newImg = fileCreate('img.png') 
    fileWrite(newImg, data) 
    fileClose(newImg) 
end 
  

Small text files (less then 2mb):

local webBrowser = createBrowser(Width, Height, false, false) -- Width, Height do not matter 
addEventHandler("onClientBrowserCreated", webBrowser, function() 
    loadBrowserURL(webBrowser, "http://direct_hotlink_to_file.txt") --note that at this point the user will likely revive a dialog to whitelist the domain, and the rest of the script will fail if he doesn't... 
--also there will be problems if the hosting site contains adds... 
end) 
addEventHandler ( "onClientBrowserDocumentReady" , root , function ( url ) --domain already whitelisted 
    if source == webBrowser then 
        getBrowserSource(webBrowser, encodeFile(code)) 
    end  
end) 
addEventHandler ( "onClientBrowserWhitelistChange" , root , function( url ) --domain whitelisted by the user 
    if source == webBrowser then 
        getBrowserSource(webBrowser, encodeFile(code)) 
    end  
end) 
function encodeFile(code) 
    destroyElement(webBrowser) 
    local newtxt = fileCreate('test.txt') 
    fileWrite(newtxt, data) 
    fileClose(newtxt) 
end 
  

thank you all the same. Actually I found a better way, but it is complicate matters.

I can use a socket system with file system as Downloading System. Like node.js or a game engine(like love2d).

I can open it manually while I am in the server.

Create an interface between MTA Client and Downloading System with a file, and download files with it's socket system.

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...