xXm0dzXx

Untitled

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