Advertisement
BananeMan

Untitled

Nov 4th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.86 KB | None | 0 0
  1. --*****************************
  2. --********BANQUE CLIENT********
  3. --*****************************
  4.  
  5. --Déclaration des variables
  6. local monX, monY = term.getSize()
  7.  
  8. local user = ""
  9. local pass = ""
  10. local idserver = 0
  11. local whilef = false
  12. local goodPass = false
  13. local isRunning = false
  14. --rondane = "/disk/rednet"
  15. local publickey = ""
  16. local crypt = "/disk/crypto"
  17. os.loadAPI(crypt)
  18. --os.loadAPI(rondane)
  19. -- Fin des déclaration des variables
  20. function keyretriver()
  21.     idserver = rednet.lookup("2banque", "server")
  22.     local messagea = "keyretrive"
  23.     if idserver == nil then
  24.         print("La connection n'a pas plus être établie")
  25.         print("Redémarage")
  26.         sleep(2)
  27.         os.reboot()
  28.     else
  29.         rednet.send(idserver, messagea, "superproto")
  30.     end
  31.  
  32.     local disable = true
  33.     while disable do
  34.         local si, mess, distance = rednet.receive()
  35.         if si == idserver then
  36.             publickey = mess
  37.             disable = false
  38.             return publickey
  39.         end
  40.     end
  41. end
  42. function interfac()
  43.     print("Connection au serveur bancaire...")
  44.     rednet.open("back")
  45.     keyretriver()
  46.     print("Banque interface")
  47.     print("Veuillez entrer votre nom d'utilisateur:")
  48.     user = read()
  49.     print("Veuillez entrer votre mot de passe")
  50.     pass = read("*")
  51.     print("Connection en cours...")
  52.     conn()
  53. end
  54.  
  55. function conn()
  56.     local logintable = {action = "login", User = user, Pass = pass, id = os.getComputerID()}
  57.     login = textutils.serialize(logintable)
  58.     idserver = rednet.lookup("2banque", "server")
  59.     logincrypt = crypto.encrypt(login, publickey)
  60.     rednet.send(idserver, logincrypt, "superproto")
  61.     while whilef == false do
  62.         senderid, message, disance = rednet.receive()
  63.         if senderid == idserver then
  64.             mesge = textutils.unserialize(message)
  65.             if mesge.action == "login" and mesge.user == user then
  66.                 whilef = True
  67.                 if mesge.response == "yes" then
  68.                     print("Vous êtes connecté !")
  69.                     sleep(2)
  70.                     goodPass = true
  71.                     break
  72.                 else
  73.                     print("Mauvais identifiant")
  74.                     break
  75.                 end
  76.             end
  77.         end
  78.     end
  79.     whilef = false
  80. end
  81.  
  82. function maininterface()
  83.     isRunning = true
  84.     money = 0
  85.     term.clear()
  86.     term.setCursorPos(1,1)
  87.     x,y = term.getSize()
  88.     paintutils.drawFilledBox(1,1,x,y, colors.lightGray)
  89.     paintutils.drawLine(1,1,x,1, colors.gray)
  90.     term.setCursorPos(1,1)
  91.     term.write("Menu de la banque")
  92.     paintutils.drawPixel(x, 1, colors.red)
  93.     term.setCursorPos(x,1)
  94.     term.write("X")
  95.     term.setCursorPos(1,2)
  96.     term.setBackgroundColor(colors.lightGray)
  97.     term.write("Vous avez : "..money)
  98.  
  99.     --Création des boutton
  100.     paintutils.drawFilledBox(1,3,x/4,y/4, colors.green)
  101.     --Actions menu
  102.     while isRunning do
  103.         sleep(0.1)
  104.     end
  105. end
  106.  
  107. function closeHandler()
  108.     while isRunning do
  109.         local event, p1, p2, p3 = os.pullEvent("mouse_click")
  110.  
  111.         --print(p2.."/"..p3)
  112.  
  113.         if p2 == monX and p3 == 1 then
  114.             isRunning = false
  115.         end
  116.     end
  117. end
  118.  
  119. interfac()
  120.  
  121. if goodPass then
  122.     parallel.waitForAll(maininterface, closeHandler)
  123. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement