HandBuzz Posted January 21, 2019 Share Posted January 21, 2019 Hey guys, so I created a script for my server so that players can download mod files from a HTTP server. I have a considerable amount of files and this is a more comfortable way of downloading them. Now, I figured it out so players can download a single file, with the following structure (stripped down): function downloadMod ( name ) --name is correspondent to a clientside list if ( name and moddinglist[name] ) then local dff = moddinglist[name][1] local txd = moddinglist[name][2] if ( fileExists ( "mods/"..dff ) ) then --overwrite old files fileDelete ( "mods/"..dff ) end if ( fileExists ( "mods/"..txd ) ) then --overwrite old files fileDelete ( "mods/"..txd ) end downloadingFiles[name] = true -- a little output so i let the player know what he downloads local f = fetchRemote ( httpModDirectory.."/"..dff, function ( data, err, name, dff, txd ) if ( err == 0 ) then local f = fileCreate ( "mods/"..dff ) fileWrite ( f, data ) fileClose ( f ) if ( moddinglist[name][4] ) then fetchRemote ( httpModDirectory.."/"..txd, function ( data, err, name, name2 ) if ( err == 0 ) then local f = fileCreate ( "mods/"..txd ) fileWrite ( f , data ) fileClose ( f ) -- some more error handling code here, unnecesary -- and so on Now, as you can figure out i use an external file index with all the values and all that, so that a list can be created with each individual name and file names, and looks something like this moddinglist = { -- ["Name"] = { "file", "txdfile", vehID, isTXD } } Finally, I have a question. I want to setup the script so that players could download all the files listed all at once, how could I do that, without eating out all my server's resources? Link to comment
Moderators IIYAMA Posted January 21, 2019 Moderators Share Posted January 21, 2019 1 hour ago, HandBuzz said: without eating out all my server's resources? What do you mean with that? Are you saying that your scripts are also located in that direction? Link to comment
HandBuzz Posted January 21, 2019 Author Share Posted January 21, 2019 (edited) I wanted to say something that wouldn't cause so much CPU usage, I know some methods may load all the mods at the time and are very laggy for that server as well as the players I am not very good at efficient scripting, help is welcome Edited January 21, 2019 by HandBuzz Link to comment
HandBuzz Posted January 21, 2019 Author Share Posted January 21, 2019 33 minutes ago, IIYAMA said: What do you mean with that? Are you saying that your scripts are also located in that direction? I wanted to say something that wouldn't cause so much CPU usage, I know some methods may load all the mods at the time and are very laggy for that server as well as the players I am not very good at efficient scripting, help is welcome Link to comment
Moderators IIYAMA Posted January 21, 2019 Moderators Share Posted January 21, 2019 (edited) 27 minutes ago, HandBuzz said: I wanted to say something that wouldn't cause so much CPU usage, I know some methods may load all the mods at the time and are very laggy for that server as well as the players I am not very good at efficient scripting, help is welcome If you are worrying about the internet usage. Get yourself a second server. Which can be a cloud server. This will reduce the impact on your main server. As for the clients. The most laggy part is loading the mods. You can queue processes like this: (untested) local nextModLoading = 0 local function processMods (modsInQueue) local timeNow = getTickCount() if timeNow > nextModLoading then local newMod = modsInQueue[1] -- load mods table.remove(modsInQueue, 1) nextModLoading = timeNow + 300 end if #modsInQueue == 0 then removeRenderEvent(processMods) end end do local modsInQueue = {} function addModToLoader (newMod) modsInQueue[#modsInQueue + 1] = newMod addRenderEvent(processMods, nil, modsInQueue) end end Edited January 21, 2019 by IIYAMA Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now