Advertisement
infiniteblock

Untitled

Apr 21st, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.84 KB | None | 0 0
  1. -- Load API's
  2. os.loadAPI("crypt")
  3. os.loadAPI("gui")
  4.  
  5. local textStart = gui.textStart
  6. local diskSide = "right"
  7. local serverId = 3
  8. local withdrawId = 14
  9. local version = "GAB-0.1"
  10. url = "http://147.135.59.131/index.php"
  11.  
  12. -- Import GUI functions
  13. local drawHeader, drawButtons, drawButton, drawError, center = gui.drawHeader, gui.drawButtons, gui.drawButton, gui.drawError, gui.center
  14. local waitForMouse, waitForButton, waitForChar, waitForKey, waitForEnter = gui.waitForMouse, gui.waitForButton, gui.waitForChar, gui.waitForKey, gui.waitForEnter
  15. local waitForDisk = gui.waitForDisk
  16.  
  17. function otherAmount()
  18. local amount = ""
  19. term.clear() drawHeader()
  20. term.setCursorPos(center(textStart, "Amount : $ ") + 12, textStart)
  21. return read()
  22. end
  23.  
  24. function balance(acc, pin)
  25. term.clear() drawHeader() drawButtons()
  26.  
  27. drawButton(4, "Cancel")
  28. drawButton(5, "Galleon Dollars")
  29.  
  30. local mult = nil
  31. while true do
  32. local button = waitForButton()
  33. if button == 4 then return
  34. elseif button == 5 then mult = 1 break
  35. end
  36. end
  37.  
  38. request = http.post(url, "command="..textutils.urlEncode(tostring("balance")).."&".."username="..textutils.urlEncode(tostring(acc)).."&".."password="..textutils.urlEncode(tostring(crypt.hashPassword(pin))))
  39. response = request.readAll()
  40. term.clear() drawHeader() drawButtons()
  41. drawButton(8, "OK")
  42.  
  43. if response ~= "-" then
  44. local displayBalance = math.floor(tonumber(response) * mult * 100) / 100
  45. center(textStart, "Balance: $" .. displayBalance .. " Galleons.")
  46. else
  47. drawError("Transaction Error")
  48. end
  49.  
  50. while true do
  51. local button = waitForButton()
  52. if button == 8 then return end
  53. end
  54. end
  55.  
  56. function transfer(acc, pin)
  57. term.clear() drawHeader() drawButtons()
  58.  
  59. drawButton(1, "$100")
  60. drawButton(2, "$200")
  61. drawButton(3, "$500")
  62. drawButton(5, "$1000")
  63. drawButton(6, "$2000")
  64. drawButton(7, "$5000")
  65.  
  66. drawButton(4, "Cancel")
  67. drawButton(8, "Other Amount")
  68.  
  69. local amountS = nil
  70. while true do
  71. local button = waitForButton()
  72. if button == 1 then amountS = "100" break
  73. elseif button == 2 then amountS = "200" break
  74. elseif button == 3 then amountS = "500" break
  75. elseif button == 5 then amountS = "1000" break
  76. elseif button == 6 then amountS = "2000" break
  77. elseif button == 7 then amountS = "5000" break
  78. elseif button == 4 then return
  79. elseif button == 8 then amountS = otherAmount() break
  80. end
  81. end
  82.  
  83. term.clear() drawHeader() drawButtons()
  84.  
  85. local amount = tonumber(amountS)
  86. if amount ~= nil and (amount % 1) == 0 then
  87. term.clear() drawHeader()
  88. term.setCursorPos(center(textStart, "Amount : $ ") + 12, textStart)
  89. term.write(amountS)
  90. term.setCursorPos(center(textStart + 1, "Account : ") + 10, textStart + 1)
  91. local account = read()
  92.  
  93. drawButtons()
  94. drawButton(4, "Cancel")
  95. drawButton(8, "Confirm")
  96.  
  97. while true do
  98. local button = waitForButton()
  99. if button == 4 then return
  100. elseif button == 8 then break
  101. end
  102. end
  103.  
  104. local senderId, response = nil, nil
  105. rednet.open(modemSide)
  106.  
  107. rednet.send(serverId, version .. textutils.serialize( { "TRANSFER", acc, crypt.hashPassword(pin), account, amountS } ) )
  108.  
  109. while true do
  110. senderId, response = rednet.receive(5)
  111. if senderId == serverId then break end
  112. end
  113. rednet.close(modemSide)
  114.  
  115. term.clear() drawHeader() drawButtons()
  116.  
  117. if response ~= "-" then
  118. center(textStart, "Transfer Successful")
  119. else
  120. drawError("Transaction Error")
  121. end
  122.  
  123. else
  124. term.clear() drawHeader() drawButtons()
  125. drawError("Invalid Amount")
  126.  
  127. --[[
  128. while true do
  129. local button = waitForButton()
  130. if button == 8 then return end
  131. end
  132. --]]
  133. end
  134.  
  135. drawButton(8, "OK")
  136. while true do
  137. local button = waitForButton()
  138. if button == 8 then return end
  139. end
  140. end
  141.  
  142. function withdraw(acc, pin)
  143. term.clear() drawHeader() drawButtons()
  144.  
  145. drawButton(1, "MC$ 100")
  146. drawButton(2, "MC$ 200")
  147. drawButton(3, "MC$ 500")
  148. drawButton(5, "MC$ 1000")
  149. drawButton(6, "MC$ 2000")
  150. drawButton(7, "MC$ 5000")
  151.  
  152. drawButton(4, "Cancel")
  153. drawButton(8, "Other Amount")
  154.  
  155. local amountS = nil
  156. while true do
  157. local button = waitForButton()
  158. if button == 1 then amountS = "100" break
  159. elseif button == 2 then amountS = "200" break
  160. elseif button == 3 then amountS = "500" break
  161. elseif button == 5 then amountS = "1000" break
  162. elseif button == 6 then amountS = "2000" break
  163. elseif button == 7 then amountS = "5000" break
  164. elseif button == 4 then return
  165. elseif button == 8 then amountS = otherAmount() break
  166. end
  167. end
  168.  
  169. term.clear() drawHeader() drawButtons()
  170.  
  171. local amount = tonumber(amountS)
  172. if amount ~= nil and (amount % 100) == 0 then
  173. term.clear() drawHeader()
  174. term.setCursorPos(center(textStart, "Amount : MC$ ") + 12, textStart)
  175. term.write(amountS)
  176. drawButtons()
  177. drawButton(4, "Cancel")
  178. drawButton(8, "Confirm")
  179.  
  180. while true do
  181. local button = waitForButton()
  182. if button == 4 then return
  183. elseif button == 8 then break
  184. end
  185. end
  186.  
  187. local senderId, response = nil, nil
  188. rednet.open(modemSide)
  189.  
  190. rednet.send(serverId, version .. textutils.serialize( { "WITHDRAW", acc, crypt.hashPassword(pin), amountS } ) )
  191.  
  192. while true do
  193. senderId, response = rednet.receive(5)
  194. if senderId == serverId then break end
  195. end
  196. rednet.close(modemSide)
  197.  
  198. term.clear() drawHeader()
  199.  
  200. if response ~= "-" then
  201. center(textStart, "Withdrawing " .. (amount) .. " MC$")
  202. rednet.open(modemSide)
  203. rednet.send(withdrawId, version .. textutils.serialize( { "WITHDRAW", (amount) .. "" } ) )
  204.  
  205. while true do
  206. senderId, response = rednet.receive(5)
  207. if senderId == withdrawId then break end
  208. end
  209. rednet.close(modemSide)
  210.  
  211. term.clear() drawHeader()
  212. if response ~= "-" then
  213. center(textStart, "Please take your cash")
  214. sleep(2)
  215. return
  216. else
  217. drawButtons()
  218. drawError("Withdrawal Error")
  219. end
  220. else
  221. drawError("Transaction Error")
  222. end
  223.  
  224. else
  225. term.clear() drawHeader() drawButtons()
  226. drawError("Invalid Amount")
  227.  
  228. --[[
  229. while true do
  230. local button = waitForButton()
  231. if button == 8 then return end
  232. end
  233. --]]
  234. end
  235.  
  236. drawButton(8, "OK")
  237. while true do
  238. local button = waitForButton()
  239. if button == 8 then return end
  240. end
  241. end
  242.  
  243. function bank(acc, pin)
  244. while true do
  245. term.clear() drawHeader() drawButtons()
  246.  
  247. drawButton(4, "Return Card")
  248. drawButton(5, "Balance Check")
  249. drawButton(6, "Withdrawal")
  250. drawButton(7, "Deposit")
  251. drawButton(8, "Transfer")
  252.  
  253. local button = waitForButton()
  254. if button == 4 then return
  255. elseif button == 5 then balance(acc, pin)
  256. elseif button == 6 then withdraw(acc, pin)
  257. --elseif button == 7 then deposit(acc, pin)
  258. elseif button == 8 then transfer(acc, pin)
  259. end
  260. end
  261. end
  262.  
  263. function begin()
  264. local acc, pin
  265. local version = "CC-Bank-0.2.0-Compatible"
  266. local serverId = 3
  267.  
  268. term.clear() drawHeader()
  269.  
  270. center(textStart, "Insert keycard or press ENTER")
  271. center(textStart + 1, "to transact without a keycard")
  272. parallel.waitForAny(waitForEnter, waitForDisk)
  273.  
  274. term.clear() drawHeader()
  275.  
  276. term.setCursorPos(center(textStart, "Account No : ") + 13, textStart)
  277.  
  278. if disk.hasData(diskSide) then
  279. acc = disk.getLabel(diskSide)
  280. term.write(acc)
  281. else
  282. acc = read()
  283. end
  284.  
  285. term.setCursorPos(center(textStart + 1, "PIN : ") + 6, textStart + 1)
  286. pin = read("*")
  287.  
  288. sleep(1)
  289. request = http.post(url, "command="..textutils.urlEncode(tostring("login")).."&".."username="..textutils.urlEncode(tostring(acc)).."&".."password="..textutils.urlEncode(tostring(crypt.hashPassword(pin))))
  290. response = request.readAll()
  291.  
  292. term.clear() drawHeader()
  293.  
  294. if response == "true" then
  295. bank(acc, pin)
  296.  
  297. term.clear() drawHeader()
  298.  
  299. disk.eject(diskSide)
  300. center(textStart, "Thank you for banking with BM")
  301. center(textStart + 1, "Please take your keycard")
  302.  
  303. sleep(6)
  304. os.reboot()
  305. else
  306. drawError("Login Error")
  307. sleep(4)
  308. os.reboot()
  309. end
  310.  
  311. while true do
  312. local button = waitForButton()
  313. if button == 8 then return end
  314. end
  315. end
  316.  
  317. while true do
  318. begin()
  319. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement