Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.45 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local term = require("term")
  4. local fs = require("filesystem")
  5. local sides = require("sides")
  6. local colors = require("colors")
  7.  
  8. local modem = component.modem
  9. local computer = component.computer
  10. local card_reader = component.os_magreader
  11. local redstone = component.redstone
  12.  
  13. local bundle = sides.right
  14. local cab100 = colors.orange
  15. local cab500 = colors.red
  16. local cab2000 = colors.yellow
  17. local cab10000 = colors.green
  18.  
  19. vyber = true
  20.  
  21. modem.open(443)
  22.  
  23. function center(str, line)
  24. c = 1 + math.floor((80 - 0) / 2) - math.floor(#str / 2)
  25. term.setCursor(c, line)
  26. term.write(str)
  27. end
  28.  
  29.  
  30. function toHeader(balance, name)
  31. term.setCursor(1, 0)
  32. term.write(balance)
  33. p = 80 - (math.floor(#balance) + math.floor(#name))
  34.  
  35. for i = p,0,-1 do
  36. term.write(" ")
  37. end
  38.  
  39. term.write(name)
  40. end
  41.  
  42.  
  43. function split(inputstr, sep)
  44. if sep == nil then
  45. sep = "%s"
  46. end
  47. local t={} ; i=1
  48. for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  49. t[i] = str
  50. i = i + 1
  51. end
  52. return t
  53. end
  54.  
  55.  
  56. function loadC(price)
  57. a = io.open("/home/bankovky/"..price, "r")
  58. b = a:read("*all")
  59. a:close()
  60. return tonumber(b)
  61. end
  62.  
  63. function writeC(val, price)
  64. a = io.open("/home/bankovky/"..price, "w")
  65. a:write(val)
  66. a:close()
  67. end
  68.  
  69. while true do
  70. c100 = loadC(100)
  71. c500 = loadC(500)
  72. c2000 = loadC(2000)
  73. c10000 = loadC(10000)
  74.  
  75. v100 = 0
  76. v500 = 0
  77. v2000 = 0
  78. v10000 = 0
  79.  
  80. celkem_skladem = c100*100 + c500*500 + c2000*2000 + c10000*10000
  81.  
  82. if c100 == 0 and c500 == 0 and c2000 == 0 and c10000 == 0 then
  83. vyber = false
  84. else
  85. vyber = true
  86. end
  87.  
  88. term.clear()
  89. center("ATM Komerční banka", 7)
  90. center("Přiložte kartu", 8)
  91.  
  92. ev, _, user, ucet, uuid = event.pull("magData")
  93. computer.beep(500, 0.5)
  94.  
  95. term.clear()
  96. center("ATM Komerční banka", 7)
  97. center("Zadejte pin: ", 8)
  98. pin = term.read();
  99.  
  100. term.clear()
  101. center("ATM Komerční banka", 7)
  102. center("Probíhá autorizace...", 8)
  103.  
  104. modem.broadcast(443, "LOGIN#" .. ucet .. "#" .. pin)
  105. local _, _, from, port, _, msg = event.pull("modem_message")
  106.  
  107. if msg == "UNKNOW_ACCOUNT" then
  108.  
  109. else
  110. if msg == "BAD_PIN" then
  111.  
  112. else
  113. logged = true
  114. while logged == true do
  115. cut = split(msg, "#")
  116. term.clear()
  117. toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
  118. center("ATM Komerční banka", 7)
  119. center("Výběr 1", 9)
  120. center("Odhlásit 0", 10)
  121. term.setCursor(39,11)
  122. volba = tonumber(term.read())
  123.  
  124. if volba == 0 then
  125. logged = false
  126. elseif volba == 1 then
  127. term.clear()
  128. toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
  129. center("ATM Komerční banka", 7)
  130. center("Zadejte částku:", 9)
  131. term.setCursor(39,10)
  132. castka = tonumber(term.read())
  133.  
  134. zbyva_vydat = castka
  135. if (tonumber(cut[1]) - castka) >= 0 then
  136. if celkem_skladem >= castka then
  137. term.clear()
  138. toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
  139. center("ATM Komerční banka", 7)
  140. center("Zpracovávání...", 9)
  141. center("Prosím počkejte!", 10)
  142. bankovky = 0
  143. while zbyva_vydat ~= 0 do
  144. if zbyva_vydat >= 10000 then
  145. numero = zbyva_vydat / 10000
  146. v10000 = math.floor(numero)
  147. if v10000 > c10000 then
  148. v10000 = c10000
  149. end
  150. zbyva_vydat = zbyva_vydat - (v10000 * 10000)
  151. bankovky = bankovky + v10000
  152. elseif zbyva_vydat >= 2000 then
  153. numero = zbyva_vydat / 2000
  154. v2000 = math.floor(numero)
  155. if v2000 > c2000 then
  156. v2000 = c2000
  157. end
  158. zbyva_vydat = zbyva_vydat - (v2000 * 2000)
  159. bankovky = bankovky + v2000
  160. elseif zbyva_vydat >= 500 then
  161. numero = zbyva_vydat / 500
  162. v500 = math.floor(numero)
  163. if v500 > c500 then
  164. v500 = c500
  165. end
  166. zbyva_vydat = zbyva_vydat - (v500 * 500)
  167. bankovky = bankovky + v500
  168. elseif zbyva_vydat >= 100 then
  169. numero = zbyva_vydat / 100
  170. v100 = math.floor(numero)
  171. if v100 > c100 then
  172. v100 = c100
  173. end
  174. zbyva_vydat = zbyva_vydat - (v100 * 100)
  175. bankovky = bankovky + v100
  176. else
  177. ignore = zbyva_vydat
  178. zbyva_vydat = 0
  179. end
  180. end--while
  181.  
  182. term.clear()
  183. toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
  184. center("ATM Komerční banka", 7)
  185. center("Zpracovávání...", 9)
  186. center("Už jen dotaz na server!", 10)
  187.  
  188. if ignore == nil then
  189. ignore = 0
  190. end
  191.  
  192. celk = (castka - ignore) * -1
  193. modem.broadcast(443, "ATM#" .. ucet .. "#" .. celk)
  194. local _, _, from, port, _, msg = event.pull("modem_message")
  195.  
  196. while bankovky ~= 0 do
  197. if v10000 ~= nil and v10000 ~= 0 then
  198. while v10000 ~= 0 do
  199. -- Výdej 10 000
  200. redstone.setBundledOutput(bundle, cab10000, 100)
  201. os.sleep(0.5)
  202. redstone.setBundledOutput(bundle, cab10000, 0)
  203. v10000 = v10000 - 1
  204. c10000 = c10000 - 1
  205. bankovky = bankovky - 1
  206. end
  207. elseif v2000 ~= nil and v2000 ~= 0 then
  208. while v2000 ~= 0 do
  209. -- Výdej 2 000
  210. redstone.setBundledOutput(bundle, cab2000, 100)
  211. os.sleep(0.5)
  212. redstone.setBundledOutput(bundle, cab2000, 0)
  213. v2000 = v2000 - 1
  214. c2000 = c2000 - 1
  215. bankovky = bankovky - 1
  216. end
  217. elseif v500 ~= nil and v500 ~= 0 then
  218. while v500 ~= 0 do
  219. -- Výdej 500
  220. redstone.setBundledOutput(bundle, cab500, 100)
  221. os.sleep(0.5)
  222. redstone.setBundledOutput(bundle, cab500, 0)
  223. v500 = v500 - 1
  224. c500 = c500 - 1
  225. bankovky = bankovky - 1
  226. end
  227. elseif v100 ~= nil and v100 ~= 0 then
  228. while v100 ~= 0 do
  229. -- Výdej 100
  230. redstone.setBundledOutput(bundle, cab100, 100)
  231. os.sleep(0.5)
  232. redstone.setBundledOutput(bundle, cab100, 0)
  233. v100 = v100 - 1
  234. c100 = c100 - 1
  235. bankovky = bankovky - 1
  236. end
  237. end
  238. end
  239.  
  240. writeC(c10000, "10000")
  241. writeC(c2000, "2000")
  242. writeC(c500, "500")
  243. writeC(c100, "100")
  244.  
  245. term.clear()
  246. toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
  247. center("ATM Komerční banka", 7)
  248. center("Bankovky byly vyslány, prosím počkejte", 9)
  249. center("než dorazí všechny.", 10)
  250.  
  251. os.sleep(5)
  252.  
  253. else
  254. term.clear()
  255. toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
  256. center("ATM Komerční banka", 7)
  257. center("Je nám líto, ale bankomat nemá dostatek financí.", 9)
  258. os.sleep(5)
  259. end--dostatekban
  260. else
  261. term.clear()
  262. toHeader("Zůstatek: " .. cut[1] .. "$", "Majitel: " .. cut[2] )
  263. center("ATM Komerční banka", 7)
  264. center("Je nám líto, ale nemáte dostatek financí na účtu.", 9)
  265. os.sleep(5)
  266. end--dostatekfin
  267. end--volba
  268. end--logged
  269. end --bad pin
  270. end --unknown acc
  271. end --while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement