mirror of
https://github.com/LDDestroier/CC/
synced 2024-12-11 18:50:29 +00:00
Update neovariable2.lua
This commit is contained in:
parent
6663341733
commit
234cb77147
@ -2,9 +2,9 @@
|
|||||||
NewVariable 2 (WIP) by LDDestroier
|
NewVariable 2 (WIP) by LDDestroier
|
||||||
Get with:
|
Get with:
|
||||||
wget https://raw.githubusercontent.com/LDDestroier/CC/master/neovariable2.lua
|
wget https://raw.githubusercontent.com/LDDestroier/CC/master/neovariable2.lua
|
||||||
|
|
||||||
To Do:
|
To Do:
|
||||||
+ asymmetrical encryption
|
+ asymmetrical encryption (actually forget that, functions wouldn't work out)
|
||||||
+ work on stability
|
+ work on stability
|
||||||
+ steal underpants
|
+ steal underpants
|
||||||
--]]
|
--]]
|
||||||
@ -79,13 +79,17 @@ local getID = function(path)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local makeNewID = function(path)
|
local makeNewID = function(path, _id)
|
||||||
local file = fs.open(path, "w")
|
local file = fs.open(path, "w")
|
||||||
local id = ""
|
if _id then
|
||||||
for i = 1, 256 do
|
file.write(_id)
|
||||||
id = id .. string.char(math.random(11, 127))
|
else
|
||||||
|
local id = ""
|
||||||
|
for i = 1, 256 do
|
||||||
|
id = id .. string.char(math.random(11, 127))
|
||||||
|
end
|
||||||
|
file.write(id)
|
||||||
end
|
end
|
||||||
file.write(id)
|
|
||||||
file.close()
|
file.close()
|
||||||
return id
|
return id
|
||||||
end
|
end
|
||||||
@ -173,7 +177,7 @@ API.runServer = function( envList, verbose )
|
|||||||
if verbose then print("got 'find' request") end
|
if verbose then print("got 'find' request") end
|
||||||
send(nil, msg.cID, "find_response", msg.publicID, nv.publicID)
|
send(nil, msg.cID, "find_response", msg.publicID, nv.publicID)
|
||||||
elseif msg.command == "set" or msg.command == "get" then
|
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
|
msg.envKey ~= nil and
|
||||||
type(msg.publicID) == "string" and
|
type(msg.publicID) == "string" and
|
||||||
msg.k ~= nil and
|
msg.k ~= nil and
|
||||||
@ -184,20 +188,22 @@ API.runServer = function( envList, verbose )
|
|||||||
|
|
||||||
if msg.command == "set" then
|
if msg.command == "set" then
|
||||||
if msg.v ~= nil 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
|
nv.environment[msg.publicID][msg.envKey][msg.k] = msg.v
|
||||||
end
|
end
|
||||||
elseif msg.command == "get" then
|
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])
|
send(msg.envKey, msg.cID, "get_response", msg.publicID, nv.environment[msg.publicID][msg.envKey][msg.k])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
envList = nv.environment
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
API.findServer = function(getList, timeout)
|
API.findServer = function(getList, timeout)
|
||||||
timeout = timeout or 1
|
timeout = tonumber(timeout) or 1
|
||||||
local cID = math.random(1, 2^30)
|
local cID = math.random(1, 2^30)
|
||||||
send(nil, cID, "find")
|
send(nil, cID, "find")
|
||||||
if getList then
|
if getList then
|
||||||
@ -219,6 +225,8 @@ API.findServer = function(getList, timeout)
|
|||||||
end
|
end
|
||||||
|
|
||||||
API.newEnvironment = function(server, envKey)
|
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(
|
return makeMT(
|
||||||
function(t, k)
|
function(t, k)
|
||||||
local cID = math.random(1, 2^30)
|
local cID = math.random(1, 2^30)
|
||||||
|
Loading…
Reference in New Issue
Block a user