Comment stuff, add (semi)-autosetup
This commit is contained in:
parent
7b4b2bca4f
commit
4db2dad592
@ -16,6 +16,7 @@ local function split(str, sep)
|
||||
return t
|
||||
end
|
||||
|
||||
-- Fetches an item with the given display name in the given quantity.
|
||||
local function fetchItem(item, toGet)
|
||||
local result
|
||||
repeat
|
||||
@ -33,6 +34,7 @@ local function fetchItem(item, toGet)
|
||||
until toGet <= 0 or result == "ERROR"
|
||||
end
|
||||
|
||||
-- Dumps an inventory slot into storage
|
||||
function dump(slot)
|
||||
if conf.introspection then
|
||||
conf.introspection.pushItems(conf.name, slot)
|
||||
@ -41,6 +43,7 @@ function dump(slot)
|
||||
query { cmd = "insert", fromInv = conf.name, fromSlot = slot }
|
||||
end
|
||||
|
||||
-- Attempts to interpret the first of a list of tokens as a number.
|
||||
function tryNumber(tokens)
|
||||
local fst = table.remove(tokens, 1)
|
||||
local qty = tonumber(fst)
|
||||
@ -52,6 +55,7 @@ function tryNumber(tokens)
|
||||
return qty
|
||||
end
|
||||
|
||||
-- Help text
|
||||
local help = [[
|
||||
Welcome to the Dragon CLI.
|
||||
Commands:
|
||||
|
14
server.lua
14
server.lua
@ -3,6 +3,7 @@ local conf = util.conf
|
||||
|
||||
rednet.open(conf.modem)
|
||||
|
||||
-- Find all chests or shulker boxes
|
||||
local inventories = {}
|
||||
for _, n in pairs(peripheral.getNames()) do
|
||||
local p = peripheral.wrap(n)
|
||||
@ -15,6 +16,9 @@ end
|
||||
|
||||
local nameCache = {}
|
||||
|
||||
-- Gets the display name of the given item (in the given chest peripheral & slot)
|
||||
-- If its name is not cached, cache it.
|
||||
-- If it is, just return the cached name
|
||||
function cache(item, chest, slot)
|
||||
local idx = item.name .. ":" .. item.damage
|
||||
|
||||
@ -47,6 +51,7 @@ function updateIndex()
|
||||
print "Indexing complete."
|
||||
end
|
||||
|
||||
-- Finds all items matching a certain predicate
|
||||
function find(predicate)
|
||||
for name, items in pairs(index) do
|
||||
for slot, item in pairs(items) do
|
||||
@ -57,6 +62,7 @@ function find(predicate)
|
||||
end
|
||||
end
|
||||
|
||||
-- Finds space in the chest system
|
||||
function findSpace()
|
||||
for name, items in pairs(index) do
|
||||
if #items < inventories[name].size() then
|
||||
@ -68,6 +74,9 @@ end
|
||||
function processRequest(msg)
|
||||
print(textutils.serialise(msg))
|
||||
|
||||
-- Extract an item. If meta and name are supplied, each supplied value must match exactly.
|
||||
-- Applies a fuzzy search to display names
|
||||
-- Extracted items are either deposited in buffer or directly in target inventory.
|
||||
if msg.cmd == "extract" then
|
||||
local inv, slot, item = find(function(item)
|
||||
return
|
||||
@ -85,6 +94,7 @@ function processRequest(msg)
|
||||
end
|
||||
|
||||
return {moved, item}
|
||||
-- Pulls items from an external inventory into storage.
|
||||
elseif msg.cmd == "insert" then
|
||||
if msg.fromInv and msg.fromSlot then
|
||||
peripheral.call(conf.bufferInExternal, "pullItems", msg.fromInv, msg.fromSlot, msg.qty or 64, 1)
|
||||
@ -98,13 +108,17 @@ function processRequest(msg)
|
||||
updateIndexFor(toInv) -- I don't know a good way to figure out where exactly the items went
|
||||
|
||||
return "OK"
|
||||
-- Just return the external network names of the buffers
|
||||
elseif msg.cmd == "buffers" then
|
||||
return { conf.bufferInExternal, conf.bufferOutExternal }
|
||||
-- Reindexes system
|
||||
elseif msg.cmd == "reindex" then
|
||||
updateIndex()
|
||||
return "OK"
|
||||
-- Returns entire index
|
||||
elseif msg.cmd == "list" then
|
||||
return index
|
||||
-- Looks up supplied name in the cache.
|
||||
elseif msg.cmd == "name" then
|
||||
msg.meta = msg.meta or 0
|
||||
return msg.name and msg.meta and nameCache[msg.name .. ":" .. msg.meta]
|
||||
|
19
setup.lua
Normal file
19
setup.lua
Normal file
@ -0,0 +1,19 @@
|
||||
local root = "https://osmarks.ml/git/osmarks/dragon/raw/branch/master/"
|
||||
|
||||
local function download(name, file)
|
||||
local contents = http.get(root .. name).readAll()
|
||||
local f = fs.open(file, "w")
|
||||
f.write(contents)
|
||||
f.close()
|
||||
end
|
||||
|
||||
local files = { "client.lua", "server.lua", "util.lua" }
|
||||
for _, f in pairs(files) do
|
||||
download(f, f)
|
||||
print("Downloaded", f)
|
||||
end
|
||||
|
||||
print "Files downloaded. Either client.lua or server.lua should be run on startup."
|
||||
print "Opening config editor..."
|
||||
shell.run "edit conf"
|
||||
fs.move("conf.lua", "conf") -- edit is really stupid, so un-.lua file
|
Loading…
Reference in New Issue
Block a user