summaryrefslogtreecommitdiff
path: root/gamemode/shared/lazyfiletransfer.lua
blob: 41699115370638d1513c355ad26ce8ef264608bd (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
38
39
40
41
42
43
44
--Lazy file transfer, loads files after the client has connected!
--[[
Uses:
  GM.DebugLazyFileTransfer
  Can be: true, false
  GM.LazyFileTransferType
  Can be: lua, http
  GM.GAMEMODE_FOLDER_NAME
  Should be the folder name for the gamemode
]]

if(CLIENT) then
  GAMEMODE.LazyFileTransferTable = {}
end
if(SERVER) then
  GM.LazyFileTransferTable = {}
  util.AddNetworkString("RequestLazyFile")--Called on the client
  util.AddNetworkString("SendLazyFile")--Called on the server
end

function requestLazyFile(name)

end

function addLazyFile(name)
  if(CLIENT) then return end
  if(GM.DebugLazyFileTransfer) then
    print("Adding file to be lazily transfered:")
    print(name)
  end
  table.insert(GM.LazyFileTransferTable,name)
end

if(SERVER) then
  net.Receive( "RequestLazyFile", function(len, ply)
    local partialpath = net.ReadString()
    local filepath = "gamemodes/" .. GM.GAMEMODE_FOLDER_NAME .. partialpath
    if(GM.DebugLazyFileTransfer) then
      print("Request for lazy file recived:")
      print(filepath)
    end
    local filedata = file.Open( filepath, 'r', "MOD" )
  end)
end