SHOW:
|
|
- or go back to the newest paste.
| 1 | _R={}
| |
| 2 | function ValidEntity(e) | |
| 3 | return (e and IsValid(e)) | |
| 4 | end | |
| 5 | local mt={__index=debug.getregistry}
| |
| 6 | setmetatable(_R, mt) | |
| 7 | - | if !ValidEntity(ply) then |
| 7 | + | |
| 8 | function file.FindDir(...) | |
| 9 | local files, dirs=file.Find(...) | |
| 10 | return dirs | |
| 11 | end | |
| 12 | dynLoad={}
| |
| 13 | if SERVER then | |
| 14 | dynLoad.UpdatedFiles={}
| |
| 15 | function dynLoad.SendCodeToClient(v, ply) | |
| 16 | local code=v | |
| 17 | if !IsValid(ply) then | |
| 18 | ply=RecipientFilter():AddAllPlayers() | |
| 19 | end | |
| 20 | if code then | |
| 21 | for i=1, string.len(code)/200+1 do | |
| 22 | local ncode=string.sub(code, (i-1)*200, (i-1)*200+99) | |
| 23 | --Msg(ncode) | |
| 24 | --MsgN(string.len(ncode)) | |
| 25 | umsg.Start("plugin_addcode", ply)
| |
| 26 | umsg.String("runCode")
| |
| 27 | umsg.String(ncode) | |
| 28 | umsg.End() | |
| 29 | end | |
| 30 | umsg.Start("plugin_runcode", ply)
| |
| 31 | umsg.String("runCode")
| |
| 32 | umsg.End() | |
| 33 | - | local code=file.Read("lua/"..v, true)
|
| 33 | + | |
| 34 | error("Error! Code not sent!", 2)
| |
| 35 | end | |
| 36 | - | for ind, addon in pairs(file.FindDir("addons/*", true)) do
|
| 36 | + | |
| 37 | - | if file.Read("addons/"..addon.."/lua/"..v, true) and !hasFound then
|
| 37 | + | |
| 38 | - | code=file.Read("addons/"..addon.."/lua/"..v, true)
|
| 38 | + | |
| 39 | dynLoad.SendCodeToClient(str, self) | |
| 40 | end | |
| 41 | ||
| 42 | - | if file.Read("gamemodes/"..v, true) and !hasFound then
|
| 42 | + | |
| 43 | - | code=file.Read("gamemodes/"..v, true)
|
| 43 | + | local code=file.Read("lua/"..v, "GAME")
|
| 44 | if !code then | |
| 45 | local hasFound=false | |
| 46 | for ind, addon in pairs(file.FindDir("addons/*", "GAME")) do
| |
| 47 | - | if !ValidEntity(ply) then |
| 47 | + | if file.Read("addons/"..addon.."/lua/"..v, "GAME") and !hasFound then
|
| 48 | code=file.Read("addons/"..addon.."/lua/"..v, "GAME")
| |
| 49 | hasFound=true | |
| 50 | end | |
| 51 | end | |
| 52 | if file.Read("gamemodes/"..v, "GAME") and !hasFound then
| |
| 53 | code=file.Read("gamemodes/"..v, "GAME")
| |
| 54 | hasFound=true | |
| 55 | end | |
| 56 | end | |
| 57 | if !IsValid(ply) then | |
| 58 | ply=RecipientFilter():AddAllPlayers() | |
| 59 | end | |
| 60 | if code then | |
| 61 | for i=1, string.len(code)/100+1 do | |
| 62 | local ncode=string.sub(code, (i-1)*100, (i-1)*100+99) | |
| 63 | --Msg(ncode) | |
| 64 | --MsgN(string.len(ncode)) | |
| 65 | umsg.Start("plugin_addcode", ply)
| |
| 66 | umsg.String(v) | |
| 67 | umsg.String(ncode) | |
| 68 | umsg.End() | |
| 69 | end | |
| 70 | umsg.Start("plugin_runcode", ply)
| |
| 71 | umsg.String(v) | |
| 72 | umsg.End() | |
| 73 | if !table.HasValue(dynLoad.UpdatedFiles, v) then | |
| 74 | dynLoad.UpdatedFiles[#dynLoad.UpdatedFiles+1]=v | |
| 75 | end | |
| 76 | else | |
| 77 | ErrorNoHalt("File "..v.." not found (anywhere)!\n")
| |
| 78 | end | |
| 79 | end | |
| 80 | ||
| 81 | concommand.Add("lua_sendfiletoclient", function(ply, cmd, args)
| |
| 82 | if !ply:IsPlayer() then | |
| 83 | dynLoad.SendLuaToClient(string.Implode(" ", args))
| |
| 84 | end | |
| 85 | end) | |
| 86 | ||
| 87 | concommand.Add("lua_openscript_cl", function(ply, cmd, args)
| |
| 88 | if !ply:IsPlayer() then | |
| 89 | dynLoad.SendLuaToClient(string.Implode(" ", args))
| |
| 90 | end | |
| 91 | end) | |
| 92 | ||
| 93 | concommand.Add("lua_openscript_dl", function(ply, cmd, args)
| |
| 94 | if !ply:IsPlayer() then | |
| 95 | dynLoad.SendLuaToClient(string.Implode(" ", args))
| |
| 96 | include(string.Implode(" ", args))
| |
| 97 | end | |
| 98 | end) | |
| 99 | ||
| 100 | concommand.Add("lua_openscript_sh", function(ply, cmd, args)
| |
| 101 | if !ply:IsPlayer() then | |
| 102 | dynLoad.SendLuaToClient(string.Implode(" ", args))
| |
| 103 | include(string.Implode(" ", args))
| |
| 104 | end | |
| 105 | end) | |
| 106 | ||
| 107 | hook.Add("PlayerInitialSpawn", "sendUpdatedFiles", function(ply)
| |
| 108 | for f, v in pairs(dynLoad.UpdatedFiles) do | |
| 109 | dynLoad.SendLuaToClient(v, ply) | |
| 110 | end | |
| 111 | end) | |
| 112 | end | |
| 113 | ||
| 114 | if CLIENT then | |
| 115 | dynLoad.PluginCode={}
| |
| 116 | ||
| 117 | usermessage.Hook("plugin_addcode", function(data)
| |
| 118 | local fname=data:ReadString() | |
| 119 | local code=data:ReadString() | |
| 120 | if dynLoad.PluginCode[fname] then | |
| 121 | dynLoad.PluginCode[fname]=dynLoad.PluginCode[fname]..code | |
| 122 | else | |
| 123 | dynLoad.PluginCode[fname]=code | |
| 124 | end | |
| 125 | end) | |
| 126 | ||
| 127 | usermessage.Hook("plugin_runcode", function(data)
| |
| 128 | local fname=data:ReadString() | |
| 129 | if !(fname=="runCode") then | |
| 130 | MsgN(fname.." loaded from server.") | |
| 131 | end | |
| 132 | RunString(dynLoad.PluginCode[fname]) | |
| 133 | dynLoad.PluginCode[fname]=nil | |
| 134 | end) | |
| 135 | end |