xXm0dzXx

Untitled

Jul 15th, 2012
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. rednet.open("top")
  2. shell.run("clear")
  3. function cPrint(str, ypos)
  4. w, h = term.getSize()
  5. for i=1,w-1 do
  6. write("-")
  7. end
  8. term.setCursorPos(w/2-#str/2, ypos)
  9. write(str)
  10. end
  11.  
  12. cPrint("ComputerCraft Virtual Bank", 1)
  13. fs.makeDir("Accounts")
  14.  
  15. while true do
  16. id, message = rednet.receive()
  17.  
  18. local tWords = {}
  19. for match in string.gmatch(message, "[^:\t]+") do
  20. table.insert( tWords, match )
  21. end
  22.  
  23. --Format:
  24. --GIVE:<YOUR NAME>:<YOUR PASS>:<HOW MUCH U WANNA GIVE TO...>:<YOUR FRIEND>
  25. if tWords[1] == "GIVE" then
  26. if tWords[5] then
  27. if fs.exists("Accounts/" ..tWords[2]) then
  28. a = fs.open("Accounts/" ..tWords[2], "r")
  29. --File Format:
  30. --<Pass>
  31. --<Your money>
  32. Password = a.readLine()
  33. YourCurrent = tonumber(a.readLine())
  34. YourPay = tonumber(tWords[4])
  35. a.close()
  36.  
  37. if tWords[3] == Password and fs.exists("Accounts/" ..tWords[5]) then
  38. if YourCurrent > YourPay or YourCurrent == YourPay then
  39. test = fs.open("Accounts/" ..tWords[5], "r")
  40. TheirPass = test.readLine()
  41. TheirCurrency = tonumber(test.readLine())
  42. test.close()
  43.  
  44. fs.delete("Accounts/" ..tWords[5])
  45.  
  46. test = fs.open("Accounts/" ..tWords[5], "w")
  47. test.writeLine(TheirPass)
  48. test.writeLine(TheirCurrency + YourPay)
  49. YourCurrent = YourCurrent - YourPay
  50. test.close()
  51.  
  52. print(tWords[2].. " gave " ..tWords[5].. " $" ..YourPay)
  53. else
  54. print("Insignificant funds")
  55. end
  56. else
  57. print("Payment failed. " ..id)
  58. end
  59. else
  60. print("Payment failed. " ..id)
  61. end
  62. else
  63. print("Junk received from " ..id)
  64. end
  65. elseif tWords[1] == "NEW" then --NEW:<UR NAME>:<UR PASS>
  66. if tWords[3] then
  67. if fs.exists("Accounts/" ..tWords[2]) then
  68. print("Register failed. " ..id)
  69. else
  70. test = fs.open("Accounts/" ..tWords[2], "w")
  71. if test then
  72. test.writeLine(tWords[3])
  73. test.writeLine("0") --0 dollars
  74. test.close()
  75. else
  76. print("Register failed... :C")
  77. end
  78.  
  79. print("Register complete!")
  80. end
  81. else
  82. print("Junk received from " ..id)
  83. end
  84. elseif tWords[1] == "VERIFY" then
  85. if tWords[3] then
  86. if fs.exists("Accounts/" ..tWords[2]) then
  87. a = fs.open("Accounts/" ..tWords[2], "r")
  88. Password = a.readLine()
  89. a.close()
  90. if Password == tWords[3] then
  91. rednet.send(id, "Correct")
  92. print(id.. " logged in.")
  93. else
  94. rednet.send(id, "Wrong")
  95. print("Failed #2 (" ..Password.. ")")
  96. end
  97.  
  98. else
  99. rednet.send(id, "Wrong")
  100. print("Failed #1")
  101. end
  102. else
  103. print("Junk received from " ..id)
  104. end
  105. elseif tWords[1] == "CHECK" then --CHECK:<UR NAME> will send you the balance of <UR NAME>
  106. if tWords[2] then
  107. test = fs.open("Accounts/" ..tWords[2], "r")
  108. if test then
  109. test.readLine()
  110. rednet.send(id, test.readLine())
  111. test.close()
  112. print("Checked!")
  113. else
  114. rednet.send(id, "Unknown Username/Pass")
  115. end
  116. else
  117. print("Junk received from " ..id)
  118. end
  119. else
  120. print("Junk received from " ..id)
  121. end
  122. end
Advertisement
Add Comment
Please, Sign In to add comment