pepeknamornik

ClientAD

Mar 11th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. local w, h = term.getSize()
  2. term.setBackgroundColor(colors.black)
  3. term.clear()
  4. term.setCursorPos(1,1)
  5. local idPC = os.getComputerID()
  6.  
  7. if fs.exists("/C/system/.core/defmodem") then
  8.         local data = fs.open ("/C/system/.core/defmodem","r")
  9.         modemPos = data.readLine()
  10.         data.close()
  11.         if not modemPos then
  12.         modemPos = "offline"
  13.         else
  14.         modem.open(idPC)
  15.         end
  16.     else
  17.         modemPos = "offline"
  18. end
  19.  
  20.  
  21. function restarting ()
  22.     term.setBackgroundColor(colors.lightGray)
  23.     term.clear()
  24.     sleep (0.1)
  25.     term.setBackgroundColor(colors.gray)
  26.     term.clear()
  27.     sleep (0.1)
  28.     term.setBackgroundColor(colors.black)
  29.     term.setTextColor(colors.black)
  30.     term.clear()
  31.     term.setBackgroundColor(colors.white)
  32.     term.setTextColor(colors.black)
  33.     term.clear()
  34.     term.setCursorPos(w/2-6, h/2)
  35.     write "Restarting..."
  36.     term.setBackgroundColor(colors.white)
  37.     term.setTextColor(colors.blue)
  38.     term.setCursorPos(w/2-5,h-1)
  39.     write "  Pepek"
  40.     term.setCursorPos(w/2+3,h-1)
  41.     write "Soft  "
  42.     term.setCursorPos(w/2+2,h-1)
  43.     term.setTextColor(colors.lime)
  44.     write "@"
  45.     sleep(1)
  46.     os.reboot ()
  47. end
  48.  
  49. function start()
  50. term.setCursorPos(1,1)
  51. write"ID serveru: "
  52. ID = tonumber(read())
  53. term.setCursorPos(1,2)
  54. write"User: "
  55. user = read()
  56. term.setCursorPos(1,3)
  57. write"Pass: "
  58. pass = read()
  59. dotaz()
  60. end
  61.  
  62. rfreq = 0
  63. i = 0
  64.  
  65.  
  66.  
  67.  
  68. function prijmout()
  69. timerRX = os.startTimer(2)
  70.     while true do
  71.     local event,p1,p2,p3,p4 = os.pullEvent()
  72.       if event == ("modem_message") then
  73.       print("Odpoved serveru "..p4)
  74.           if (p3 == 552) then
  75.                 if (p4 == "true") then
  76.                 local c = fs.open ("/C/system/.core/AD", "w")
  77.                 c.writeLine(tostring(ID))
  78.                 c.close()
  79.                 restarting()
  80.                 else
  81.                 print"error"
  82.                 end
  83.             end
  84.       sleep(1)
  85.       shell.run("/C/desktop.lua")
  86.       elseif event == "timer" then
  87.         if p1 >= timerRX then
  88.             shell.run("/C/desktop.lua")
  89.         end
  90.       end
  91.     end
  92. end
  93.  
  94. function dotaz()
  95. modem.open(idPC)
  96. modem.transmit(tonumber(ID),550,idPC)
  97. modem.transmit(tonumber(ID),551,user)
  98. modem.transmit(tonumber(ID),552,pass)
  99. prijmout() 
  100. end
  101.  
  102. start()
Add Comment
Please, Sign In to add comment