Advertisement
Guest User

server

a guest
Nov 23rd, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. local sides = {"top","bottom","left","right","front","back"}
  2. for i = 1,6 do
  3.   a = sides[i]
  4.   if peripheral.getType(a) == "modem" then
  5.     rednet.open(a)
  6.     break
  7.   end
  8. end
  9. while true do
  10. for i = 1,6 do
  11.   a = sides[i]
  12.   if peripheral.getType(a) == "drive" then
  13.     dr = a
  14.     drive = peripheral.wrap(a)
  15.     break
  16.   end
  17. end
  18.   id,msg,protocol = rednet.receive()
  19.   if protocol == "money" then
  20.     if not fs.exists("disk/"..msg) then
  21.       print("[CREATE] Created account "..msg.." with 0$")
  22.       rednet.send(id,"new")
  23.       file = fs.open("disk/"..msg,"w")
  24.       file.write("0")
  25.       file.close()
  26.     else
  27.       file = fs.open("disk/"..msg,"r")
  28.       money = file.readAll()
  29.       file.close()
  30.       print(msg.." has "..money.."$")
  31.       rednet.send(id,money)
  32.     end
  33.   else
  34.     from = string.sub(msg,1,4)
  35.     from = tonumber(from)+0
  36.     money = string.sub(msg,5,string.len(msg))
  37.     to = protocol
  38.     file1 = fs.open("disk/"..from,"r")
  39.     money1 = tonumber(file1.readAll())
  40.     file1.close()
  41.     if money1 >= tonumber(money) then
  42.       file1 = fs.open("disk/"..from,"w")
  43.       file1.write(money1-money)
  44.       file1.close()
  45.       print("[PAY] Taken from "..from.." "..money.."$")
  46.       rednet.send(id,200)
  47.       if fs.exists("money/"..to) then
  48.         file2 = fs.open("money/"..to,"r")
  49.         money2 = file2.readAll()
  50.         file2.close()
  51.         file2 = fs.open("money/"..to,"w")
  52.         file2.write(money2+money)
  53.         print("[PAY] Payed "..money.."$ to "..to)
  54.       else
  55.         file2 = fs.open("money/"..to,"w")
  56.         file2.write(money)
  57.         file2.close()
  58.         print("[CREATE] Created account "..to.." with "..money.."$")
  59.         print("[PAY] Payed "..money.."$ to "..to)
  60.       end
  61.     else
  62.       print("[ERROR] "..from.."hasn't got enough money")  
  63.     end
  64.   end
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement