SHOW:
|
|
- or go back to the newest paste.
| 1 | os.loadAPI("/Base64")
| |
| 2 | os.loadAPI("uap")
| |
| 3 | os.loadAPI("lg/lg")
| |
| 4 | rednet.open("back")
| |
| 5 | lg.setup("term")
| |
| 6 | local balance = nil | |
| 7 | local screen = 1 | |
| 8 | local card = nil | |
| 9 | local psw = nil | |
| 10 | local name = nil | |
| 11 | function saveCreds(id,psw) | |
| 12 | local cf = fs.open("/bank/creds","w")
| |
| 13 | cf.writeLine(id) | |
| 14 | cf.writeLine(psw) | |
| 15 | cf.close() | |
| 16 | local cardff = fs.open("card","w")
| |
| 17 | cardff.write(id) | |
| 18 | cardff.close() | |
| 19 | end | |
| 20 | function writeCreds() | |
| 21 | local cf = fs.open("/bank/creds","r")
| |
| 22 | if cf then | |
| 23 | cardf = cf.readLine() | |
| 24 | pswf = cf.readLine() | |
| 25 | cf.close() | |
| 26 | if cardf and pswf then | |
| 27 | term.setBackgroundColor(colors.gray) | |
| 28 | term.setTextColor(colors.white) | |
| 29 | term.setCursorPos(2,10) | |
| 30 | term.write(cardf) | |
| 31 | card = cardf | |
| 32 | term.setCursorPos(2,14) | |
| 33 | term.write(pswf) | |
| 34 | psw = pswf | |
| 35 | end | |
| 36 | else | |
| 37 | end | |
| 38 | end | |
| 39 | function drawMAIN() | |
| 40 | uap.upd() | |
| 41 | term.setBackgroundColor(colors.white) | |
| 42 | term.clear() | |
| 43 | term.setCursorPos(9,3) | |
| 44 | term.setTextColor(colors.red) | |
| 45 | term.write("Creatopico")
| |
| 46 | term.setCursorPos(12,4) | |
| 47 | term.write("Bank")
| |
| 48 | local sx,sy = term.getSize() | |
| 49 | term.setBackgroundColor(colors.red) | |
| 50 | for i=1,sx do | |
| 51 | term.setCursorPos(i,6) | |
| 52 | term.write(" ")
| |
| 53 | end | |
| 54 | term.setTextColor(colors.gray) | |
| 55 | term.setCursorPos(12,8) | |
| 56 | term.write("LOGIN")
| |
| 57 | term.setCursorPos(10,10) | |
| 58 | term.write("REGISTER")
| |
| 59 | for i=1,sx do | |
| 60 | term.setCursorPos(i,14) | |
| 61 | term.write(" ")
| |
| 62 | end | |
| 63 | uap.upd() | |
| 64 | end | |
| 65 | drawMAIN() | |
| 66 | local soffset = 0 | |
| 67 | function drawHistory(offset) | |
| 68 | screen = 5 | |
| 69 | lg.fillScreen(colors.white) | |
| 70 | lg.fill(1,lg.getSize().x,3,3,colors.red) | |
| 71 | lg.drawText(2,3,colors.white,colors.red,"Istorija Perevodov") | |
| 72 | rednet.send(40,Base64.encode("getlt "..card.." "..psw),"bank44")
| |
| 73 | local sId = nil | |
| 74 | local msg = nil | |
| 75 | local prt = nil | |
| 76 | repeat | |
| 77 | event, senderId, message, distance = os.pullEvent("rednet_message")
| |
| 78 | sId = senderId | |
| 79 | msg = message | |
| 80 | prt = distance | |
| 81 | until prt ~= "base44" and sId == 40 | |
| 82 | gi = 1 | |
| 83 | for i=1, #msg do | |
| 84 | gi = i + offset | |
| 85 | if msg[gi] then | |
| 86 | lg.drawText(2,5+i,colors.red,colors.white,"- "..msg[gi]) | |
| 87 | end | |
| 88 | if i == lg.getSize().y - 4 then break end | |
| 89 | end | |
| 90 | - | local card = read() |
| 90 | + | lg.drawBT("close1",2,10,lg.getSize().y-1,lg.getSize().y-1,colors.white,colors.red,"Nazad")
|
| 91 | if offset == 0 then | |
| 92 | lg.drawBT("up",lg.getSize().x,lg.getSize().x,17,17,colors.white,colors.gray,"\30")
| |
| 93 | else | |
| 94 | lg.drawBT("up",lg.getSize().x,lg.getSize().x,17,17,colors.white,colors.red,"\30")
| |
| 95 | end | |
| 96 | lg.drawBT("down",lg.getSize().x,lg.getSize().x,19,19,colors.white,colors.red,"\31")
| |
| 97 | lg.fill(lg.getSize().x,lg.getSize().x,5,15,colors.gray) | |
| 98 | local percentage = (offset / 10) * 100 | |
| 99 | local rp = math.floor(percentage) / 10 | |
| 100 | lg.drawText(lg.getSize().x,5+rp,colors.lightGray,colors.gray,"\8") | |
| 101 | uap.upd() | |
| 102 | - | end |
| 102 | + | |
| 103 | function drawLOGIN() | |
| 104 | term.setBackgroundColor(colors.white) | |
| 105 | term.clear() | |
| 106 | term.setTextColor(colors.red) | |
| 107 | term.setCursorPos(12,3) | |
| 108 | term.write("LOGIN")
| |
| 109 | term.setBackgroundColor(colors.red) | |
| 110 | term.setTextColor(colors.white) | |
| 111 | local sx,sy = term.getSize() | |
| 112 | uap.upd() | |
| 113 | for i=1,sx do | |
| 114 | term.setCursorPos(i,6) | |
| 115 | term.write(" ")
| |
| 116 | end | |
| 117 | term.setBackgroundColor(colors.gray) | |
| 118 | term.setCursorPos(2,10) | |
| 119 | for i=1,10 do | |
| 120 | term.write(" ")
| |
| 121 | term.setCursorPos(2+i,10) | |
| 122 | end | |
| 123 | term.setTextColor(colors.red) | |
| 124 | term.setBackgroundColor(colors.white) | |
| 125 | term.setCursorPos(3,9) | |
| 126 | term.write("CARD-ID")
| |
| 127 | term.setBackgroundColor(colors.gray) | |
| 128 | term.setCursorPos(2,14) | |
| 129 | for f=1,10 do | |
| 130 | term.write(" ")
| |
| 131 | term.setCursorPos(2+f,14) | |
| 132 | end | |
| 133 | term.setTextColor(colors.red) | |
| 134 | term.setBackgroundColor(colors.white) | |
| 135 | term.setCursorPos(3,13) | |
| 136 | term.write("PASSWORD")
| |
| 137 | term.setBackgroundColor(colors.red) | |
| 138 | term.setTextColor(colors.white) | |
| 139 | term.setCursorPos(2,17) | |
| 140 | term.write("BACK")
| |
| 141 | term.setCursorPos(10,17) | |
| 142 | term.write("LOGIN")
| |
| 143 | writeCreds() | |
| 144 | uap.upd() | |
| 145 | end | |
| 146 | function drawACC() | |
| 147 | term.setBackgroundColor(colors.white) | |
| 148 | term.clear() | |
| 149 | term.setTextColor(colors.red) | |
| 150 | term.setCursorPos(8,3) | |
| 151 | term.write("Hi, "..name)
| |
| 152 | term.setBackgroundColor(colors.red) | |
| 153 | term.setTextColor(colors.white) | |
| 154 | lg.drawBT("perevod",2,15,13,16,colors.white,colors.red," Perevod\n Deneg")
| |
| 155 | lg.drawBT("history",19,25,13,16,colors.white,colors.red," Isto\n rija")
| |
| 156 | local sx,sy = term.getSize() | |
| 157 | for i=1,sx do | |
| 158 | term.setCursorPos(i,6) | |
| 159 | term.write(" ")
| |
| 160 | end | |
| 161 | term.setTextColor(colors.red) | |
| 162 | term.setBackgroundColor(colors.white) | |
| 163 | term.setCursorPos(2,10) | |
| 164 | term.write("- Balance: "..balance.." AR")
| |
| 165 | uap.upd() | |
| 166 | ||
| 167 | end | |
| 168 | -- loop | |
| 169 | while true do | |
| 170 | local event, button, x, y = os.pullEvent( "mouse_click" ) | |
| 171 | -- LOGIN BT HANDL | |
| 172 | if (screen == 1) then | |
| 173 | if (y == 8 and x > 11 and x < 18) then | |
| 174 | drawLOGIN() | |
| 175 | screen = 2 | |
| 176 | else | |
| 177 | end | |
| 178 | elseif (screen == 2) then | |
| 179 | if (y == 17 and x > 1 and x < 7) then | |
| 180 | drawMAIN() | |
| 181 | screen = 1 | |
| 182 | elseif (y == 10 and x > 1 and x < 13) then | |
| 183 | term.setBackgroundColor(colors.lightGray) | |
| 184 | term.setTextColor(colors.white) | |
| 185 | term.setCursorPos(1,10) | |
| 186 | for i=1,10 do | |
| 187 | term.setCursorPos(1+i,10) | |
| 188 | term.write(" ")
| |
| 189 | end | |
| 190 | term.setCursorPos(2,10) | |
| 191 | card = read() | |
| 192 | term.setBackgroundColor(colors.gray) | |
| 193 | term.setCursorPos(1,10) | |
| 194 | for i=1,10 do | |
| 195 | term.setCursorPos(1+i,10) | |
| 196 | term.write(" ")
| |
| 197 | end | |
| 198 | term.setCursorPos(2,10) | |
| 199 | term.write(card) | |
| 200 | elseif (y == 14 and x > 1 and x < 13) then | |
| 201 | term.setBackgroundColor(colors.lightGray) | |
| 202 | term.setTextColor(colors.white) | |
| 203 | term.setCursorPos(1,14) | |
| 204 | for i=1,10 do | |
| 205 | term.setCursorPos(1+i,14) | |
| 206 | term.write(" ")
| |
| 207 | end | |
| 208 | term.setCursorPos(2,14) | |
| 209 | psw = read() | |
| 210 | term.setBackgroundColor(colors.gray) | |
| 211 | term.setCursorPos(1,14) | |
| 212 | for i=1,10 do | |
| 213 | term.setCursorPos(1+i,14) | |
| 214 | term.write(" ")
| |
| 215 | end | |
| 216 | term.setCursorPos(2,14) | |
| 217 | term.write(psw) | |
| 218 | elseif (y == 17 and x > 10 and x < 16) then | |
| 219 | rednet.send(40,Base64.encode("login "..card.." "..psw),"bank44")
| |
| 220 | term.setBackgroundColor(colors.white) | |
| 221 | term.setTextColor(colors.red) | |
| 222 | term.setCursorPos(10,17) | |
| 223 | term.write("Loading...")
| |
| 224 | local sId = nil | |
| 225 | local msg = nil | |
| 226 | local prt = nil | |
| 227 | repeat | |
| 228 | event, senderId, message, distance = os.pullEvent("rednet_message")
| |
| 229 | sId = senderId | |
| 230 | msg = Base64.decode(message) | |
| 231 | prt = distance | |
| 232 | until prt ~= "base44" and sId == 40 | |
| 233 | local ii = 1 | |
| 234 | for word in string.gmatch(msg,"%S+") do | |
| 235 | if (ii == 1) then | |
| 236 | name = word | |
| 237 | elseif (ii == 2) then | |
| 238 | balance = word | |
| 239 | end | |
| 240 | ii = ii + 1 | |
| 241 | end | |
| 242 | if (msg == "error2") then | |
| 243 | term.setCursorPos(10,17) | |
| 244 | term.write("Oshibka!")
| |
| 245 | term.setCursorPos(2,18) | |
| 246 | term.write(" -Incorect password")
| |
| 247 | elseif (msg == "error1") then | |
| 248 | term.setCursorPos(10,17) | |
| 249 | term.write("Oshibka!")
| |
| 250 | term.setCursorPos(2,18) | |
| 251 | term.write(" - No account")
| |
| 252 | else | |
| 253 | screen = 3 | |
| 254 | saveCreds(card, psw) | |
| 255 | drawACC() | |
| 256 | end | |
| 257 | else | |
| 258 | end | |
| 259 | elseif screen == 3 and lg.isButton(x,y) == "perevod" then | |
| 260 | screen = 4 | |
| 261 | lg.fillScreen(colors.white) | |
| 262 | lg.fill(1,lg.getSize().x,3,3,colors.red) | |
| 263 | lg.drawInput("id",2,10,7,7,8)
| |
| 264 | lg.drawText(2,6,colors.red,colors.white,"ID karty") | |
| 265 | lg.drawText(2,3,colors.white,colors.red,"Perevod deneg") | |
| 266 | lg.drawText(2,10,colors.red,colors.white,"Summa AR") | |
| 267 | lg.drawText(2,14,colors.red,colors.white,"Comment") | |
| 268 | lg.drawInput("suma",2,10,11,11,8)
| |
| 269 | lg.drawInput("comment",2,20,15,15,18)
| |
| 270 | lg.drawBT("pay",2,13,17,20,colors.white,colors.red," Perevesti")
| |
| 271 | uap.upd() | |
| 272 | elseif screen == 4 and lg.isInput(x,y) then | |
| 273 | if lg.isInput(x,y) == "id" then | |
| 274 | id = lg.getInput(x,y) | |
| 275 | elseif lg.isInput(x,y) == "suma" then | |
| 276 | suma = lg.getInput(x,y,true) | |
| 277 | elseif lg.isInput(x,y) == "comment" then | |
| 278 | comment = lg.getInput(x,y) | |
| 279 | end | |
| 280 | elseif screen == 4 and lg.isButton(x,y) == "pay" then | |
| 281 | if (id ~= card and card ~= nil and id ~= nil) then | |
| 282 | if comment then | |
| 283 | comment = string.gsub(comment, " ", "_") | |
| 284 | rednet.send(40,Base64.encode("send_money "..card.." "..psw.." "..id.." "..suma.." "..comment),"bank44")
| |
| 285 | else | |
| 286 | rednet.send(40,Base64.encode("send_money "..card.." "..psw.." "..id.." "..suma),"bank44")
| |
| 287 | end | |
| 288 | local sId = nil | |
| 289 | local msg = nil | |
| 290 | local prt = nil | |
| 291 | repeat | |
| 292 | event, senderId, message, distance = os.pullEvent("rednet_message")
| |
| 293 | sId = senderId | |
| 294 | msg = Base64.decode(message) | |
| 295 | prt = distance | |
| 296 | until prt ~= "base44" and sId == 40 | |
| 297 | lg.fillScreen(colors.red) | |
| 298 | screen = 10 | |
| 299 | local answer = nil | |
| 300 | if msg == "error1" then | |
| 301 | answer = "Takoy karty netu!" | |
| 302 | elseif msg == "error2" then | |
| 303 | answer = "Nevernyi parol!" | |
| 304 | elseif msg == "error3" then | |
| 305 | answer = "Nedostatochno deneg!" | |
| 306 | elseif msg == "error4" then | |
| 307 | answer = "Takoy karty netu! ("..id..")"
| |
| 308 | else | |
| 309 | answer = "Gotovo!" | |
| 310 | end | |
| 311 | lg.drawText(1,lg.getSize().y/2,colors.white,colors.red,answer) | |
| 312 | os.sleep(1) | |
| 313 | rednet.send(40,Base64.encode("login "..card.." "..psw),"bank44")
| |
| 314 | local sId = nil | |
| 315 | local msg = nil | |
| 316 | local prt = nil | |
| 317 | repeat | |
| 318 | event, senderId, message, distance = os.pullEvent("rednet_message")
| |
| 319 | sId = senderId | |
| 320 | msg = Base64.decode(message) | |
| 321 | prt = distance | |
| 322 | until prt ~= "base44" and sId == 40 | |
| 323 | local ii = 1 | |
| 324 | for word in string.gmatch(msg,"%S+") do | |
| 325 | if (ii == 1) then | |
| 326 | name = word | |
| 327 | elseif (ii == 2) then | |
| 328 | balance = word | |
| 329 | end | |
| 330 | ii = ii + 1 | |
| 331 | end | |
| 332 | os.sleep(3) | |
| 333 | screen = 3 | |
| 334 | drawACC() | |
| 335 | else | |
| 336 | lg.fillScreen(colors.red) | |
| 337 | screen = 10 | |
| 338 | local answer = "Nelzya otpravit sebe!" | |
| 339 | lg.drawText(1,lg.getSize().y/2,colors.white,colors.red,answer) | |
| 340 | os.sleep(1) | |
| 341 | screen = 3 | |
| 342 | drawACC() | |
| 343 | end | |
| 344 | elseif screen == 3 and lg.isButton(x,y) == "history" then | |
| 345 | soffset = 0 | |
| 346 | drawHistory(soffset) | |
| 347 | elseif screen == 5 and lg.isButton(x,y) == "close1" then | |
| 348 | screen = 3 | |
| 349 | drawACC() | |
| 350 | elseif screen == 5 and lg.isButton(x,y) == "down" then | |
| 351 | soffset = soffset + 1 | |
| 352 | drawHistory(soffset) | |
| 353 | elseif screen == 5 and lg.isButton(x,y) == "up" then | |
| 354 | if soffset > 0 then | |
| 355 | soffset = soffset - 1 | |
| 356 | drawHistory(soffset) | |
| 357 | end | |
| 358 | end | |
| 359 | end | |
| 360 | lg.exit() |