1
0
mirror of https://github.com/LDDestroier/CC/ synced 2024-12-11 18:50:29 +00:00

Update neovariable2.lua

This commit is contained in:
LDDestroier 2019-02-20 02:08:14 -05:00 committed by GitHub
parent 6663341733
commit 234cb77147
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,9 +2,9 @@
NewVariable 2 (WIP) by LDDestroier
Get with:
wget https://raw.githubusercontent.com/LDDestroier/CC/master/neovariable2.lua
To Do:
+ asymmetrical encryption
+ asymmetrical encryption (actually forget that, functions wouldn't work out)
+ work on stability
+ steal underpants
--]]
@ -79,13 +79,17 @@ local getID = function(path)
end
end
local makeNewID = function(path)
local makeNewID = function(path, _id)
local file = fs.open(path, "w")
local id = ""
for i = 1, 256 do
id = id .. string.char(math.random(11, 127))
if _id then
file.write(_id)
else
local id = ""
for i = 1, 256 do
id = id .. string.char(math.random(11, 127))
end
file.write(id)
end
file.write(id)
file.close()
return id
end
@ -173,7 +177,7 @@ API.runServer = function( envList, verbose )
if verbose then print("got 'find' request") end
send(nil, msg.cID, "find_response", msg.publicID, nv.publicID)
elseif msg.command == "set" or msg.command == "get" then
if ( -- check the types of all the input
if ( -- check the types of all the input
msg.envKey ~= nil and
type(msg.publicID) == "string" and
msg.k ~= nil and
@ -184,20 +188,22 @@ API.runServer = function( envList, verbose )
if msg.command == "set" then
if msg.v ~= nil then
if verbose then print("[" .. msg.envKey .. "] " .. tostring(msg.k) .. " = " .. tostring(msg.v)) end
if verbose then print("[" .. tostring(msg.envKey) .. "] " .. tostring(msg.k) .. " = " .. tostring(msg.v)) end
nv.environment[msg.publicID][msg.envKey][msg.k] = msg.v
end
elseif msg.command == "get" then
if verbose then print("[" .. msg.envKey .. "] " .. tostring(msg.k)) end
if verbose then print("[" .. tostring(msg.envKey) .. "] " .. tostring(msg.k)) end
send(msg.envKey, msg.cID, "get_response", msg.publicID, nv.environment[msg.publicID][msg.envKey][msg.k])
end
end
end
envList = nv.environment
end
end
API.findServer = function(getList, timeout)
timeout = timeout or 1
timeout = tonumber(timeout) or 1
local cID = math.random(1, 2^30)
send(nil, cID, "find")
if getList then
@ -219,6 +225,8 @@ API.findServer = function(getList, timeout)
end
API.newEnvironment = function(server, envKey)
assert(type(server) == "string", "server ID must be a string")
assert(envKey ~= nil, "envKey must not be nil")
return makeMT(
function(t, k)
local cID = math.random(1, 2^30)