SHOW:
|
|
- or go back to the newest paste.
| 1 | - | rednet.open "top" |
| 1 | + | local f = fs.open("conf", "r")
|
| 2 | local conf = textutils.unserialise(f.readAll()) | |
| 3 | f.close() | |
| 4 | - | local t = {}
|
| 4 | + | |
| 5 | - | for sub in str:gmatch("[^" .. sep .. "]+") do
|
| 5 | + | rednet.open(conf.modem) |
| 6 | - | table.insert(t, sub) |
| 6 | + | |
| 7 | - | end |
| 7 | + | if conf.introspection then |
| 8 | - | return t |
| 8 | + | conf.introspection = peripheral.call(conf.introspection, "getInventory") |
| 9 | print(conf.introspection) | |
| 10 | end | |
| 11 | ||
| 12 | - | local msg |
| 12 | + | |
| 13 | - | repeat |
| 13 | + | local t = {}
|
| 14 | - | rednet.broadcast(m, "mw") |
| 14 | + | for sub in str:gmatch("[^" .. sep .. "]+") do
|
| 15 | - | _, msg = rednet.receive("mw", 1)
|
| 15 | + | table.insert(t, sub) |
| 16 | - | until msg |
| 16 | + | end |
| 17 | - | return msg |
| 17 | + | |
| 18 | return t | |
| 19 | end | |
| 20 | ||
| 21 | local function query(m) | |
| 22 | - | write "|> " |
| 22 | + | local msg |
| 23 | - | local tokens = split(read(), " ") |
| 23 | + | repeat |
| 24 | - | local cmd = table.remove(tokens, 1) |
| 24 | + | rednet.broadcast(m, "mw") |
| 25 | _, msg = rednet.receive("mw", 1)
| |
| 26 | - | if cmd == "w" then |
| 26 | + | until msg |
| 27 | - | local fst = table.remove(tokens, 1) |
| 27 | + | return msg |
| 28 | - | local qty = tonumber(fst) |
| 28 | + | |
| 29 | ||
| 30 | - | if not qty then |
| 30 | + | local function fetchItem(item, toGet) |
| 31 | - | table.insert(tokens, fst) |
| 31 | + | print(item, toGet) |
| 32 | - | qty = math.huge |
| 32 | + | local result |
| 33 | - | end |
| 33 | + | repeat |
| 34 | local toGetNow = 64 | |
| 35 | - | local item = table.concat(tokens, " ") |
| 35 | + | if toGet < 64 then toGetNow = toGet end |
| 36 | - | local sources, hasFound, result = {}, 0
|
| 36 | + | |
| 37 | - | repeat |
| 37 | + | result = query { cmd = "extract", dname = item, destInv = conf.name, qty = toGetNow }
|
| 38 | - | result = query { cmd = "find", dname = item }
|
| 38 | + | if result and type(result) == "table" and result[1] then |
| 39 | - | if result then |
| 39 | + | toGet = toGet - result[1] |
| 40 | - | table.insert(sources, { result[1], result[2] })
|
| 40 | + | end |
| 41 | - | hasFound = hasFound + result[3].count |
| 41 | + | |
| 42 | - | end |
| 42 | + | if conf.introspection then |
| 43 | - | until hasFound >= qty or not result |
| 43 | + | conf.introspection.pullItems(conf.name, 1) |
| 44 | end | |
| 45 | until toGet <= 0 or result == "ERROR" | |
| 46 | - | end |
| 46 | + | |
| 47 | ||
| 48 | function dump(slot) | |
| 49 | if conf.introspection then | |
| 50 | conf.introspection.pushItems(conf.name, slot) | |
| 51 | slot = 1 | |
| 52 | end | |
| 53 | query { cmd = "insert", fromInv = conf.name, fromSlot = slot }
| |
| 54 | end | |
| 55 | ||
| 56 | function tryNumber(tokens) | |
| 57 | local fst = table.remove(tokens, 1) | |
| 58 | local qty = tonumber(fst) | |
| 59 | ||
| 60 | if not qty then | |
| 61 | table.insert(tokens, 1, fst) | |
| 62 | end | |
| 63 | ||
| 64 | return qty | |
| 65 | end | |
| 66 | ||
| 67 | local help = [[ | |
| 68 | Welcome to the Multiplexed Warehousing CLI Terminal (Alpha). | |
| 69 | Commands: | |
| 70 | w [name] - withdraw all items whose names contain [name] | |
| 71 | w [qty] [name] - withdraw [qty] items whose names contain [name] | |
| 72 | c - Craft item, using the turtle's inventory as a grid (turtle.craft) | |
| 73 | d - Dump all items into storage | |
| 74 | d [slot] - Dump items in [slot] into storage | |
| 75 | r - Force connected storage server to reindex | |
| 76 | help - Display this | |
| 77 | This is an unstable alpha version and does not support a GUI or multiple storage servers.]] | |
| 78 | ||
| 79 | print "Multiplexed Warehousing: CLI Terminal" | |
| 80 | while true do | |
| 81 | write "|> " | |
| 82 | local tokens = split(read(), " ") | |
| 83 | local cmd = table.remove(tokens, 1) | |
| 84 | ||
| 85 | if cmd == "w" then | |
| 86 | local qty = tryNumber(tokens) | |
| 87 | if not qty then | |
| 88 | qty = math.huge | |
| 89 | end | |
| 90 | ||
| 91 | local item = table.concat(tokens, " ") | |
| 92 | fetchItem(item, qty) | |
| 93 | elseif cmd == "c" then | |
| 94 | turtle.craft() | |
| 95 | elseif cmd == "d" then | |
| 96 | local slot = tryNumber(tokens) | |
| 97 | ||
| 98 | if slot then dump(slot) else | |
| 99 | local size = 16 | |
| 100 | if conf.introspection then size = conf.introspection.size() end | |
| 101 | for i = 1, size do | |
| 102 | dump(i) | |
| 103 | end | |
| 104 | end | |
| 105 | elseif cmd == "r" then | |
| 106 | query { cmd = "reindex" }
| |
| 107 | elseif cmd == "help" then | |
| 108 | textutils.pagedPrint(help) | |
| 109 | end | |
| 110 | end |