Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ LanteaCraft ]]--
- --[[ c c D H D ]]--
- --[[ core ver. 5.0.5 ]]--
- --[[ ui ver. 4.4.2 ]]--
- --[[ by Dog ]]--
- --[[ aka HydrantHunter ]]--
- --[[ with help from ]]--
- --[[ Bomb Bloke ]]--
- --[[ pastebin vMtcSz2e ]]--
- --[[ GPL v3 ]]--
- local ccDHDVer = "1.1.31"
- --[[
- Tested with/requires:
- - Minecraft 1.6.4
- - LanteaCraft (snapshot 82+ and RC1_15-RC1_22)
- - ComputerCraft ver. 1.57-1.58 for MC 1.6.4
- - HTTP API enabled (for pastebin installer - not required for ccDHD)
- - 1 Advanced Computer (color, mouse), 4 optional Advanced Monitors (color, touch)
- - gateLiaison running on an Advanced Computer (with 3 optional Advanced Monitors) or an Advanced Wireless Turtle (no monitors)
- - ccDHD also supports the Biometric Lock (Fistprint Scanner) in GopherATL's Biolocks MOD ver. 2.1.3 (updated for 1.6.4 by gamax92)
- ]]--
- if os.clock() < 5 then
- sleep(2)
- end
- -- AUTOMATIC/STATIC CONFIGURATION
- -- Default Settings
- local settingsData = "/data/DHDconfig"
- local dhdSettings = {
- thisGate = "--ERROR--",
- highlight = "YES",
- password = "password",
- monA = "none",
- monB = "none",
- bio = { lock = "OFF", func = "none", auth = 4 },
- net = "C",
- gate = 65536,
- channels = { send = 1776, recv = 1787 },
- pSync = "OFF",
- pChannels = { send = 24747, recv = 24242 },
- ecShield = "ON",
- startShield = "OFF",
- callEnd = "OFF",
- logs = "OFF",
- lastGate = "/data/DHDlast",
- gateHistory = "/data/DHDhistory",
- gateData = "/data/DHDgates",
- }
- local allGates = { { addr = "NEWGATE", rating = "U", note = "short note", loc = { x = 99999, y = 99999, z = 99999, dim = "Overworld", } } }
- local fistAuth = false
- local longName, tY
- local drawCLI, drawRatingList, assignRating, assignColor
- -- Peripherals
- local termX, termY = term.getSize() -- portable 26x20 / standard 51x19 / cBang & OneOS = 51x18
- local modem = nil -- Modem (for ccNet)
- local monA = dhdSettings.monA -- List monitor
- local monB = dhdSettings.monB -- Marquee Monitor
- local hardware = { netSide = "none", bioSide = "none" } -- Modem and Biolock sides
- -- Status Info
- local shieldStatus, gateStatus, secureStatus = "QRY", "QRY", "QRY"
- local runState, currentState, displayState = "init", "ZZ", "list"
- local kernelState, menuState = false, false
- local configChange, gateChange = false, false
- local tempState, currentEdit, fuelGauge, dialAddress
- -- Gate List
- local pNum = "001"
- local numPages, pageNum = 1, 1
- local listPages, listPage = 1, 1
- -- Call History
- local histPages, histPage = 1, 1
- local callHistory, lastCall = { }, { }
- -- Color Definitions
- local white = colors.white
- local lgray = 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 lblue = colors.lightBlue
- local cyan = colors.cyan
- local lime = colors.lime
- local green = colors.green
- -- END AUTOMATIC/STATIC CONFIGURATION
- local function pSync(pushpull) -- Sync allGates with a portable advanced computer running ccDialer
- if pushpull == "pPull" then
- sleep(0.1)
- local pGateData = textutils.serialize(allGates)
- modem.transmit(dhdSettings.pChannels.send, dhdSettings.pChannels.recv, pGateData)
- elseif pushpull == "pPush" then
- local newGates = { os.pullEvent("modem_message") }
- if newGates[3] == dhdSettings.pChannels.recv and newGates[4] == dhdSettings.pChannels.send then
- allGates = { }
- local newGateData = newGates[5]
- allGates = textutils.unserialize(newGateData)
- gateChange = true
- if pageNum == numPages then term.setBackgroundColor(black) term.clear() end
- drawCLI()
- end
- end
- end
- local function recordSessionData() -- Human readable log files (last gate & history)
- if not fs.exists("/data") then fs.makeDir("/data") end
- local dateStamp = tostring(textutils.formatTime(os.time(), false) .. " / Day " .. tostring(os.day()))
- local lastCall = fs.open(dhdSettings.lastGate, "w")
- lastCall.writeLine(dateStamp)
- lastCall.writeLine(dialAddress)
- lastCall.close()
- if dhdSettings.logs == "ON" then
- local gateArchive = fs.open(dhdSettings.gateHistory, fs.exists(dhdSettings.gateHistory) and "a" or "w")
- gateArchive.writeLine(dateStamp)
- gateArchive.writeLine(dialAddress)
- gateArchive.close()
- end
- end
- local function updateStatus(newInfo) -- Update status info
- if newInfo == "000" then -- bit/trit/bit
- shieldStatus = "OFF" -- 1st/bit = shield
- gateStatus = "Disconnected" -- 2nd/trit = connection/dialing
- secureStatus = "allclear"
- fuelGauge = false -- 3rd/bit = fuel
- dialAddress = ""
- elseif newInfo == "001" then
- shieldStatus = "OFF"
- gateStatus = "Disconnected"
- secureStatus = "allclear"
- dialAddress = ""
- fuelGauge = true
- elseif newInfo == "010" then
- shieldStatus = "OFF"
- gateStatus = "Connected"
- secureStatus = "allclear"
- fuelGauge = false
- elseif newInfo == "011" then
- shieldStatus = "OFF"
- gateStatus = "Connected"
- secureStatus = "allclear"
- fuelGauge = true
- elseif newInfo == "020" then
- shieldStatus = "OFF"
- gateStatus = "Dialing"
- secureStatus = "allclear"
- fuelGauge = false
- if dialAddress == "" then
- dialAddress = "Inbound"
- recordSessionData()
- dialAddress = ""
- else
- recordSessionData()
- end
- elseif newInfo == "021" then
- shieldStatus = "OFF"
- gateStatus = "Dialing"
- secureStatus = "allclear"
- fuelGauge = true
- if dialAddress == "" then
- dialAddress = "Inbound"
- recordSessionData()
- dialAddress = ""
- else
- recordSessionData()
- end
- elseif newInfo == "100" then
- shieldStatus = "ON"
- gateStatus = "Disconnected"
- secureStatus = "allclear"
- dialAddress = ""
- fuelGauge = false
- elseif newInfo == "101" then
- shieldStatus = "ON"
- gateStatus = "Disconnected"
- secureStatus = "allclear"
- dialAddress = ""
- fuelGauge = true
- elseif newInfo == "110" then
- shieldStatus = "ON"
- gateStatus = "Connected"
- secureStatus = "allclear"
- fuelGauge = false
- elseif newInfo == "111" then
- shieldStatus = "ON"
- gateStatus = "Connected"
- secureStatus = "allclear"
- fuelGauge = true
- elseif newInfo == "120" then
- shieldStatus = "ON"
- gateStatus = "Dialing"
- secureStatus = "allclear"
- fuelGauge = false
- if dialAddress == "" then
- dialAddress = "Inbound"
- recordSessionData()
- dialAddress = ""
- else
- recordSessionData()
- end
- elseif newInfo == "121" then
- shieldStatus = "ON"
- gateStatus = "Dialing"
- secureStatus = "allclear"
- fuelGauge = true
- if dialAddress == "" then
- dialAddress = "Inbound"
- recordSessionData()
- dialAddress = ""
- else
- recordSessionData()
- end
- elseif newInfo == "Dialing" then
- gateStatus = "Dialing"
- secureStatus = "allclear"
- if dialAddress == "" then
- dialAddress = "Inbound"
- recordSessionData()
- dialAddress = ""
- else
- recordSessionData()
- end
- elseif newInfo == "YY0" then
- secureStatus = "allclear"
- shieldStatus = "OFF"
- gateStatus = "Disconnected"
- fuelGauge = false
- dialAddress = ""
- term.setBackgroundColor(black)
- term.clear()
- elseif newInfo == "YY1" then
- secureStatus = "allclear"
- shieldStatus = "OFF"
- gateStatus = "Disconnected"
- fuelGauge = true
- dialAddress = ""
- term.setBackgroundColor(black)
- term.clear()
- elseif newInfo == "XX0" then
- secureStatus = "lockdown"
- shieldStatus = "ON"
- gateStatus = "Disconnected"
- fuelGauge = false
- dialAddress = ""
- elseif newInfo == "XX1" then
- secureStatus = "lockdown"
- shieldStatus = "ON"
- gateStatus = "Disconnected"
- fuelGauge = true
- dialAddress = ""
- elseif newInfo == "pPull" or newInfo == "pPush" then
- pSync(newInfo)
- return
- end
- if newInfo ~= "pPush" and newInfo ~= "pPull" and currentState ~= "ZZ" and runState ~= "init" then currentState = newInfo end
- if currentState ~= "ZZ" and runState ~= "init" then drawCLI() end
- return
- end
- local function netSend(dataPack)
- if dhdSettings.net == "R" then
- rednet.send(dhdSettings.gate, dataPack)
- elseif dhdSettings.net == "C" then
- modem.transmit(dhdSettings.channels.send, dhdSettings.channels.recv, dataPack)
- end
- end
- local function netReceive()
- while true do
- if dhdSettings.net == "R" then
- local id, message = rednet.receive()
- if id == dhdSettings.gate then
- if currentState ~= message then
- updateStatus(message)
- return
- end
- end
- elseif dhdSettings.net == "C" then
- local netEvent = { os.pullEvent("modem_message") }
- if netEvent[3] == dhdSettings.channels.recv and netEvent[4] == dhdSettings.channels.send then
- if currentState ~= netEvent[5] then
- updateStatus(netEvent[5])
- return
- end
- end
- end
- end
- end
- local function pSyncReceive()
- while true do
- local pSyncEvent = { os.pullEvent("modem_message") }
- if pSyncEvent[3] == dhdSettings.pChannels.recv and pSyncEvent[4] == dhdSettings.pChannels.send then
- if pSyncEvent[5] == "pPull" or pSyncEvent[5] == "pPush" then
- pSync(pSyncEvent[5])
- else
- if #tostring(pSyncEvent[5]) > 6 and #tostring(pSyncEvent[5]) < 10 then
- dialAddress = pSyncEvent[5]
- netSend(dialAddress)
- end
- end
- end
- end
- end
- local function makeLongName(name) -- This spaces out the name for a 7 character address
- if #name ~= 7 then
- return name
- end
- local letters = { 'A', 'A', 'A', 'A', 'A', 'A', 'A' }
- for i = 1, 7 do
- letters[i] = i == 7 and name:sub(7) or name:sub(i, i) .. " "
- end
- return table.concat(letters)
- end
- local function saveData(filename, filetype)
- menuState = false
- if not fs.exists("/data") then fs.makeDir("/data") end
- if fs.exists("/disk") and filename == ("/disk/data/DHDgates") then
- if not fs.exists("/disk/data") then fs.makeDir("/disk/data") end
- end
- local dhdConfig = fs.open(tostring(filename), "w") or error("saveData(): Cannot open " .. filename .. " for writing", 2)
- if filetype == "cfg" then
- dhdConfig.write(textutils.serialize(dhdSettings))
- configChange = false
- elseif filetype == "gate" then
- dhdConfig.write(textutils.serialize(allGates))
- if fs.exists("/disk/DHDgates") then fs.delete("/disk/DHDgates") end
- if filename == dhdSettings.gateData then gateChange = false end
- end
- dhdConfig.close()
- end
- local function ingestData(fileName, fileType)
- if not fs.exists(tostring(fileName)) then return end
- local dhdConfig = fs.open(tostring(fileName), "r") or error("ingestData(): Cannot open " .. fileName .. " for reading", 2)
- local dhdCfg = dhdConfig.readAll()
- dhdConfig.close()
- if fileType == "cfg" then
- dhdSettings = textutils.unserialize(dhdCfg)
- if dhdSettings.monA ~= "none" then
- monA = peripheral.wrap(dhdSettings.monA)
- end
- if dhdSettings.monB ~= "none" then
- monB = peripheral.wrap(dhdSettings.monB)
- end
- if dhdSettings.gate == nil and dhdSettings.server ~= nil then
- dhdSettings.gate = dhdSettings.server
- dhdSettings.server = nil
- saveData(settingsData, "cfg")
- end
- longName = makeLongName(dhdSettings.thisGate)
- elseif fileType == "gate" then
- allGates = textutils.unserialize(dhdCfg)
- if allGates[1].addr == "NEWGATE" then
- allGates[1].addr = dhdSettings.thisGate
- end
- numPages = math.ceil(#allGates / 24)
- listPages = math.ceil(#allGates / 8)
- pageNum = 1
- listPage = 1
- if fs.exists("/disk/DHDgates") then fs.delete("/disk/DHDgates") end
- if fileName == "/disk/data/DHDgates" then gateChange = true end
- end
- end
- local function ingestLogData()
- if not fs.exists(dhdSettings.gateHistory) then
- local tmpHist = fs.open(dhdSettings.gateHistory, "w")
- tmpHist.close()
- end
- if fs.exists(dhdSettings.gateHistory) then
- local dhdHist = fs.open(dhdSettings.gateHistory, "r") or error("ingestLogData(): Cannot open /data/DHDhistory for reading", 2)
- while true do
- local timeDate = dhdHist.readLine()
- local gateAddr = dhdHist.readLine()
- if gateAddr == "" or gateAddr == nil then gateAddr = "No Data" end
- if timeDate == nil or timeDate == "" then break end
- local tTime = timeDate:sub(1, string.find(timeDate, " / ")) -- separate time from time/day
- local dDate = timeDate:sub(#tTime + 7) -- separate day from time/day
- if #tTime == 8 then tTime = " " .. tTime end -- move single digit hour times to the right one space (this must happen after date so date doesn't get skewed by 1)
- table.insert(callHistory, 1, tTime .. "_" .. dDate .. "/" .. gateAddr) -- insert concatenated data into callHistory table
- end
- dhdHist.close()
- end
- histPages = math.ceil(#callHistory / 10) -- paginate call logs
- if histPages < 1 then histPages = 1 end -- probably not necessary with math.ceil
- if not fs.exists(dhdSettings.lastGate) then
- local tmpLast = fs.open(dhdSettings.lastGate, "w")
- tmpLast.close()
- end
- local dhdLast = fs.open(dhdSettings.lastGate, "r") or error("ingestLogData(): Cannot open /data/DHDlast for reading", 2)
- for i = 1, 2, 1 do
- local lastInfo = dhdLast.readLine()
- table.insert(lastCall, lastInfo)
- end
- dhdLast.close()
- end
- do
- local colorBurst = {
- B = { blue, "Base/Outpost/Hub" },
- H = { lblue, "Home/Camp" },
- V = { brown, "Village" },
- M = { purple, "Misc/Special" },
- S = { green, "Safe" },
- C = { orange, "Caution" },
- D = { red, "Danger" },
- U = { lgray, "Unknown" },
- }
- assignColor = function(gateNumber)
- return colorBurst[allGates[gateNumber].rating][1]
- end
- assignRating = function(gateNumber)
- return colorBurst[allGates[gateNumber].rating][2]
- end
- end
- local function displayMarquee()
- if dhdSettings.monB == "none" then return end
- monB.setTextScale(2)
- monB.setBackgroundColor(black)
- monB.clear()
- monB.setTextColor(cyan)
- monB.setCursorPos(1, 1)
- monB.write("Stargate")
- monB.setTextColor(yellow)
- if #dhdSettings.thisGate == 7 then
- monB.setCursorPos(2, 2)
- else
- monB.setCursorPos(4, 2)
- end
- monB.write(longName)
- end
- local function displayGateList()
- local mX, mY = monA.getSize()
- local firstGate = (listPage - 1) * 8 + 1
- local tmY = 1
- monA.setTextScale(0.5)
- monA.setBackgroundColor(black)
- monA.clear()
- for i = firstGate, firstGate + 7, 1 do
- if tmY == 9 then break end
- if i > #allGates then break end
- local tmX = 5
- if #allGates[i].addr > 7 then tmX = 4 end
- monA.setCursorPos(tmX, tmY)
- monA.setTextColor(assignColor(i))
- if dhdSettings.thisGate == allGates[i].addr and dhdSettings.highlight == "YES" then
- monA.setTextColor(gray)
- end
- monA.write(allGates[i].addr)
- tmY = tmY + 1
- end
- monA.setBackgroundColor(cyan)
- monA.setTextColor(white)
- monA.setCursorPos(1, 10)
- monA.write(" /\\ \\/ ")
- end
- local function displayNotes(pY)
- local listEntry = (listPage - 1) * 8 + pY
- if listEntry > #allGates then listEntry = #allGates end
- if listEntry < 1 then listEntry = 1 end
- if dhdSettings.monA ~= "none" then
- monA.setBackgroundColor(black)
- monA.clear()
- if #allGates[listEntry].addr > 7 then
- monA.setTextScale(0.5)
- monA.setCursorPos(4, 5)
- else
- monA.setTextScale(1)
- monA.setCursorPos(1, 3)
- end
- monA.setTextColor(assignColor(listEntry))
- monA.write(allGates[listEntry].addr)
- end
- if dhdSettings.monB ~= "none" then
- monB.setTextScale(1)
- monB.setBackgroundColor(black)
- monB.clear()
- monB.setCursorPos(1, 2)
- monB.setTextColor(lblue)
- monB.write(allGates[listEntry].loc.dim)
- monB.setCursorPos(1, 4)
- monB.setTextColor(white)
- monB.write(allGates[listEntry].note)
- end
- end
- local function displayStatus()
- if dhdSettings.monB == "none" then return end
- local longAddress = ""
- monB.setTextScale(2)
- monB.setBackgroundColor(black)
- monB.clear()
- monB.setCursorPos(1, 1)
- if (gateStatus == "Dialing" or gateStatus == "Connected") and (dialAddress ~= "" and dialAddress ~= nil) then
- monB.setTextColor(lblue)
- if gateStatus == "Dialing" then
- monB.write("Dialing")
- elseif gateStatus == "Connected" then
- monB.write("Connected to")
- end
- local xPos = 9 - #dialAddress
- if xPos < 2 then
- xPos = 4
- longAddress = dialAddress
- end
- monB.setCursorPos(xPos, 2)
- longAddress = makeLongName(dialAddress)
- monB.setTextColor(yellow)
- monB.write(longAddress)
- elseif (gateStatus == "Dialing" or gateStatus == "Connected" ) and (dialAddress == "" or dialAddress == nil) then
- monB.setTextColor(yellow)
- monB.write("Incoming")
- monB.setCursorPos(2, 2)
- monB.write("Connection")
- else
- if displayState == "list" then
- displayMarquee()
- elseif displayState == "info" then
- displayNotes(tY)
- end
- end
- end
- local function drawElement(x, y, w, h, txtColor, bgColor, text)
- local sText = text and tostring(text) or ""
- term.setCursorPos(x, y)
- if type(w) == "string" then
- term.setBackgroundColor(w == "OFF" and gray or green)
- term.write(" ")
- term.setBackgroundColor(w == "OFF" and red or gray)
- term.write(" ")
- else
- if bgColor then term.setBackgroundColor(bgColor) end
- if w > #sText or h > 1 then -- We're 'drawing' something more than text
- for i = 1, h do --
- term.write(string.rep(" ", w)) -- Draw the 'element' (box/rectangle/line-seg)
- term.setCursorPos(x, y + i) --
- end
- end
- if sText ~= "" then
- if txtColor then term.setTextColor(txtColor) end
- if w < #sText then w = #sText end -- Ensure minimum length
- local xW = (x + math.floor(w / 2)) - math.floor(#sText / 2) -- Center the text horizontally
- local xH = y + math.floor(h / 2) -- Center the text vertically
- term.setCursorPos(xW, xH)
- term.write(sText)
- end
- end
- end
- local function drawHeader()
- local bgColor
- term.setBackgroundColor(black)
- term.setTextColor(white)
- if secureStatus == "allclear" then
- local runStates = {
- Dial = blue,
- DialCfg = lblue,
- rCmd = blue,
- viewing = blue,
- goPage = blue,
- Edit = brown,
- EditCfg = lblue,
- GateEdit = brown,
- Trim = orange,
- logs = yellow,
- quit = purple,
- init = blue,
- }
- bgColor = runStates[runState]
- elseif secureStatus == "lockdown" then
- bgColor = red
- end
- drawElement(1, 1, termX, 1, runState == "logs" and black or white, bgColor, longName)
- if runState == "logs" then -- If we're viewing the logs, show the last call info instead of connect/shield info
- term.setBackgroundColor(gray)
- term.setTextColor(lgray)
- drawElement(1, 2, termX, 3, nil, gray, "")
- drawElement(2, 2, 23, 1, yellow, gray, "C A L L H I S T O R Y")
- drawElement(termX-6, 2, 7, 1, red, lgray, " Close ")
- drawElement(termX-6, 4, 7, 1, orange, lgray, " Clear ")
- drawElement(2, 3, 11, 1, lgray, gray, "Last Call: ")
- term.setTextColor(white)
- if lastCall[1] == nil and lastCall[2] == nil then
- lastCall[1], lastCall[2] = "none" .. string.rep(" ", 13), "nogate"
- end
- term.write(lastCall[1] .. " ")
- term.setTextColor(lblue)
- term.write(lastCall[2])
- drawElement(2, 4, 25, 1, black, gray, "Time Day Gate")
- return
- end
- if (runState == "Dial" or runState == "Edit") and secureStatus == "allclear" then -- Dial and Edit modes get the -DHD- menu
- drawElement(2, 1, 5, 1, white, black, "-DHD-")
- end
- drawElement(1, 2, termX, 3, nil, gray, "") -- Draw 'status' area
- if #dhdSettings.thisGate > 7 then
- drawElement(2, 3, 7, 1, lgray, gray, "Iris is")
- else
- drawElement(2, 3, 9, 1, lgray, gray, "Shield is")
- end
- drawElement(20, 3, 5, 1, lgray, gray, "Gate:")
- local tgColor
- term.setBackgroundColor(gray)
- -- Shield & Gate Status
- if shieldStatus == "ON" then
- tgColor = lime
- elseif shieldStatus == "OFF" then
- tgColor = orange
- else
- tgColor = red
- end
- if #dhdSettings.thisGate > 7 and shieldStatus == "ON" then -- Iris open/closed
- drawElement(10, 3, 6, 1, tgColor, gray, "CLOSED")
- elseif #dhdSettings.thisGate > 7 and shieldStatus == "OFF" then
- drawElement(10, 3, 4, 1, tgColor, gray, "OPEN")
- else
- drawElement(12, 3, (#shieldStatus) + 1, 1, tgColor, gray, shieldStatus .. " ") -- Shield ON/OFF
- end
- if gateStatus == "Connected" then
- tgColor = orange
- elseif gateStatus == "Disconnected" then
- tgColor = lime
- elseif gateStatus == "Dialing" then
- tgColor = cyan
- else
- tgColor = red
- end
- term.setTextColor(tgColor)
- term.setCursorPos(26, 3)
- if (gateStatus == "Connected" or gateStatus == "Dialing") and (dialAddress == "" or dialAddress == nil) then
- term.write("Incoming Connection")
- else
- if gateStatus == "Connected" and dialAddress ~= "" and dialAddress ~= nil then
- term.write(gateStatus .. " to" .. string.rep(" ", 10))
- term.setCursorPos(39, 3)
- else
- term.write(gateStatus .. string.rep(" ", 13))
- term.setCursorPos(34, 3)
- end
- if gateStatus ~= "Disconnected" then
- term.setTextColor(yellow)
- term.write(dialAddress)
- end
- if gateStatus == "Disconnected" and fuelGauge == false then
- local nf = "N O F U E L" .. string.rep(" ", 13)
- drawElement(26, 3, 1, 1, red, gray, nf)
- end
- end
- if secureStatus == "allclear" then displayStatus() end
- end
- local function drawControlUI()
- local dhdCommandOptions = {
- " D I A L",
- " E D I T",
- " T R I M",
- "Shield", "Iris",
- "END Call",
- "LOCKDOWN",
- "rCmd",
- "+ Entry",
- "Import",
- "Export",
- "Save",
- "- Undo -",
- "-COMMIT-",
- }
- drawElement(42, 6, 10, 11, nil, gray, "") -- Control UI 'box'
- term.setTextColor(white)
- term.setCursorPos(43, 7)
- if runState == "Dial" then
- if fuelGauge then -- FUEL
- term.setBackgroundColor(green) -- full color
- else --
- term.setBackgroundColor(red) -- empty color
- end
- term.write(dhdCommandOptions[1] .. " ") -- D I A L
- elseif runState == "Edit" then
- term.setBackgroundColor(brown)
- term.write(dhdCommandOptions[2] .. " ") -- E D I T
- elseif runState == "Trim" then
- term.setBackgroundColor(orange)
- term.write(dhdCommandOptions[3] .. " ") -- T R I M
- end
- if runState == "Dial" then
- if #dhdSettings.thisGate == 7 then
- drawElement(43, 9, 1, 1, white, lblue, dhdCommandOptions[4] .. " ") -- Shield
- else
- drawElement(43, 9, 1, 1, white, lblue, dhdCommandOptions[5] .. " ") -- Iris
- end
- if shieldStatus == "ON" then
- drawElement(termX, 9, 1, 1, nil, green, "") -- Iris/Shield pip ON
- else
- drawElement(termX, 9, 1, 1, nil, orange, "") -- Iris/Shield pip OFF
- end
- drawElement(43, 11, 1, 1, black, orange, dhdCommandOptions[6] .. " ") -- endCall
- drawElement(43, 13, 1, 1, orange, red, dhdCommandOptions[7] .. " ") -- Lockdown
- drawElement(43, 15, 1, 1, gray, cyan, dhdCommandOptions[8] .. " ") -- rCmd
- elseif runState == "Edit" then
- if #allGates < 23977 then
- drawElement(43, 9, 1, 1, white, blue, dhdCommandOptions[9] .. " ") -- +Entry
- end
- drawElement(43, 11, 1, 1, white, orange, dhdCommandOptions[10] .. " ") -- Import Gate Data
- drawElement(43, 13, 1, 1, white, green, dhdCommandOptions[11] .. " ") -- Export Gate Data
- if gateChange then
- drawElement(43, 15, 1, 1, lime, cyan, dhdCommandOptions[12] .. " ") -- Save Gate Data
- term.setTextColor(lime)
- else
- drawElement(43, 15, 1, 1, white, cyan, dhdCommandOptions[12] .. " ") -- Save Gate Data
- end
- elseif runState == "Trim" then
- drawElement(43, 11, 8, 1, gray, lgray, dhdCommandOptions[13] .. " ") -- Undo
- drawElement(43, 13, 8, 1, black, red, dhdCommandOptions[14] .. " ") -- Commit
- end
- term.setBackgroundColor(black)
- end
- local function drawNaviUI()
- pNum = tostring(pageNum)
- if pageNum < 100 then pNum = "0" .. pNum end -- Add a "0" before double digit page numbers
- if pageNum < 10 then pNum = "0" .. pNum end -- Add another "0" before single digit page numbers
- drawElement(((termX / 2) - (math.floor(pNum:len() / 4))) - 5, termY, 3, 1, lgray, black, pNum) -- Page Number
- if pageNum > 1 then
- drawElement((termX / 2) - 14, termY, 7, 1, gray, black, "<< BACK") -- Show "BACK" option if page number is > 1
- elseif pageNum == 1 then
- drawElement((termX / 2) - 14, termY, 7, 1, gray, black, string.rep(" ", 7)) -- Overwrite "BACK" instead of clearing screen
- end
- if pageNum < numPages then
- drawElement(termX / 2, termY, 7, 1, gray, black, "NEXT >>") -- Show "NEXT" option if page number is < numPages
- elseif pageNum == numPages then
- drawElement(termX / 2, termY, 7, 1, gray, black, string.rep(" ", 7)) -- Overwrite "NEXT" instead of clearing screen
- end
- end
- local function drawMainUI() -- Gate Address Book (Dial / Edit / Trim)
- local xPos, yPos = 2, 4
- local j = ((pageNum - 1) * 23) + pageNum
- local k = ((pageNum - 1) * 24)
- for i = j, #allGates, 1 do
- if i > k and i < k + 7 then -- Column 1
- xPos, yPos = 2, 4
- elseif i > k + 6 and i < k + 13 then -- Column 2
- xPos, yPos = 12, -8
- elseif i > k + 12 and i < k + 19 then -- Column 3
- xPos, yPos = 22, -20
- elseif i > k + 18 and i < k + 25 then -- Column 4
- xPos, yPos = 32, -32
- end
- term.setCursorPos(xPos, yPos + ((i - ((pageNum - 1) * 24)) * 2))
- if runState == "Dial" then
- term.setBackgroundColor(assignColor(i))
- if dialAddress == allGates[i].addr and dhdSettings.thisGate ~= allGates[i].addr then -- Highlight the gate being dialed
- term.setTextColor(black)
- else
- term.setTextColor(white)
- end
- if dhdSettings.thisGate == allGates[i].addr and dhdSettings.highlight == "YES" then -- Highlight this gate / Dial
- term.setTextColor(lgray)
- term.setBackgroundColor(gray)
- end
- elseif runState == "Edit" then
- term.setBackgroundColor(black)
- term.setTextColor(assignColor(i))
- if dhdSettings.thisGate == allGates[i].addr and dhdSettings.highlight == "YES" then -- Highlight this gate / Edit
- term.setTextColor(gray)
- end
- elseif runState == "Trim" then
- term.setBackgroundColor(gray)
- term.setTextColor(assignColor(i))
- if dhdSettings.thisGate == allGates[i].addr and dhdSettings.highlight == "YES" then -- Highlight this gate / Trim
- term.setTextColor(black)
- end
- end
- if i > (pageNum * 24) or i > #allGates then
- break
- else
- if #allGates[i].addr < 10 then
- local spacer
- local spacerSet = { Dial = " ", Edit = "|", Trim = "/", }
- for l, m in pairs(spacerSet) do
- if runState == tostring(l) then
- spacer = m
- end
- end
- term.write(string.rep(spacer, math.ceil((9 - #allGates[i].addr) / 2)) .. allGates[i].addr .. string.rep(spacer, math.floor((9 - #allGates[i].addr) / 2))) -- Address
- else
- term.write("ERROR #10") -- ERROR #10 = address is 10 or more characters
- end
- end
- end
- term.setBackgroundColor(black)
- end
- local function drawHelpUI()
- local colorDefs = {
- blue,
- green,
- purple,
- lblue,
- orange,
- lgray,
- brown,
- red
- }
- local colorDesc = {
- "Base/Outpost/Hub",
- "Secured/Safe",
- "Misc./Special",
- "Home/Camp",
- "Caution",
- "Unknown",
- "Village",
- "Danger",
- }
- local colorCount = #colorDesc
- local xMod = 2
- local yMod = 4
- term.setBackgroundColor(black)
- term.clear()
- local hColor
- if runState == "DialHelp" then -- Header color
- hColor = cyan
- elseif runState == "EditHelp" then
- hColor = brown
- end
- drawElement(1, 1, termX, 1, nil, hColor, "") -- Header
- drawElement((termX / 2) - (((#runState - 4) / 2) + 3), 1, 11, 1, white, gray, runState:sub(1, #runState - 4) .. " Help") -- Header text
- drawElement(1, 2, termX, 1, nil, gray, "")
- drawElement(1, termY, termX, 1, nil, gray, "") -- Footer
- drawElement(2, 2, 9, 1, lgray, gray, "-- Key --")
- drawElement(termX-6, 2, 7, 1, red, lgray, " Close ")
- for q, r in ipairs(colorDefs) do -- Color key for gate classifications
- drawElement(xMod, yMod, 1, 1, r, black, colorDesc[q])
- if xMod == 2 then
- xMod = 20
- elseif xMod == 20 then
- xMod = 38
- elseif xMod == 38 then
- xMod = 2
- yMod = yMod + 1
- end
- end
- drawElement(1, colorCount, termX, 1, nil, gray, "")
- drawElement(2, colorCount, 11, 1, lgray, gray, "-- Notes --")
- local lowLine = "ccDHD ver. " .. ccDHDVer .. string.rep(" ", 5) .. "cc# " .. os.getComputerID()
- drawElement(2, termY, 1, 1, lgray, gray, lowLine)
- local tmpLabel = os.getComputerLabel()
- drawElement(termX-#tmpLabel, termY, 1, 1, lgray, gray, tmpLabel)
- if runState == "DialHelp" then
- drawElement(2, colorCount + 2, 31, 1, white, black, "- Left click an address to dial")
- drawElement(2, colorCount + 3, 40, 1, white, black, "- Right click an address to view details")
- drawElement(2, colorCount + 4, 42, 1, white, black, "- rCmd: manually send commands to the gate")
- drawElement(2, colorCount + 5, 43, 1, white, black, " - ADDRESS / sON / sOFF / endCall / hangup")
- drawElement(2, colorCount + 6, 22, 1, white, black, " - lockdown / restart")
- drawElement(2, colorCount + 7, 27, 1, white, black, " - reboot & quit are local")
- drawElement(2, colorCount + 8, 37, 1, white, black, " - reset = reboots DHD & gateLiaison")
- elseif runState == "EditHelp" then
- drawElement(2, colorCount + 2, 42, 1, white, black, "- EDIT Mode: Left click an address to edit")
- drawElement(2, colorCount + 3, 49, 1, white, black, " Right click an address for Trim Mode")
- drawElement(2, colorCount + 4, 47, 1, white, black, " '+ Entry' Right click '+ Entry' to quick-add")
- drawElement(2, colorCount + 5, 41, 1, white, black, " 'Import' Load gate data from diskette")
- drawElement(2, colorCount + 6, 39, 1, white, black, " 'Export' Save gate data to diskette")
- drawElement(2, colorCount + 7, 44, 1, white, black, "- TRIM Mode: Left click an address to delete")
- drawElement(2, colorCount + 8, 49, 1, white, black, " '-COMMIT-' Saves new gate data, exits Trim Mode")
- drawElement(2, colorCount + 9, 47, 1, white, black, " '- Undo -' Cancels deletions, exits Trim Mode")
- end
- end
- local function drawSettingsUI()
- term.setBackgroundColor(black)
- term.clear()
- drawElement(1, 1, termX, 1, nil, lblue, "")
- drawElement(1, 2, termX, 1, nil, gray, "")
- local settingsHeader = " " .. dhdSettings.thisGate .. " Settings "
- drawElement((termX / 2) - ((#dhdSettings.thisGate / 2)) - 4, 1, 1, 1, white, gray, settingsHeader)
- drawElement(1, termY, termX, 1, nil, gray, "")
- local tsColor
- if configChange then
- tsColor = lime
- else
- tsColor = gray
- end
- drawElement(39, 2, 6, 1, tsColor, lgray, " Save ") -- Save / Close buttons
- drawElement(45, 2, 7, 1, red, lgray, " Close ") --
- -- Settings 1st Column
- drawElement(2, 4, 9, 1, gray, black, "This gate")
- drawElement(17, 4, 1, 1, cyan, black, dhdSettings.thisGate) -- thisGate
- drawElement(2, 6, 1, 1, gray, black, "Lockdown pass")
- drawElement(17, 6, 1, 1, orange, black, dhdSettings.password) -- superSecretPassword
- drawElement(2, 8, 1, 1, gray, black, "Biolock Login")
- if dhdSettings.bio.lock == "OFF" then -- Fistprint Authentication (Biolock mod)
- drawElement(17, 8, "OFF")
- elseif dhdSettings.bio.lock == "ON" then
- drawElement(17, 8, "ON")
- end
- drawElement(23, 8, 1, 1, black, gray, "#") -- Biolock auth. level
- drawElement(2, 10, 1, 1, gray, black, "Net:")
- if dhdSettings.net == "R" then -- redNet (specify server #)
- drawElement(7, 10, 1, 1, red, black, "redNet")
- elseif dhdSettings.net == "C" then -- ccNet (specify send/receive channels)
- drawElement(7, 10, 1, 1, green, black, "ccNet")
- end
- if dhdSettings.net == "R" then -- Red for redNet
- drawElement(17, 10, "OFF")
- elseif dhdSettings.net == "C" then -- Green for ccNet
- drawElement(17, 10, "ON")
- end
- drawElement(23, 10, 1, 1, black, gray, "#") -- hardware.netSide
- if dhdSettings.net == "R" then -- if redNet show "Gate Liaison"
- drawElement(2, 12, 1, 1, gray, black, "Gate Liaison")
- elseif dhdSettings.net == "C" then -- if ccNet show "Send/Rec"
- drawElement(2, 12, 1, 1, gray, black, "Send/Rec")
- end
- if dhdSettings.net == "R" then
- drawElement(17, 12, 1, 1, red, black, tostring(dhdSettings.gate)) -- Gate Liaison (redNet)
- elseif dhdSettings.net == "C" then
- local ccSnd = string.rep(" ", 5-#tostring(dhdSettings.channels.send)) .. tostring(dhdSettings.channels.send)
- drawElement(11, 12, 1, 1, green, black, ccSnd)
- drawElement(16, 12, 1, 1, lgray, black, "/")
- local ccRec = string.rep(" ", 5-#tostring(dhdSettings.channels.recv)) .. tostring(dhdSettings.channels.recv)
- drawElement(17, 12, 1, 1, green, black, ccRec)
- end
- drawElement(2, 14, 1, 1, gray, black, "Marquee") -- Marquee (monB)
- if dhdSettings.monB == "none" then
- drawElement(17, 14, "OFF")
- else
- drawElement(17, 14, "ON")
- end
- drawElement(23, 14, 1, 1, black, gray, "#") -- Marquee side (monB)
- drawElement(2, 16, 12, 1, gray, black, "List Monitor") -- List Monitor (monA)
- if dhdSettings.monA == "none" then
- drawElement(17, 16, "OFF")
- else
- drawElement(17, 16, "ON")
- end
- drawElement(23, 16, 1, 1, black, gray, "#") -- List Monitor side (monA)
- -- Settings 2nd column
- drawElement(28, 4, 1, 1, gray, black, "Highlight gate") -- Whether or not to display the local gate differently than the rest of the list
- if dhdSettings.highlight == "YES" then
- drawElement(45, 4, "ON")
- elseif dhdSettings.highlight == "NO" then
- drawElement(45, 4, "OFF")
- end
- drawElement(28, 6, 1, 1, gray, black, "pSync (ccDialer)") -- Enable/Disable ccDialer pSync
- if dhdSettings.pSync == "ON" then
- drawElement(45, 6, "ON")
- elseif dhdSettings.pSync == "OFF" then
- drawElement(45, 6, "OFF")
- end
- drawElement(28, 8, 1, 1, gray, black, "Bio: ") -- Whether Biolock controls shield or initiates lockdown or does nothing (this is separate from BioLogin)
- if dhdSettings.bio.func == "none" then
- drawElement(33, 8, 1, 1, lgray, black, "No Function")
- elseif dhdSettings.bio.func == "shield" then
- if #dhdSettings.thisGate == 7 then
- drawElement(33, 8, 1, 1, green, black, "Shield")
- elseif #dhdSettings.thisGate > 7 then
- drawElement(33, 8, 1, 1, green, black, "Iris")
- end
- elseif dhdSettings.bio.func == "lock" then
- drawElement(33, 8, 1, 1, red, black, "Lockdown")
- end
- term.setCursorPos(45, 8)
- if dhdSettings.bio.func == "none" then -- Bio - Iris/Lockdown/None function switch
- term.setBackgroundColor(green)
- term.write(" ")
- term.setBackgroundColor(gray)
- term.write(" ")
- term.setBackgroundColor(red)
- term.write(" ")
- elseif dhdSettings.bio.func == "shield" then
- drawElement(45, 8, "ON")
- elseif dhdSettings.bio.func == "lock" then
- drawElement(45, 8, "OFF")
- end
- if #dhdSettings.thisGate == 7 then
- drawElement(28, 10, 1, 1, gray, black, "STARTUP Shield")
- elseif #dhdSettings.thisGate > 7 then
- drawElement(28, 10, 1, 1, gray, black, "STARTUP Iris")
- end
- if dhdSettings.startShield == "OFF" then
- drawElement(45, 10, "OFF")
- elseif dhdSettings.startShield == "ON" then
- drawElement(45, 10, "ON")
- end
- if #dhdSettings.thisGate == 7 then -- END Call Shield (ON/OFF)
- drawElement(28, 12, 1, 1, gray, black, "END Call Shield")
- elseif #dhdSettings.thisGate > 7 then
- drawElement(28, 12, 1, 1, gray, black, "END Call Iris")
- end
- if dhdSettings.ecShield == "OFF" then
- drawElement(45, 12, "OFF")
- elseif dhdSettings.ecShield == "ON" then
- drawElement(45, 12, "ON")
- end
- drawElement(28, 14, 1, 1, gray, black, "Call Logging") -- ccDHD should/not log outbound calls
- if dhdSettings.logs == "OFF" then
- drawElement(45, 14, "OFF")
- elseif dhdSettings.logs == "ON" then
- drawElement(45, 14, "ON")
- end
- drawElement(28, 16, 1, 1, gray, black, "Initiator Only") -- Only call initiator can end call (ON/OFF)
- if dhdSettings.callEnd == "OFF" then
- drawElement(45, 16, "OFF")
- elseif dhdSettings.callEnd == "ON" then
- drawElement(45, 16, "ON")
- end
- end
- local function drawSecureUI()
- -- Uh, oh...doubleSecretProbation()
- if monA ~= "none" then
- monA.setBackgroundColor(black)
- monA.clear()
- end
- if monB ~= "none" then
- monB.setBackgroundColor(black)
- monB.setTextColor(red)
- monB.setTextScale(2)
- monB.clear()
- monB.setCursorPos(1, 1)
- monB.write("!! LOCKDOWN !!")
- end
- term.setBackgroundColor(black)
- term.clear()
- drawHeader()
- drawElement((termX / 2) - 7, 9, 1, 1, red, black, "!! LOCKDOWN !!")
- drawElement((termX / 2) - 10, 15, 1, 1, gray, black, "password:")
- end
- drawCLI = function()
- if menuState == false then
- drawHeader()
- end
- if runState == "viewing" or runState == "GateEdit" then return end
- if secureStatus == "lockdown" then
- return
- else
- if menuState == false then
- if displayState == "list" then
- if monB ~= "none" then
- displayStatus()
- end
- if monA ~= "none" then
- displayGateList()
- end
- end
- if runState == "Dial" or runState == "Edit" or runState == "Trim" then
- drawMainUI()
- drawControlUI()
- drawNaviUI()
- displayStatus()
- elseif runState == "DialCfg" or runState == "EditCfg" then
- drawSettingsUI()
- elseif runState == "DialHelp" or runState == "EditHelp" then
- drawHelpUI()
- end
- end
- end
- end
- local function drawSideList(pSide)
- local tPos = { 5, 7, 9, 11, 13, 15 }
- local tSide = { "top", "bottom", "front", "back", "left", "right" }
- drawElement(26, 4, 8, 13, nil, gray, "") -- menu body
- local tsColor
- for j, k in ipairs(tSide) do
- if pSide == k then
- tsColor = lime
- else
- tsColor = white
- end
- local tWord = string.upper(k):sub(1, 1) .. k:sub(2)
- drawElement(27, tPos[j], 1, 1, tsColor, gray, tWord)
- end
- end
- do
- local ratings = {
- [1] = { rating = "B", color = blue, word = "Base/Outpost/Hub" },
- [2] = { rating = "H", color = lblue, word = "Home/Camp" },
- [3] = { rating = "V", color = brown, word = "Village" },
- [4] = { rating = "M", color = purple, word = "Misc/Special" },
- [5] = { rating = "S", color = green, word = "Safe/Secured" },
- [6] = { rating = "C", color = orange, word = "Caution" },
- [7] = { rating = "D", color = red, word = "Danger" },
- [8] = { rating = "U", color = lgray, word = "Unknown" },
- }
- drawRatingList = function(gRating)
- local tColor
- drawElement(15, 6, 19, 8, nil, gray, "") -- menu body
- for i = 1, 8 do
- drawElement(14, i + 5, 1, 1, nil, ratings[i].color, "") --# color pips
- if gRating == ratings[i].rating and gRating == "U" then
- tColor = white
- elseif gRating == ratings[i].rating and gRating ~= "U" then
- tColor = ratings[i].color
- end
- drawElement(16, i + 5, 1, 1, gRating == ratings[i].rating and tColor or lgray, gray, ratings[i].word) --# rating word
- if gRating == ratings[i].rating then drawElement(33, i + 5, 1, 1, nil, ratings[i].color, "") end
- end
- end
- end
- local function drawAuthList(cAuth)
- local cPos = { 5, 7, 9, 11, 13 }
- drawElement(26, 4, 3, 11, nil, gray, "") -- menu body
- local taColor
- for j, k in ipairs(cPos) do
- if cAuth == j then
- taColor = lime
- else
- taColor = white
- end
- drawElement(26, k, 3, 1, taColor, gray, tostring(j))
- end
- end
- local function drawMenu()
- menuState = true
- drawElement(2, 1, 5, 1, white, black, "_DHD_")
- drawElement(2, 2, 1, 9, nil, gray, "") -- dark gray line along left side of menu
- drawElement(3, 2, 9, 9, nil, lgray, "") -- menu body
- drawElement(2, 3, 1, 1, nil, lblue, "") -- Settings pip
- drawElement(3, 3, 8, 1, gray, lgray, "Settings")
- drawElement(2, 5, 1, 1, nil, yellow, "") -- Logs pip
- drawElement(3, 5, 9, 1, gray, lgray, "View Logs")
- if runState == "Dial" then -- Whether to show Dial Help or Edit Help color pip in menu
- drawElement(2, 7, 1, 1, nil, cyan, "") -- Help pip
- elseif runState == "Edit" or runState == "Trim" then
- drawElement(2, 7, 1, 1, nil, brown, "") -- Help pip
- end
- drawElement(3, 7, 9, 1, gray, lgray, runState .. " Help")
- drawElement(2, 9, 1, 1, nil, red, "") -- Exit pip
- drawElement(3, 9, 8, 1, gray, lgray, " EXIT ")
- end
- local function flashChoice(choice)
- if choice == "cfg" then
- drawElement(3, 3, 9, 1, white, lblue, "Settings ")
- sleep(0.1)
- drawMenu()
- elseif choice == "logs" then
- drawElement(3, 5, 9, 1, black, yellow, "View Logs")
- sleep(0.1)
- drawMenu()
- elseif choice == "dhelp" then
- drawElement(3, 7, 9, 1, white, cyan, "Dial Help")
- sleep(0.1)
- drawMenu()
- elseif choice == "ehelp" then
- drawElement(3, 7, 9, 1, white, brown, "Edit Help")
- sleep(0.1)
- drawMenu()
- elseif choice == "exit" then
- drawElement(3, 9, 9, 1, white, red, " EXIT ")
- sleep(0.1)
- drawMenu()
- elseif choice == "close" then
- drawElement(termX-6, 2, 7, 1, white, red, " Close ")
- sleep(0.1)
- drawElement(termX-6, 2, 7, 1, red, lgray, " Close ")
- elseif choice == "clear" then
- drawElement(termX-6, 4, 7, 1, white, orange, " Clear ")
- sleep(0.1)
- drawElement(termX-6, 4, 7, 1, gray, lgray, " Clear ")
- elseif choice == "cfgsave" then
- drawElement(termX-12, 2, 6, 1, white, green, " Save ")
- sleep(0.1)
- drawElement(termX-12, 2, 6, 1, gray, lgray, " Save ")
- elseif choice == "new" then
- drawElement(43, 9, 9, 1, blue, white, "+ Entry ")
- sleep(0.1)
- elseif choice == "end" then
- drawElement(43, 11, 9, 1, orange, black, "END Call ")
- sleep(0.1)
- drawControlUI()
- elseif choice == "import" then
- drawElement(43, 11, 9, 1, orange, white, "Import ")
- sleep(0.1)
- drawControlUI()
- elseif choice == "undo" then
- drawElement(43, 11, 9, 1, white, brown, "- Undo - ")
- sleep(0.1)
- elseif choice == "lock" then
- drawElement(43, 13, 9, 1, red, orange, "LOCKDOWN ")
- sleep(0.1)
- elseif choice == "export" then
- drawElement(43, 13, 9, 1, green, white, "Export ")
- sleep(0.1)
- drawControlUI()
- elseif choice == "commit" then
- drawElement(43, 13, 9, 1, red, black, "-COMMIT- ")
- sleep(0.1)
- elseif choice == "rcmd" then
- drawElement(43, 15, 9, 1, cyan, lgray, "rCmd ")
- sleep(0.1)
- drawControlUI()
- elseif choice == "save" then
- drawElement(43, 15, 9, 1, cyan, white, "Save ")
- sleep(0.1)
- drawControlUI()
- elseif choice == "page" then
- drawElement(((termX / 2) - (math.floor(#tostring(pNum) / 4))) - 5, termY, 3, 1, black, white, pNum)
- sleep(0.1)
- drawCLI()
- end
- end
- local function areYouSure()
- runState = "asking"
- drawElement(termX / 2 - 5, math.floor(termY / 2) - 2, 13, 1, black, yellow, "Clear Logs?")
- drawElement(termX / 2 - 5, math.floor(termY / 2) - 1, 13, 3, nil, gray, "")
- drawElement(termX / 2 - 4, math.floor(termY / 2), 5, 1, white, green, "YES")
- drawElement(termX / 2 + 2, math.floor(termY / 2), 5, 1, white, red, "N O")
- while true do
- local _, mButton, mX, mY = os.pullEvent("mouse_click")
- if mY == math.floor(termY / 2) then
- if mX > (termX / 2) - 5 and mX < termX / 2 then
- drawElement(termX / 2 - 5, math.floor(termY / 2) - 2, 13, 4, nil, black, "")
- runState = "logs"
- return true
- elseif mX > termX / 2 and mX < (termX / 2) + 6 then
- drawElement(termX / 2 - 5, math.floor(termY / 2) - 2, 13, 4, nil, black, "")
- runState = "logs"
- return false
- end
- end
- end
- end
- local function viewLogs()
- if histPage == histPages then
- term.setBackgroundColor(black)
- term.clear()
- drawHeader()
- end
- drawElement(1, termY, termX, 1, nil, gray, "")
- drawElement(5, termY, 7, 1, black, gray, "page # ")
- term.setTextColor(white)
- term.write(tostring(histPage))
- term.setTextColor(black)
- term.write(" of ")
- term.setTextColor(white)
- term.write(tostring(histPages))
- term.setBackgroundColor(black)
- local currentEntry = ((histPage - 1) * 10) + 1 -- Set the first entry to show (based on page number)
- if callHistory[1] == "" or callHistory[1] == nil then callHistory[1] = "No Logs_/" end -- no logs
- for i = currentEntry, #callHistory, 1 do -- Display logs
- term.setCursorPos(2, i - ((histPage - 1) * 10) + 5) -- position entry
- term.setTextColor(gray) --
- term.write(callHistory[i]:sub(1, string.find(callHistory[i], "_") - 1)) -- write time
- term.setCursorPos(13, i - ((histPage - 1) * 10) + 5) -- position entry
- term.write(callHistory[i]:sub(string.find(callHistory[i], "_") + 1, string.find(callHistory[i], "/") - 1)) -- write day
- term.setCursorPos(23, i - ((histPage - 1) * 10) + 5) -- position entry
- local tGate = callHistory[i]:sub(string.find(callHistory[i], "/") + 1) -- get gate
- if tGate == "No Data" then
- term.setTextColor(gray)
- elseif tGate == "Inbound" then
- term.setTextColor(lgray)
- else
- term.setTextColor(lblue)
- end
- if #tGate < 9 then tGate = " " .. tGate .. " " end -- if tGate is LT 9 characters add buffer spaces
- term.write(tGate) -- write gate
- if i > currentEntry + 9 or i > #callHistory then break end -- if we've 'filled' the page or reached the end of the log then stop the loop
- end
- end
- local function viewGateEntry(dataBlock)
- currentEdit = dataBlock
- tempState = runState
- if tempState ~= "GateEdit" then runState = "viewing" end
- if currentEdit == "new" or currentEdit == "newFast" then
- if #allGates < 23976 then -- If we're adding a new gate, create a generic gate to edit
- local newGate = { addr = "NEWGATE", rating = "U", note = "short note", loc = {x=99999, y=99999, z=99999, dim="Overworld", }, }
- table.insert(allGates, newGate)
- numPages = math.ceil(#allGates / 24) -- Re-paginate gates
- listPages = math.ceil(#allGates / 8)
- if currentEdit == "newFast" then
- runState = "Edit"
- drawCLI()
- return
- end
- currentEdit = #allGates
- end
- end
- term.setBackgroundColor(black)
- term.clear()
- drawHeader()
- -- Display data for viewing/editing
- term.setBackgroundColor(black)
- if currentEdit <= #allGates then
- local teColor = assignColor(currentEdit)
- if teColor ~= nil then
- drawElement(2, 7, #allGates[currentEdit].addr, 1, teColor, black, allGates[currentEdit].addr)
- local ratingWord = assignRating(currentEdit)
- drawElement(14, 7, #ratingWord, 1, gray, black, ratingWord)
- if allGates[currentEdit].addr == dhdSettings.thisGate then
- drawElement(34, 7, 9, 1, yellow, black, "THIS GATE")
- end
- drawElement(2, 9, #allGates[currentEdit].note, 1, white, black, allGates[currentEdit].note)
- drawElement(2, 12, 10, 1, lgray, black, "Dimension:")
- drawElement(13, 12, #allGates[currentEdit].loc.dim, 1, lblue, black, allGates[currentEdit].loc.dim)
- drawElement(2, 13, 2, 1, lgray, black, "x:")
- drawElement(5, 13, #tostring(allGates[currentEdit].loc.x), 1, brown, black, allGates[currentEdit].loc.x)
- drawElement(2, 14, 2, 1, lgray, black, "y:")
- drawElement(5, 14, #tostring(allGates[currentEdit].loc.y), 1, brown, black, allGates[currentEdit].loc.y)
- drawElement(2, 15, 2, 1, lgray, black, "z:")
- drawElement(5, 15, #tostring(allGates[currentEdit].loc.z), 1, brown, black, allGates[currentEdit].loc.z)
- end
- end
- drawElement((termX / 2) - 8, termY - 1, 19, 1, black, gray, " < < < CLOSE > > > ")
- end
- local function deleteGate(tGate) -- TRIM mode: delete gate
- if #allGates > 1 then -- Don't delete if only 1 gate remaining
- table.remove(allGates, tGate)
- numPages = math.ceil(#allGates / 24) -- Re-paginate gates
- listPages = math.ceil(#allGates / 8)
- if pageNum > numPages then pageNum = numPages end
- if listPage > listPages then listPage = listPages end
- drawElement(2, 6, termX, 11, nil, black, "") -- Clear gate entry area of screen
- end
- end
- local function readInput(cX, cY, cO, bG) -- cursor X, Y, text color, bg color
- local word = ""
- local curX, curY = cX, cY
- if bG == nil then bG = black end
- term.setTextColor(cO)
- term.setCursorBlink(true)
- term.setCursorPos(curX, curY)
- while true do
- local event, data = os.pullEvent()
- if event == "key" then
- if data == keys.backspace then
- if curX > cX then
- curX = curX - 1
- word = word:sub(1, #word-1)
- end
- term.setTextColor(cO)
- term.setBackgroundColor(bG)
- term.setCursorPos(curX, curY)
- term.write(" ")
- term.setCursorPos(curX, curY)
- elseif data == keys.enter then
- term.setCursorBlink(false)
- return word
- end
- elseif event == "char" then
- term.setTextColor(cO)
- term.setBackgroundColor(bG)
- term.setCursorPos(curX, curY)
- term.write(data)
- word = word .. data
- curX = curX + 1
- end
- end
- end
- local function remoteCommand()
- tempState = runState
- runState = "rCmd"
- drawElement((termX / 2) - 11, 8, 15, 1, white, gray, " RemoteCommand ")
- drawElement((termX / 2) - 11, 9, 15, 2, nil, gray, "")
- drawElement((termX / 2) - 10, 9, 13, 1, nil, black, "") -- input area bg
- term.setBackgroundColor(black)
- local commandLine = tostring(readInput((termX / 2) - 10, 9, lime))
- drawElement((termX / 2) - 11, 8, 15, 3, nil, black, "")
- if string.lower(commandLine) == "quit" or string.lower(commandLine) == "exit" then
- runState = "quit"
- kernelState = false
- return
- elseif string.lower(commandLine) == "reboot" then
- runState = "reboot"
- kernelState = false
- return
- elseif string.lower(commandLine) == "reset" then
- runState = "reset"
- kernelState = false
- netSend(commandLine)
- return
- elseif string.lower(commandLine) == "lockdown" then
- flashChoice("lock")
- secureStatus = "lockdown"
- netSend(secureStatus)
- elseif string.lower(commandLine) == "restart" then
- netSend("restart")
- elseif string.lower(commandLine) == "son" then
- netSend("sON")
- elseif string.lower(commandLine) == "soff" then
- netSend("sOFF")
- elseif string.lower(commandLine) == "endcall" or string.lower(commandLine) == "hangup" then
- flashChoice("end")
- netSend("endCall")
- elseif string.lower(commandLine) == "help" or commandLine == "?" then
- runState = "DialHelp"
- drawHelpUI()
- return
- else
- if commandLine ~= "" and (commandLine:len() == 7 or commandLine:len() == 9) then
- if gateStatus ~= "Dialing" and gateStatus ~= "Connected" then
- dialAddress = string.upper(commandLine)
- netSend(dialAddress)
- end
- end
- end
- runState = tempState
- drawCLI()
- end
- local function goToPage()
- tempState = runState
- runState = "goPage"
- drawElement((termX / 2) - 11, 8, 15, 1, white, gray, " Go To Page: ")
- drawElement((termX / 2) - 11, 9, 15, 2, nil, gray, "")
- drawElement((termX / 2) - 10, 9, 13, 1, nil, black, "") -- input area bg
- term.setBackgroundColor(black)
- local newPage = tonumber(readInput((termX / 2 - 10), 9, lime))
- drawElement((termX / 2) - 11, 8, 15, 3, nil, black, "")
- if newPage == nil then newPage = pageNum end
- if newPage < 1 then newPage = 1 end
- if newPage > numPages then newPage = numPages end
- if newPage == numPages then
- term.setBackgroundColor(black)
- term.clear()
- end
- pageNum = newPage
- runState = tempState
- drawCLI()
- end
- local function wrapPerp(perp, side)
- if peripheral.isPresent(side) then
- if perp == "A" or perp == "B" then
- if peripheral.getType(side) == "monitor" then
- if perp == "B" then
- if dhdSettings.monA ~= side and dhdSettings.monB ~= side then
- if peripheral.getType(dhdSettings.monB) == "monitor" then
- monB.setBackgroundColor(black)
- monB.clear()
- monB = "none"
- end
- monB = peripheral.wrap(side)
- dhdSettings.monB = side
- configChange = true
- displayStatus()
- end
- elseif perp == "A" then
- if dhdSettings.monA ~= side and dhdSettings.monB ~= side then
- if peripheral.getType(dhdSettings.monA) == "monitor" then
- monA.setBackgroundColor(black)
- monA.clear()
- monA = "none"
- end
- monA = peripheral.wrap(side)
- dhdSettings.monA = side
- configChange = true
- if displayState == "list" then
- displayGateList()
- elseif displayState == "info" then
- displayNotes(tY)
- end
- end
- end
- end
- elseif perp == "C" then
- if peripheral.getType(side) == "modem" then
- if peripheral.call(side, "isWireless") == true then
- if hardware.netSide ~= side then
- if modem then
- modem.close(dhdSettings.channels.recv)
- modem.close(dhdSettings.pChannels.recv)
- modem = nil
- end
- hardware.netSide = side
- modem = peripheral.wrap(hardware.netSide)
- modem.open(dhdSettings.channels.recv)
- if dhdSettings.pSync == "ON" then modem.open(dhdSettings.pChannels.recv) end
- end
- end
- end
- elseif perp == "R" then
- if peripheral.getType(side) == "modem" then
- if peripheral.call(side, "isWireless") == true then
- if hardware.netSide ~= side then
- if peripheral.getType(hardware.netSide) == "modem" then
- if peripheral.call(hardware.netSide, "isWireless") == true then
- rednet.close(hardware.netSide)
- end
- end
- if dhdSettings.pSync == "ON" then
- modem.close(dhdSettings.pChannels.recv)
- modem = nil
- end
- hardware.netSide = side
- rednet.open(hardware.netSide)
- if dhdSettings.pSync == "ON" then
- modem = peripheral.wrap(hardware.netSide)
- modem.open(dhdSettings.pChannels.recv)
- end
- end
- end
- end
- end
- end
- end
- local function keyClick()
- while true do
- local _, key = os.pullEvent("key")
- if key == 59 then -- F1 (Help)
- if runState == "Dial" then
- runState = "DialHelp"
- drawHelpUI()
- elseif runState == "Edit" then
- runState = "EditHelp"
- drawHelpUI()
- end
- elseif key == 199 then -- HOME
- pageNum = 1
- drawCLI()
- elseif key == 207 then -- END
- pageNum = numPages
- term.setBackgroundColor(black)
- term.clear()
- drawCLI()
- elseif key == 201 then -- pageUP
- if runState == "Dial" or runState == "Edit" then
- if pageNum < numPages then
- pageNum = pageNum + 1
- if pageNum == numPages then
- term.setBackgroundColor(black)
- term.clear()
- end
- end
- end
- drawCLI()
- elseif key == 209 then -- pageDN
- if runState == "Dial" or runState == "Edit" then
- if pageNum > 1 then
- pageNum = pageNum - 1
- end
- end
- drawCLI()
- end
- end
- end
- local function mClick()
- while true do
- local _, mButton, mcX, mcY = os.pullEvent("mouse_click")
- -- Menu & Menu Selections
- if menuState then
- if mcX > 1 and mcX < 11 then
- if mcY == 3 and runState == "Dial" then
- runState = "DialCfg"
- flashChoice("cfg")
- menuState = false
- drawSettingsUI()
- return
- elseif mcY == 3 and runState == "Edit" then
- runState = "EditCfg"
- flashChoice("cfg")
- menuState = false
- drawSettingsUI()
- return
- elseif mcY == 5 and (runState == "Dial" or runState == "Edit") then
- tempState = runState
- runState = "logs"
- flashChoice("logs")
- menuState = false
- ingestLogData()
- term.setBackgroundColor(black)
- term.clear()
- drawHeader()
- viewLogs()
- return
- elseif mcY == 7 and runState == "Dial" then
- runState = "DialHelp"
- flashChoice("dhelp")
- menuState = false
- drawHelpUI()
- return
- elseif mcY == 7 and runState == "Edit" then
- runState = "EditHelp"
- flashChoice("ehelp")
- menuState = false
- drawHelpUI()
- return
- elseif mcY == 9 then
- flashChoice("exit")
- runState = "quit"
- kernelState = false
- menuState = false
- break -- required to exit properly
- elseif mcY < 2 or mcY > 10 then
- menuState = false
- drawElement(2, 5, 11, 6, nil, black, "") -- clear menu
- drawCLI()
- return
- end
- else
- menuState = false
- drawElement(2, 5, 11, 6, nil, black, "") -- clear menu
- drawCLI()
- return
- end
- else
- if runState == "DialHelp" then
- if mcX > 44 and mcY == 2 then
- flashChoice("close")
- term.setBackgroundColor(black)
- term.clear()
- runState = "Dial"
- drawCLI()
- return
- end
- elseif runState == "EditHelp" then
- if mcX > 44 and mcY == 2 then
- flashChoice("close")
- term.setBackgroundColor(black)
- term.clear()
- runState = "Edit"
- drawCLI()
- return
- end
- elseif runState == "logs" then
- if mcX > 44 and mcY == 2 then
- flashChoice("close")
- term.setBackgroundColor(black)
- term.clear()
- callHistory = { }
- lastCall = { }
- runState = tempState
- drawCLI()
- return
- elseif mcX > 44 and mcY == 4 then
- flashChoice("clear")
- local makeSure = areYouSure()
- if makeSure then
- local clearLog = fs.open("/data/DHDhistory", "w")
- clearLog.close()
- callHistory = { }
- --lastCall = { }
- histPages = 1
- histPage = 1
- end
- viewLogs()
- return
- end
- elseif runState == "viewing" then
- if mcX > 16 and mcX < 36 and mcY == termY-1 then
- -- Clean up select parts of the screen instead of clearing the entire screen
- runState = tempState
- drawElement(2, 7, termX, 1, nil, black, "")
- drawElement(2, 9, termX, 1, nil, black, "")
- drawElement(2, 12, 16, 4, nil, black, "")
- drawElement(13, 12, termX, 1, nil, black, "")
- drawElement(1, termY-1, termX, 1, nil, black, "")
- drawCLI()
- return
- end
- elseif runState ~= "DialCfg" and runState ~= "EditCfg" and runState ~= "GateEdit" and runState ~= "viewing" then
- if mcY == 1 and runState ~= "Trim" then
- if mcX > 1 and mcX < 9 then
- menuState = true
- drawMenu()
- return
- end
- end
- end
- -- Command Buttons (change modes, mode operation)
- if mcX > 41 and mcX <= termX and (runState == "Dial" or runState == "Edit" or runState == "Trim") then
- if mcY == 7 then
- if runState == "Dial" then
- runState = "Edit"
- drawCLI()
- elseif runState == "Edit" then
- runState = "Dial"
- drawCLI()
- end
- return
- elseif mcY == 9 then
- if runState == "Dial" and shieldStatus == "OFF" then
- netSend("sON")
- return
- elseif runState == "Dial" and shieldStatus == "ON" and secureStatus == "allclear" then
- netSend("sOFF")
- return
- elseif runState == "Edit" then
- if #allGates < 23977 then
- flashChoice("new")
- gateChange = true
- if mButton == 1 then
- runState = "GateEdit"
- viewGateEntry("new")
- elseif mButton == 2 then
- viewGateEntry("newFast")
- end
- end
- end
- elseif mcY == 11 then
- if runState == "Dial" then
- if dhdSettings.ecShield == "ON" then
- netSend("sON")
- end
- if dhdSettings.callEnd == "OFF" or (dhdSettings.callEnd == "ON" and dialAddress ~= "") then
- flashChoice("end")
- netSend("endCall")
- dialAddress = ""
- end
- elseif runState == "Edit" then
- if fs.exists("/disk") then
- flashChoice("import")
- ingestData("/disk/data/DHDgates", "gate")
- term.setBackgroundColor(black)
- term.clear()
- drawCLI()
- end
- elseif runState == "Trim" then
- flashChoice("undo")
- runState = "Edit"
- ingestData(dhdSettings.gateData, "gate")
- if gateChange then
- term.setBackgroundColor(black)
- term.clear()
- end
- gateChange = false
- drawCLI()
- end
- return
- elseif mcY == 13 then
- if runState == "Dial" then
- flashChoice("lock")
- secureStatus = "lockdown"
- netSend(secureStatus)
- sleep(0.1) -- this gives ccDHD time to get updated info from gateLiaison before invoking secureUI()
- elseif runState == "Edit" then
- if fs.exists("/disk") then
- flashChoice("export")
- saveData("/disk/data/DHDgates", "gate")
- end
- elseif runState == "Trim" then
- flashChoice("commit")
- runState = "Edit"
- saveData(dhdSettings.gateData, "gate")
- gateChange = false
- drawCLI()
- end
- return
- elseif mcY == 15 then
- if runState == "Dial" then
- flashChoice("rcmd")
- remoteCommand()
- elseif runState == "Edit" then
- flashChoice("save")
- gateChange = false
- saveData(dhdSettings.gateData, "gate")
- drawControlUI()
- end
- if runState == "reboot" or runState == "reset" or runState == "quit" then break end
- end
- end
- end
- -- Page Navigation via click
- if mcY == termY then
- if runState == "Dial" or runState == "Edit" or runState == "Trim" then
- if mcX < 20 and mcY == termY then -- Bottom row of screen - Back
- if pageNum > 1 then
- pageNum = pageNum - 1
- term.clear()
- drawCLI()
- return
- end
- elseif mcX > 19 and mcX < 23 and mcY == termY then -- Bottom row of screen - Page Numbers (Go To Page dialogue)
- flashChoice("page")
- goToPage()
- elseif mcX > 22 and mcY == termY then -- Bottom row of screen - Forward
- if pageNum < numPages then
- pageNum = pageNum + 1
- term.clear()
- drawCLI()
- return
- end
- end
- end
- end
- -- Dial a listed address, view it's info, edit entry, or enter trim mode & delete gates
- local j = ((pageNum - 1) * 23) + pageNum
- local k = ((pageNum - 1) * 23)
- local l = ((pageNum - 1) * 24)
- if menuState == false then
- if mcY > 5 and mcY < 17 then
- for i = j, #allGates, 1 do
- -- Addresses Column 1
- if mcX > 1 and mcX < 11 and mcY == 4 + ((i - l) * 2) and i <= #allGates then
- if runState == "Dial" then
- if mButton == 1 and gateStatus ~= "Dialing" and gateStatus ~= "Connected" then
- if allGates[i].addr ~= dhdSettings.thisGate and allGates[i].addr ~= "NEWGATE" then
- dialAddress = allGates[i].addr
- netSend(dialAddress)
- return
- end
- elseif mButton == 2 then
- viewGateEntry(i)
- return
- end
- elseif runState == "Edit" then
- if mButton == 1 then
- runState = "GateEdit"
- viewGateEntry(i)
- return
- elseif mButton == 2 then
- runState = "Trim"
- drawCLI()
- return
- end
- elseif runState == "Trim" then
- if mButton == 1 then
- deleteGate(i)
- drawCLI()
- return
- end
- end
- -- Addresses Column 2
- elseif mcX > 11 and mcX < 21 and mcY == 4 + ((i - l) * 2) and (i + 6) <= #allGates then
- if runState == "Dial" then
- if mButton == 1 and gateStatus ~= "Dialing" and gateStatus ~= "Connected" then
- if allGates[i + 6].addr ~= dhdSettings.thisGate and allGates[i + 6].addr ~= "NEWGATE" then
- dialAddress = allGates[i + 6].addr
- netSend(dialAddress)
- return
- end
- elseif mButton == 2 then
- viewGateEntry(i + 6)
- return
- end
- elseif runState == "Edit" then
- if mButton == 1 then
- runState = "GateEdit"
- viewGateEntry(i + 6)
- return
- elseif mButton == 2 then
- runState = "Trim"
- drawCLI()
- return
- end
- elseif runState == "Trim" then
- if mButton == 1 then
- deleteGate(i + 6)
- drawCLI()
- return
- end
- end
- -- Addresses Column 3
- elseif mcX > 21 and mcX < 31 and mcY == 4 + ((i - l) * 2) and (i + 12) <= #allGates then
- if runState == "Dial" then
- if mButton == 1 and gateStatus ~= "Dialing" and gateStatus ~= "Connected" then
- if allGates[i + 12].addr ~= dhdSettings.thisGate and allGates[i + 12].addr ~= "NEWGATE" then
- dialAddress = allGates[i + 12].addr
- netSend(dialAddress)
- return
- end
- elseif mButton == 2 then
- viewGateEntry(i + 12)
- return
- end
- elseif runState == "Edit" then
- if mButton == 1 then
- runState = "GateEdit"
- viewGateEntry(i + 12)
- return
- elseif mButton == 2 then
- runState = "Trim"
- drawCLI()
- return
- end
- elseif runState == "Trim" then
- if mButton == 1 then
- deleteGate(i + 12)
- drawCLI()
- return
- end
- end
- -- Addresses Column 4
- elseif mcX > 31 and mcX < 41 and mcY == 4 + ((i - l) * 2) and (i + 18) <= #allGates then
- if runState == "Dial" then
- if mButton == 1 and gateStatus ~= "Dialing" and gateStatus ~= "Connected" then
- if allGates[i + 18].addr ~= dhdSettings.thisGate and allGates[i + 18].addr ~= "NEWGATE" then
- dialAddress = allGates[i + 18].addr
- netSend(dialAddress)
- end
- elseif mButton == 2 then
- viewGateEntry(i + 18)
- return
- end
- elseif runState == "Edit" then
- if mButton == 1 then
- runState = "GateEdit"
- viewGateEntry(i + 18)
- return
- elseif mButton == 2 then
- runState = "Trim"
- drawCLI()
- return
- end
- elseif runState == "Trim" then
- if mButton == 1 then
- deleteGate(i + 18)
- drawCLI()
- return
- end
- end
- end
- end
- end
- end
- -- Gate Editing
- if runState == "GateEdit" then
- if mcY == 7 then
- -- Edit Gate Address
- if mcX > 1 and mcX < 11 then
- drawElement(2, 7, #allGates[currentEdit].addr, 1, gray, black, allGates[currentEdit].addr)
- local newGate = string.upper(tostring(readInput(2, 7, yellow)))
- if newGate ~= "" and newGate ~= "NIL" and newGate:len() > 6 and newGate:len() < 10 then
- allGates[currentEdit].addr = newGate
- gateChange = true
- end
- local gColor = assignColor(currentEdit)
- drawElement(2, 7, 1, 1, gColor, black, allGates[currentEdit].addr .. " ")
- -- Edit Gate Rating/Classification
- elseif mcX > 13 and mcX < 30 then
- term.setBackgroundColor(black)
- term.setTextColor(yellow)
- drawRatingList(allGates[currentEdit].rating)
- local newRating = { os.pullEvent("mouse_click") }
- if newRating[3] > 14 and newRating[3] < 33 then
- if newRating[4] == 6 then
- if allGates[currentEdit].rating ~= "B" then
- allGates[currentEdit].rating = "B"
- gateChange = true
- end
- elseif newRating[4] == 7 then
- if allGates[currentEdit].rating ~= "H" then
- allGates[currentEdit].rating = "H"
- gateChange = true
- end
- elseif newRating[4] == 8 then
- if allGates[currentEdit].rating ~= "V" then
- allGates[currentEdit].rating = "V"
- gateChange = true
- end
- elseif newRating[4] == 9 then
- if allGates[currentEdit].rating ~= "M" then
- allGates[currentEdit].rating = "M"
- gateChange = true
- end
- elseif newRating[4] == 10 then
- if allGates[currentEdit].rating ~= "S" then
- allGates[currentEdit].rating = "S"
- gateChange = true
- end
- elseif newRating[4] == 11 then
- if allGates[currentEdit].rating ~= "C" then
- allGates[currentEdit].rating = "C"
- gateChange = true
- end
- elseif newRating[4] == 12 then
- if allGates[currentEdit].rating ~= "D" then
- allGates[currentEdit].rating = "D"
- gateChange = true
- end
- elseif newRating[4] == 13 then
- if allGates[currentEdit].rating ~= "U" then
- allGates[currentEdit].rating = "U"
- gateChange = true
- end
- end
- end
- drawElement(2, 9, termX, 2, nil, black, "")
- drawElement(14, 5, 20, 10, nil, black, "")
- local gtColor = assignColor(currentEdit)
- local gtRating = assignRating(currentEdit)
- drawElement(2, 7, #allGates[currentEdit].addr, 1, gtColor, black, allGates[currentEdit].addr)
- drawElement(14, 7, #gtRating, 1, gray, black, gtRating)
- drawElement(13, 12, #allGates[currentEdit].loc.dim, 1, lblue, black, allGates[currentEdit].loc.dim)
- drawElement(2, 9, #allGates[currentEdit].note, 1, white, black, allGates[currentEdit].note)
- end
- -- Edit Gate Notes
- elseif mcY > 8 and mcY < 11 then
- if mcX < 40 then
- drawElement(2, 9, #allGates[currentEdit].note, 1, gray, black, allGates[currentEdit].note)
- term.setBackgroundColor(black)
- local newNote = tostring(readInput(2, 9, white))
- if newNote ~= "" and newNote ~= "nil" then
- allGates[currentEdit].note = newNote
- gateChange = true
- end
- drawElement(2, 9, termX, 2, nil, black, "")
- drawElement(2, 9, #allGates[currentEdit].note, 1, white, black, allGates[currentEdit].note)
- end
- -- Gate Dimension
- elseif mcY == 12 then
- if mcX > 12 and mcX < 32 then
- drawElement(13, 12, #allGates[currentEdit].loc.dim, 1, gray, black, allGates[currentEdit].loc.dim)
- local newDim = tostring(readInput(13, 12, lblue))
- if newDim ~= "" and tostring(newDim) ~= "nil" then
- allGates[currentEdit].loc.dim = newDim
- drawElement(13, 12, 38, 1, nil, black, "")
- gateChange = true
- end
- drawElement(13, 12, 5, 1, nil, black, "")
- drawElement(13, 12, #allGates[currentEdit].loc.dim, 1, lblue, black, allGates[currentEdit].loc.dim)
- end
- -- Gate X position
- elseif mcY == 13 then
- if mcX > 4 and mcX < 10 then
- local oldX = tostring(allGates[currentEdit].loc.x)
- drawElement(5, 13, 1, 1, gray, black, oldX)
- local newX = tonumber(readInput(5, 13, brown))
- if tostring(newX) ~= "" and newX ~= nil and newX ~= allGates[currentEdit].loc.x then
- allGates[currentEdit].loc.x = newX
- gateChange = true
- end
- drawElement(5, 13, 6, 1, nil, black, "")
- local tmpX = tostring(allGates[currentEdit].loc.x)
- drawElement(5, 13, 1, 1, brown, black, tmpX)
- end
- -- Gate Y position
- elseif mcY == 14 then
- if mcX > 4 and mcX < 10 then
- local oldY = tostring(allGates[currentEdit].loc.y)
- drawElement(5, 14, #oldY, 1, gray, black, oldY)
- local newY = tonumber(readInput(5, 14, brown))
- if tostring(newY) ~= "" and newY ~= nil and newY ~= allGates[currentEdit].loc.y then
- allGates[currentEdit].loc.y = newY
- gateChange = true
- end
- drawElement(5, 14, 6, 1, nil, black, "")
- local tmpY = tostring(allGates[currentEdit].loc.y)
- drawElement(5, 14, #tmpY, 1, brown, black, tmpY)
- end
- -- Gate Z position
- elseif mcY == 15 then
- if mcX > 4 and mcX < 10 then
- local oldZ = tostring(allGates[currentEdit].loc.z)
- drawElement(5, 15, #oldZ, 1, gray, black, oldZ)
- local newZ = tonumber(readInput(5, 15, brown))
- if tostring(newZ) ~= "" and newZ ~= nil and newZ ~= allGates[currentEdit].loc.z then
- allGates[currentEdit].loc.z = newZ
- gateChange = true
- end
- drawElement(5, 15, 6, 1, nil, black, "")
- local tmpZ = tostring(allGates[currentEdit].loc.z)
- drawElement(5, 15, #tmpZ, 1, brown, black, tmpZ)
- end
- -- Exit Edit Screen
- elseif mcY == (termY-1) then
- runState = "Edit"
- drawElement(2, 7, termX, termY, nil, black, "")
- drawCLI()
- end
- end
- end
- end
- local function mClickSettings()
- while true do
- local _, mButton, mcX, mcY = os.pullEvent("mouse_click")
- -- ccDHD Settings
- if runState == "DialCfg" or runState == "EditCfg" then
- local cfgPos = { 5, 7, 9, 11, 13, 15 }
- local cfgSides = { "top", "bottom", "front", "back", "left", "right" }
- -- Save Settings
- if mcY == 2 and mcX > 38 and mcX < 45 then
- flashChoice("cfgsave")
- saveData(settingsData, "cfg")
- configChange = false
- drawSettingsUI()
- -- Close Settings (no save)
- elseif mcY == 2 and mcX > 44 and mcX <= termX then
- flashChoice("close")
- if runState == "DialCfg" then
- runState = "Dial"
- elseif runState == "EditCfg" then
- runState = "Edit"
- end
- term.setBackgroundColor(black)
- term.clear()
- drawCLI()
- return
- end
- -- Settings Column 1
- -- Edit thisGate
- if mcY == 4 and mcX > 16 and mcX < 27 then
- drawElement(17, 4, #dhdSettings.thisGate, 1, gray, black, dhdSettings.thisGate)
- local newGate = string.upper(tostring(readInput(17, 4, cyan)))
- if newGate ~= "" and newGate ~= "NIL" and newGate ~= dhdSettings.thisGate and newGate:len() > 6 and newGate:len() < 10 then
- configChange = true
- dhdSettings.thisGate = newGate
- longName = makeLongName(dhdSettings.thisGate)
- if gateStatus == "Disconnected" then displayMarquee() end
- end
- drawElement(16, 4, 9, 1, nil, black, "")
- drawSettingsUI()
- -- Change LOCKDOWN Password
- elseif mcY == 6 and mcX > 16 and mcX < 31 then
- drawElement(17, 6, #dhdSettings.password, 1, gray, black, dhdSettings.password)
- local newPass = tostring(readInput(17, 6, orange))
- if newPass ~= "" and newPass ~= "nil" and newPass ~= dhdSettings.password then
- configChange = true
- dhdSettings.password = newPass
- end
- drawElement(17, 6, 11, 1, nil, black, "")
- drawSettingsUI()
- -- Biolock ON/OFF
- elseif mcY == 8 and mcX > 16 and mcX < 21 and dhdSettings.bio.lock ~= "none" then
- if hardware.bioSide ~= "none" then
- if dhdSettings.bio.lock == "ON" then
- dhdSettings.bio.lock = "OFF"
- configChange = true
- elseif dhdSettings.bio.lock == "OFF" then
- dhdSettings.bio.lock = "ON"
- configChange = true
- end
- end
- drawSettingsUI()
- elseif mcY == 8 and mcX > 22 and mcX < 24 and dhdSettings.bio.lock ~= "none" then
- drawAuthList(dhdSettings.bio.auth)
- local bioAuth = { os.pullEvent("mouse_click") }
- if bioAuth[3] > 26 and bioAuth[2] < 31 then
- local secPos = { 5, 7, 9, 11, 13 }
- for j, k in ipairs(secPos) do
- if bioAuth[4] == k then
- dhdSettings.bio.auth = j
- configChange = true
- break
- end
- end
- end
- drawSettingsUI()
- -- redNet/ccNet
- elseif mcY == 10 and mcX > 16 and mcX < 21 then
- if dhdSettings.net == "R" then
- netSend("ccNet")
- rednet.close(hardware.netSide)
- dhdSettings.net = "C"
- if not modem then modem = peripheral.wrap(hardware.netSide) end
- modem.open(dhdSettings.channels.recv)
- saveData(settingsData, "cfg")
- elseif dhdSettings.net == "C" then
- netSend("redNet")
- modem.close(dhdSettings.channels.recv)
- if dhdSettings.pSync == "OFF" then modem = nil end
- dhdSettings.net = "R"
- rednet.open(hardware.netSide)
- saveData(settingsData, "cfg")
- end
- drawSettingsUI()
- elseif mcY == 10 and mcX > 22 and mcX < 24 then
- -- Select redNet Side
- if dhdSettings.net == "R" then
- drawSideList(hardware.netSide)
- local modemSide = { os.pullEvent("mouse_click") }
- if modemSide[3] > 26 and modemSide[2] < 35 then
- for jr, kr in ipairs(cfgPos) do
- if modemSide[4] == kr then
- wrapPerp("R", cfgSides[jr])
- break
- end
- end
- end
- drawSettingsUI()
- -- Select ccNet Side
- elseif dhdSettings.net == "C" then
- drawSideList(hardware.netSide)
- local modemSide = { os.pullEvent("mouse_click") }
- if modemSide[3] > 26 and modemSide[2] < 35 then
- for jc, kc in ipairs(cfgPos) do
- if modemSide[4] == kc then
- wrapPerp("C", cfgSides[jc])
- break
- end
- end
- end
- drawSettingsUI()
- end
- -- Change redNet gateLiaison / ccNet Receive Channel
- elseif mcY == 12 and mcX > 16 and mcX < 22 then
- if dhdSettings.net == "R" then
- drawElement(17, 12, #tostring(dhdSettings.gate), 1, gray, black, dhdSettings.gate)
- local newGate = tonumber(readInput(17, 12, red))
- if tostring(newGate) ~= "" and newGate ~= nil and newGate ~= dhdSettings.gate and newGate < 65536 and newGate >= 0 then
- dhdSettings.gate = newGate
- configChange = true
- end
- drawSettingsUI()
- elseif dhdSettings.net == "C" then
- local ccRec = tostring(dhdSettings.channels.recv) .. string.rep(" ", 5-#tostring(dhdSettings.channels.recv))
- drawElement(17, 12, #ccRec, 1, gray, black, ccRec)
- local newChannel = tonumber(readInput(17, 12, green))
- if tostring(newChannel) ~= "" and newChannel ~= nil and newChannel ~= dhdSettings.channels.recv and newChannel ~= dhdSettings.channels.send and newChannel ~= dhdSettings.pChannels.send and newChannel ~= dhdSettings.pChannels.recv and newChannel < 65536 and newChannel > 0 then
- netSend("CR")
- sleep(0.1)
- netSend(newChannel)
- modem.close(dhdSettings.channels.recv)
- dhdSettings.channels.recv = newChannel
- modem.open(dhdSettings.channels.recv)
- saveData(settingsData, "cfg")
- end
- drawElement(17, 12, 5, 1, nil, black, "")
- drawSettingsUI()
- end
- -- Change ccNet Send Channel
- elseif mcY == 12 and mcX > 10 and mcX < 16 then
- if dhdSettings.net == "C" then
- local ccSnd = tostring(dhdSettings.channels.send) .. string.rep(" ", 5-#tostring(dhdSettings.channels.send))
- drawElement(11, 12, #ccSnd, 1, gray, black, ccSnd)
- local newSend = tonumber(readInput(11, 12, green))
- if tostring(newSend) ~= "" and newSend ~= nil and newSend ~= dhdSettings.channels.send and newSend ~= dhdSettings.channel.recv and newSend~= dhdSettings.pChannels.send and newSend ~= dhdSettings.pChannels.recv and newSend < 65536 and newSend > 0 then
- netSend("CS")
- sleep(0.1)
- netSend(newSend)
- dhdSettings.channels.send = newSend
- saveData(settingsData, "cfg")
- end
- drawElement(11, 12, 5, 1, nil, black, "")
- drawSettingsUI()
- end
- -- Select Marquee Side
- elseif mcY == 14 and mcX < 24 then
- if mcX > 16 and mcX < 21 and dhdSettings.monB ~= "none" then
- monB.setBackgroundColor(black)
- monB.clear()
- monB = nil
- dhdSettings.monB = "none"
- configChange = true
- elseif mcX > 22 and mcX < 24 then
- drawSideList(dhdSettings.monB)
- local monBSide = { os.pullEvent("mouse_click") }
- if monBSide[3] > 26 and monBSide[2] < 35 then
- for jb, kb in ipairs(cfgPos) do
- if monBSide[4] == kb then
- wrapPerp("B", cfgSides[jb])
- break
- end
- end
- end
- end
- drawSettingsUI()
- -- Select List Monitor Side
- elseif mcY == 16 and mcX < 24 then
- if mcX > 16 and mcX < 21 and dhdSettings.monA ~= "none" then
- monA.setBackgroundColor(black)
- monA.clear()
- monA = nil
- dhdSettings.monA = "none"
- configChange = true
- elseif mcX > 22 and mcX < 24 then
- drawSideList(dhdSettings.monA)
- local monASide = { os.pullEvent("mouse_click") }
- if monASide[3] > 26 and monASide[2] < 35 then
- for jb, kb in ipairs(cfgPos) do
- if monASide[4] == kb then
- wrapPerp("A", cfgSides[jb])
- break
- end
- end
- end
- end
- drawSettingsUI()
- -- Settings Column 2
- -- Highlight thisGate in Dial/Edit/Trim modes & on List monitor
- elseif mcY == 4 and mcX > 44 and mcX < 49 then
- if dhdSettings.highlight == "YES" then
- dhdSettings.highlight = "NO"
- configChange = true
- elseif dhdSettings.highlight == "NO" then
- dhdSettings.highlight = "YES"
- configChange = true
- end
- drawSettingsUI()
- -- pSync ON/OFF for ccDialer
- elseif mcY == 6 and mcX > 44 and mcX < 49 then
- if dhdSettings.pSync == "ON" then
- dhdSettings.pSync = "OFF"
- modem.close(dhdSettings.pChannels.recv)
- configChange = true
- elseif dhdSettings.pSync == "OFF" then
- dhdSettings.pSync = "ON"
- if not modem then modem = peripheral.wrap(hardware.netSide) end
- modem.open(dhdSettings.pChannels.recv)
- configChange = true
- end
- drawSettingsUI()
- -- Bioscanner function (shield/lockdown)
- elseif mcY == 8 and mcX > 44 and mcX < 49 then
- if dhdSettings.bio.func == "none" then
- dhdSettings.bio.func = "shield"
- configChange = true
- elseif dhdSettings.bio.func == "shield" then
- dhdSettings.bio.func = "lock"
- configChange = true
- elseif dhdSettings.bio.func == "lock" then
- dhdSettings.bio.func = "none"
- configChange = true
- end
- drawSettingsUI()
- -- Startup Shield (ON/OFF)
- elseif mcY == 10 and mcX > 44 and mcX < 49 then
- if dhdSettings.startShield == "ON" then
- dhdSettings.startShield = "OFF"
- configChange = true
- elseif dhdSettings.startShield == "OFF" then
- dhdSettings.startShield = "ON"
- configChange = true
- end
- drawSettingsUI()
- -- End Call Shield (ON/OFF)
- elseif mcY == 12 and mcX > 44 and mcX < 49 then
- if dhdSettings.ecShield == "ON" then
- dhdSettings.ecShield = "OFF"
- configChange = true
- elseif dhdSettings.ecShield == "OFF" then
- dhdSettings.ecShield = "ON"
- configChange = true
- end
- drawSettingsUI()
- -- Call Logging (ON/OFF)
- elseif mcY == 14 and mcX > 44 and mcX < 49 then
- if dhdSettings.logs == "ON" then
- dhdSettings.logs = "OFF"
- configChange = true
- elseif dhdSettings.logs == "OFF" then
- dhdSettings.logs = "ON"
- configChange = true
- end
- drawSettingsUI()
- -- Call Initiator ONLY for endCall (ON/OFF)
- elseif mcY == 16 and mcX > 44 and mcX < 49 then
- if dhdSettings.callEnd == "ON" then
- dhdSettings.callEnd = "OFF"
- configChange = true
- elseif dhdSettings.callEnd == "OFF" then
- dhdSettings.callEnd = "ON"
- configChange = true
- end
- drawSettingsUI()
- end
- end
- end
- end
- local function mScroll()
- while true do
- local _, scrollEvent = os.pullEvent("mouse_scroll")
- menuState = false
- if runState == "Dial" or runState == "Edit" or runState == "Trim" then
- pageNum = scrollEvent == 1 and math.min(pageNum + 1, numPages) or math.max(pageNum - 1, 1)
- if pageNum == numPages then
- term.setBackgroundColor(black)
- term.clear()
- end
- drawCLI()
- elseif runState == "logs" then
- histPage = scrollEvent == 1 and math.min(histPage + 1, histPages) or math.max(histPage - 1, 1)
- viewLogs()
- end
- end
- end
- local function monTouch()
- while true do
- local touchEvent = { os.pullEvent("monitor_touch") }
- if touchEvent[2] == dhdSettings.monA and displayState == "info" then
- displayState = "list"
- drawCLI() -- Maybe change monitor events to displayStatus() or something separate from CLI
- elseif touchEvent[2] == dhdSettings.monA and displayState == "list" then
- local tX = touchEvent[3]
- tY = touchEvent[4]
- if tY < 9 then
- displayState = "info"
- if dhdSettings.monB ~= "none" then displayNotes(tY) end
- elseif tY > 8 then
- if tX < 10 then
- listPage = listPage - 1
- if listPage < 1 then listPage = 1 end
- displayGateList()
- elseif tX > 9 then
- listPage = listPage + 1
- if listPage > listPages then listPage = listPages end
- displayGateList()
- end
- end
- elseif touchEvent[2] == dhdSettings.monB and displayState == "info" and gateStatus == "Disconnected" and secureStatus == "allclear" then
- local dialNum = (tY + ((listPage - 1) * 8))
- if dialNum > #allGates then dialNum = #allGates end
- dialAddress = allGates[dialNum].addr
- if dialAddress == dhdSettings.thisGate then return end
- gateStatus = "Dialing"
- netSend(dialAddress)
- elseif touchEvent[2] == dhdSettings.monB and gateStatus ~= "Disconnected" and secureStatus == "allclear" then
- netSend("endCall")
- end
- end
- end
- local function bioAnimation()
- while true do
- for i = 2, 20, 1 do
- term.setCursorPos(i, 4)
- term.setBackgroundColor(blue)
- term.write(" ")
- term.setBackgroundColor(black)
- term.setCursorPos(i - 1, 4)
- term.write(" ")
- sleep(0.04)
- end
- for i = 20, 2, -1 do
- term.setCursorPos(i, 4)
- term.setBackgroundColor(blue)
- term.write(" ")
- term.setBackgroundColor(black)
- term.setCursorPos(i + 1, 4)
- term.write(" ")
- sleep(0.04)
- end
- end
- end
- local function bioScan()
- while true do
- local fistPrint = {os.pullEvent("biolock")}
- if runState == "init" then
- if fistPrint[5] >= dhdSettings.bio.auth then
- fistAuth = true
- end
- return fistAuth
- else
- --if fistPrint[5] >= dhdSettings.bio.auth - 1 then -- one level less than 'unlock' to activate shield/lockdown
- if dhdSettings.bio.func == "shield" then
- if shieldStatus == "OFF" then
- netSend("sON")
- elseif shieldStatus == "ON" then
- netSend("sOFF")
- else
- netSend("sON")
- end
- elseif dhdSettings.bio.func == "lock" then
- if secureStatus == "allclear" then
- secureStatus = "lockdown"
- netSend("lockdown")
- return
- end
- end
- --end
- end
- end
- end
- local function bioLogin()
- local bio = peripheral.wrap(hardware.bioSide)
- fistAuth = false
- term.setBackgroundColor(black)
- term.clear()
- drawElement(2, 2, 19, 1, yellow, black, "Waiting for Bioscan")
- if monA ~= "none" then
- monA.setBackgroundColor(black)
- monA.setTextColor(yellow)
- monA.setTextScale(1)
- monA.setCursorPos(1, 2)
- monA.write("Waiting")
- monA.setCursorPos(3, 3)
- monA.write("for")
- monA.setCursorPos(1, 4)
- monA.write("Bioscan")
- end
- while fistAuth == false do
- local fistPrint = parallel.waitForAny(bioScan, bioAnimation)
- if fistAuth then
- bio = nil
- return fistAuth
- end
- end
- end
- local function secKernel() -- LOCKDOWN handler
- drawSecureUI()
- local passSymbols = { "!", "@", "#", "$", "%", "*", "?", "+", "x", "X" }
- while secureStatus == "lockdown" do
- drawElement(termX / 2, 15, termX, 1, nil, black, "")
- term.setCursorPos(termX / 2, 15)
- term.setTextColor(yellow)
- local securePass = tostring(read(passSymbols[math.random(1, #passSymbols)]))
- if securePass == dhdSettings.password then
- netSend("allclear")
- if dhdSettings.net == "R" then
- local senderID, message = rednet.receive(1)
- if senderID == dhdSettings.gate and (message == "YY0" or message == "YY1") then
- secureStatus = "allclear"
- end
- elseif dhdSettings.net == "C" then
- local ccNetEvent = { os.pullEvent("modem_message") }
- if ccNetEvent[3] == dhdSettings.channels.recv and ccNetEvent[4] == dhdSettings.channels.send and (ccNetEvent[5] == "YY0" or ccNetEvent[5] == "YY1") then
- secureStatus = "allclear"
- end
- end
- drawElement(15, 9, termX, 1, nil, black, "")
- drawElement(15, 15, termX, 1, nil, black, "")
- netSend("QRY")
- drawCLI()
- break
- end
- end
- end
- local function dhdKernel()
- if kernelState == true and secureStatus == "lockdown" then
- secKernel()
- elseif kernelState == true and secureStatus == "allclear" then
- if runState ~= "DialCfg" and runState ~= "EditCfg" and runState ~= "rCmd" and runState ~= "goPage" and dhdSettings.pSync == "ON" then
- parallel.waitForAny(keyClick, mClick, mScroll, bioScan, monTouch, netReceive, pSyncReceive)
- elseif runState ~= "DialCfg" and runState ~= "EditCfg" and runState ~= "rCmd" and runState ~= "goPage" and dhdSettings.pSync == "OFF" then
- parallel.waitForAny(keyClick, mClick, mScroll, bioScan, monTouch, netReceive)
- elseif (runState == "DialCfg" or runState == "EditCfg") and dhdSettings.pSync == "ON" then
- parallel.waitForAny(keyClick, mClickSettings, bioScan, monTouch, netReceive, pSyncReceive)
- elseif (runState == "DialCfg" or runState == "EditCfg") and dhdSettings.pSync == "OFF" then
- parallel.waitForAny(keyClick, mClickSettings, bioScan, monTouch, netReceive)
- end
- end
- if runState == "reset" then
- netSend("reset")
- kernelState = false
- end
- if runState == "quit" then
- kernelState = false
- end
- return kernelState
- end
- local function missingComponent(id)
- term.setBackgroundColor(black)
- term.clear()
- if id == "modem" then
- drawElement(2, 2, 27, 1, red, black, "No wireless modem detected!")
- drawElement(2, 4, 32, 1, red, black, "ccDHD REQUIRES a wireless modem.")
- elseif id == "cfg" then
- drawElement(2, 2, 20, 1, red, black, "Please restart ccDHD")
- drawElement(2, 4, 18, 1, red, black, "to complete setup.")
- else
- drawElement(2, 2, 26, 1, red, black, "Unknown component missing!")
- drawElement(2, 4, 27, 1, red, black, "ccDHD REQUIRES a something.")
- end
- term.setCursorPos(1, 8)
- runState = "quit"
- kernelState = false
- end
- local function detectHardware(hType)
- if hType == "bio" then
- hardware.bioSide = "none"
- for _, bSide in ipairs(rs.getSides()) do
- if peripheral.isPresent(bSide) then
- if peripheral.getType(bSide) == "biolock" then
- hardware.bioSide = bSide
- break
- end
- end
- end
- if hardware.bioSide == "none" then -- This accounts for a removed scanner
- dhdSettings.bio.lock = "OFF" --
- end
- return
- elseif hType == "modem" then
- if modem then
- modem.close(dhdSettings.channels.recv)
- modem.close(dhdSettings.pChannels.recv)
- modem = nil
- end
- hardware.netSide = "none"
- local side
- for _, side in ipairs(rs.getSides()) do
- if peripheral.isPresent(tostring(side)) then
- local perp = peripheral.getType(tostring(side))
- if tostring(perp) == "modem" then
- if peripheral.call(tostring(side), "isWireless") == true then
- hardware.netSide = side
- if dhdSettings.net == "R" then
- rednet.open(hardware.netSide)
- elseif dhdSettings.net == "C" then
- modem = peripheral.wrap(hardware.netSide)
- modem.open(dhdSettings.channels.recv)
- end
- break
- end
- end
- end
- end
- return
- elseif hType == "mon" then
- dhdSettings.monA = "none"
- dhdSettings.monB = "none"
- local side
- for _, side in ipairs(rs.getSides()) do
- if peripheral.isPresent(tostring(side)) then
- local perp = peripheral.getType(tostring(side))
- if tostring(perp) == "monitor" and peripheral.call(side, "isColor") then
- peripheral.call(side, "setTextScale", 1)
- local tmX, tmY = peripheral.call(side, "getSize")
- if tmX == 7 then
- dhdSettings.monA = side
- elseif tmX == 29 then
- dhdSettings.monB = side
- end
- end
- end
- end
- return
- end
- end
- local function firstRun()
- netSend("1stRun")
- sleep(0.1)
- netSend(os.getComputerID())
- while true do
- local myGateInfo = { os.pullEvent("modem_message") }
- if myGateInfo[3] == dhdSettings.channels.recv and myGateInfo[4] == dhdSettings.channels.send then
- local tempSettings = myGateInfo[5]
- dhdSettings.thisGate = tempSettings.addr
- allGates[1].addr = dhdSettings.thisGate
- dhdSettings.gate = tempSettings.gate
- break
- end
- end
- if dhdSettings.thisGate == "--ERROR--" then return end
- saveData(settingsData, "cfg")
- if not fs.exists(dhdSettings.gateData) then
- saveData(dhdSettings.gateData, "gate")
- end
- -- Check and, if necessary, set computer label
- local ccLabel = os.getComputerLabel()
- if ccLabel == nil or tostring(ccLabel) == "" or ccLabel == "DHD" then
- os.setComputerLabel(dhdSettings.thisGate .. " DHD")
- end
- end
- local function initMe()
- term.setBackgroundColor(black)
- term.clear()
- drawElement(2, 2, 18, 1, white, black, "Initializing . . .")
- term.setCursorPos(2, 4)
- if not fs.exists(settingsData) then
- detectHardware("mon")
- detectHardware("modem")
- if hardware.netSide == "none" then missingComponent("modem") return end
- firstRun()
- end
- if not fs.exists(settingsData) then missingComponent("cfg") dhdSettings.thisGate = "--ERROR--" return end
- ingestData(settingsData, "cfg")
- drawElement(2, 4, 24, 1, white, black, "Hardware Discovery . . .")
- detectHardware("modem")
- if hardware.netSide == "none" then missingComponent("modem") dhdSettings.thisGate = "--ERROR--" return end
- if dhdSettings.pSync == "ON" then
- if dhdSettings.net == "R" then
- modem = peripheral.wrap(hardware.netSide)
- end
- modem.open(dhdSettings.pChannels.recv)
- end
- if dhdSettings.monA ~= "none" then
- monA.setBackgroundColor(black)
- monA.clear()
- end
- if dhdSettings.monB ~= "none" then
- monB.setBackgroundColor(black)
- monB.clear()
- end
- detectHardware("bio")
- if dhdSettings.bio.lock == "ON" and hardware.bioSide ~= "none" then bioLogin() end -- Biolock login
- local trWord = "Querying gateLiaison @ " .. dhdSettings.thisGate .. " . . ."
- drawElement(2, 6, #trWord, 1, white, black, trWord)
- netSend("QRY")
- drawElement(2, 8, 23, 1, white, black, "Awaiting response . . .")
- if dhdSettings.net == "R" then
- local senderID, message = rednet.receive()
- if senderID == dhdSettings.gate then
- updateStatus(message)
- end
- elseif dhdSettings.net == "C" then
- local netEvent = { os.pullEvent("modem_message") }
- if netEvent[3] == dhdSettings.channels.recv and netEvent[4] == dhdSettings.channels.send then
- updateStatus(netEvent[5])
- end
- end
- drawElement(2, 10, 20, 1, white, black, "Setting Shield . . .")
- if dhdSettings.startShield == "ON" then
- netSend("sON")
- end
- drawElement(2, 12, 25, 1, white, black, "Ingesting gate data . . .")
- ingestData(dhdSettings.gateData, "gate")
- term.setBackgroundColor(black)
- term.clear()
- kernelState = true
- runState = "Dial"
- currentState = "Dial"
- drawCLI()
- end
- initMe()
- repeat
- dhdKernel()
- if runState == "quit" then kernelState = false end
- if kernelState == false then
- if monA ~= "none" then
- monA.setBackgroundColor(black)
- monA.clear()
- end
- if monB ~= "none" then
- monB.setBackgroundColor(black)
- monB.clear()
- end
- term.setBackgroundColor(black)
- term.setTextColor(white)
- if dhdSettings.thisGate ~= "--ERROR--" then
- term.clear()
- term.setCursorPos(1, 1)
- end
- if hardware.netSide ~= "none" then
- if dhdSettings.pSync == "ON" then
- modem.close(dhdSettings.pChannels.recv)
- end
- if dhdSettings.net == "R" then
- rednet.close(hardware.netSide)
- elseif dhdSettings.net == "C" then
- modem.close(dhdSettings.channels.recv)
- end
- modem = nil
- end
- if runState == "reboot" or runState == "reset" then os.reboot() end
- return
- end
- until kernelState == false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement