Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ LanteaCraft ]]--
- --[[ and SGCraft ]]--
- --[[ ccDialer ]]--
- --[[ by Dog ]]--
- --[[ aka HydrantHunter ]]--
- --[[ pastebin TUQvDbbm ]]--
- local ccDialVer = "1.5.02"
- --[[
- Tested with/requires:
- - Minecraft 1.7.10
- - LanteaCraft-1.7.10-70 || SGCraft1.95-mc1.7.10
- - ComputerCraft 1.73, 1.74, 1.75
- - An advanced wireless pocket computer
- - ccDHD (with pSync turned ON) running on an Advanced Computer (with a wireless modem) or gateBuddy running on a Computer (standard or advanced with a wireless modem) or a wireless turtle (standard or advanced)
- ]]--
- --# AUTOMATIC/STATIC CONFIGURATION
- --# Peripherals
- local termX, termY = term.getSize() --# pocket 26x20 / tab 26x19
- local netSide = "none"
- --# Status Info
- local runState, thisGate = "init", "NO HOST"
- local drawCLI, drawRatingList, assignRating, assignColor, pSyncHost, tempState, pNum, currentEdit
- local pHosts, gateHosts = { }, { }
- --# Address Book
- local addressBook = { { name = "NO GATES", addr = "ADDRESS", rating = "U", iris = "none", note = "Short note", loc = { x = 99999, y = 99999, z = 99999, dim = "Overworld", }, }, }
- local gateChange = false
- local gatePages, gatePage = 1, 1
- --# Color Definitions
- local white = colors.white
- local silver = colors.lightGray
- local gray = colors.gray
- local black = colors.black
- local brown = colors.brown
- local yellow = colors.yellow
- local orange = colors.orange
- local red = colors.red
- local magenta = colors.magenta
- local purple = colors.purple
- local blue = colors.blue
- local sky = colors.lightBlue
- local cyan = colors.cyan
- local lime = colors.lime
- local green = colors.green
- --# END AUTOMATIC/STATIC CONFIGURATION
- local function netSend(dataPack)
- if not rednet.isOpen(netSide) then
- rednet.open(netSide)
- end
- local data = { program = "pSync", gate = thisGate, command = dataPack }
- if pSyncHost then
- rednet.send(pSyncHost, data)
- end
- end
- local function mergeAddressBooks(newGates)
- local matchFound = false --# use matchFound to indicate if a matching gate was found or not
- for i = 1, #newGates do --# start cycling through the 'new' list of gates
- for j = 1, #addressBook do --# search the address book for a matching address
- if newGates[i].addr == addressBook[j].addr then --# if the gate is already in the address book...
- matchFound = true --# ...set matchFound to true and...
- break --# stop the address book search loop and move on to the next gate in the 'new' list
- end
- end
- if not matchFound then --# if a match wasn't found...
- addressBook[#addressBook + 1] = { } --# initialize a new address book entry
- for k, v in pairs(newGates[i]) do --# loop through the gate entries...
- addressBook[#addressBook][k] = v --# ...and add them to the new address book entry
- end
- if not addressBook[#addressBook].iris then
- addressBook[#addressBook].iris = "none"
- end
- gateChange = true --# indicate that address book data has changed
- else
- matchFound = false --# if a match was found, reset the variable for the next iteration of the loop
- end
- end
- gatePages = math.ceil(#addressBook / 14) --# repaginate gates
- end
- local function pSync(pushpull) --# Sync addressBook with ccDHD
- if pSyncHost then
- netSend(pushpull)
- end
- if pushpull == "pPull" then
- local id, message = rednet.receive(1)
- if id == pSyncHost then
- mergeAddressBooks(message)
- end
- elseif pushpull == "pPush" then
- sleep(0.1)
- netSend(addressBook)
- end
- end
- local function shutDown()
- if rednet.isOpen(netSide) then
- rednet.close(netSide)
- end
- end
- local function saveData()
- local dhdConfig = fs.open("/data/DHDgates", "w") or function() shutDown() error("saveData(): Cannot open /data/DHDgates for writing", 0) end
- dhdConfig.write(textutils.serialize(addressBook))
- dhdConfig.close()
- gateChange = false
- end
- local function ingestData()
- if not fs.exists("/data/DHDgates") then return end
- local dhdConfig = fs.open("/data/DHDgates", "r") or function() shutDown() error("ingestData(): Cannot open /data/DHDgates for reading", 0) end
- addressBook = textutils.unserialize(dhdConfig.readAll())
- dhdConfig.close()
- gatePages = math.max(1, math.ceil(#addressBook / 14))
- local resaveAB = false
- for i = 1, #addressBook do
- if not addressBook[i].name then
- addressBook[i].name = addressBook[i].addr
- resaveAB = true
- end
- if not addressBook[i].iris then
- addressBook[i].iris = "none"
- resaveAB = true
- end
- end
- if resaveAB then saveData() end
- end
- do
- local colorBurst = {
- B = { blue, "Base/Outpost/Hub" },
- H = { sky, "Home/Camp" },
- V = { brown, "Village" },
- M = { purple, "Misc/Special" },
- S = { green, "Safe/Secured" },
- C = { orange, "Caution" },
- D = { red, "Danger" },
- U = { silver, "Unknown/Unclassified" }
- }
- assignColor = function(gateNumber)
- return colorBurst[addressBook[gateNumber].rating][1]
- end
- assignRating = function(gateNumber)
- return colorBurst[addressBook[gateNumber].rating][2]
- end
- end
- local function clearScreen(bgColor)
- term.setBackgroundColor(bgColor or black)
- term.clear()
- end
- local function drawElement(x, y, w, h, txtColor, bgColor, text)
- if bgColor then term.setBackgroundColor(bgColor) end
- local deText = text and tostring(text) or ""
- if w > #deText or h > 1 then --# We're drawing something more than text
- local line = string.rep(" ", w) --# Define one line of the 'element' (box/rectange/line-seg)
- for i = 1, h do
- term.setCursorPos(x, y + i - 1) --# Increment the cursor position
- term.write(line) --# Draw 1 of h lines of the 'element' (box/rectangle/line-seg)
- end
- end
- if deText ~= "" then
- if txtColor then term.setTextColor(txtColor) end
- w = math.max(w, #deText) --# Ensure minimum length
- local xW = (x + math.floor(w / 2)) - math.floor(#deText / 2) --# Center the text horizontally
- local yH = y + math.floor(h / 2) --# Center the text vertically
- term.setCursorPos(xW, yH) --# Set the cursor position
- term.write(deText) --# Write the text
- end
- end
- do
- local ratings = {
- [1] = { rating = "B", color = blue, desc = "Base/Outpost/Hub" },
- [2] = { rating = "H", color = sky, desc = "Home/Camp" },
- [3] = { rating = "V", color = brown, desc = "Village" },
- [4] = { rating = "M", color = purple, desc = "Misc/Special" },
- [5] = { rating = "S", color = green, desc = "Safe/Secured" },
- [6] = { rating = "C", color = orange, desc = "Caution" },
- [7] = { rating = "D", color = red, desc = "Danger" },
- [8] = { rating = "U", color = silver, desc = "Unk/Unclassified" },
- }
- drawRatingList = function(gRating)
- local rColor
- drawElement(7, 6, 19, 8, nil, gray, "") --# menu body
- for i = 1, #ratings do
- if gRating == ratings[i].rating then
- rColor = gRating == "U" and white or ratings[i].color
- drawElement(25, i + 5, 1, 1, nil, ratings[i].color, "") --# selected rating color pip
- else
- rColor = silver
- end
- drawElement(6, i + 5, 1, 1, nil, ratings[i].color, "") --# color pip
- drawElement(8, i + 5, 1, 1, rColor, gray, ratings[i].desc)
- end
- end
- end
- local function drawHeader()
- --local title = "[ ] [ ]" .. string.rep(" ", math.floor(termX / 2) - 9) .. "ccDialer" .. string.rep(" ", math.ceil(termX / 2) - 9) .. "[ ]"
- local title
- if runState == "viewing" or runState == "Help" then
- title = string.rep(" ", math.floor(termX / 2) - 4) .. "ccDialer" .. string.rep(" ", math.ceil(termX / 2) - 7) .. "[ ]"
- else
- title = "[ ] [ ]" .. string.rep(" ", math.floor(termX / 2) - 9) .. "ccDialer" .. string.rep(" ", math.ceil(termX / 2) - 9) .. "[ ]"
- end
- drawElement(1, 1, termX, 1, white, blue, title) --# title bar
- if runState ~= "viewing" and runState ~= "Help" then
- drawElement(2, 1, 1, 1, pSyncHost and green or gray, nil, "H") --# 'H' for pSync Hosts
- drawElement(6, 1, 1, 1, pSyncHost and green or gray, nil, "I") --# 'I' for Iris control
- end
- drawElement(termX - 1, 1, 1, 1, red, nil, "X") --# 'X' for Exit
- local hostName = thisGate
- if runState == "Dial" or runState == "pSync" then
- for i = 1, #addressBook do
- if addressBook[i].addr == thisGate then
- hostName = addressBook[i].name
- break
- end
- end
- end
- if runState == "Dial" then
- drawElement(1, 2, termX, 1, silver, gray, "Host: " .. hostName)
- drawElement(1, 3, 1, 1, white, cyan, " pSync ")
- term.setBackgroundColor(green)
- if gateChange then term.setTextColor(orange) end
- term.write(" + ")
- term.setBackgroundColor(red)
- if gateChange then term.setTextColor(white) end --# change the text color back to white if it was changed to orange
- term.write(" END Call ")
- elseif runState == "pSync" then
- drawElement(1, 2, termX, 1, silver, gray, "Host: " .. hostName)
- elseif runState == "Help" then
- drawElement(1, 2, termX, 1, silver, gray, "+ button")
- elseif runState == "viewing" then
- drawElement(1, 2, termX, 1, silver, gray, "Gate Information")
- end
- end
- local function drawHelpUI()
- drawElement(1, 6, termX, 1, silver, gray, "Address Book")
- drawElement(1, 11, termX, 1, nil, nil, "Header buttons")
- drawElement(1, 16, termX, 1, nil, nil, "pSync button")
- drawElement(1, termY, termX, 1, nil, nil, "version " .. ccDialVer)
- drawElement(2, 3, 1, 1, black, white, "(L) click: Add address")
- drawElement(2, 4, 1, 1, nil, nil, "(R) click: Save addr book")
- drawElement(2, 7, 1, 1, nil, nil, "(L) click: dial address")
- drawElement(2, 8, 1, 1, nil, nil, "(R) click: view or edit")
- drawElement(2, 9, 1, 1, nil, nil, "(M) click: del. address")
- drawElement(2, 12, 1, 1, nil, nil, "[H] = locate pSync host")
- drawElement(2, 13, 1, 1, nil, nil, "[I] = open remote iris")
- drawElement(2, 14, 1, 1, nil, nil, "[X] = Exit/Quit")
- drawElement(2, 17, 1, 1, nil, nil, "(L) click: Send/Receive")
- drawElement(13, 18, 1, 1, nil, nil, "address book")
- end
- local function drawHostsUI()
- drawElement(8, 5, 13, 1, white, blue, "pSync Hosts") --# Header
- drawElement(8, 6, 13, 11, nil, gray, "") --# Body
- local curPos = 7
- term.setBackgroundColor(silver)
- term.setTextColor(white)
- if gateHosts[1] then
- local hostNames = { }
- for i = 1, #gateHosts do
- hostNames[i] = gateHosts[i]
- for j = 1, #addressBook do
- if addressBook[j].addr == gateHosts[i] then
- hostNames[i] = addressBook[j].name
- break
- end
- end
- end
- for i = 1, #hostNames do
- term.setCursorPos(9, curPos)
- term.write(" " .. hostNames[i] .. " ") --# Gate host
- if i == 5 then break end
- curPos = curPos + 2
- end
- else
- if runState ~= "init" then
- runState = "Dial"
- clearScreen()
- end
- end
- end
- local function drawIrisPasswordUI()
- drawElement(2, 5, termX - 2, 1, gray, black, "Remote iris password")
- drawElement(6, 6, 16, 3, nil, silver, "")
- drawElement(7, 7, 14, 1, nil, gray, "")
- end
- local function drawPsyncUI()
- drawElement(2, 5, termX - 2, 3, white, green, "GET Address Book")
- drawElement(2, 9, termX - 2, 3, nil, orange, "SEND Address Book")
- drawElement(2, 13, termX - 2, 3, nil, red, "C A N C E L")
- end
- local function drawNaviUI()
- pNum = tostring(gatePage) .. " of " .. tostring(gatePages)
- drawElement((termX / 2) - 10, termY, 7, 1, gray, black, "<< < > >>")
- drawElement(math.floor(termX / 2) - (math.floor(#pNum / 2)) + 1, termY, 3, 1, silver, nil, pNum)
- end
- local function drawAddressList() --# Gate Address Book (Dial / Edit / Trim)
- local xPos, yPos = 3, 5
- local magicNumber = ((gatePage - 1) * 13) + gatePage
- for i = magicNumber, #addressBook do
- if thisGate == addressBook[i].addr or addressBook[i].addr == thisGate:sub(1, 7) then --# Highlight this gate / Dial
- term.setBackgroundColor(gray)
- term.setTextColor(silver)
- else
- term.setBackgroundColor(assignColor(i))
- term.setTextColor(white)
- end
- term.setCursorPos(xPos, yPos)
- term.write(string.rep(" ", math.floor((9 - #addressBook[i].name) / 2)) .. addressBook[i].name .. string.rep(" ", math.ceil((9 - #addressBook[i].name) / 2))) --# Dial
- yPos = yPos + 2
- if yPos > 17 then xPos = xPos + 13 yPos = 5 end
- if xPos > 17 then break end
- end
- end
- do
- local stateTable = {
- Dial = function() drawAddressList() drawNaviUI() end,
- pSync = function() drawPsyncUI() end,
- syncHosts = function() drawHostsUI() end,
- gateHosts = function() drawHostsUI() end,
- Help = function() drawHelpUI() end
- }
- drawCLI = function() --# Client Interface 'decider'
- drawHeader()
- stateTable[runState]()
- end
- end
- local function flashDial(gate, gX, gY, gateNum)
- local gColor = assignColor(gateNum)
- local gLabel = string.rep(" ", math.floor((9 - #gate) / 2)) .. gate .. string.rep(" ", math.ceil((9 - #gate) / 2)) --# Address
- drawElement(gX, gY, 9, 1, gColor, black, gLabel)
- sleep(0.1)
- drawElement(gX, gY, 9, 1, white, gColor, gLabel)
- end
- local function flashChoice(x, y, tCo, bCo, label)
- drawElement(x, y, 1, 1, tCo, bCo, label)
- sleep(0.1)
- end
- local function gateDataChange()
- gateChange = true
- drawElement(6, termY - 1, 6, 1, green, gray, "Save")
- end
- local function deleteGate(gateNum)
- if #addressBook > 1 then --# Don't delete if only 1 gate remaining
- table.remove(addressBook, gateNum)
- gateChange = true
- gatePages = math.ceil(#addressBook / 14) --# Re-paginate gates
- gatePage = math.min(gatePage, gatePages)
- if gatePage == gatePages then
- drawElement(2, 5, termX - 2, termY - 5, nil, black, "") --# Clear address book area of screen
- end
- drawElement(13, 3, 1, 1, orange, green, "+")
- drawAddressList()
- drawNaviUI()
- end
- end
- local function drawGateData()
- local teColor = assignColor(currentEdit)
- drawElement(2, 4, 1, 1, yellow, black, addressBook[currentEdit].name .. string.rep(" ", 9 - #addressBook[currentEdit].name)) --# Name
- if thisGate == addressBook[currentEdit].addr or thisGate:sub(1, 7) == addressBook[currentEdit].addr then
- drawElement(15, 6, 1, 1, gray, nil, "pSync Host") --# pSync Host
- else
- drawElement(15, 6, 1, 1, nil, nil, " ")
- end
- drawElement(2, 6, #addressBook[currentEdit].addr, 1, teColor, nil, addressBook[currentEdit].addr .. " ") --# Address
- local ratingWord = assignRating(currentEdit)
- drawElement(2, 8, 1, 1, silver, nil, "(" .. ratingWord .. ") ")
- drawElement(3, 8, 1, 1, teColor, nil, ratingWord) --# Classification
- drawElement(21, 4, 1, 1, white, nil, currentEdit .. " ") --# Entry number ('#')
- if #addressBook[currentEdit].note > 24 then --# Note
- drawElement(2, 10, 1, 1, nil, nil, addressBook[currentEdit].note:sub(1, 24))
- drawElement(2, 11, 1, 1, nil, nil, addressBook[currentEdit].note:sub(25, 43) .. string.rep(" ", 19 - #addressBook[currentEdit].note:sub(25, 43)))
- else
- drawElement(2, 10, 1, 1, nil, nil, addressBook[currentEdit].note .. string.rep(" ", 24 - #addressBook[currentEdit].note:sub(1,24)))
- end
- local xStr, yStr, zStr = tostring(addressBook[currentEdit].loc.x), tostring(addressBook[currentEdit].loc.y), tostring(addressBook[currentEdit].loc.z)
- drawElement(7, 13, 1, 1, yellow, nil, addressBook[currentEdit].loc.dim .. string.rep(" ", 19 - #addressBook[currentEdit].loc.dim)) --# Dimension
- drawElement(5, 14, 1, 1, silver, nil, xStr .. string.rep(" ", 9 - #xStr)) --# X
- drawElement(5, 15, 1, 1, nil, nil, yStr .. string.rep(" ", 9 - #yStr)) --# Y
- drawElement(5, 16, 1, 1, nil, nil, zStr .. string.rep(" ", 9 - #zStr)) --# Z
- drawElement(15, termY - 1, 7, 1, red, gray, "Close")
- drawElement(6, termY - 1, 6, 1, gateChange and green or silver, nil, "Save")
- end
- local function drawGateLabels()
- clearScreen()
- drawHeader()
- drawElement(19, 4, 1, 1, gray, black, "#")
- drawElement(2, 13, 4, 1, nil, nil, "Dim:")
- drawElement(2, 14, 2, 1, nil, nil, "x:")
- drawElement(2, 15, 2, 1, nil, nil, "y:")
- drawElement(2, 16, 2, 1, nil, nil, "z:")
- drawGateData()
- end
- local function addNewAddress(fast)
- if #addressBook < 23976 then
- if #addressBook == 1 and addressBook[1].name == "NO GATES" and addressBook[1].addr == "ADDRESS" then
- addressBook[1].name = "Name"
- else
- local newGate = { name = "Name", addr = "ADDRESS", rating = "U", iris = "none", note = "short note", loc = { x = 99999, y = 99999, z = 99999, dim = "Overworld", }, }
- table.insert(addressBook, newGate)
- end
- gateChange = true
- gatePages = math.ceil(#addressBook / 14) --# Re-paginate gates
- if fast then --# if the new gate is a quick-add....
- if gatePage == gatePages then drawAddressList() end --# ...redraw the address list
- drawNaviUI()
- else
- currentEdit = #addressBook --# currentEdit = new gate
- drawGateLabels()
- end
- else
- runState = "Dial"
- end
- end
- local function getGateAddress()
- local id, message = rednet.receive(1)
- if id == pSyncHost and type(message) == "string" then
- local msgLen = #message
- if msgLen == 7 or msgLen == 9 or message == "lockdown" then
- thisGate = message
- else
- return
- end
- else
- return
- end
- local gateMatch = false
- for i = 1, #addressBook do
- if thisGate and (thisGate == addressBook[i].addr or addressBook[i].addr == thisGate:sub(1, 7)) then gateMatch = true break end
- end
- if not gateMatch and thisGate ~= "lockdown" then
- clearScreen()
- if runState ~= "init" then drawHeader() end
- local tempState = runState
- runState = "newGate"
- drawElement(4, 7, 19, 1, white, blue, "New Gate Detected") --# Header
- drawElement(4, 8, 19, 5, nil, gray, "") --# Body
- drawElement((termX / 2) - (#thisGate / 2) + 1, 9, 1, 1, silver, nil, thisGate)
- drawElement(7, 11, 5, 1, white, green, "Add")
- drawElement(14, 11, 6, 1, nil, orange, "Skip")
- while true do
- local _, button, mX, mY = os.pullEvent("mouse_click")
- if mX > 6 and mX < 12 and mY == 11 then
- if #addressBook == 1 and (addressBook[1].name == "NO GATES" or addressBook[1].name == "NEW GATE" or addressBook[1].name == "Name") and addressBook[1].addr == "ADDRESS" then table.remove(addressBook, 1) end
- local newGate = { name = thisGate, addr = thisGate, rating = "U", iris = "none", note = "Discovered gate", loc = { x = 99999, y = 99999, z = 99999, dim = "Overworld", }, }
- table.insert(addressBook, newGate)
- saveData()
- break
- elseif mX > 13 and mX < 20 and mY == 11 then
- break
- end
- end
- runState = tempState
- drawElement(4, 7, 19, 6, nil, black, "") --# Clear body
- end
- end
- local function selectHost()
- local hostNames = { }
- for i = 1, #gateHosts do
- hostNames[i] = gateHosts[i]
- for j = 1, #addressBook do
- if addressBook[j].addr == gateHosts[i] then
- hostNames[i] = addressBook[j].name
- break
- end
- end
- end
- while gateHosts[1] do
- local _, button, mX, mY = os.pullEvent("mouse_click")
- if mX > 8 and mX < 20 and mY > 6 and mY < 16 then
- local gCounter = 0
- for i = 7, 15, 2 do
- gCounter = gCounter + 1
- if gCounter <= #pHosts then
- if mY == i then
- drawElement(9, i, 11, 1, black, white, hostNames[gCounter])
- sleep(0.1)
- drawElement(9, i, 11, 1, gray, silver, hostNames[gCounter])
- pSyncHost = pHosts[gCounter]
- thisGate = gateHosts[gCounter]
- return
- end
- end
- end
- end
- end
- end
- local function findHosts()
- for i = #pHosts, 1, -1 do --# clear pHosts table
- pHosts[i] = nil
- end
- for i = #gateHosts, 1, -1 do --# clear gateHosts table
- gateHosts[i] = nil
- end
- pSyncHost, thisGate = nil, "NO HOST" --# clear pSyncHost and thisGate variables
- pHosts = { rednet.lookup("pSync") } --# populate pHosts table
- if pHosts[1] then
- for i = 1, #pHosts do --# process host list
- pSyncHost = pHosts[i] --# set the host
- thisGate = "NO HOST" --# reset gate information
- netSend("QRY") --# query the host
- getGateAddress() --# get gate information
- gateHosts[i] = thisGate --# store gate address
- end
- pSyncHost, thisGate = nil, "NO HOST" --# clear host info
- for i = #pHosts, 1, -1 do --# process and sanitize host list
- if gateHosts[i] == "lockdown" or gateHosts[i] == "NO HOST" then --# if gate is in lockdown or hasn't replied...
- table.remove(pHosts, i) --# ...remove the host from the list and...
- table.remove(gateHosts, i) --# ...remove the gate address from the gateHosts table
- end
- end
- end
- if #pHosts > 1 then --# more than 1 host responds
- if runState == "init" then
- drawElement(2, 4, termX, termY, nil, black, "") --# clear most of screen
- drawHostsUI()
- selectHost()
- else
- drawElement(4, 7, 20, 4, nil, black, "") --# clear 'searching for hosts' dialogue
- drawCLI()
- end
- elseif #pHosts == 1 then --# only one host responds
- pSyncHost = pHosts[1] --# set pSyncHost
- thisGate = gateHosts[1] --# set gate address
- if runState == "init" then
- drawElement(5, 12, 1, 1, green, gray, "O")
- else
- runState = runState == "syncHosts" and "pSync" or "Dial"
- drawElement(4, 7, 20, 4, nil, black, "") --# clear pSync pop-up
- drawCLI()
- end
- else --# no hosts respond
- if runState == "init" then
- drawElement(5, 12, 1, 1, red, gray, "0")
- else
- runState = "Dial"
- drawElement(4, 7, 20, 4, nil, black, "") --# clear pSync pop-up
- drawCLI()
- end
- end
- end
- local function readInput(cX, cY, cO, bG, _limit, gField, mask) --# cursor X, Y, text color, bg color, character limit, limit characters to valid address characters, character mask
- local symbols = { ["A"] = true, ["B"] = true, ["C"] = true, ["D"] = true, ["E"] = true , ["F"] = true, ["G"] = true, ["H"] = true, ["I"] = true, ["J"] = true, ["K"] = true, ["L"] = true, ["M"] = true, ["N"] = true, ["O"] = true, ["P"] = true, ["Q"] = true, ["R"] = true, ["S"] = true, ["T"] = true, ["U"] = true, ["V"] = true, ["W"] = true, ["X"] = true, ["Y"] = true, ["Z"] = true, ["0"] = true, ["1"] = true, ["2"] = true, ["3"] = true, ["4"] = true, ["5"] = true, ["6"] = true, ["7"] = true, ["8"] = true, ["9"] = true, ["-"] = true, ["+"] = true }
- local word = ""
- local wordA = nil
- local curX, curY = cX, math.floor(cY)
- local bCurX, bCurY = cX, math.floor(cY)
- local pos = 0
- _limit = (_limit and type(_limit) == "number" and _limit > 0) and _limit or 43
- if type(mask) ~= "string" then mask = nil end
- if bG then term.setBackgroundColor(bG) end
- term.setTextColor(cO)
- term.setCursorBlink(true)
- term.setCursorPos(curX, curY)
- while true do
- local event, data, mX, mY = os.pullEvent()
- if event == "key" then
- if data == keys.backspace then
- curX = curX - 1
- pos = math.max(0, pos - 1)
- if curX < bCurX and curY == bCurY then curX = bCurX end
- if curX < bCurX and curY > bCurY then
- curY = curY - 1
- curX = termX
- word = wordA
- wordA = nil
- end
- word = (#word > 0) and word:sub(1, #word - 1) or ""
- drawElement(curX, curY, 1, 1, nil, bG, " ")
- elseif data == keys.enter or data == keys.numPadEnter then
- break
- end
- elseif event == "char" and pos < _limit then
- local goodData = false
- if gField then
- if symbols[data:upper()] then
- goodData = true
- end
- else
- goodData = true
- end
- if goodData then
- if mask then
- drawElement(curX, curY, 1, 1, cO, bG, mask)
- else
- drawElement(curX, curY, 1, 1, cO, bG, data)
- end
- word = word .. data
- curX = curX + 1
- pos = pos + 1
- end
- if curX > termX then
- curY = curY + 1
- curX = bCurX
- wordA = word
- word = ""
- end
- elseif event == "paste" and pos < _limit then
- if pos + #data > _limit then
- data = data:sub(1, _limit - pos)
- end
- if gField then
- local newWord, glyph = { }, ""
- for i = 1, #data do
- glyph = string.upper(data:sub(i, i))
- if symbols[glyph] then
- newWord[i] = glyph
- else
- newWord[i] = "?"
- end
- end
- data = table.concat(newWord)
- end
- if mask then
- local maskTable = { }
- for i = 1, #data do
- maskTable[i] = mask
- end
- drawElement(curX, curY, 1, 1, cO, bG, table.concat(maskTable))
- else
- drawElement(curX, curY, 1, 1, cO, bG, data:sub(1, 24))
- if #data > 24 then
- drawElement(curX, curY + 1, 1, 1, cO, bG, data:sub(25, 43))
- end
- end
- word = word .. data
- curX = curX + #data
- pos = pos + #data
- if curX > termX then
- curY = curY + 1
- curX = bCurX
- wordA = word:sub(1, 24)
- word = word:sub(25, 43) .. ""
- end
- elseif event == "mouse_click" then
- if mY ~= curY or mX < bCurX or mX >= bCurX + _limit then
- break
- end
- elseif event == "mouse_scroll" and runState == "viewing" then
- break
- end
- term.setCursorPos(curX, curY)
- end
- term.setCursorBlink(false)
- if wordA then
- word = wordA .. word
- wordA = nil
- end
- return word
- end
- local function requestIrisOpen()
- if not rednet.isOpen(netSide) then
- rednet.open(netSide)
- end
- drawElement(2, 4, termX, termY, nil, black, "")
- drawIrisPasswordUI()
- local irisPass = readInput(8, 7, white, gray, 12, nil, "*")
- local data = { program = "pSync", password = irisPass }
- rednet.send(pSyncHost, data)
- runState = "Dial"
- drawElement(2, 5, termX - 2, 5, nil, black, "")
- drawCLI()
- end
- local function goToPage()
- runState = "goPage" --# temporarily set runState
- drawElement((termX / 2) - 3, termY - 3, 8, 1, white, gray, " :Page: ") --# header
- drawElement((termX / 2) - 3, termY - 2, 8, 2, nil, nil, "") --# body
- drawElement((termX / 2) - 2, termY - 2, 6, 1, nil, black, "") --# input area bg
- local newPage = tonumber(readInput((termX / 2 - 1), termY - 2, lime, nil, 4)) --# user input
- drawElement((termX / 2) - 3, termY - 3, 8, 3, nil, nil, "") --# clear 'Page' dialogue
- gatePage = newPage or gatePage --# set gate page
- gatePage = math.max(1, gatePage)
- gatePage = math.min(gatePage, gatePages)
- if gatePage == gatePages and gatePages > 1 then --# if on the last page and there's more than one page...
- drawElement(2, 4, termX, termY, nil, nil, "") --# ...clear the data area
- end
- runState = "Dial" --# restore runState
- drawAddressList()
- drawNaviUI()
- end
- local function saveAndQuit()
- drawElement((termX / 2) - 9, math.floor(termY / 2) - 2, 20, 1, white, blue, "Save Addr Book ?")
- drawElement((termX / 2) - 9, math.floor(termY / 2) - 1, 20, 3, nil, gray, "")
- drawElement((termX / 2) - 8, math.floor(termY / 2), 8, 1, nil, green, "Save")
- drawElement((termX / 2) + 2, math.floor(termY / 2), 8, 1, nil, orange, "Quit")
- while true do
- local _, button, mX, mY = os.pullEvent("mouse_click")
- if mX > (termX / 2) - 10 and mX < (termX / 2) + 9 and mY > math.floor(termY / 2) - 3 and mY < math.floor(termY / 2) + 2 and button == 1 then
- if mX > (termX / 2) - 9 and mX < (termX / 2) - 1 and mY == math.floor(termY / 2) then
- flashChoice((termX / 2) - 8, math.floor(termY / 2), green, white, " Save ")
- saveData(gateData, "gate")
- return true
- elseif mX > (termX / 2) + 1 and mX < (termX / 2) + 9 and mY == math.floor(termY / 2) then
- flashChoice((termX / 2) + 2, math.floor(termY / 2), orange, white, " Quit ")
- return true
- end
- else
- runState = "Dial"
- drawElement(2, 5, termX - 2, termY - 7, nil, black, "") --# clear data area of screen
- drawAddressList()
- return false
- end
- end
- end
- local function inputKey()
- while true do
- local _, thisKey = os.pullEvent("key")
- if thisKey == keys.f1 and (runState == "Dial" or runState == "Help") then --# F1
- runState = runState == "Dial" and "Help" or "Dial"
- clearScreen(runState == "Dial" and black or white)
- drawCLI()
- end
- if runState == "Dial" then
- if thisKey == keys.home then
- gatePage = 1
- drawAddressList()
- drawNaviUI()
- elseif thisKey == keys.pageUp then
- gatePage = math.max(1, gatePage - 1)
- drawAddressList()
- drawNaviUI()
- elseif thisKey == keys.pageDown then
- gatePage = math.min(gatePage + 1, gatePages)
- if gatePage == gatePages and gatePages > 1 then
- drawElement(2, 4, termX-2, termY-4, nil, black, "")
- end
- drawAddressList()
- drawNaviUI()
- elseif thisKey == keys["end"] then
- gatePage = gatePages
- if gatePages > 1 then
- drawElement(2, 4, termX-2, termY-4, nil, black, "")
- end
- drawAddressList()
- drawNaviUI()
- end
- end
- end
- end
- local function inputMouse()
- while true do
- local _, mButton, mcX, mcY = os.pullEvent("mouse_click")
- if mcY == 1 and mButton == 1 then
- if mcX > termX - 3 and mcX <= termX then --# 'X' (exit button)
- flashChoice(termX - 1, 1, white, blue, "X")
- drawElement(termX - 1, 1, 1, 1, red, nil, "X")
- if runState == "Dial" then
- if gateChange then
- if saveAndQuit() then return end
- else
- break
- end
- else
- runState = "Dial"
- clearScreen()
- drawCLI()
- end
- elseif mcX < 4 and runState == "Dial" then --# 'H' (hosts button)
- drawElement(2, 1, 1, 1, gray, blue, "H")
- drawElement(1, 3, termX, termY, nil, black, "") --# clear most of screen
- drawElement(4, 7, 20, 1, white, blue, "pSync") --# pSync search header
- drawElement(4, 8, 20, 3, nil, gray, "Locating host...") --# pSync search body
- runState = "gateHosts"
- findHosts()
- elseif mcX > 4 and mcX < 8 and runState == "Dial" and thisGate ~= "NO HOST" then
- runState = "Iris"
- requestIrisOpen()
- end
- end
- if runState == "viewing" then --# Gate Viewing / Editing
- if mcY == 4 and mButton == 1 then
- if mcX > 1 and mcX < 11 then --# Name
- drawElement(2, 4, 1, 1, gray, black, addressBook[currentEdit].name)
- local newGateName = readInput(2, 4, yellow, nil, 9)
- if newGateName and newGateName ~= addressBook[currentEdit].name and newGateName ~= "" then
- addressBook[currentEdit].name = newGateName
- gateDataChange()
- end
- drawElement(2, 4, 1, 1, yellow, black, addressBook[currentEdit].name .. string.rep(" ", 9 - #addressBook[currentEdit].name))
- elseif mcX > 20 and mcX < 21 + #tostring(currentEdit) then --# Position / reorder
- drawElement(21, 4, 1, 1, gray, black, currentEdit)
- local oldPos = currentEdit
- local newPos = tonumber(readInput(21, 4, white, nil, 5))
- if newPos and newPos > 0 and newPos <= #addressBook and newPos ~= oldPos then
- local tempGateData = { }
- for k, v in pairs(addressBook[currentEdit]) do
- tempGateData[k] = v
- end
- table.remove(addressBook, currentEdit)
- table.insert(addressBook, newPos, tempGateData)
- currentEdit = newPos
- gateDataChange()
- end
- drawElement(21, 4, 1, 1, white, black, currentEdit .. string.rep(" ", 5 - #tostring(currentEdit)))
- end
- elseif mcY == 6 and mButton == 1 then
- if mcX > 1 and mcX < 11 then --# Address
- drawElement(2, 6, 1, 1, gray, black, addressBook[currentEdit].addr)
- local newGateAddress = string.upper(readInput(2, 6, yellow, nil, 9))
- if newGateAddress and (#newGateAddress == 7 or #newGateAddress == 9) and newGateAddress ~= addressBook[currentEdit].addr then
- addressBook[currentEdit].addr = newGateAddress
- if addressBook[currentEdit].name == "Name" then
- addressBook[currentEdit].name = newGateAddress
- drawElement(2, 4, #addressBook[currentEdit].name, 1, yellow, nil, addressBook[currentEdit].name .. string.rep(" ", 9 - #addressBook[currentEdit].name))
- end
- gateDataChange()
- end
- drawElement(2, 6, #addressBook[currentEdit].addr, 1, assignColor(currentEdit), nil, addressBook[currentEdit].addr .. " ")
- end
- elseif mcY == 8 and mButton == 1 then --# Classification
- if mcX > 1 and mcX < 4 + #assignRating(currentEdit) then
- drawRatingList(addressBook[currentEdit].rating)
- local selected = false
- local gRatings = { "B", "H", "V", "M", "S", "C", "D", "U", }
- while true do
- local _, button, mX, mY = os.pullEvent("mouse_click")
- if mX > 5 and mX < 25 and mY > 5 and mY < 14 then
- for i = 1, #gRatings do
- if mY == i + 5 then
- if addressBook[currentEdit].rating ~= gRatings[i] then
- addressBook[currentEdit].rating = gRatings[i]
- gateDataChange()
- end
- selected = true
- break
- end
- end
- if selected then break end
- else
- break
- end
- end
- drawGateLabels()
- end
- elseif mcY == 10 and mButton == 1 then --# Note
- if mcX > 1 and mcX < 2 + #addressBook[currentEdit].note:sub(1, 24) then
- if #addressBook[currentEdit].note > 24 then
- drawElement(2, 10, 1, 1, gray, black, addressBook[currentEdit].note:sub(1, 24))
- drawElement(2, 11, 1, 1, nil, nil, addressBook[currentEdit].note:sub(25, 43))
- else
- drawElement(2, 10, 1, 1, gray, black, addressBook[currentEdit].note)
- end
- local getNewNote = readInput(2, 10, white, nil, 43)
- if getNewNote and getNewNote ~= "" then
- addressBook[currentEdit].note = getNewNote
- gateDataChange()
- end
- if #addressBook[currentEdit].note > 24 then
- drawElement(2, 10, 1, 1, white, nil, addressBook[currentEdit].note:sub(1, 24))
- drawElement(2, 11, 1, 1, nil, nil, addressBook[currentEdit].note:sub(25, 43) .. string.rep(" ", 19 - #addressBook[currentEdit].note:sub(25, 43)))
- else
- drawElement(2, 10, 1, 1, white, nil, addressBook[currentEdit].note .. string.rep(" ", 24 - #addressBook[currentEdit].note))
- end
- end
- elseif mcY == 13 and mButton == 1 then --# Dimension
- if mcX > 6 and mcX < 7 + #addressBook[currentEdit].loc.dim then
- drawElement(7, 13, 1, 1, gray, black, addressBook[currentEdit].loc.dim)
- local getNewDim = readInput(7, 13, yellow, nil, 19)
- if getNewDim and getNewDim ~= "" then
- addressBook[currentEdit].loc.dim = getNewDim
- gateDataChange()
- end
- drawElement(7, 13, 1, 1, yellow, black, addressBook[currentEdit].loc.dim .. string.rep(" ", 19 - #addressBook[currentEdit].loc.dim))
- end
- elseif mcY == 14 and mButton == 1 then --# X
- if mcX > 4 and mcX < 5 + #tostring(addressBook[currentEdit].loc.x) then
- drawElement(5, 14, 1, 1, gray, black, addressBook[currentEdit].loc.x)
- local getNewX = tonumber(readInput(5, 14, silver, nil, 9))
- if getNewX then
- addressBook[currentEdit].loc.x = getNewX
- gateDataChange()
- end
- drawElement(5, 14, 1, 1, silver, black, addressBook[currentEdit].loc.x .. string.rep(" ", 9 - #tostring(addressBook[currentEdit].loc.x)))
- end
- elseif mcY == 15 and mButton == 1 then --# Y
- if mcX > 4 and mcX < 5 + #tostring(addressBook[currentEdit].loc.y) then
- drawElement(5, 15, 1, 1, gray, black, addressBook[currentEdit].loc.y)
- local getNewY = tonumber(readInput(5, 15, silver, nil, 9))
- if getNewY then
- addressBook[currentEdit].loc.y = getNewY
- gateDataChange()
- end
- drawElement(5, 15, 1, 1, silver, black, addressBook[currentEdit].loc.y .. string.rep(" ", 9 - #tostring(addressBook[currentEdit].loc.y)))
- end
- elseif mcY == 16 and mButton == 1 then --# Z
- if mcX > 4 and mcX < 5 + #tostring(addressBook[currentEdit].loc.z) then
- drawElement(5, 16, 1, 1, gray, black, addressBook[currentEdit].loc.z)
- local getNewZ = tonumber(readInput(5, 16, silver, nil, 9))
- if getNewZ then
- addressBook[currentEdit].loc.z = getNewZ
- gateDataChange()
- end
- drawElement(5, 16, 1, 1, silver, black, addressBook[currentEdit].loc.z .. string.rep(" ", 9 - #tostring(addressBook[currentEdit].loc.z)))
- end
- elseif mcY == termY - 1 and mButton == 1 then --# Save / Close
- if mcX > 5 and mcX < 13 and gateChange then
- flashChoice(6, termY - 1, white, green, " Save ")
- drawElement(6, termY - 1, 6, 1, silver, gray, "Save")
- saveData()
- elseif mcX > 14 and mcX < 22 then
- flashChoice(15, termY - 1, white, red, " Close ")
- runState = "Dial"
- drawElement(2, 4, termX, termY, nil, black, "")
- drawCLI()
- end
- end
- elseif runState == "Dial" then --# Dial
- if mcY == 3 then
- if mcX < 12 and mButton == 1 then --# pSync
- flashChoice(1, 3, cyan, white, " pSync ")
- drawElement(1, 3, 11, 1, white, cyan, "pSync")
- drawElement(1, 3, termX, termY, nil, black, "")
- drawElement(4, 7, 20, 1, nil, blue, "pSync")
- drawElement(4, 8, 20, 3, nil, gray, "Locating host...")
- runState = "syncHosts"
- findHosts()
- elseif mcX > 11 and mcX < 15 then --# Add Gate / Save Address Book
- if mButton == 1 then --# Add gate
- flashChoice(12, 3, green, white, " + ")
- drawElement(12, 3, 1, 1, orange, green, " + ")
- runState = "viewing"
- addNewAddress()
- elseif mButton == 2 and gateChange then --# Save Address Book
- flashChoice(12, 3, green, white, " + ")
- drawElement(12, 3, 1, 1, white, green, " + ")
- saveData()
- elseif mButton == 3 then --# Quick-Add gate
- flashChoice(12, 3, green, white, " + ")
- drawElement(12, 3, 1, 1, orange, green, " + ")
- addNewAddress(true)
- end
- elseif mcX > 14 and mButton == 1 then --# End Call
- flashChoice(15, 3, red, white, " END Call ")
- drawElement(15, 3, 12, 1, white, red, "END Call")
- netSend("endCall")
- end
- --# Dial a listed address, view it's info, or delete it
- elseif mcY > 4 and mcY < 18 then
- local magicNumber = ((gatePage - 1) * 13) + gatePage
- local xPos, yPos = 3, 5
- for i = magicNumber, #addressBook do
- if mcX >= xPos and mcX <= xPos + 8 and mcY == yPos then
- if mButton == 1 then
- if addressBook[i].addr == thisGate or addressBook[i].addr == thisGate:sub(1, 7) then
- --# do nothing
- else
- flashDial(addressBook[i].name, xPos, mcY, i)
- netSend(addressBook[i].addr)
- end
- elseif mButton == 2 then
- flashDial(addressBook[i].name, xPos, mcY, i)
- runState = "viewing"
- currentEdit = i
- drawGateLabels()
- elseif mButton == 3 then
- flashDial(addressBook[i].name, xPos, mcY, i)
- deleteGate(i)
- end
- break
- else
- yPos = yPos + 2
- if yPos >= termY - 2 then xPos = xPos + 13 yPos = 5 end
- if xPos > 16 then break end
- end
- end
- --# Page Navigation via click
- elseif mcY == termY and mButton == 1 then
- if mcX > 2 and mcX < 5 then --# Home
- gatePage = 1
- drawAddressList()
- drawNaviUI()
- elseif mcX > 5 and mcX < 7 then --# Page Back
- gatePage = math.max(1, gatePage - 1)
- drawAddressList()
- drawNaviUI()
- elseif mcX > (math.floor(termX / 2) - (math.floor(#pNum / 2))) and mcX < (math.floor(termX / 2) + (math.floor(#pNum / 2))) + 1 then --# Page Numbers (Go To Page dialogue)
- flashChoice((math.floor(termX / 2) - (math.floor(#pNum / 2))) + 1, termY, black, gray, pNum)
- drawElement((math.floor(termX / 2) - (math.floor(#pNum / 2))) + 1, termY, 1, 1, gray, black, pNum)
- goToPage()
- elseif mcX > 20 and mcX < 22 then --# Page Forward
- gatePage = math.min(gatePage + 1, gatePages)
- if gatePage == gatePages and gatePages > 1 then
- drawElement(2, 4, termX, termY, nil, black, "")
- end
- drawAddressList()
- drawNaviUI()
- elseif mcX > 22 and mcX < 25 then --# End
- gatePage = gatePages
- if gatePages > 1 then
- drawElement(2, 4, termX, termY, nil, black, "")
- end
- drawAddressList()
- drawNaviUI()
- end
- end
- elseif runState == "pSync" then --# pSync
- if mcX > 2 and mcX < termX - 2 and mButton == 1 then
- local followUp = false
- if mcY > 4 and mcY < 8 then --# Import
- drawElement(2, 5, termX - 2, 3, green, white, "GET Address Book")
- sleep(0.1)
- drawElement(2, 5, termX - 2, 3, white, green, "GET Address Book")
- pSync("pPull")
- saveData()
- followUp = true
- elseif mcY > 8 and mcY < 12 then --# Export
- drawElement(2, 9, termX - 2, 3, orange, white, "SEND Address Book")
- sleep(0.1)
- drawElement(2, 9, termX - 2, 3, white, orange, "SEND Address Book")
- pSync("pPush")
- followUp = true
- elseif mcY > 12 and mcY < 16 then --# Cancel
- drawElement(2, 13, termX - 2, 3, red, white, "C A N C E L")
- sleep(0.1)
- drawElement(2, 13, termX - 2, 3, white, red, "C A N C E L")
- followUp = true
- end
- if followUp then
- runState = "Dial"
- drawElement(2, 4, termX, termY, nil, black, "")
- drawCLI()
- end
- end
- elseif runState == "gateHosts" or runState == "syncHosts" then --# Hosts list
- local hostNames = { }
- for i = 1, #gateHosts do
- hostNames[i] = gateHosts[i]
- for j = 1, #addressBook do
- if addressBook[j].addr == gateHosts[i] then
- hostNames[i] = addressBook[j].name
- break
- end
- end
- end
- if mcX > 8 and mcX < 19 and mcY > 6 and mcY < 14 and mButton == 1 then
- local gSelect = false
- local gCounter = 0
- for i = 7, 15, 2 do
- gCounter = gCounter + 1
- if gCounter <= #pHosts then
- if mcY == i then
- drawElement(9, i, 11, 1, black, white, hostNames[gCounter])
- sleep(0.1)
- drawElement(9, i, 11, 1, gray, silver, hostNames[gCounter])
- pSyncHost = pHosts[gCounter]
- thisGate = gateHosts[gCounter]
- gSelect = true
- runState = runState == "gateHosts" and "Dial" or "pSync"
- break
- end
- else
- break
- end
- end
- if gSelect then
- drawElement(8, 5, 13, 12, nil, black, "") --# Clear hosts UI
- drawCLI()
- end
- end
- end
- end
- end
- local function inputScroll()
- while true do
- local _, data = os.pullEvent("mouse_scroll")
- if runState == "Dial" then
- gatePage = data == 1 and math.min(gatePage + 1, gatePages) or math.max(1, gatePage - 1)
- if gatePage == gatePages and gatePages > 1 then
- drawElement(2, 4, termX, termY, nil, black, "") --# clear address book area
- end
- drawAddressList()
- drawNaviUI()
- elseif runState == "viewing" then
- currentEdit = data == 1 and math.min(currentEdit + 1, #addressBook) or math.max(1, currentEdit - 1)
- term.setCursorBlink(false)
- drawElement(2, 4, termX, termY, nil, black, "")
- drawGateLabels()
- end
- end
- end
- local function missingComponent(which)
- clearScreen()
- if which == "colorPDA" then
- drawElement(2, 2, 1, 1, white, black, "No advanced pocket")
- drawElement(2, 3, 1, 1, nil, nil, "computer detected!")
- drawElement(2, 5, 1, 1, nil, nil, "ccDialer REQUIRES an")
- drawElement(2, 6, 1, 1, nil, nil, "advanced pocket computer.")
- elseif which == "modem" then
- drawElement(2, 2, 1, 1, red, black, "No wireless")
- drawElement(2, 3, 1, 1, nil, nil, "modem detected!")
- drawElement(2, 5, 1, 1, nil, nil, "ccDialer REQUIRES")
- drawElement(2, 6, 1, 1, nil, nil, "a wireless modem.")
- end
- term.setCursorPos(1, 9)
- return false
- end
- local function initMe()
- if not term.isColor() or not pocket then return missingComponent("colorPDA") end
- clearScreen()
- drawElement(4, 4, 21, 1, white, blue, "ccDialer Init...")
- drawElement(4, 5, 21, 9, nil, gray, "")
- drawElement(7, 6, 1, 1, nil, nil, "Check CC label")
- drawElement(7, 8, 1, 1, silver, nil, "Harware Discovery")
- drawElement(7, 10, 1, 1, nil, nil, "Ingest gate data")
- drawElement(7, 12, 1, 1, nil, nil, "Locate pSync host")
- drawElement(5, 6, 1, 1, orange, nil, "0")
- drawElement(5, 8, 1, 1, red, nil, "0")
- drawElement(5, 10, 1, 1, nil, nil, "0")
- drawElement(5, 12, 1, 1, nil, nil, "0")
- local ccLabel = os.getComputerLabel()
- if ccLabel == nil or tostring(ccLabel) == "" then
- os.setComputerLabel("ccDialer")
- end
- drawElement(5, 6, 1, 1, green, nil, "O")
- drawElement(5, 8, 1, 1, orange, nil, "0")
- drawElement(7, 8, 1, 1, white, nil, "Harware Discovery")
- for _, side in ipairs(rs.getSides()) do
- if peripheral.isPresent(side) then
- local perp = peripheral.getType(side)
- if perp == "modem" and peripheral.call(side, "isWireless") then
- rednet.open(side)
- netSide = side
- break
- end
- end
- end
- if netSide == "none" then return missingComponent("modem") end
- drawElement(5, 8, 1, 1, green, nil, "O")
- drawElement(5, 10, 1, 1, orange, nil, "0")
- drawElement(7, 10, 1, 1, white, nil, "Ingest gate data")
- if not fs.exists("/data") then fs.makeDir("/data") end
- ingestData()
- drawElement(5, 10, 1, 1, green, nil, "O")
- drawElement(5, 12, 1, 1, orange, nil, "0")
- drawElement(7, 12, 1, 1, white, nil, "Locate pSync host")
- findHosts()
- runState = "Dial"
- clearScreen()
- drawCLI()
- return true
- end
- if not initMe() then return end
- parallel.waitForAny(inputMouse, inputScroll, inputKey)
- shutDown()
- term.setBackgroundColor(black)
- term.setTextColor(white)
- term.clear()
- term.setCursorPos(1, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement