SHOW:
|
|
- or go back to the newest paste.
1 | - | local jenisis = require("jenisis") |
1 | + | local jenisis = require("jenisis") |
2 | - | local component = require("component") |
2 | + | local component = require("component") |
3 | - | local fs = require("filesystem") |
3 | + | local fs = require("filesystem") |
4 | - | local textutils = require("serialization") |
4 | + | local textutils = require("serialization") |
5 | - | local beep = require("computer") |
5 | + | local beep = require("computer") |
6 | - | local event = require("event") |
6 | + | local event = require("event") |
7 | - | local modem = component.getPrimary("modem") |
7 | + | local modem = component.getPrimary("modem") |
8 | - | local gpu = component.getPrimary("gpu") |
8 | + | local gpu = component.getPrimary("gpu") |
9 | - | local scrX, scrY = gpu.getResolution() |
9 | + | local scrX, scrY = gpu.getResolution() |
10 | - | |
10 | + | |
11 | - | local function broadcast(packet) |
11 | + | local function broadcast(packet) |
12 | - | local packet_ = textutils.serialize(packet) |
12 | + | local packet_ = textutils.serialize(packet) |
13 | - | |
13 | + | |
14 | - | modem.broadcast(1024, packet_) |
14 | + | modem.broadcast(1024, packet_) |
15 | end | |
16 | - | |
16 | + | |
17 | - | local function receive() |
17 | + | local function receive() |
18 | - | event_ = {event.pull(5, "modem_message")} |
18 | + | event_ = {event.pull(5, "modem_message")} |
19 | - | |
19 | + | |
20 | - | return textutils.unserialize(event_[6]) |
20 | + | return textutils.unserialize(event_[6]) |
21 | end | |
22 | - | |
22 | + | |
23 | - | currentaccount = {} |
23 | + | currentaccount = {} |
24 | - | currentaccount.accountName = "You shouldn't see this. Call Alex" |
24 | + | currentaccount.accountName = "You shouldn't see this. Call Alex" |
25 | - | |
25 | + | |
26 | - | if fs.exists("/cache/bank.cache") then |
26 | + | if fs.exists("/cache/bank.cache") then |
27 | - | file = io.open("/cache/bank.cache") |
27 | + | file = io.open("/cache/bank.cache") |
28 | - | currentaccount = textutils.unserialize(file:read("*a")) |
28 | + | currentaccount = textutils.unserialize(file:read("*a")) |
29 | - | file:close() |
29 | + | file:close() |
30 | - | |
30 | + | |
31 | - | loggedIn = true |
31 | + | loggedIn = true |
32 | end | |
33 | - | |
33 | + | |
34 | - | local function getFunds() |
34 | + | local function getFunds() |
35 | - | if not loggedIn then |
35 | + | if not loggedIn then |
36 | - | jenisis.errorMes("Please log in.") |
36 | + | jenisis.errorMes("Please log in.") |
37 | - | return |
37 | + | return |
38 | - | end |
38 | + | end |
39 | - | |
39 | + | |
40 | - | local packet = { |
40 | + | local packet = { |
41 | - | type = "getfunds", |
41 | + | type = "getfunds", |
42 | - | target = currentaccount.accountName, |
42 | + | target = currentaccount.accountName, |
43 | - | account = currentaccount |
43 | + | account = currentaccount |
44 | - | } |
44 | + | } |
45 | - | |
45 | + | |
46 | - | broadcast(packet) |
46 | + | broadcast(packet) |
47 | - | local response = receive() |
47 | + | local response = receive() |
48 | - | |
48 | + | |
49 | - | if response ~= false then |
49 | + | if response ~= false then |
50 | - | jenisis.errorMes("You have $"..response, "green") |
50 | + | jenisis.errorMes("You have $"..response, "green") |
51 | - | return |
51 | + | return |
52 | - | else |
52 | + | else |
53 | - | jenisis.errorMes("Unexpected Error") |
53 | + | jenisis.errorMes("Unexpected Error") |
54 | - | end |
54 | + | end |
55 | end | |
56 | - | |
56 | + | |
57 | - | local function transfer() |
57 | + | local function transfer() |
58 | - | if not loggedIn then |
58 | + | if not loggedIn then |
59 | - | jenisis.errorMes("Please log in.") |
59 | + | jenisis.errorMes("Please log in.") |
60 | - | return |
60 | + | return |
61 | - | end |
61 | + | end |
62 | - | |
62 | + | |
63 | - | local packet = { |
63 | + | local packet = { |
64 | - | account = currentaccount, |
64 | + | account = currentaccount, |
65 | - | type = "transfer" |
65 | + | type = "transfer" |
66 | - | } |
66 | + | } |
67 | - | |
67 | + | |
68 | - | packet.target = jenisis.inputBar("Whoms't ya sendin dollas 2 b?") |
68 | + | packet.target = jenisis.inputBar("Whoms't ya sendin dollas 2 b?") |
69 | - | packet.amount = tonumber(jenisis.inputBar("Enter amount:")) |
69 | + | packet.amount = tonumber(jenisis.inputBar("Enter amount:")) |
70 | - | |
70 | + | |
71 | - | broadcast(packet) |
71 | + | broadcast(packet) |
72 | - | response = receive() |
72 | + | response = receive() |
73 | - | |
73 | + | |
74 | - | if response then |
74 | + | if response then |
75 | - | jenisis.errorMes("Transfer Succesful.", "green") |
75 | + | jenisis.errorMes("Transfer Succesful.", "green") |
76 | - | else |
76 | + | else |
77 | - | jenisis.errorMes("Unexpected Error") |
77 | + | jenisis.errorMes("Unexpected Error") |
78 | - | end |
78 | + | end |
79 | end | |
80 | - | |
80 | + | |
81 | - | local function newAccount() |
81 | + | local function newAccount() |
82 | - | local newacc = {} |
82 | + | local newacc = {} |
83 | - | |
83 | + | |
84 | - | newacc.accountName = jenisis.inputBar("Enter new account name:") |
84 | + | newacc.accountName = jenisis.inputBar("Enter new account name:") |
85 | - | newacc.accountKey = jenisis.inputBar("Enter Passkey:", true) |
85 | + | newacc.accountKey = jenisis.inputBar("Enter Passkey:", true) |
86 | - | newacc.balance = 0 |
86 | + | newacc.balance = 0 |
87 | - | newacc.isFlagged = false |
87 | + | newacc.isFlagged = false |
88 | - | newacc.isFront = false |
88 | + | newacc.isFront = false |
89 | - | newacc.owners = {} |
89 | + | newacc.owners = {} |
90 | - | |
90 | + | |
91 | - | packet = { |
91 | + | packet = { |
92 | - | type = "newaccount", |
92 | + | type = "newaccount", |
93 | - | account = newacc |
93 | + | account = newacc |
94 | - | } |
94 | + | } |
95 | - | |
95 | + | |
96 | - | broadcast(packet) |
96 | + | broadcast(packet) |
97 | - | result = receive() |
97 | + | result = receive() |
98 | - | |
98 | + | |
99 | - | if result == true then |
99 | + | if result == true then |
100 | - | jenisis.errorMes("Account creation succesful.", "green") |
100 | + | jenisis.errorMes("Account creation succesful.", "green") |
101 | - | else |
101 | + | else |
102 | - | jenisis.errorMes("Unexpected Error") |
102 | + | jenisis.errorMes("Unexpected Error") |
103 | - | end |
103 | + | end |
104 | end | |
105 | - | |
105 | + | |
106 | - | local function doLog() |
106 | + | local function doLog() |
107 | - | if loggedIn then |
107 | + | if loggedIn then |
108 | - | currentaccount.accountName = nil |
108 | + | currentaccount.accountName = nil |
109 | - | currentaccount.accountKey = nil |
109 | + | currentaccount.accountKey = nil |
110 | - | |
110 | + | |
111 | - | loggedIn = false |
111 | + | loggedIn = false |
112 | - | |
112 | + | |
113 | - | fs.remove("/bank/bank.cache") |
113 | + | fs.remove("/bank/bank.cache") |
114 | - | jenisis.errorMes("Logged Out", "green") |
114 | + | jenisis.errorMes("Logged Out", "green") |
115 | - | return |
115 | + | return |
116 | - | end |
116 | + | end |
117 | - | |
117 | + | |
118 | - | currentaccount.accountName = jenisis.inputBar("Enter account:") |
118 | + | currentaccount.accountName = jenisis.inputBar("Enter account:") |
119 | - | currentaccount.accountKey = jenisis.inputBar("Enter passkey:", true) |
119 | + | currentaccount.accountKey = jenisis.inputBar("Enter passkey:", true) |
120 | - | |
120 | + | |
121 | - | local packet = { |
121 | + | local packet = { |
122 | - | type = "auth", |
122 | + | type = "auth", |
123 | - | account = currentaccount |
123 | + | account = currentaccount |
124 | - | } |
124 | + | } |
125 | - | |
125 | + | |
126 | - | broadcast(packet) |
126 | + | broadcast(packet) |
127 | - | local result = receive() |
127 | + | local result = receive() |
128 | - | |
128 | + | |
129 | - | if result then |
129 | + | if result then |
130 | - | jenisis.errorMes("Logged In", "green") |
130 | + | jenisis.errorMes("Logged In", "green") |
131 | - | loggedIn = true |
131 | + | loggedIn = true |
132 | - | |
132 | + | |
133 | - | local file = io.open("/cache/bank.cache", "w") |
133 | + | local file = io.open("/cache/bank.cache", "w") |
134 | - | file:write(textutils.serialize(currentaccount)) |
134 | + | file:write(textutils.serialize(currentaccount)) |
135 | - | file:close() |
135 | + | file:close() |
136 | - | else |
136 | + | else |
137 | - | jenisis.errorMes("Authentication Failed") |
137 | + | jenisis.errorMes("Authentication Failed") |
138 | - | loggedIn = false |
138 | + | loggedIn = false |
139 | - | end |
139 | + | end |
140 | end | |
141 | - | |
141 | + | |
142 | - | local function centerText(line, text) |
142 | + | local function centerText(line, text) |
143 | - | local length = string.len(text) |
143 | + | local length = string.len(text) |
144 | - | |
144 | + | |
145 | - | local target = (scrX - length) / 2 |
145 | + | local target = (scrX - length) / 2 |
146 | - | term.setCursor(target, line) |
146 | + | term.setCursor(target, line) |
147 | - | term.write(text) |
147 | + | term.write(text) |
148 | end | |
149 | - | |
149 | + | |
150 | - | local function displayInfo(table) |
150 | + | local function displayInfo(table) |
151 | - | local amount = #table |
151 | + | local amount = #table |
152 | - | |
152 | + | |
153 | - | local lTarget = ((scrY - amount) / 2) - 1 |
153 | + | local lTarget = ((scrY - amount) / 2) - 1 |
154 | - | |
154 | + | |
155 | - | for i=1, amount do |
155 | + | for i=1, amount do |
156 | - | centerText(lTarget + i, table[i]) |
156 | + | centerText(lTarget + i, table[i]) |
157 | - | end |
157 | + | end |
158 | end | |
159 | - | |
159 | + | |
160 | - | local function manageAccount() |
160 | + | local function manageAccount() |
161 | - | if not loggedIn then |
161 | + | if not loggedIn then |
162 | - | jenisis.errorMes("Please Log In") |
162 | + | jenisis.errorMes("Please Log In") |
163 | - | end |
163 | + | end |
164 | - | |
164 | + | |
165 | - | if jenisis.inputBar("Please re-enter password:", true) ~= currentaccount.accountKey then |
165 | + | if jenisis.inputBar("Please re-enter password:", true) ~= currentaccount.accountKey then |
166 | - | return false |
166 | + | return false |
167 | - | end |
167 | + | end |
168 | - | |
168 | + | |
169 | - | manStatic = { |
169 | + | manStatic = { |
170 | - | "Account Management Menu" |
170 | + | "Account Management Menu" |
171 | - | } |
171 | + | } |
172 | - | |
172 | + | |
173 | - | manMenu = { |
173 | + | manMenu = { |
174 | - | "Get Full Info", |
174 | + | "Get Full Info", |
175 | - | "View Owners", |
175 | + | "View Owners", |
176 | - | "Setup Multi-Ownership", |
176 | + | "Setup Multi-Ownership", |
177 | - | "Exit" |
177 | + | "Exit" |
178 | - | } |
178 | + | } |
179 | - | |
179 | + | |
180 | - | while true do |
180 | + | while true do |
181 | - | cselected = jenisis.drawScreen(manStatic, manMenu) |
181 | + | cselected = jenisis.drawScreen(manStatic, manMenu) |
182 | - | |
182 | + | |
183 | - | if cselected == 1 then |
183 | + | if cselected == 1 then |
184 | - | local packet = { |
184 | + | local packet = { |
185 | - | type = "getinfo", |
185 | + | type = "getinfo", |
186 | - | account = currentaccount |
186 | + | account = currentaccount |
187 | - | } |
187 | + | } |
188 | - | |
188 | + | |
189 | - | broadcast(packet) |
189 | + | broadcast(packet) |
190 | - | local result = receive() |
190 | + | local result = receive() |
191 | - | |
191 | + | |
192 | - | term.clear() |
192 | + | term.clear() |
193 | - | local info = { |
193 | + | local info = { |
194 | - | "Account Name: "..result.accountName, |
194 | + | "Account Name: "..result.accountName, |
195 | - | "Account Key: "..result.accountKey, |
195 | + | "Account Key: "..result.accountKey, |
196 | - | "Account Balance: "..result.balance, |
196 | + | "Account Balance: "..result.balance, |
197 | - | "Account Flag: "..tostring(result.isFlagged), |
197 | + | "Account Flag: "..tostring(result.isFlagged), |
198 | - | "Account Co-Owned: "..tostring(result.isFront) |
198 | + | "Account Co-Owned: "..tostring(result.isFront) |
199 | - | } |
199 | + | } |
200 | - | |
200 | + | |
201 | - | displayInfo(info) |
201 | + | displayInfo(info) |
202 | - | event.pull("key_down") |
202 | + | event.pull("key_down") |
203 | - | elseif cselected == 2 then |
203 | + | elseif cselected == 2 then |
204 | - | term.clear() |
204 | + | term.clear() |
205 | - | |
205 | + | |
206 | - | local packet = { |
206 | + | local packet = { |
207 | - | type = "getinfo", |
207 | + | type = "getinfo", |
208 | - | account = currentaccount |
208 | + | account = currentaccount |
209 | - | } |
209 | + | } |
210 | - | |
210 | + | |
211 | - | broadcast(packet) |
211 | + | broadcast(packet) |
212 | - | currentaccount = receive() |
212 | + | currentaccount = receive() |
213 | - | |
213 | + | |
214 | - | if not currentaccount.isFront then |
214 | + | if not currentaccount.isFront then |
215 | - | centerText(scrY / 2, "Privatly Owned Account") |
215 | + | centerText(scrY / 2, "Privatly Owned Account") |
216 | - | else |
216 | + | else |
217 | - | local ownersList = {} |
217 | + | local ownersList = {} |
218 | - | |
218 | + | |
219 | - | for k, v in pairs(currentaccount.owners) do |
219 | + | for k, v in pairs(currentaccount.owners) do |
220 | - | table.insert(ownersList, "Account "..k.." owns "..(v * 100).."%") |
220 | + | table.insert(ownersList, "Account "..k.." owns "..(v * 100).."%") |
221 | - | end |
221 | + | end |
222 | - | |
222 | + | |
223 | - | displayInfo(ownersList) |
223 | + | displayInfo(ownersList) |
224 | - | end |
224 | + | end |
225 | - | |
225 | + | |
226 | - | event.pull("key_down") |
226 | + | event.pull("key_down") |
227 | - | elseif cselected == 3 then |
227 | + | elseif cselected == 3 then |
228 | - | local tutorial = { |
228 | + | local tutorial = { |
229 | - | "A prompt will appear asking you to enter the new owners,", |
229 | + | "A prompt will appear asking you to enter the new owners,", |
230 | - | "Followed by the % share they own. Ensure that the total", |
230 | + | "Followed by the % share they own. Ensure that the total", |
231 | - | "shares add up to 100% or you will be asked to restart.", |
231 | + | "shares add up to 100% or you will be asked to restart.", |
232 | - | "Press any button to continue..." |
232 | + | "Press any button to continue..." |
233 | - | } |
233 | + | } |
234 | - | |
234 | + | |
235 | - | displayInfo(tutorial) |
235 | + | displayInfo(tutorial) |
236 | - | event.pull("key_down") |
236 | + | event.pull("key_down") |
237 | - | local done = nil |
237 | + | local done = nil |
238 | - | local total = 0 |
238 | + | local total = 0 |
239 | - | local newOwners = {} |
239 | + | local newOwners = {} |
240 | - | |
240 | + | |
241 | - | repeat |
241 | + | repeat |
242 | - | local name = jenisis.inputBar("Input the owner name:") |
242 | + | local name = jenisis.inputBar("Input the owner name:") |
243 | - | local amount = jenisis.inputBar("Input the % share:") |
243 | + | local amount = jenisis.inputBar("Input the % share:") |
244 | - | |
244 | + | |
245 | - | local i, j = string.find(amount, "%%") |
245 | + | local i, j = string.find(amount, "%%") |
246 | - | |
246 | + | |
247 | - | if i ~= nil then |
247 | + | if i ~= nil then |
248 | - | local amount = string.sub(0, string.len(amount) - 1) |
248 | + | local amount = string.sub(0, string.len(amount) - 1) |
249 | - | end |
249 | + | end |
250 | - | |
250 | + | |
251 | - | amount = tonumber(amount) |
251 | + | amount = tonumber(amount) |
252 | - | total = total + amount |
252 | + | total = total + amount |
253 | - | |
253 | + | |
254 | - | if total == 100 then |
254 | + | if total == 100 then |
255 | - | done = true |
255 | + | done = true |
256 | - | newOwners[name] = amount * 0.01 |
256 | + | newOwners[name] = amount * 0.01 |
257 | - | elseif total > 100 then |
257 | + | elseif total > 100 then |
258 | - | jenisis.errorMes("You have gone over 100. Restarting...") |
258 | + | jenisis.errorMes("You have gone over 100. Restarting...") |
259 | - | total = 0 |
259 | + | total = 0 |
260 | - | else |
260 | + | else |
261 | - | tutorial[4] = (" Current counted shares at "..total.."% ") |
261 | + | tutorial[4] = (" Current counted shares at "..total.."% ") |
262 | - | displayInfo(tutorial) |
262 | + | displayInfo(tutorial) |
263 | - | newOwners[name] = (amount * 0.01) |
263 | + | newOwners[name] = (amount * 0.01) |
264 | - | end |
264 | + | end |
265 | - | until done |
265 | + | until done |
266 | - | |
266 | + | |
267 | - | local temp = 0 |
267 | + | local temp = 0 |
268 | - | for k, v in pairs(newOwners) do |
268 | + | for k, v in pairs(newOwners) do |
269 | - | temp = temp + v |
269 | + | temp = temp + v |
270 | - | end |
270 | + | end |
271 | - | |
271 | + | |
272 | - | if temp ~= 1 then |
272 | + | if temp ~= 1 then |
273 | - | jenisis.errorMes("Shares exeeded 100% ("..temp..")") |
273 | + | jenisis.errorMes("Shares exeeded 100% ("..temp..")") |
274 | - | return |
274 | + | return |
275 | - | else |
275 | + | else |
276 | - | currentaccount.owners = newOwners |
276 | + | currentaccount.owners = newOwners |
277 | - | end |
277 | + | end |
278 | - | |
278 | + | |
279 | - | local packet = { |
279 | + | local packet = { |
280 | - | type = "dofront", |
280 | + | type = "dofront", |
281 | - | account = currentaccount |
281 | + | account = currentaccount |
282 | - | } |
282 | + | } |
283 | - | |
283 | + | |
284 | - | broadcast(packet) |
284 | + | broadcast(packet) |
285 | - | local result = receive() |
285 | + | local result = receive() |
286 | - | |
286 | + | |
287 | - | if result then |
287 | + | if result then |
288 | - | jenisis.errorMes("Successfully set up ownership", "green") |
288 | + | jenisis.errorMes("Successfully set up ownership", "green") |
289 | - | else |
289 | + | else |
290 | - | jenisis.errorMes("Unexpected Error") |
290 | + | jenisis.errorMes("Unexpected Error") |
291 | - | end |
291 | + | end |
292 | - | else |
292 | + | else |
293 | - | return |
293 | + | return |
294 | - | end |
294 | + | end |
295 | - | end |
295 | + | end |
296 | end | |
297 | - | |
297 | + | |
298 | - | while true do |
298 | + | while true do |
299 | - | |
299 | + | |
300 | - | static = { |
300 | + | static = { |
301 | - | "Bank ATM by Horyzon", |
301 | + | "Bank ATM by Horyzon", |
302 | - | "" |
302 | + | "" |
303 | - | } |
303 | + | } |
304 | - | |
304 | + | |
305 | - | menu = { |
305 | + | menu = { |
306 | - | "Check Funds", |
306 | + | "Check Funds", |
307 | - | "Transfer", |
307 | + | "Transfer", |
308 | - | "Account Management", |
308 | + | "Account Management", |
309 | - | "New Account", |
309 | + | "New Account", |
310 | - | "", |
310 | + | "", |
311 | - | "Exit" |
311 | + | "Exit" |
312 | - | } |
312 | + | } |
313 | - | |
313 | + | |
314 | - | if loggedIn then |
314 | + | if loggedIn then |
315 | - | static[2] = ("Logged in as "..currentaccount.accountName) |
315 | + | static[2] = ("Logged in as "..currentaccount.accountName) |
316 | - | menu[5] = "Log Out" |
316 | + | menu[5] = "Log Out" |
317 | - | else |
317 | + | else |
318 | - | static[2] = "Please log in." |
318 | + | static[2] = "Please log in." |
319 | - | menu[5] = "Log In" |
319 | + | menu[5] = "Log In" |
320 | - | end |
320 | + | end |
321 | - | |
321 | + | |
322 | - | result = jenisis.drawScreen(static, menu) |
322 | + | result = jenisis.drawScreen(static, menu) |
323 | - | |
323 | + | |
324 | - | if result == 1 then |
324 | + | if result == 1 then |
325 | - | getFunds() |
325 | + | getFunds() |
326 | - | elseif result == 2 then |
326 | + | elseif result == 2 then |
327 | - | transfer() |
327 | + | transfer() |
328 | - | elseif result == 3 then |
328 | + | elseif result == 3 then |
329 | - | manageAccount() |
329 | + | manageAccount() |
330 | - | elseif result == 4 then |
330 | + | elseif result == 4 then |
331 | - | newAccount() |
331 | + | newAccount() |
332 | - | elseif result == 5 then |
332 | + | elseif result == 5 then |
333 | - | doLog() |
333 | + | doLog() |
334 | - | elseif result == 6 then |
334 | + | elseif result == 6 then |
335 | - | break |
335 | + | break |
336 | - | end |
336 | + | end |
337 | end |