local component = require("component")
local sg = component.stargate
local event = require("event")
local os = require("os")
local gpu = component.gpu
local colors = { blue = 0x4286F4, purple = 0xB673d6, red = 0xC14141, green = 0xDA841,
black = 0x000000, white = 0xFFFFFF, grey = 0x47494C, lightGrey = 0xBBBBBB, orange = 0xFFA500, alert = 0xFF0000}
local selected = 0
local w, h = gpu.getResolution()
local addresseArray = {}
local addresseLength = 0
local entry = 0
local tmpAdd = ""
local secured = false
local is_ended = false
gpu.setForeground(0xffffff)
function parseAddress(add)
return string.format("%s-%s-%s",string.sub(add,1,4),string.sub(add,5,7),string.sub(add,8))
end
function alert(text)
gpu.fill((w/2+w/4), 1, w/4, 1, " ")
gpu.setForeground(colors.alert)
gpu.set((w/2+w/4), 1 , text)
gpu.setForeground(colors.white)
end
function getAddress()
file = io.open("address", "r")
if file == nil then
file = io.open("address", "w")
file:close()
file = io.open("address", "r")
end
while file:read() ~= nil do
if addresseLength>0 then
file:seek("set",9*addresseLength+1)
else
file:seek("set",9*addresseLength)
end
addresseArray[addresseLength] = file:read()
addresseLength = addresseLength+1
end
file:close()
end
function drawList()
for i=5, h do
if i%2==0 then
gpu.setBackground(colors.grey)
else
gpu.setBackground(colors.lightGrey)
end
gpu.fill(1,i,w/2,1," ")
if (i-5) < addresseLength then
gpu.set(1,i, parseAddress(addresseArray[i-5]))
end
end
end
function drawControls()
gpu.setBackground(colors.green)
gpu.fill(w/2+w/4, 5, w, 10, " ")
gpu.set((w/2+w/4)+(w-(w/2+w/4))/2, 10, "CALL")
gpu.setBackground(colors.grey)
gpu.fill(w/2+w/6, 20, w/4, 1, " ")
gpu.setBackground(colors.black)
gpu.set((w/2+w/4), 16, "ADD ADDRESS")
gpu.setBackground(colors.blue)
gpu.set((w/2+w/4)+(w/4)/2, 23, " SAVE ")
gpu.setBackground(colors.orange)
gpu.set((w/2+w/6), 23, "CANCEL")
gpu.setBackground(colors.red)
gpu.fill(w/2+1, 5, w/4, 10, " ")
gpu.set((w/2+(w/4)/2), 10, "DISCONNECT")
if sg.irisState() ~= "Offline" then
if sg.irisState() == "Closing" then
gpu.setBackground(colors.red)
else
gpu.setBackground(colors.green)
end
gpu.fill(w/2+1, 28, w, 10, " ")
gpu.set((w/2+w/4)-11, 33, "TOGGLE IRIS")
end
gpu.setBackground(colors.black)
end
function main()
gpu.setBackground(colors.black)
getAddress()
gpu.fill(1, 1, w, h, " ")
gpu.set(w/2-6,1, parseAddress(sg.localAddress()))
drawList()
drawControls()
end
main()
function clickChecker(name, id, x, y)
if x < w/2 and y >= 5 then
drawList()
selected = y-5
gpu.setBackground(colors.blue)
gpu.fill(1,y,w/2,1, " ")
if selected < addresseLength then
gpu.set(1,y,parseAddress(addresseArray[selected]))
end
elseif x > w/2+w/4 and y>=5 and y<=10 then
if addresseArray[selected] == nil then
alert("PLEASE SELECT AN ADDRESS")
else
sg.dial(addresseArray[selected])
if sg.irisState() ~= "Closed" then
sg.closeIris()
end
end
elseif x >= ((w/2+w/4)+(w/4)/2) and x <= (((w/2+w/4)+(w/4)/2)+6) and y==23 then
if entry == 9 then
file = io.open("address", "a")
file:write(tmpAdd.."\n")
file:close()
tmpAdd = ""
entry = 0
gpu.setBackground(colors.grey)
gpu.fill(w/2+w/6, 20, w/4, 1, " ")
gpu.setBackground(colors.black)
main()
else
alert("PLEASE ENTER A COMPLETE ADDRESS")
end
elseif x >= (w/2+w/6) and x <= (w/2+w/6)+6 and y==23 then
tmpAdd = ""
entry = 0
gpu.setBackground(colors.grey)
gpu.fill(w/2+w/6, 20, w/4, 1, " ")
gpu.setBackground(colors.black)
elseif x > w/2 and x < w/2+w/4 and y>=5 and y<=15 then
sg.disconnect()
elseif x > w/2 and y >= 28 and y<=38 and sg.irisState() ~= "Offline" then
if sg.irisState() == "Closed" then
sg.openIris()
else
sg.closeIris()
end
drawControls()
end
gpu.setBackground(colors.black)
end
function keyPress(e,add,key)
gpu.setBackground(colors.grey)
if ((key >=97 and key <= 122) or (key >= 48 and key <= 57)) and entry < 9 then
gpu.set(w/2+w/6+entry, 20, string.upper(string.char(key)))
tmpAdd = tmpAdd .. string.upper(string.char(key))
entry = entry+1
elseif key == 8 and entry > 0 then
entry = entry-1
gpu.set(w/2+w/6+entry, 20, " ")
tmpAdd = string.sub(tmpAdd,1,entry)
end
gpu.setBackground(colors.black)
end
function isCalling(this, src, remote)
gpu.setBackground(colors.alert)
gpu.fill(w/4, h/4, w/2, h/2, " ")
gpu.set(w/4+w/6, h/2, remote.." is calling")
os.sleep(3)
if (secured and ifIn(remote) == false and sg.irisState() ~= "Closed") then
sg.closeIris()
end
main()
end
function ifIn(remote)
local check = false
for i=0, addresseLength do
check = (parseAddress(addresseArray[i]) == remote)
end
return check;
end
function stop()
print("soft interrupt, closing")
event.ignore("key_up",keyPress)
event.ignore("sgDialIn", isCalling)
event.ignore("touch", clickChecker)
is_ended = true
end
event.listen("key_up", keyPress)
event.listen("sgDialIn", isCalling)
event.listen("touch", clickChecker)
event.listen("interrupted", stop)
while not is_ended do
os.sleep(15)
end
Comments