cuber1098

LNEX or Client Code

Dec 31st, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | None | 0 0
  1. function os.pullEvent()
  2.     local cEvent, p1, p2, p3, p4, p5 = os.pullEventRaw()
  3.         if cEvent == "terminate" then
  4.         end
  5.     return cEvent, p1, p2, p3, p4, p5
  6. end
  7.  
  8. term.clear()
  9.  
  10. file = io.open("/LNEX/Client-DB/connect-info/id" , "r")
  11. ci = file:read()
  12. file:close()
  13. cs = tonumber(ci)
  14. print(cs)
  15.  
  16.  
  17.  
  18. function getRight(sLin)
  19.     local nWidth = term.getSize()
  20.     local x = math.floor(nWidth) - string.len(sLin)
  21.     return x + 1
  22. end
  23.  
  24. function getExist() --Send comp id, server checks if passuid exists with id, if not return false if yes return true. client reqests access to that file
  25.     rednet.send(cs , "req")
  26.     event , p1 , p2 = os.pullEvent("rednet_message")
  27.     if p2 == "true" then
  28.         rednet.send(cs , "cred")
  29.         repeat
  30.             p1 , p2 = rednet.receive(2) --or whatever timeout you like
  31.         until p1 and p1 == cs
  32.         assert(type(p2) == "table" , "Received message not account table!")
  33.         passes = textutils.unserialize(p2)
  34.         pr = true
  35.         return passes
  36.     elseif p2 == "false" then
  37.         pr = false
  38.     else
  39.         term.clear()
  40.         term.setCursorPos(1,1)
  41.         print("Server recommunication error")
  42.         os.pullEvent("key")
  43.         os.reboot()
  44.     end
  45. end
  46.  
  47. kim = getExist()
  48.  
  49. if kim == nil and pr == true then
  50.     print("Profile Load Error")
  51.     return false
  52. end
  53.  
  54. if  pr == false then
  55.     pass = ""
  56. end
  57.  
  58. function termRight(sLin)
  59.     local nWidth, nHeight = term.getSize()
  60.     local y = nHeight
  61.     local x = getRight(sLin)
  62.     term.setCursorPos(x, y)
  63.     term.write(sLin)
  64.  
  65.  
  66. end
  67.  
  68. function run()
  69. termRight("powered by: LNEX")
  70. term.setCursorPos(1,1)
  71. term.clearLine()
  72. write "Password: "
  73. input = read("*")
  74. if pr == true then
  75.     for i = 1,#kim do
  76.         if input == kim[i] then
  77.             term.setTextColor(colors.green)
  78.             print "Logged in"
  79.             sleep(2)
  80.             rednet.open("right")
  81.             shell.run("cc-get" , "update" , "lnexi")
  82.             shell.run("lnexi")
  83.             term.clear()
  84.             term.setCursorPos(1,1)
  85.             term.setTextColor(colors.yellow)
  86.             term.write("LNET SECURITY SYSTEM: Client")
  87.             term.setCursorPos(1,2)
  88.         elseif pr == false then
  89.             if pass == input then
  90.                 term.setTextColor(colors.green)
  91.                 print "Logged in"
  92.                 sleep(2)
  93.                 rednet.open("right")
  94.                 shell.run("cc-get" , "update" , "lnexi")
  95.                 shell.run("lnexi")
  96.                 term.clear()
  97.                 term.setCursorPos(1,1)
  98.                 term.setTextColor(colors.yellow)
  99.                 term.write("LNET SECURITY SYSTEM: Client")
  100.                 term.setCursorPos(1,2)
  101.             else
  102.                 print "Password Incorrect"
  103.                 sleep(2)
  104.                 os.shutdown()
  105.             end
  106.         end
  107.     end
  108. end
  109. if unexpected_condition then error() end
  110. end
  111.  
  112. if not pcall(run) then
  113.     term.clear("Error loading user data")
  114.     assert(kim ~= nil, "Error on account array: kim")
  115. end
Advertisement
Add Comment
Please, Sign In to add comment