Advertisement
infiniteblock

Untitled

Apr 24th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.63 KB | None | 0 0
  1. -- Load API
  2. os.loadAPI("sha256")
  3. os.loadAPI("gui")
  4.  
  5. local textStart = gui.textStart
  6. local diskSide = "bottom"
  7. local serverId = 3
  8. local withdrawId = 14
  9. local version = "GAB-0.1"
  10. local 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 deposit(acc, pin)
  57. term.clear() drawHeader() drawButtons()
  58.  
  59. drawButton(4, "Cancel")
  60.  
  61. local mult = nil
  62. while true do
  63. local button = waitForButton()
  64. if button == 4 then return
  65. end
  66. end
  67.  
  68. request = http.post(url, "deposit="..textutils.urlEncode(tostring(acc))
  69. --response = request.readAll()
  70. term.clear() drawHeader() drawButtons()
  71. drawButton(8, "OK")
  72. redstone.setAnalogOutput("back",15)
  73. sleep(10)
  74. -- if response ~= "-" then
  75. -- local displayBalance = math.floor(tonumber(response) * mult * 100) / 100
  76. --center(textStart, "Balance: $" .. displayBalance .. " Galleons.")
  77. -- else
  78. -- drawError("Transaction Error")
  79. -- end
  80.  
  81. while true do
  82. local button = waitForButton()
  83. if button == 8 then return end
  84. end
  85. end
  86.  
  87. function transfer(acc, pin)
  88. term.clear() drawHeader() drawButtons()
  89.  
  90. drawButton(1, "$100")
  91. drawButton(2, "$200")
  92. drawButton(3, "$500")
  93. drawButton(5, "$1000")
  94. drawButton(6, "$2000")
  95. drawButton(7, "$5000")
  96.  
  97. drawButton(4, "Cancel")
  98. drawButton(8, "Other Amount")
  99.  
  100. local amountS = nil
  101. while true do
  102. local button = waitForButton()
  103. if button == 1 then amountS = "100" break
  104. elseif button == 2 then amountS = "200" break
  105. elseif button == 3 then amountS = "500" break
  106. elseif button == 5 then amountS = "1000" break
  107. elseif button == 6 then amountS = "2000" break
  108. elseif button == 7 then amountS = "5000" break
  109. elseif button == 4 then return
  110. elseif button == 8 then amountS = otherAmount() break
  111. end
  112. end
  113.  
  114. term.clear() drawHeader() drawButtons()
  115.  
  116. local amount = tonumber(amountS)
  117. if amount ~= nil and (amount % 1) == 0 then
  118. term.clear() drawHeader()
  119. term.setCursorPos(center(textStart, "Amount : $ ") + 12, textStart)
  120. term.write(amountS)
  121. term.setCursorPos(center(textStart + 1, "Account : ") + 10, textStart + 1)
  122. local account = read()
  123.  
  124. drawButtons()
  125. drawButton(4, "Cancel")
  126. drawButton(8, "Confirm")
  127.  
  128. while true do
  129. local button = waitForButton()
  130. if button == 4 then return
  131. elseif button == 8 then break
  132. end
  133. end
  134.  
  135. --local senderId, response = nil, nil
  136. --rednet.open(modemSide)
  137.  
  138. -- rednet.send(serverId, version .. textutils.serialize( { "TRANSFER", acc, crypt.hashPassword(pin), account, amountS } ) )
  139.  
  140. -- while true do
  141. -- senderId, response = rednet.receive(5)
  142. -- if senderId == serverId then break end
  143. -- end
  144. -- rednet.close(modemSide)
  145. -- request = http.post(url, "command="..textutils.urlEncode(tostring("transfer")).."&".."username="..textutils.urlEncode(tostring(acc)).."&".."password="..textutils.urlEncode(tostring(sha256.sha256(pin)).."&".."account="..textutils.urlEncode(tostring(account)).."&".."amountS="..textutils.urlEncode(tostring(amountS))))
  146. request = http.post(url,"command="..textutils.urlEncode(tostring("trans")).."&".."username="..textutils.urlEncode(tostring(acc)).."&".."account="..textutils.urlEncode(tostring(account)).."&".."amount="..textutils.urlEncode(tostring(amount)).."&".."password="..textutils.urlEncode(tostring(sha256.sha256(pin))))
  147. term.clear() drawHeader() drawButtons()
  148. response = request.readAll()
  149. if response == "sendok" then
  150. center(textStart, "Transfer Successful")
  151. else
  152. drawError("Transaction Error")
  153. end
  154.  
  155. else
  156. term.clear() drawHeader() drawButtons()
  157. drawError("Invalid Amount")
  158.  
  159. --[[
  160. while true do
  161. local button = waitForButton()
  162. if button == 8 then return end
  163. end
  164. --]]
  165. end
  166.  
  167. drawButton(8, "OK")
  168. while true do
  169. local button = waitForButton()
  170. if button == 8 then return end
  171. end
  172. end
  173.  
  174. function withdraw(acc, pin)
  175. term.clear() drawHeader() drawButtons()
  176.  
  177. drawButton(1, "$100")
  178. drawButton(2, "$200")
  179. drawButton(3, "$500")
  180. drawButton(5, "$1000")
  181. drawButton(6, "$2000")
  182. drawButton(7, "$5000")
  183.  
  184. drawButton(4, "Cancel")
  185. drawButton(8, "Other Amount")
  186.  
  187. local amountS = nil
  188. while true do
  189. local button = waitForButton()
  190. if button == 1 then amountS = "100" break
  191. elseif button == 2 then amountS = "200" break
  192. elseif button == 3 then amountS = "500" break
  193. elseif button == 5 then amountS = "1000" break
  194. elseif button == 6 then amountS = "2000" break
  195. elseif button == 7 then amountS = "5000" break
  196. elseif button == 4 then return
  197. elseif button == 8 then amountS = otherAmount() break
  198. end
  199. end
  200.  
  201. term.clear() drawHeader() drawButtons()
  202.  
  203. local amount = tonumber(amountS)
  204. if amount ~= nil and (amount % 100) == 0 then
  205. term.clear() drawHeader()
  206. term.setCursorPos(center(textStart, "Amount : MC$ ") + 12, textStart)
  207. term.write(amountS)
  208. drawButtons()
  209. drawButton(4, "Cancel")
  210. drawButton(8, "Confirm")
  211.  
  212. while true do
  213. local button = waitForButton()
  214. if button == 4 then return
  215. elseif button == 8 then break
  216. end
  217. end
  218.  
  219. local senderId, response = nil, nil
  220. rednet.open(modemSide)
  221.  
  222. rednet.send(serverId, version .. textutils.serialize( { "WITHDRAW", acc, crypt.hashPassword(pin), amountS } ) )
  223.  
  224. while true do
  225. senderId, response = rednet.receive(5)
  226. if senderId == serverId then break end
  227. end
  228. rednet.close(modemSide)
  229.  
  230. term.clear() drawHeader()
  231.  
  232. if response ~= "-" then
  233. center(textStart, "Withdrawing " .. (amount) .. " MC$")
  234. rednet.open(modemSide)
  235. rednet.send(withdrawId, version .. textutils.serialize( { "WITHDRAW", (amount) .. "" } ) )
  236.  
  237. while true do
  238. senderId, response = rednet.receive(5)
  239. if senderId == withdrawId then break end
  240. end
  241. rednet.close(modemSide)
  242.  
  243. term.clear() drawHeader()
  244. if response ~= "-" then
  245. center(textStart, "Please take your cash")
  246. sleep(2)
  247. return
  248. else
  249. drawButtons()
  250. drawError("Withdrawal Error")
  251. end
  252. else
  253. drawError("Transaction Error")
  254. end
  255.  
  256. else
  257. term.clear() drawHeader() drawButtons()
  258. drawError("Invalid Amount")
  259.  
  260. --[[
  261. while true do
  262. local button = waitForButton()
  263. if button == 8 then return end
  264. end
  265. --]]
  266. end
  267.  
  268. drawButton(8, "OK")
  269. while true do
  270. local button = waitForButton()
  271. if button == 8 then return end
  272. end
  273. end
  274.  
  275. function bank(acc, pin)
  276. while true do
  277. term.clear() drawHeader() drawButtons()
  278.  
  279. drawButton(4, "Return Card")
  280. drawButton(5, "Balance Check")
  281. drawButton(6, "Withdrawal")
  282. drawButton(7, "Deposit")
  283. drawButton(8, "Transfer")
  284.  
  285. local button = waitForButton()
  286. if button == 4 then return
  287. elseif button == 5 then balance(acc, pin)
  288. elseif button == 6 then withdraw(acc, pin)
  289. elseif button == 7 then deposit(acc, pin)
  290. elseif button == 8 then transfer(acc, pin)
  291. end
  292. end
  293. end
  294.  
  295. function begin()
  296. local acc, pin
  297.  
  298.  
  299. term.clear() drawHeader()
  300. drawButtons()
  301. drawButton(8, "Open Account")
  302. -- local button = waitForButton()
  303. -- if button == 4 then return
  304. --elseif button == 8 then --break
  305. --end
  306. --while true do
  307. center(textStart, "Insert keycard or press ENTER")
  308. center(textStart + 1, "to transact without a keycard")
  309. parallel.waitForAny(waitForEnter, waitForDisk)
  310.  
  311. term.clear() drawHeader()
  312.  
  313. term.setCursorPos(center(textStart, "Account No : ") + 13, textStart)
  314. -- local button = waitForButton()
  315. --if button == 4 then return
  316. --elseif button == 8 then
  317. --os.reboot()
  318. --end
  319. if disk.hasData(diskSide) then
  320. acc = disk.getLabel(diskSide)
  321. term.write(acc)
  322. else
  323. acc = read()
  324. end
  325.  
  326. term.setCursorPos(center(textStart + 1, "PIN : ") + 6, textStart + 1)
  327. pin = read("*")
  328.  
  329. sleep(1)
  330. request = http.post(url, "command="..textutils.urlEncode(tostring("login")).."&".."username="..textutils.urlEncode(tostring(acc)).."&".."password="..textutils.urlEncode(tostring(sha256.sha256(pin))))
  331. response = request.readAll()
  332.  
  333. term.clear() drawHeader()
  334.  
  335. if response == "true" then
  336. bank(acc, pin)
  337.  
  338. term.clear() drawHeader()
  339.  
  340. disk.eject(diskSide)
  341. center(textStart, "Thank you for banking with GA")
  342. center(textStart + 1, "Please take your keycard")
  343.  
  344. sleep(6)
  345. os.reboot()
  346. else
  347. drawError("Login Error")
  348. sleep(4)
  349. os.reboot()
  350. end
  351.  
  352. while true do
  353. local button = waitForButton()
  354. if button == 8 then return end
  355. end
  356. end
  357.  
  358. while true do
  359. begin()
  360. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement