diff options
Diffstat (limited to 'gamemode/core/pac/sv_pac.lua')
| -rw-r--r-- | gamemode/core/pac/sv_pac.lua | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/gamemode/core/pac/sv_pac.lua b/gamemode/core/pac/sv_pac.lua index 482dea6..30d2ef7 100644 --- a/gamemode/core/pac/sv_pac.lua +++ b/gamemode/core/pac/sv_pac.lua @@ -48,28 +48,42 @@ hook.Add("PrePACConfigApply", "stoppacs", function(ply, outfit_data) end end) +local pacsources = { + ["data/artery/pacs/"] = "GAME" +} +function p3.AddPacSource(filepath,from) + pacsources[filepath] = from +end + --When the server starts, get all the pacs and calculate their hashes so we can index them quickly without haveing to read from disk each time. local pachashes = {} local function loadhashes() - local files,_ = file.Find("artery/pacs/*","DATA") - for _,v in ipairs(files) do - local filepath = string.format("artery/pacs/%s",v) - local filetext = file.Read(filepath,"DATA") - local filehash = util.CRC(filetext) - pachashes[string.StripExtension(v)] = tonumber(filehash) + for path,part in pairs(pacsources) do + local files,_ = file.Find(path.."*",part) + for _,v in ipairs(files) do + local filepath = string.format("%s%s",path,v) + local filetext = file.Read(filepath,part) + local filehash = util.CRC(filetext) + pachashes[string.StripExtension(v)] = tonumber(filehash) + end end end loadhashes() +concommand.Add("artery_reload_pac_hashes",loadhashes) local appliedpacs = {} function p3.ApplyPac(what, name) - print("Applying pac", what, "to",name) + print("Applying pac", name, "to",what) appliedpacs[what] = appliedpacs[what] or {} appliedpacs[what][name] = pachashes[name] net.Start("artery_applypac") net.WriteEntity(what) net.WriteString(name) + --If this pac is from an addon that was loaded after this file was, we may need to reload hashes. + if not pachashes[name] then + loadhashes() + end net.WriteUInt(pachashes[name],32) net.Broadcast() end @@ -107,6 +121,7 @@ local pac_cache = {} local function cacheload(key) --If it's already in the cache, just update the time it was last used and return the pac. if pac_cache[key] ~= nil then + print("Pac was already in the cache.") pac_cache[key].time = CurTime() if pac_cache[key].pac == nil then PrintTable(pac_cache) @@ -116,8 +131,9 @@ local function cacheload(key) end --Otherwise, we need to load it. - local pacpath = string.format("artery/pacs/%s.txt",key) - local pacfile = file.Read(pacpath,"DATA") + local pacpath = string.format("data/artery/pacs/%s.txt",key) + local pacfile = file.Read(pacpath,"GAME") + print("Pac was not in cache, reloading, pac txt is",pacfile) --If we haven't reached max cache yet, just put it in if pacs_in_cache < max_pacs_in_cache then @@ -155,6 +171,9 @@ net.Receive("artery_requestpac",function(ln,ply) local pac_txt = cacheload(pac_name) + assert(pac_name,"Pac's name was nil!") + assert(pac_txt, "Pac's txt was nil (from the cache)") + net.Start("artery_downloadpac") net.WriteString(pac_name) net.WriteString(pac_txt) |
