TheDrunx

Untitled

Apr 8th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. function OpenAll()
  2. for _,side in ipairs(rs.getSides()) do
  3. rednet.open(side)
  4. end
  5. end
  6.  
  7. function split(str, pat)
  8. local t = { }
  9. local fpat = "(.-)"..pat
  10. local last_end = 1
  11. local s, e, cap = str:find(fpat, 1)
  12. while s do
  13. if s ~= 1 or cap ~= "" then
  14. table.insert(t,cap)
  15. end
  16. last_end = e+1
  17. s, e, cap = str:find(fpat, last_end)
  18. end
  19. if last_end <= #str then
  20. cap = str:sub(last_end)
  21. table.insert(t, cap)
  22. end
  23. return t
  24. end
  25.  
  26. function runServer()
  27. OpenAll()
  28. id, msg, d = rednet.receive()
  29. rmsg = split(msg, "!SP!")
  30. id2 = rmsg[1]
  31. cmd = rmsg[2]
  32. if cmd == "Activate" then
  33. fs.makeDir(id2)
  34. make = fs.open(id2.."/funds", "w")
  35. make.write("100")
  36. make.close()
  37. elseif cmd == "Transaction" then
  38. usr2 = rmsg[3]
  39. transaction = rmsg[4]
  40. usrmoney = fs.open(id2.."/funds", "r")
  41. money = usrmoney.readAll()
  42. usrmoney.close()
  43. usr2money = fs.open(usr2.."/funds", "r")
  44. money2 = usr2money.readAll()
  45. usr2money.close()
  46. money = money - transaction
  47. money2 = money2 + transaction
  48. nmoney = fs.open(id2.."/funds", "w")
  49. nmoney.write(money)
  50. nmoney.close()
  51. nmoney2 = fs.open(usr2.."/funds", "w")
  52. nmoney2.write(money2)
  53. nmoney2.close()
  54. elseif cmd == "ATM" then
  55. usrmoney = fs.open(id2.."/funds", "r")
  56. money = usrmoney.readAll()
  57. usrmoney.close()
  58. rednet.send(id, money)
  59. end
  60. runServer()
  61. end
  62.  
  63. runServer()
Add Comment
Please, Sign In to add comment