Advertisement
AR2000

Computercraft Banque serveur

Mar 27th, 2016 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. local modem = peripheral.wrap("top")
  2. local disk = peripheral.wrap("bottom")
  3. --local tx = 1
  4. local rx = 0 --id serveur
  5. term.clear()
  6. term.setCursorPos(1,1)
  7. modem.open(rx)
  8.  
  9. --=============================================================
  10. while (disk.hasData() == true) do
  11.     local input,s,f,reply,command = os.pullEvent("modem_message")
  12.     print("=======================")
  13.    
  14.     if command[2] == "start" then
  15.         print(command[1],"~~~start")
  16.         if fs.exists(command[1]) == true then
  17.             print("path ok")
  18.             local compte = fs.open(command[1],"r")
  19.             local val = compte.readLine(1)
  20.             compte.close()
  21.             sleep(1)
  22.             modem.transmit(reply,rx,val)
  23.         else
  24.             sleep(1)
  25.             modem.transmit(reply,rx,"error")
  26.         end
  27.     end
  28.     if command[2] == "add" then
  29.         print("add")
  30.         local compte = fs.open(command[1],"r")
  31.         local val = compte.readLine(1)
  32.         compte.close()
  33.         nval = val+command[3]
  34.         print(nval)
  35.         local compte = fs.open(command[1],"w")
  36.         compte.write(nval)
  37.         compte.close()
  38.     end
  39.     if command[2] == "take" then
  40.         print("take")
  41.         local compte = fs.open(command[1],"r")
  42.         local val = compte.readLine(1)
  43.         compte.close()
  44.         nval = val-command[3]
  45.         print(nval)
  46.         local compte = fs.open(command[1],"w")
  47.         compte.write(nval)
  48.         compte.close()
  49.     end
  50.     if command[2] == "new" then
  51.         print("new")
  52.         compte = fs.open(command[1],"w")
  53.         compte.write(0)
  54.         compte.close()
  55.     end
  56.     if command[2] == "transf" then
  57.         print("transf")
  58.         local compte = fs.open(command[1],"r")
  59.         local val = compte.readLine(1)
  60.         compte.close()
  61.         nval = val-command[3]
  62.         print(nval)
  63.         local compte = fs.open(command[1],"w")
  64.         compte.write(nval)
  65.         compte.close()
  66.         local compte = fs.open(command[4],"r")
  67.         local val = compte.readLine(1)
  68.         compte.close()
  69.         nval = val+command[3]
  70.         print(nval)
  71.         local compte = fs.open(command[4],"w")
  72.         compte.write(nval)
  73.         compte.close()
  74.     end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement