aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core/dataloader/cl_loadglobals.lua
blob: d286f36c57f36fd0938d711c30e74c65f998ea39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
local log = nrequire("log.lua")
net.Receive("artery_respondfile",function()
	local filename = net.ReadString()
	local filetext = net.ReadString()
	local dirname = string.GetPathFromFilename(filename)
	file.CreateDir("artery/client/files/" .. dirname)
	assert(#filetext > 0, "Retreived a size 0 file: " .. filename)
	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
		print("I need to load a file",filename," but my hash was old, redownloading!")
		net.Start("artery_requestcsfile")
		net.WriteString(filename)
		net.SendToServer()
	else
		assert(#cache > 0, "File was size 0 on: " .. filename)
		local err = CompileString(cache,filename,false)
		if type(err) == "function"  then
			err()
		else
			log.error(err)
		end
	end
end)