diff options
Diffstat (limited to 'gamemode/core/dataloader')
| -rw-r--r-- | gamemode/core/dataloader/cl_loadglobals.lua | 29 | ||||
| -rw-r--r-- | gamemode/core/dataloader/sv_loadglobals.lua | 70 |
2 files changed, 99 insertions, 0 deletions
diff --git a/gamemode/core/dataloader/cl_loadglobals.lua b/gamemode/core/dataloader/cl_loadglobals.lua new file mode 100644 index 0000000..919ecb5 --- /dev/null +++ b/gamemode/core/dataloader/cl_loadglobals.lua @@ -0,0 +1,29 @@ + +net.Receive("artery_respondfile",function() + local filename = net.ReadString() + local filetext = net.ReadString() + local dirname = string.GetPathFromFilename(filename) + file.CreateDir("artery/client/files/" .. dirname) + file.Write("artery/client/files/" .. filename,filetext) + CompileString(filetext,filename)() +end) + +net.Receive("artery_loadfile",function() + local filename = net.ReadString() + local hash = net.ReadUInt(32) + local cache = file.Read("artery/client/files/" .. filename,"DATA") + if cache == nil then --We don't have this file downloaded! + net.Start("artery_requestcsfile") + net.WriteString(filename) + net.SendToServer() + return + end + local thash = tonumber(util.CRC(cache)) + if hash != thash then + net.Start("artery_requestcsfile") + net.WriteString(filename) + net.SendToServer() + else + CompileString(cache,filename)() + end +end) diff --git a/gamemode/core/dataloader/sv_loadglobals.lua b/gamemode/core/dataloader/sv_loadglobals.lua new file mode 100644 index 0000000..85bbc5f --- /dev/null +++ b/gamemode/core/dataloader/sv_loadglobals.lua @@ -0,0 +1,70 @@ +print("Load globals called") + +local function ExecuteOnFolder(dir, recursive, func) + recursive = recursive ~= nil and recursive or false + local path = "data/artery/" + local fpath = table.concat({path,dir,"/*"}) + local files, directories = file.Find(fpath,"GAME") + for k,v in pairs(files) do + local callpath = table.concat({path,dir,"/",v}) + func(callpath) + end + if recursive then + for k,v in pairs(directories) do + local npath = table.concat({dir,"/",v}) + ExecuteOnFolder(npath,true,func) + end + end +end + +util.AddNetworkString("artery_loadfile") +util.AddNetworkString("artery_requestcsfile") +util.AddNetworkString("artery_respondfile") +local toload = {} +local function loadglobals() + ExecuteOnFolder("global",true,function(f) + local filetxt = file.Read(f,"GAME") + local filename = string.GetFileFromFilename(f) + if string.find(filename,"^cl_") then + toload[f] = filetxt + elseif string.find(filename,"^sv_") then + CompileString(filetxt,f)() + else + toload[f] = filetxt + CompileString(filetxt,f)() + end + end) +end + +local function load_cs_files(ply) + for k,v in pairs(toload) do + net.Start("artery_loadfile") + net.WriteString(k) + local hash = util.CRC(v) + net.WriteUInt(tonumber(hash),32) + net.Send(ply) + end +end + +hook.Add("PlayerInitialSpawn","artery_loadglobals",function(ply) + timer.Simple(1,function() + load_cs_files(ply) + end) +end) + +net.Receive("artery_requestcsfile",function(ln,ply) + local which = net.ReadString() + net.Start("artery_respondfile") + net.WriteString(which) + net.WriteString(toload[which]) + net.Send(ply) +end) + +concommand.Add("artery_reloadglobals",function(ply,cmd,args) + if not ply:IsAdmin() then return end + loadglobals() + for k,v in pairs(player.GetAll()) do + load_cs_files(v) + end +end) +loadglobals() |
