Lord_Proxene

AXA BANK 4.0 Server

May 13th, 2016 (edited)
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.30 KB | None | 0 0
  1. side = "right" -- Modem Side
  2. maintenance2 = "0" -- For Enable 1 or Disable 0 the maintenance
  3. rednet.open(side)  -- Don't Change This (End of Setup)
  4. term.clear()
  5.  
  6. function adminbutton()
  7.     term.setBackgroundColor(colors.orange)
  8.     term.setCursorPos(37,1)
  9.     print("  Admin  ")
  10. end
  11.  
  12. function drawStart()
  13.     term.clear()
  14.     term.setCursorPos(1,1)
  15.     print "Bank Server 4.0 Status: Online"
  16.     print "------------------------------"
  17.     adminbutton()
  18.     term.setCursorPos(1,3)
  19.     start()
  20. end
  21.  
  22. function start()
  23.     id, message = rednet.receive()
  24.     if message == "Create" then
  25.         create()
  26.     elseif message == "Login" then
  27.         login()
  28.     elseif message == "Suspend" then
  29.         suspend()
  30.     elseif message == "Delete" then
  31.         delete()
  32.     elseif message == "Balance" then
  33.         balance()
  34.     elseif message == "Transfert" then
  35.         transfert()
  36.     elseif message == "Addfunds" then
  37.         addfunds()
  38.     elseif message == "Withdraw" then
  39.         withdraw()
  40.     elseif message == "Parcelles" then
  41.         parcelles()
  42.     elseif message == "Turtlebankadd" then
  43.         turtlebankadd()
  44.     elseif message == "Turtlebankremove" then
  45.         turtlebankremove()
  46.     elseif message == "Maintenance" then
  47.         maintenance()
  48.     end
  49. end
  50.  
  51. function create()
  52.     id, user = rednet.receive()
  53.     id, pass = rednet.receive()
  54.     if fs.exists("user/"..user) then
  55.         rednet.send(id," L'utilisateur existe deja ")
  56.         term.setBackgroundColor(colors.red)
  57.         print("Connexion de "..id.." Error #1")
  58.         start()
  59.     else
  60.         h = fs.open("user/"..user,"w")
  61.         h.write(pass)
  62.         h.close()
  63.         h = fs.open("$/"..user,"w")
  64.         h.write("0")
  65.         h.close()
  66.         rednet.send(id,"  Compte cree avec succes  ")
  67.         term.setBackgroundColor(colors.lime)
  68.         print("Connexion de "..id.." Success #1")
  69.         start()
  70.     end
  71. end
  72.  
  73. function login()
  74.     id, user = rednet.receive()
  75.     id, pass = rednet.receive()
  76.     if type(user) == "string" then
  77.         if type(pass) == "string" then
  78.             if fs.exists("user/"..user) == true then
  79.                 h = fs.open("user/"..user, "r")
  80.                 passReal = h.readAll()
  81.                 h.close()
  82.                
  83.                 if pass == passReal then
  84.                     rednet.send(id,"Connexion avec succes")
  85.                     term.setBackgroundColor(colors.lime)
  86.                     print("Connexion de "..id.." Success #2")
  87.                     start()
  88.                 else
  89.                     rednet.send(id,"   Mot de passe invalide   ")
  90.                     term.setBackgroundColor(colors.red)
  91.                     print("Connexion de "..id.." Error #2")
  92.                   start()
  93.                 end
  94.             else
  95.                 rednet.send(id," Votre compte n'existe pas ")
  96.                 term.setBackgroundColor(colors.red)
  97.                 print("Connexion de "..id.." Error #3")
  98.                 start()
  99.             end
  100.         end
  101.     end
  102. end
  103.  
  104. function balance()
  105.     id, user = rednet.receive()
  106.     if type(user) == "string" then
  107.         h = fs.open("$/"..user, "r")
  108.         bal = tonumber(h.readAll())
  109.         h.close()
  110.         rednet.send(id,bal)
  111.        
  112.         term.setBackgroundColor(colors.lime)
  113.         print("Connexion de "..id.." balance "..user)
  114.  
  115.         start()
  116.     end
  117. end
  118.  
  119. function transfert()
  120.     id, user = rednet.receive()
  121.     id, user2 = rednet.receive()
  122.     id, montantdeduit = rednet.receive()
  123.     if type(user) == "string" then
  124.         h = fs.open("$/"..user, "r")
  125.         bal2 = tonumber(h.readAll())
  126.         h.close()
  127.  
  128.         h = fs.open("$/"..user2, "r")
  129.         bal3 = tonumber(h.readAll())
  130.         h.close()
  131.        
  132.         if bal2 >= montantdeduit then
  133.             bal2 = bal2 - montantdeduit
  134.             bal3 = bal3 + montantdeduit
  135.            
  136.             h = fs.open("$/"..user, "w")
  137.             h.write(bal2)
  138.             h.close()
  139.            
  140.             h = fs.open("$/"..user2, "w")
  141.             h.write(bal3)
  142.             h.close()
  143.            
  144.             rednet.send(id," Credits transferer avec succes ")
  145.             term.setBackgroundColor(colors.lime)
  146.             print("Connexion de "..id.." Transfert "..user)
  147.             start()
  148.         else
  149.             rednet.send(id,"      Credits insuffisant     ")
  150.             term.setBackgroundColor(colors.red)
  151.             print("Connexion de "..id.." Transfert Failed "..user)
  152.             start()
  153.         end
  154.     end
  155. end
  156.  
  157. function delete()
  158.     id, user = rednet.receive()
  159.     if type(user) == "string" then
  160.         fs.delete("$/"..user)
  161.         fs.delete("user/"..user)
  162.         rednet.send(id," Votre compte a ete supprimer ")
  163.         term.setBackgroundColor(colors.lime)
  164.         print("Connexion de "..id.." Suppression "..user)
  165.         start()
  166.     end
  167. end
  168.  
  169. function parcelles()
  170.     term.setBackgroundColor(colors.black)
  171.     id, user2 = rednet.receive()
  172.     id, pass = rednet.receive()
  173.     id, atm = rednet.receive()
  174.  
  175.     h = fs.open("$/"..user2, "r")
  176.     bal2 = tonumber(h.readAll())
  177.     h.close()
  178.    
  179.     if bal2 >= atm then
  180.         rednet.send(id,"balok")
  181.         if fs.exists("user/"..user2) == true then
  182.             h = fs.open("user/"..user2, "r")
  183.             passReal = h.readAll()
  184.             h.close()
  185.  
  186.             if pass == passReal then
  187.                 rednet.send(id,"passok")
  188.            
  189.                 bal2 = bal2 - atm
  190.  
  191.                 h = fs.open("$/"..user2, "w")
  192.                 h.write(bal2)
  193.                 h.close()
  194.                
  195.                 term.setBackgroundColor(colors.lime)   
  196.                 print("Connexion de "..id.." Parcelles Success")
  197.                 start()
  198.             else
  199.                 term.setBackgroundColor(colors.red)
  200.                 print("Connexion de "..id.." Parcelles Failed #1")
  201.                 start()
  202.             end
  203.         else
  204.             rednet.send(id,"nop")
  205.             term.setBackgroundColor(colors.red)
  206.             print("Connexion de "..id.." Parcelles Failed #2")
  207.             start()
  208.         end
  209.     else
  210.         rednet.send(id,"nop")
  211.         term.setBackgroundColor(colors.red)
  212.         print("Connexion de "..id.." Parcelles Failed #3")
  213.         start()
  214.     end
  215. end
  216.  
  217. function turtlebankadd()
  218.     id, user2 = rednet.receive()
  219.     id, datavalue = rednet.receive()
  220.  
  221.     h = fs.open("$/"..user2, "r")
  222.     bal2 = tonumber(h.readAll())
  223.     h.close()
  224.  
  225.     datavalue = datavalue
  226.     bal3 = bal2 + datavalue
  227.    
  228.     h = fs.open("$/"..user2, "w")
  229.     h.write(bal3)
  230.     h.close()
  231.  
  232.     term.setBackgroundColor(colors.lime)
  233.     print("Connexion de "..id.." Ajout de "..datavalue.." a "..user2)
  234.    
  235.     start()
  236. end
  237.  
  238. function turtlebankremove()
  239.     id, user2 = rednet.receive()
  240.     id, pass = rednet.receive()
  241.     id, datavalue = rednet.receive()
  242.  
  243.     if fs.exists("user/"..user) == true then
  244.         h = fs.open("user/"..user, "r")
  245.         passReal = h.readAll()
  246.         h.close()
  247.        
  248.         if pass == passReal then
  249.             h = fs.open("$/"..user2, "r")
  250.             bal2 = tonumber(h.readAll())
  251.             h.close()
  252.            
  253.             datavalue = datavalue
  254.             bal3 = bal2 - datavalue
  255.            
  256.             h = fs.open("$/"..user2, "w")
  257.             h.write(bal3)
  258.             h.close()
  259.            
  260.             rednet.send(id,"successremovebank")
  261.            
  262.             term.setBackgroundColor(colors.lime)
  263.             print("Connexion de "..id.." Compte deduit "..datavalue.." a "..user)
  264.             start()
  265.         else
  266.             rednet.send(id,"fail2")
  267.             start()
  268.         end
  269.     else
  270.         rednet.send(id,"fail3")
  271.         start()
  272.     end
  273.    
  274.     start()
  275. end
  276.  
  277. drawStart()
Advertisement
Add Comment
Please, Sign In to add comment