aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core/dataloader/sv_loadglobals.lua
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/core/dataloader/sv_loadglobals.lua')
-rw-r--r--gamemode/core/dataloader/sv_loadglobals.lua145
1 files changed, 0 insertions, 145 deletions
diff --git a/gamemode/core/dataloader/sv_loadglobals.lua b/gamemode/core/dataloader/sv_loadglobals.lua
deleted file mode 100644
index 9621c5e..0000000
--- a/gamemode/core/dataloader/sv_loadglobals.lua
+++ /dev/null
@@ -1,145 +0,0 @@
-do return end
-
----Loads code from the data directory.
--- Simple data loader, loads code from the data directory, sv_* files only get loaded server side, cl_* files only get loaded client-side, other files are loaded shared
---@server sv_loadglobals.lua
-
-print("Load globals called")
-local log = nrequire("log.lua")
-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")
- print("Looking for files in ", fpath, "Found:")
- print("files:")
- PrintTable(files)
- print("dirs:")
- PrintTable(directories)
- 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 co
-local function loadglobals()
- co = coroutine.create(function()
- ExecuteOnFolder("global",true,function(f)
- log.debug("Loading global file : " .. f)
- local filetxt = file.Read(f,"GAME")
- local filename = string.GetFileFromFilename(f)
- if string.find(filename,"^cl_") then
- coroutine.yield(f,filetxt)
- elseif string.find(filename,"^sv_") then
- local func = CompileString(filetxt,f,false)
- if type(func) == "function" then
- xpcall(func,function(e)
- log.error(string.format("%s : %s",f,e))
- end)
- else
- log.error(string.format("Failed to compile file %s :\n%s"),filename,func)
- end
- coroutine.yield()
- else
- local func = CompileString(filetxt,f,false)
- if type(func) == "function" then
- xpcall(func,function(e)
- log.error(string.format("%s : %s",f,e))
- end)
- else
- log.error(string.format("Failed to compile file %s :\n%s",filename,func))
- end
- coroutine.yield(f,filetxt)
- end
- end)
- end)
-end
-
-local csco = {}
-local function load_cs_files(ply)
- log.debug("Told to load csfiles for", ply:Nick())
- csco[ply] = coroutine.create(function()
- for k,v in pairs(toload) do print(k) end
- for k,v in pairs(toload) do
- log.debug("Loading cs file:", k,"for",ply:Nick())
- net.Start("artery_loadfile")
- net.WriteString(k)
- local hash = util.CRC(v)
- net.WriteUInt(tonumber(hash),32)
- net.Send(ply)
- coroutine.yield()
- end
- end)
-end
-
-local state = "done"
-local n
-timer.Create("inc_load_timer",0.1,0,function()
- if state == "loading_sv" then
- if coroutine.status(co) == "suspended" then
- local _,fn,t = coroutine.resume(co)
- if fn and t then
- toload[fn] = t
- end
- else
- print("Done loading sv, setting state to load cl")
- state = "loading_cl"
- end
- elseif state == "loading_cl" then
- if not n then
- _,n = next(csco)
- end
- if n and coroutine.status(n) == "suspended" then
- coroutine.resume(n)
- else
- state = "done"
- end
- 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)
-
----Reloads client-side files.
--- Reloads all files that have been downloaded client side, does not re-download files.
---@concommand artery_reloadglobals_cs
-concommand.Add("artery_reloadglobals_cs",function(ply,cmd,args)
- load_cs_files(ply)
- state = "loading_cl"
-end)
-
----Reloads all global/ files on all clients.
--- Tells all clients to reload their client-side files, and reloads server-side files.
---@concommand artery_reloadglobals
---@reqadmin
-concommand.Add("artery_reloadglobals",function(ply,cmd,args)
- if not ply:IsAdmin() then return end
- loadglobals()
- state = "loading_sv"
-end)
-
-loadglobals()
-state = "loading_sv"
-hook.Add("PlayerInitialSpawn","artery_loadglobals",function(ply)
- log.debug("Doing player inital spawn, loading globals for " , ply:Nick())
- timer.Simple(1,function()
- load_cs_files(ply)
- state = "loading_cl"
- end)
-end)