Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------------------------
- ------------------------------------------------------------------
- local codename = 'stairctrl'
- local codeversion = '0.4.0.2'
- local whoami = os.getComputerID ()
- term.clear ()
- print (">>>"..codename.." Version "..codeversion.."@ID:"..whoami)
- ------------------------------------------------------------------
- ------------------------------------------------------------------
- local password = 'IAO'
- local msg_expected_paramcount = 4 -- message format: <SenderID>|<ReceiverID>|<Secret>|<Command>
- local shared_secret = "OpenUpMofo"
- local sendChannel = 59999
- local listenChannel = 60000
- local rs_signal_output = 'right'
- local current_status = false
- local monitor = peripheral.wrap('left')
- local mon_maxx, mon_maxy = monitor.getSize()
- local quote = {"Improvise,", "Adapt,", "Overcome."}
- local charoffsettable = {}
- local stairvisible = false
- ------------------------------------------------------------------
- local function parseMessage (msg)
- local msgparam = {}
- for param in string.gmatch (msg, "[^|]+") do
- table.insert (msgparam, param)
- end
- return msgparam
- end
- ------------------------------------------------------------------
- local function showStairs ()
- calicommAPI.modemtable[1][1].transmit(sendChannel, listenChannel, whoami.."|2|"..shared_secret.."|on")
- calicommAPI.modemtable[1][1].transmit(sendChannel, listenChannel, whoami.."|4|"..shared_secret.."|on")
- sleep (1)
- calicommAPI.modemtable[1][1].transmit(sendChannel, listenChannel, whoami.."|3|"..shared_secret.."|on")
- end
- ------------------------------------------------------------------
- local function hideStairs ()
- calicommAPI.modemtable[1][1].transmit(sendChannel, listenChannel, whoami.."|3|"..shared_secret.."|off")
- sleep (1)
- calicommAPI.modemtable[1][1].transmit(sendChannel, listenChannel, whoami.."|2|"..shared_secret.."|off")
- calicommAPI.modemtable[1][1].transmit(sendChannel, listenChannel, whoami.."|4|"..shared_secret.."|off")
- end
- local function drawQuote ()
- monitor.clear()
- local ypos = math.ceil((mon_maxy / 2) - (#quote / 2))
- for i=1,#quote do
- local xpos = math.ceil((mon_maxx / 2) - (string.len(quote[i]) / 2)) + 1
- ypos = ypos + 1
- table.insert (charoffsettable, {xpos, ypos})
- monitor.setCursorPos(xpos,ypos)
- monitor.write(quote[i])
- end
- end
- local function getKeyFromScreen (xclick, yclick)
- for i=1,#charoffsettable do
- if (yclick == charoffsettable[i][2]) then
- local xoffset = xclick - charoffsettable[i][1]
- if ((xoffset >= 0) and ((xoffset + 1) <= #quote[i])) then
- --print ("X:"..xclick.." Y:"..yclick.." Key:"..string.sub (quote[i], xoffset + 1, xoffset + 1))
- return (string.sub (quote[i], xoffset + 1, xoffset + 1))
- end
- end
- end
- print ("X:"..xclick.." Y:"..yclick.." Key:")
- end
- -- MAIN ----------------------------------------------------------
- os.loadAPI ('calicommAPI')
- calicommAPI.enableDebug (false)
- calicommAPI.initModems ()
- calicommAPI.openModemChannel (calicommAPI.modemtable[1][1], listenChannel)
- while (true) do
- drawQuote ()
- if (stairvisible) then
- local event, monside, xpos, ypos = os.pullEvent("monitor_touch")
- print "*closed stairs"
- hideStairs ()
- stairvisible = false
- else
- local pwentered = ''
- while (tonumber(string.len(pwentered)) < tonumber(string.len(password))) do
- local event, monside, xpos, ypos = os.pullEvent("monitor_touch")
- local pressed = getKeyFromScreen (xpos, ypos)
- if (pressed ~= nil) then
- pwentered = pwentered .. pressed
- end
- end
- if (pwentered == password) then
- print "*Password ok"
- showStairs ()
- stairvisible = true
- else
- print "*Password error"
- end
- end
- end
- calicommAPI.closeModemChannel (calicommAPI.modemtable[1][1], listenChannel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement