SHOW:
|
|
- or go back to the newest paste.
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 | local all = "0123456789abcdefghijklmnopqrstuvwxyz" | |
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 | function register() | |
56 | local accname, accpin | |
57 | ||
58 | term.clear() drawHeader() | |
59 | ||
60 | center(textStart, "Insert keycard or press ENTER") | |
61 | center(textStart + 1, "to transact without a keycard") | |
62 | parallel.waitForAny(waitForEnter, waitForDisk) | |
63 | ||
64 | term.clear() drawHeader() | |
65 | for i = 1, 10 do | |
66 | r = math.random(#all) | |
67 | e = e.. string.sub(all, r, r) | |
68 | end | |
69 | term.setCursorPos(center(textStart, "Account No : "..e.."") + 13, textStart) | |
70 | ||
71 | accname = e | |
72 | if disk.hasData(diskSide) then | |
73 | disk.setLabel(diskSide,accname) | |
74 | else | |
75 | end | |
76 | term.setCursorPos(center(textStart + 1, "PIN : ") + 6, textStart + 1) | |
77 | accpin = read("*") | |
78 | request = http.post(url, "command="..textutils.urlEncode(tostring("register")).."&".."username="..textutils.urlEncode(tostring(e)).."&".."password="..textutils.urlEncode(tostring(sha256.sha256(accpin)))) | |
79 | response = request.readAll() | |
80 | term.clear() drawHeader() drawButtons() | |
81 | drawButton(8, "OK") | |
82 | ||
83 | if response == "Saved!" then | |
84 | center(textStart, "Added User: " .. accname .."") | |
85 | sleep(3) | |
86 | disk.eject(diskSide) | |
87 | os.reboot() | |
88 | else | |
89 | drawError("ERROR") | |
90 | end | |
91 | ||
92 | while true do | |
93 | local button = waitForButton() | |
94 | if button == 8 then return end | |
95 | end | |
96 | end | |
97 | function deposit(acc, pin) | |
98 | term.clear() drawHeader() drawButtons() | |
99 | ||
100 | drawButton(4, "Cancel") | |
101 | ||
102 | local mult = nil | |
103 | --while true do | |
104 | -- local button = waitForButton() | |
105 | -- if button == 4 then return | |
106 | -- end | |
107 | -- end | |
108 | ||
109 | request = http.post(url, "command="..textutils.urlEncode(tostring("deposit")).."&".."username="..textutils.urlEncode(tostring(acc))) | |
110 | response = request.readAll() | |
111 | term.clear() drawHeader() drawButtons() | |
112 | drawButton(8, "OK") | |
113 | redstone.setOutput("back",true) | |
114 | center(textStart, "Now Accepting:") | |
115 | center(textStart + 1, "Gold Blocks, Ingots, Nuggets ") | |
116 | center(textStart + 2, "Please Close Terminal.") | |
117 | center(textStart + 3, "Then drop stacks of items ONLY") | |
118 | sleep(10) | |
119 | -- if response ~= "-" then | |
120 | -- local displayBalance = math.floor(tonumber(response) * mult * 100) / 100 | |
121 | --center(textStart, "Balance: $" .. displayBalance .. " Galleons.") | |
122 | -- else | |
123 | -- drawError("Transaction Error") | |
124 | -- end | |
125 | ||
126 | while true do | |
127 | local button = waitForButton() | |
128 | if button == 8 then redstone.setOutput("back",false) return end | |
129 | end | |
130 | end | |
131 | ||
132 | function transfer(acc, pin) | |
133 | term.clear() drawHeader() drawButtons() | |
134 | ||
135 | drawButton(1, "$100") | |
136 | drawButton(2, "$200") | |
137 | drawButton(3, "$500") | |
138 | drawButton(5, "$1000") | |
139 | drawButton(6, "$2000") | |
140 | drawButton(7, "$5000") | |
141 | ||
142 | drawButton(4, "Cancel") | |
143 | drawButton(8, "Other Amount") | |
144 | ||
145 | local amountS = nil | |
146 | while true do | |
147 | local button = waitForButton() | |
148 | if button == 1 then amountS = "100" break | |
149 | elseif button == 2 then amountS = "200" break | |
150 | elseif button == 3 then amountS = "500" break | |
151 | elseif button == 5 then amountS = "1000" break | |
152 | elseif button == 6 then amountS = "2000" break | |
153 | elseif button == 7 then amountS = "5000" break | |
154 | elseif button == 4 then return | |
155 | elseif button == 8 then amountS = otherAmount() break | |
156 | end | |
157 | end | |
158 | ||
159 | term.clear() drawHeader() drawButtons() | |
160 | ||
161 | local amount = tonumber(amountS) | |
162 | if amount ~= nil and (amount % 1) == 0 then | |
163 | term.clear() drawHeader() | |
164 | term.setCursorPos(center(textStart, "Amount : $ ") + 12, textStart) | |
165 | term.write(amountS) | |
166 | term.setCursorPos(center(textStart + 1, "Account : ") + 10, textStart + 1) | |
167 | local account = read() | |
168 | ||
169 | drawButtons() | |
170 | drawButton(4, "Cancel") | |
171 | drawButton(8, "Confirm") | |
172 | ||
173 | while true do | |
174 | local button = waitForButton() | |
175 | if button == 4 then return | |
176 | elseif button == 8 then break | |
177 | end | |
178 | end | |
179 | ||
180 | --local senderId, response = nil, nil | |
181 | --rednet.open(modemSide) | |
182 | ||
183 | -- rednet.send(serverId, version .. textutils.serialize( { "TRANSFER", acc, crypt.hashPassword(pin), account, amountS } ) ) | |
184 | ||
185 | -- while true do | |
186 | -- senderId, response = rednet.receive(5) | |
187 | -- if senderId == serverId then break end | |
188 | -- end | |
189 | -- rednet.close(modemSide) | |
190 | -- 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)))) | |
191 | 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)))) | |
192 | term.clear() drawHeader() drawButtons() | |
193 | response = request.readAll() | |
194 | if response == "sendok" then | |
195 | center(textStart, "Transfer Successful") | |
196 | else | |
197 | drawError("Transaction Error") | |
198 | end | |
199 | ||
200 | else | |
201 | term.clear() drawHeader() drawButtons() | |
202 | drawError("Invalid Amount") | |
203 | ||
204 | --[[ | |
205 | while true do | |
206 | local button = waitForButton() | |
207 | if button == 8 then return end | |
208 | end | |
209 | --]] | |
210 | end | |
211 | ||
212 | drawButton(8, "OK") | |
213 | while true do | |
214 | local button = waitForButton() | |
215 | if button == 8 then return end | |
216 | end | |
217 | end | |
218 | ||
219 | function withdraw(acc, pin) | |
220 | term.clear() drawHeader() drawButtons() | |
221 | ||
222 | drawButton(1, "$100") | |
223 | drawButton(2, "$200") | |
224 | drawButton(3, "$500") | |
225 | drawButton(5, "$1000") | |
226 | drawButton(6, "$2000") | |
227 | drawButton(7, "$5000") | |
228 | ||
229 | drawButton(4, "Cancel") | |
230 | drawButton(8, "Other Amount") | |
231 | ||
232 | local amountS = nil | |
233 | while true do | |
234 | local button = waitForButton() | |
235 | if button == 1 then amountS = "100" break | |
236 | elseif button == 2 then amountS = "200" break | |
237 | elseif button == 3 then amountS = "500" break | |
238 | elseif button == 5 then amountS = "1000" break | |
239 | elseif button == 6 then amountS = "2000" break | |
240 | elseif button == 7 then amountS = "5000" break | |
241 | elseif button == 4 then return | |
242 | elseif button == 8 then amountS = otherAmount() break | |
243 | end | |
244 | end | |
245 | ||
246 | term.clear() drawHeader() drawButtons() | |
247 | ||
248 | local amount = tonumber(amountS) | |
249 | if amount ~= nil and (amount % 100) == 0 then | |
250 | term.clear() drawHeader() | |
251 | term.setCursorPos(center(textStart, "Amount : MC$ ") + 12, textStart) | |
252 | term.write(amountS) | |
253 | drawButtons() | |
254 | drawButton(4, "Cancel") | |
255 | drawButton(8, "Confirm") | |
256 | ||
257 | while true do | |
258 | local button = waitForButton() | |
259 | if button == 4 then return | |
260 | elseif button == 8 then break | |
261 | end | |
262 | end | |
263 | ||
264 | local senderId, response = nil, nil | |
265 | rednet.open(modemSide) | |
266 | ||
267 | rednet.send(serverId, version .. textutils.serialize( { "WITHDRAW", acc, crypt.hashPassword(pin), amountS } ) ) | |
268 | ||
269 | while true do | |
270 | senderId, response = rednet.receive(5) | |
271 | if senderId == serverId then break end | |
272 | end | |
273 | rednet.close(modemSide) | |
274 | ||
275 | term.clear() drawHeader() | |
276 | ||
277 | if response ~= "-" then | |
278 | center(textStart, "Withdrawing " .. (amount) .. " MC$") | |
279 | rednet.open(modemSide) | |
280 | rednet.send(withdrawId, version .. textutils.serialize( { "WITHDRAW", (amount) .. "" } ) ) | |
281 | ||
282 | while true do | |
283 | senderId, response = rednet.receive(5) | |
284 | if senderId == withdrawId then break end | |
285 | end | |
286 | rednet.close(modemSide) | |
287 | ||
288 | term.clear() drawHeader() | |
289 | if response ~= "-" then | |
290 | center(textStart, "Please take your cash") | |
291 | sleep(2) | |
292 | return | |
293 | else | |
294 | drawButtons() | |
295 | drawError("Withdrawal Error") | |
296 | end | |
297 | else | |
298 | drawError("Transaction Error") | |
299 | end | |
300 | ||
301 | else | |
302 | term.clear() drawHeader() drawButtons() | |
303 | drawError("Invalid Amount") | |
304 | ||
305 | --[[ | |
306 | while true do | |
307 | local button = waitForButton() | |
308 | if button == 8 then return end | |
309 | end | |
310 | --]] | |
311 | end | |
312 | ||
313 | drawButton(8, "OK") | |
314 | while true do | |
315 | local button = waitForButton() | |
316 | if button == 8 then return end | |
317 | end | |
318 | end | |
319 | ||
320 | function bank(acc, pin) | |
321 | while true do | |
322 | term.clear() drawHeader() drawButtons() | |
323 | ||
324 | drawButton(4, "Return Card") | |
325 | drawButton(5, "Balance Check") | |
326 | drawButton(6, "Withdrawal") | |
327 | drawButton(7, "Deposit") | |
328 | drawButton(8, "Transfer") | |
329 | ||
330 | local button = waitForButton() | |
331 | if button == 4 then return | |
332 | elseif button == 5 then balance(acc, pin) | |
333 | elseif button == 6 then withdraw(acc, pin) | |
334 | elseif button == 7 then deposit(acc, pin) | |
335 | elseif button == 8 then transfer(acc, pin) | |
336 | end | |
337 | end | |
338 | end | |
339 | ||
340 | function begin() | |
341 | local acc, pin | |
342 | ||
343 | ||
344 | term.clear() drawHeader() | |
345 | drawButtons() | |
346 | drawButton(4, "Login") | |
347 | drawButton(8, "Open Account") | |
348 | while true do | |
349 | local button = waitForButton() | |
350 | if button == 4 then break | |
351 | elseif button == 8 then register() | |
352 | end | |
353 | end | |
354 | --while true do | |
355 | center(textStart, "Insert keycard or press ENTER") | |
356 | center(textStart + 1, "to transact without a keycard") | |
357 | parallel.waitForAny(waitForEnter, waitForDisk) | |
358 | ||
359 | term.clear() drawHeader() | |
360 | ||
361 | term.setCursorPos(center(textStart, "Account No : ") + 13, textStart) | |
362 | -- local button = waitForButton() | |
363 | -- if button == 4 then return | |
364 | -- elseif button == 8 then | |
365 | -- os.reboot() | |
366 | -- end | |
367 | if disk.hasData(diskSide) then | |
368 | acc = disk.getLabel(diskSide) | |
369 | term.write(acc) | |
370 | else | |
371 | acc = read() | |
372 | end | |
373 | ||
374 | term.setCursorPos(center(textStart + 1, "PIN : ") + 6, textStart + 1) | |
375 | pin = read("*") | |
376 | ||
377 | sleep(1) | |
378 | request = http.post(url, "command="..textutils.urlEncode(tostring("login")).."&".."username="..textutils.urlEncode(tostring(acc)).."&".."password="..textutils.urlEncode(tostring(sha256.sha256(pin)))) | |
379 | response = request.readAll() | |
380 | ||
381 | term.clear() drawHeader() | |
382 | ||
383 | if response == "true" then | |
384 | bank(acc, pin) | |
385 | ||
386 | term.clear() drawHeader() | |
387 | ||
388 | disk.eject(diskSide) | |
389 | center(textStart, "Thank you for banking with GA") | |
390 | center(textStart + 1, "Please take your keycard") | |
391 | ||
392 | sleep(6) | |
393 | os.reboot() | |
394 | else | |
395 | drawError("Login Error") | |
396 | sleep(4) | |
397 | os.reboot() | |
398 | end | |
399 | ||
400 | while true do | |
401 | local button = waitForButton() | |
402 | if button == 8 then return end | |
403 | end | |
404 | end | |
405 | ||
406 | while true do | |
407 | begin() | |
408 | end |