Muzze77

UU-Bank by Muzze77

Jan 5th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 23.16 KB | None | 0 0
  1. shell.run("clear")
  2. mon = peripheral.wrap("top")
  3. rednet.open("right")
  4. p = peripheral.wrap("bottom")
  5. uu = p.getItemIdentifierIDFor(30188,0)
  6. uuID = 30188
  7. dayTime = os.day()
  8. mon.clear()
  9. mon.setCursorPos(1,1)
  10. mon.setTextColor(colors.green)
  11. mon.setTextScale(0.5)
  12. timeC = 0
  13. os.loadAPI("ocs/apis/sensor")
  14. sen = sensor.wrap("back")
  15. function getItemCount()
  16.     i = 0
  17.     s = sen.getTargets()
  18.     for v, k in pairs(s) do
  19.         if k.Name == "ME Wireless Access Point" then
  20.         targPos = v
  21.         end
  22.         if targPos == nil then
  23.         i = 0
  24.         else
  25.        
  26.         s1 = sen.getTargetDetails(targPos)
  27.             for v1, k1 in pairs(s1.Items) do
  28.                     if k1.Name == "UU-Matter" then
  29.                     i = k1.Size
  30.                     end
  31.             end
  32.        
  33.         end
  34.    
  35.     end
  36.     cbut(2,15,"Bank UU-Matter:" .. i  .. " ",colors.cyan,colors.black)
  37.     return i
  38. end
  39.  
  40. if fs.exists("time") == false then
  41.   cFile = fs.open("time","w")
  42.   cFile.writeLine(math.floor(0))
  43.   cFile.close()
  44.   bankTime = 0
  45. else
  46.   rFile = fs.open("time","r")
  47.   curTime = rFile.readLine()
  48.   rFile.close()
  49.     if curTime == "" or curTime == nil then
  50.         curTime = 0
  51.     end
  52.   bankTime = math.floor(curTime)
  53.  
  54. end
  55.  
  56. function saveTime(n)
  57. sFile = fs.open("time","w")
  58. if n == nil or n == "" then
  59.     n = 0
  60. end
  61. sFile.writeLine(math.floor(n))
  62. sFile.close()
  63. end
  64.  
  65. function cbut(cx,cy,text,bcol,tcol)
  66.     if bcol == nil then
  67.         bcol = colors.black
  68.     end
  69.     if tcol == nil then
  70.         tcol = colors.green
  71.     end
  72.    
  73.     mon.setBackgroundColor(bcol)
  74.     mon.setTextColor(tcol)
  75.     mon.setCursorPos(cx,cy)
  76.     mon.write(text)
  77.     mon.setBackgroundColor(colors.black)
  78.     mon.setTextColor(colors.green)
  79. end
  80. bankUU = 0
  81. gx, gy = mon.getSize()
  82. gxH = gx / 2
  83. gyH = gy / 2
  84.  
  85. function clearMsgLine()
  86.         cbut(2,gy - 2,"                                            ",nil,colors.orange)
  87.         cbut(2,gy - 1,"                                            ",nil,colors.orange)
  88.         cbut(2,gy,"                                            ",nil,colors.orange)
  89. end
  90.  
  91. function wlan(col)
  92.  
  93. if col == nil then
  94.     col = colors.red
  95. end
  96.     cbut(51,gy-10," ",col)
  97.     cbut(50,gy-9," ",col)
  98.     cbut(49,gy-8," ",col)
  99.     cbut(49,gy-7," ",col)
  100.     cbut(49,gy-6," ",col)
  101.     cbut(50,gy-5," ",col)
  102.     cbut(51,gy-4," ",col)
  103.            
  104.     cbut(53,gy-9," ",col)
  105.     cbut(52,gy-8," ",col)
  106.     cbut(52,gy-7," ",col)
  107.     cbut(52,gy-6," ",col)
  108.     cbut(53,gy-5," ",col)
  109.                
  110.                
  111.                
  112.     cbut(55,gy-6," ",col)
  113.     cbut(54,gy-7," ",col)
  114.     cbut(55,gy-8," ",col)
  115.  
  116.  
  117. end
  118.  
  119. function startscreen(gCol)
  120.  
  121.  
  122. m = getItemCount()
  123.  
  124. if m == nil then
  125.     wlanCol = colors.red
  126. else
  127.     wlanCol = colors.green
  128. end
  129. if timeC == nil then
  130.     timeC = 0
  131. end
  132. if gcol == nil then
  133.     gcol = colors.red
  134. end
  135. mon.clear()
  136. cbut(gxH -13 ,2,"Willkommen bei der UU-Bank")
  137. cbut(2,4,"Hier kannst du UU-Matter einzahlen und Abheben")
  138. cbut(2,6,"Dazu wird eine DISK benötigt.")
  139. cbut(2,7,"Diese erhälst du von Muzze77")
  140. cbut(2,8,"/mail send Muzze77 [Anfrage] : UU-Bank Account anmeldung")
  141. cbut(2,10,"Nach 12 MC Tagen bekommst du ein Bonus:",nil,colors.yellow)
  142. cbut(2,11,"ab  100 UU -> 1 UU",nil,colors.yellow)
  143. cbut(2,12,"ab  500 UU -> 4 UU",nil,colors.yellow)
  144. cbut(2,13,"ab 1000 UU -> 16 UU",nil,colors.yellow)
  145. cbut(2,14,"ab 5000 UU -> 64 UU",nil,colors.yellow)
  146. cbut(2,15,"Bank UU-Matter:" .. m  .. " ",colors.cyan,colors.black)
  147. clearMsgLine()
  148. cbut(2,gy - 2,"Disk einwerfen um Kontostand abzufragen",nil,colors.orange)
  149. cbut(gx-9,gy - 2,"EINZAHLEN",colors.blue,colors.orange)
  150. cbut(gx-9,gy - 1,"AUSZAHLEN",colors.red, colors.orange)
  151.  
  152. cbut(gxH-8,16," [ACCOUNT]  ",colors.yellow,colors.black)
  153. cbut(gxH-8,17," ---------  ",colors.yellow,colors.black)
  154. cbut(gxH-8,19,"[KONTOSTAND]",colors.yellow,colors.black)
  155. cbut(gxH-8,20,"------------",colors.yellow,colors.black)
  156. cbut(gxH-8,21,"Bonus Tage:" .. timeC .. " ",colors.yellow,colors.black)
  157. bankTime = os.day()
  158. cbut(36,1,"Day:                ",colors.red,colors.black)
  159. cbut(36,1,"Day: " .. bankTime,colors.red,colors.black)
  160. wlan(gCol)
  161. end
  162. wlanCol = colors.red
  163. startscreen(wlanCol)
  164.  
  165. function loadUser()
  166.  
  167.    
  168.         sleep(0.5)
  169.         term.setCursorPos(2,2)
  170.         term.write("List User")
  171.             x = 2
  172.             y = 3
  173.             list = fs.list("")
  174.             i = 1
  175.             for v ,k in pairs(list) do
  176.            
  177.                 if k == "1" or k == "startup" or k == "rom" or k == "disk" or k == "time" or k == "update" then
  178.                 else
  179.                     term.setCursorPos(x,y)
  180.                     term.write(" " .. i .. " " .. k)
  181.                     i = i + 1
  182.                     x = x + 14
  183.                     if x > 42 then
  184.                         x = 2
  185.                         y = y + 1
  186.                     end
  187.                 end
  188.             end
  189. end
  190.  
  191. function delUser()
  192. mp = "MZ115"
  193.         term.setCursorPos(2,2)
  194.         term.write("enter Masterpassword")
  195.         term.setCursorPos(2,3)
  196.         code = read("*")
  197.        
  198.             if code == mp then
  199.            
  200.             term.setCursorPos(2,5)
  201.             term.write("Enter Username")
  202.             term.setCursorPos(2,6)
  203.             uname = io.read()
  204.             if fs.exists(uname) then
  205.                 fs.delete(uname)
  206.                 tab = {["Key"] = "Delete",["Name"]=uname}
  207.                 rednet.broadcast(textutils.serialize(tab))
  208.                 sleep(0.02)
  209.                 term.setCursorPos(2,8)
  210.                 mon.write("User geloescht")
  211.             else
  212.                 term.setCursorPos(2,8)
  213.                 mon.write("User nicht gefunden")
  214.             end
  215.             sleep(1)
  216.             term.clear()
  217.             end
  218. end
  219.  
  220. function createUser()
  221.        
  222.         sleep(0.5)
  223.         mp = "MZ115"
  224.         term.setCursorPos(2,2)
  225.         term.write("enter Masterpassword")
  226.         term.setCursorPos(2,3)
  227.         code = read("*")
  228.             if code == mp then
  229.             term.setCursorPos(2,5)
  230.             term.write("Enter Username")
  231.             term.setCursorPos(2,7)
  232.             term.write("Enter UID")
  233.             term.setCursorPos(2,6)
  234.             uname = io.read()
  235.             term.setCursorPos(2,9)
  236.                 if fs.exists(uname) then
  237.                     term.write("User existiert bereits")
  238.                 else
  239.                     term.setCursorPos(2,8)
  240.                     numcode = math.random(0,9) .. math.random(0,9).. math.random(0,9) .. math.random(0,9)..math.random(0,9)..math.random(0,9)..math.random(0,9)..math.random(0,9)
  241.                    
  242.                     term.write(numcode)
  243.                     term.setCursorPos(2,9)
  244.                     term.write("DISK einlegen")
  245.            
  246.                     evt = os.pullEvent("disk")
  247.                     term.setCursorPos(2,10)
  248.                     term.write("User wird erstellt")
  249.    
  250.    
  251.                     sleep(0.2)
  252.                     cUser = fs.open(uname,"w")
  253.                     cUser.writeLine(0) -- Moneycount
  254.                     cUser.writeLine(0.0) -- Timecount
  255.                     cUser.writeLine(os.day()) -- Last logintime
  256.                     cUser.writeLine(numcode) -- UID
  257.                     cUser.close()
  258.                     tab = {["Key"] = "Create",["Name"]=uname,["Money"] = 0,["Time"] = 0.0,["LastLogin"] = 0.0,["UID"] = numcode}
  259.                     rednet.broadcast(textutils.serialize(tab))
  260.                     sleep(0.02)
  261.                     cDisk = fs.open("disk/key","w")
  262.                     cDisk.writeLine(numcode)
  263.                     cDisk.writeLine("Code nicht aendern! Code ist an User gebunden")
  264.                     cDisk.close()
  265.                     disk.setLabel("left",uname)
  266.                    
  267.                     term.setCursorPos(2,11)
  268.                     term.write("User :" .. uname .. " mit UID:" .. numcode .. " erstellt")
  269.                     term.setCursorPos(2,12)
  270.                     term.write("Disk entnehmen")
  271.                     evt = os.pullEvent("disk_eject")
  272.                    
  273.                 end
  274.             end
  275.             sleep(1)
  276.             term.clear()
  277. end
  278.  
  279. einz = 0
  280. ausz = 0
  281.  
  282. p = peripheral.wrap("bottom")
  283.  
  284. while true do
  285.    
  286.     evt , keys, side,id,msg = os.pullEventRaw()
  287.    
  288.     term.clear()
  289.     term.setCursorPos(1,1)
  290.     print("Evt: " .. evt)
  291.     startscreen(wlanCol)
  292.  
  293.     if evt == "terminate" then
  294.         break
  295.     end
  296.  
  297.     if evt == "disk_eject" then
  298.         dayTime = os.day()
  299.         cbut(36,20,"Zeit: " .. dayTime,colors.red,colors.black)
  300.         startscreen(wlanCol)
  301.     end
  302.  
  303.     if evt == "disk" then
  304.         startscreen(wlanCol)
  305.         clearMsgLine()
  306.         cbut(2,gy - 2,"Methode waehlen                      ->",nil,colors.orange)
  307.         cbut(2,gy - 1,"Methode waehlen                      ->",nil,colors.orange)
  308.         uname = disk.getLabel("left")
  309.        
  310.         lUser = fs.open(uname,"r")
  311.         money = tonumber(lUser.readLine())
  312.         timeC = lUser.readLine()
  313.         lastLogin = lUser.readLine()
  314.         curTime = os.day()
  315.         calTime = curTime - lastLogin
  316.         if calTime >= 12 then
  317.             timeC = 0
  318.             if money >= 0 or money <= 100 then
  319.                 money = money + 1
  320.             elseif money > 100 or money <= 500 then
  321.                 money = money + 4
  322.             elseif money > 500 or money <= 1000 then
  323.                 money = money + 16
  324.             elseif  money > 5000 then
  325.                 money = money + 64
  326.             end
  327.         elseif calTime < 12 then
  328.             timeC = calTime
  329.         end
  330.        
  331.         uid = lUser.readLine()
  332.         lUser.close()
  333.         tab = {["Key"] = "Update",["Name"]=uname,["Money"] = money ,["Time"] = timeC,["LastLogin"] = lastLogin,["UID"] = uid}
  334.         rednet.broadcast(textutils.serialize(tab))
  335.         cbut(gxH-8,17," " .. uname .. " ",colors.yellow,colors.black)
  336.         cbut(gxH-8,20," " .. money .. " ",colors.yellow,colors.black)
  337.         cbut(2,21,"Bonus Tage:" .. timeC .. " ",colors.yellow,colors.black)
  338.         cbut(2,gy ,"[Abbrechen]",nil,colors.orange)
  339.        
  340.         evt , side, x1, y1 = os.pullEvent("monitor_touch")
  341.         if x1 >= 2 and x1 <= 12 and y1 == gy then
  342.         disk.eject("left")
  343.        
  344.         end
  345.         sleep(0.02)
  346.     end
  347.    
  348.     if evt == "char" then
  349.  
  350.         if keys == "u" or key == "U" then
  351.             shell.run("update")
  352.         end
  353.         if keys == "l" or key == "L" then
  354.             loadUser()
  355.         end
  356.        
  357.         if keys == "d" or key == "D" then
  358.        
  359.         loadUser()
  360.         delUser()
  361.         end
  362.                
  363.         if keys == "c" or key == "C" then
  364.             createUser()
  365.         end
  366.     end
  367.        
  368.     if evt == "monitor_touch" then
  369.         x = side
  370.         y = id
  371.  
  372.        
  373.         if x >= 2 and x <= 12 and y == gy then
  374.                     disk.eject("left")
  375.         end
  376.        
  377.             if y == gy-1 and x >= 48 and x <= 56 then
  378.             dayTime = os.day()
  379.             cbut(36,20,"Zeit: " .. dayTime,colors.red,colors.black)
  380.                 if ausz == 0 then
  381.                     ausz = 1
  382.                     gNum = {}
  383.                     b  = 0
  384.                     f = 0
  385.                     cbut(gx-9,gy - 1,"AUSZAHLEN",colors.red,colors.green)
  386.                     clearMsgLine()
  387.                     cbut(2,gy - 2,"Disk einwerfen um Auszahlung zu starten",nil,colors.orange)
  388.                    
  389.                    
  390.                     if disk.isPresent("left") then
  391.                         uname = disk.getLabel("left")
  392.                     else
  393.                         evt = os.pullEvent("disk")
  394.                         uname = disk.getLabel("left")
  395.                     end
  396.                    
  397.                     cbut(3,gy-4,"_",colors.white)
  398.                     cbut(4,gy-4,"_",colors.white)
  399.                     cbut(5,gy-4,"_",colors.white)
  400.                     cbut(6,gy-4,"_",colors.white)
  401.                     cbut(7,gy-4,"_",colors.white)
  402.                    
  403.                     cbut(4,gy-8,"1",colors.white)
  404.                     cbut(5,gy-8,"2",colors.white)
  405.                     cbut(6,gy-8,"3",colors.white)
  406.                     cbut(4,gy-7,"4",colors.white)
  407.                     cbut(5,gy-7,"5",colors.white)
  408.                     cbut(6,gy-7,"6",colors.white)
  409.                     cbut(4,gy-6,"7",colors.white)
  410.                     cbut(5,gy-6,"8",colors.white)
  411.                     cbut(6,gy-6,"9",colors.white)
  412.                     cbut(4,gy-5,"C",colors.white)
  413.                     cbut(5,gy-5,"0",colors.white)
  414.                     cbut(6,gy-5,"<",colors.white)
  415.                     while b == 0 do
  416.                     if uname == nil then
  417.                    
  418.                         disk.eject("left")
  419.                         clearMsgLine()
  420.                         cbut(2,gy - 2,"User konnte nicht geladen werden!",nil,colors.orange)
  421.                         disk.eject("left")
  422.                         sleep(2)
  423.                         b = 1
  424.                     else
  425.                    
  426.                    
  427.                     nBank = getItemCount()
  428.                     lUser = fs.open(uname,"r")
  429.                     money = lUser.readLine()
  430.                     timeC = lUser.readLine()
  431.                     lastLogin = lUser.readLine()
  432.                     curTime = os.day()
  433.                     calTime = curTime - lastLogin
  434.                     print("Usermoney = " .. money)
  435.                     if calTime >= 12 then
  436.                         timeC = 0
  437.                         if money >= 0 or money <= 100 then
  438.                             money = money + 1
  439.                         elseif money > 100 or money <= 500 then
  440.                             money = money + 4
  441.                         elseif money > 500 or money <= 1000 then
  442.                             money = money + 16
  443.                         elseif  money > 5000 then
  444.                             money = money + 64
  445.                         end
  446.                     elseif calTime < 12 then
  447.                         timeC = calTime
  448.                     end
  449.                    
  450.                     uid = lUser.readLine()
  451.                     lUser.close()
  452.                         d = fs.open("disk/key","r")
  453.                         diskUID = d.readLine()
  454.                         d.close()
  455.                        
  456.                         cbut(gxH-8,17," " .. uname .. " ",colors.yellow,colors.black)
  457.                         cbut(gxH-8,20," " .. money .. " ",colors.yellow,colors.black)
  458.                         cbut(2,21,"Bonus Tage:" .. timeC .. " ",colors.yellow,colors.black)
  459.    
  460.                         iCount = getItemCount()
  461.                         clearMsgLine()
  462.                        
  463.  
  464.                        
  465.  
  466.                        
  467.                         cbut(2,gy ,"[Abbrechen]",nil,colors.orange)
  468.                         cbut(24,gy ,"[Bestätigen]",nil,colors.orange) 
  469.                         evt, side, x, y = os.pullEvent("monitor_touch")
  470.                        
  471.  
  472.                             if x >= 2 and x <= 12 and y == gy then
  473.                                 cbut(2,gy ,"[Abbrechen]",nil,colors.red)
  474.                                 sleep(0.1)
  475.                                 clearMsgLine()
  476.                                 cbut(2,gy - 2,"Abgebrochen",nil,colors.orange) 
  477.                                 disk.eject("left")
  478.                                 sleep(2)           
  479.                                 b = 1
  480.                        
  481.                             end
  482.                             if x >= 24 and x <= 34 and y == gy then
  483.                                 if f == 0 then
  484.                                     cbut(24,gy ,"[Bestätigen]",nil,colors.red)
  485.                                     sleep(0.1)
  486.                                     clearMsgLine()
  487.                                     cbut(2,gy - 2,"Nichts ausgewählt",nil,colors.orange)  
  488.                                     disk.eject("left")
  489.                                     sleep(2)           
  490.                                     b = 1                              
  491.                                 else
  492.                                     for nC = 1,#gNum,1 do
  493.                                         if numStr == nil then
  494.                                             numStr =  gNum[nC]
  495.                                         else
  496.                                             numStr = numStr .. gNum[nC]
  497.                                         end
  498.                                     end
  499.                                     money = tonumber(money)
  500.                                     numInt = tonumber(numStr)
  501.                                     if numInt > money then
  502.                                         cbut(24,gy ,"[Bestätigen]",nil,colors.red)
  503.                                         sleep(0.1)
  504.                                         clearMsgLine()
  505.                                         cbut(2,gy - 2,"Nicht genug auf UU-Matter auf deinem Account",nil,colors.orange)
  506.                                         sleep(2)
  507.                                     elseif  numInt > nBank then
  508.                                         cbut(24,gy ,"[Bestätigen]",nil,colors.red)
  509.                                         sleep(0.1)
  510.                                         clearMsgLine()
  511.                                         cbut(2,gy - 2,"Nicht genug auf UU-Matter auf der Bank",nil,colors.orange)  
  512.                                         cbut(2,gy - 1,"Bitte Muzze77 Kontaktieren",nil,colors.orange)  
  513.                                         sleep(2)                                   
  514.                                    
  515.                                     else
  516.                                    
  517.                                         fs.delete(uname)
  518.                                         uUser = fs.open(uname,"w")
  519.                                         uUser.writeLine(money - numInt) -- Moneycount
  520.                                         uUser.writeLine(timeC) -- Timecount
  521.                                         uUser.writeLine(lastLogin) -- Last logintime
  522.                                         uUser.writeLine(uid) -- UID
  523.                                         uUser.close()
  524.                                    
  525.                                         p = peripheral.wrap("bottom")
  526.                                         uu = p.getItemIdentifierIDFor(30188,0)
  527.                                         p.makeRequest(uu,numInt)
  528.                                    
  529.                                         cbut(24,gy ,"[Bestätigen]",nil,colors.red)
  530.                                         sleep(0.1)
  531.                                         clearMsgLine()
  532.                                         cbut(2,gy - 2,numInt .. " UU-Matter wird ausgezahlt",nil,colors.orange)
  533.                                         disk.eject("left")
  534.                                         sleep(2)           
  535.                                         b = 1
  536.                                     end
  537.                                     end
  538.                                
  539.                             end
  540.                            
  541.                            
  542.                            
  543.                             if x == 4 and y == gy-8 then
  544.                                 if f < 6 then
  545.                                     cbut(4,gy-8,"1",colors.white,colors.red)
  546.                                     table.insert(gNum,"1")
  547.                                     sleep(0.02)
  548.                                     cbut(4,gy-8,"1",colors.white)
  549.                                     f = f + 1
  550.                                 end
  551.                             end
  552.                             if x == 5 and y == gy- 8 then
  553.                                 if f < 6 then
  554.                                     cbut(5,gy-8,"2",colors.white,colors.red)
  555.                                     table.insert(gNum,"2")
  556.                                     sleep(0.01)
  557.                                     cbut(5,gy-8,"2",colors.white)
  558.                                     f = f + 1
  559.                                 end
  560.                             end
  561.                             if x == 6 and y == gy- 8 then
  562.                                 if f < 6 then
  563.                                     cbut(6,gy-8,"3",colors.white,colors.red)
  564.                                     table.insert(gNum,"3")
  565.                                     sleep(0.01)
  566.                                     cbut(6,gy-8,"3",colors.white)
  567.                                     f = f + 1
  568.                                 end
  569.                             end
  570.                            
  571.                             if x == 4 and y == gy-7  then
  572.                                 if f < 6 then
  573.                                     cbut(4,gy-7,"4",colors.white,colors.red)
  574.                                     table.insert(gNum,"4")
  575.                                     sleep(0.01)
  576.                                     cbut(4,gy-7,"4",colors.white)
  577.                                     f = f + 1
  578.                                 end
  579.                             end
  580.                             if x == 5 and y == gy-7 then
  581.                                 if f < 6 then
  582.                                     cbut(5,gy-7,"5",colors.white,colors.red)
  583.                                     table.insert(gNum,"5")
  584.                                     sleep(0.01)
  585.                                     cbut(5,gy-7,"5",colors.white)
  586.                                     f = f + 1
  587.                                 end
  588.                             end
  589.                             if x == 6 and y == gy-7 then
  590.                                 if f < 6 then
  591.                                     cbut(6,gy-7,"6",colors.white,colors.red)
  592.                                     table.insert(gNum,"6")
  593.                                     sleep(0.01)
  594.                                     cbut(6,gy-7,"6",colors.white)
  595.                                     f = f + 1
  596.                                 end
  597.                             end
  598.                            
  599.                             if x == 4 and y == gy-6 then
  600.                                 if f < 6 then
  601.                                     cbut(4,gy-6,"7",colors.white,colors.red)
  602.                                     table.insert(gNum,"6")
  603.                                     sleep(0.01)
  604.                                     cbut(4,gy-6,"7",colors.white)
  605.                                     f = f + 1
  606.                                 end
  607.                             end
  608.                             if x == 5 and y == gy-6 then
  609.                                 if f < 6 then
  610.                                     cbut(5,gy-6,"8",colors.white,colors.red)
  611.                                     table.insert(gNum,"8")
  612.                                     sleep(0.01)
  613.                                     cbut(5,gy-6,"8",colors.white)
  614.                                     f = f + 1
  615.                                 end
  616.                             end
  617.                             if x == 6 and y == gy-6 then
  618.                                 if f < 6 then
  619.                                     cbut(6,gy-6,"9",colors.white,colors.red)
  620.                                     table.insert(gNum,"9")
  621.                                     sleep(0.01)
  622.                                     cbut(6,gy-6,"9",colors.white)
  623.                                     f = f + 1
  624.                                 end
  625.                             end                        
  626.                            
  627.                             if x == 5 and y == gy-5 then
  628.                                 if f < 6 and f > 0 then
  629.                                     cbut(5,gy-5,"0",colors.white,colors.red)
  630.                                     table.insert(gNum,"0")
  631.                                     sleep(0.01)
  632.                                     cbut(5,gy-5,"0",colors.white)
  633.                                     f = f + 1
  634.                                 end
  635.                             end
  636.                            
  637.                             if x == 4 and y == gy-5 then
  638.                                 cbut(4,gy-5,"C",colors.white,colors.red)
  639.                                 sleep(0.01)
  640.                                 cbut(4,gy-5,"C",colors.white)
  641.                                 gNum = {}
  642.                                 f = 0
  643.                                
  644.                             end                        
  645.                            
  646.                             if x == 6 and y == gy-5 then
  647.                                     cbut(6,gy-5,"<",colors.white,colors.red)
  648.                                     sleep(0.01)
  649.                                     cbut(6,gy-5,"<",colors.white)
  650.                                     gNum[#gNum] = nil
  651.                                     f = f - 1
  652.                             end                    
  653.                            
  654.                            
  655.                             if f > 0 then
  656.                                 for v = 1, 5, 1 do
  657.                            
  658.                                     if gNum[v] == nil then
  659.                                        
  660.                                         cbut(v+2,gy-4,"_",colors.white)
  661.                                     else
  662.                                        
  663.                                         cbut(v+2,gy-4,gNum[v],colors.white)
  664.                                     end
  665.                                 end
  666.                             else
  667.                                 cbut(3,gy-4,"_",colors.white)
  668.                                 cbut(4,gy-4,"_",colors.white)
  669.                                 cbut(5,gy-4,"_",colors.white)
  670.                                 cbut(6,gy-4,"_",colors.white)
  671.                                 cbut(7,gy-4,"_",colors.white)
  672.                             end
  673.                            
  674.  
  675.                            
  676.                            
  677.                             end
  678.                         end
  679.                         tab = {["Key"] = "Update",["Name"]=uname,["Money"] = money  ,["Time"] = timeC,["LastLogin"] = lastLogin,["UID"] = uid}
  680.                             rednet.broadcast(textutils.serialize(tab))
  681.                             sleep(0.01)
  682.                     end
  683.                 elseif ausz == 1 then
  684.                     ausz = 0
  685.                     cbut(gx-9,gy - 1,"AUSZAHLEN",colors.red,colors.green)
  686.                     clearMsgLine()
  687.                     cbut(2,gy - 2,"Disk einwerfen um Kontostand abzufragen",nil,colors.orange)
  688.                 end
  689.            
  690.    
  691.        
  692.         if y == gy-2 and x >= 48 and x <= 56 then
  693.        
  694.             if einz == 0 then
  695.                 einz = 1
  696.                 cbut(gx-9,gy - 2,"EINZAHLEN",colors.blue,colors.green)
  697.                 clearMsgLine()
  698.                 cbut(2,gy - 2,"Disk einwerfen um Einzahlung zu starten",nil,colors.orange)
  699.                
  700.                
  701.                 if disk.isPresent("left") then
  702.                     uname = disk.getLabel("left")
  703.                 else
  704.                     evt = os.pullEvent("disk")
  705.                     uname = disk.getLabel("left")
  706.                 end
  707.                
  708.                 if uname == nil then
  709.                     disk.eject("left")
  710.                     clearMsgLine()
  711.                     cbut(2,gy - 2,"User konnte nicht geladen werden!",nil,colors.orange)
  712.                     disk.eject("left")
  713.                     sleep(2)
  714.                     shell.run("1")
  715.                 else
  716.                    
  717.                     lUser = fs.open(uname,"r")
  718.                     money = tonumber(lUser.readLine())
  719.                     timeC = lUser.readLine()
  720.                     lastLogin = lUser.readLine()
  721.                     curTime = os.day()
  722.                     calTime = curTime - lastLogin
  723.                     if calTime >= 12 then
  724.                         timeC = 0
  725.                         if money >= 0 or money <= 100 then
  726.                             money = money + 1
  727.                         elseif money > 100 or money <= 500 then
  728.                             money = money + 4
  729.                         elseif money > 500 or money <= 1000 then
  730.                             money = money + 16
  731.                         elseif  money > 5000 then
  732.                             money = money + 64
  733.                         end
  734.                     elseif calTime < 12 then
  735.                         timeC = calTime
  736.                     end
  737.                    
  738.                     uid = lUser.readLine()
  739.                     lUser.close()
  740.                     d = fs.open("disk/key","r")
  741.                     diskUID = d.readLine()
  742.                     d.close()
  743.                    
  744.                     cbut(gxH-8,17," " .. uname .. " ",colors.yellow,colors.black)
  745.                     cbut(gxH-8,20," " .. money .. " ",colors.yellow,colors.black)
  746.                     cbut(2,21,"Bonus Tage:" .. timeC .. " ",colors.yellow,colors.black)
  747.                     iCount = getItemCount()
  748.                     clearMsgLine()
  749.  
  750.                     cbut(2,gy - 2,"Zum einzahlen UU-Matter gegen den Collector",nil,colors.orange)
  751.                     cbut(2,gy - 1,"werfen. Nach einwurf auf Monitor klicken",nil,colors.orange)        
  752.                     cbut(2,gy ,"[Abbrechen]",nil,colors.orange)
  753.                     cbut(24,gy ,"[Bestätigen]",nil,colors.orange) 
  754.                     sleep(2)
  755.                     b = 0
  756.                     while b == 0 do
  757.                     evt,side, x, y = os.pullEvent("monitor_touch")
  758.                     sleep(0.05)        
  759.                    
  760.                     niCount = getItemCount()
  761.                     c = niCount - iCount
  762.                    
  763.                    
  764.                     if x>= 24 and x <= 34 and y == gy then
  765.                             cbut(24,gy ,"[Bestätigen]",nil,colors.red)
  766.                             sleep(0.1)     
  767.                             b = 1
  768.                                    
  769.  
  770.                         if uid == diskUID then
  771.    
  772.                             uUser = fs.open(uname,"w")
  773.                             uUser.writeLine(money + c)
  774.                             uUser.writeLine(timeC)
  775.                             uUser.writeLine(os.day())
  776.                             uUser.writeLine(uid)
  777.                             uUser.close()
  778.                             tab = {["Key"] = "Update",["Name"]=uname,["Money"] = money + c ,["Time"] = timeC,["LastLogin"] = lastLogin,["UID"] = uid}
  779.                             rednet.broadcast(textutils.serialize(tab))
  780.                            
  781.                             clearMsgLine()
  782.                             cbut(2,gy - 2,c .. " UU-Matter eingezahlt",nil,colors.orange)  
  783.                            
  784.                             cbut(gxH-8,17," " .. uname .. " ",colors.yellow,colors.black)          
  785.                             cbut(gxH-8,20," " .. money + c.. " ",colors.yellow,colors.black)
  786.                        
  787.                             disk.eject("left")
  788.                             sleep(2)
  789.                            
  790.                             b = 1
  791.                         else
  792.    
  793.                             if c > 0 then  
  794.                                 p = peripheral.wrap("bottom")
  795.                                 uu = p.getItemIdentifierIDFor(30188,0)
  796.                                 p.makeRequest(uu,c)
  797.                             end
  798.                             clearMsgLine()
  799.                             cbut(2,gy - 2,"Code ist falsch ",nil,colors.orange)
  800.                             disk.eject("left")
  801.                             sleep(2)           
  802.                             b = 1
  803.                         end
  804.                     end
  805.                    
  806.                    
  807.                     if x >= 2 and x <= 12 and y == gy then
  808.                         cbut(2,gy ,"[Abbrechen]",nil,colors.red)
  809.                         sleep(0.1)     
  810.                         rednet.broadcast("getItemCount")
  811.                    
  812.                         c = niCount - iCount                   
  813.                    
  814.                         if c > 0 then  
  815.                             p = peripheral.wrap("bottom")
  816.                             uu = p.getItemIdentifierIDFor(30188,0)
  817.                             p.makeRequest(uu,c)
  818.                         end
  819.                         clearMsgLine()
  820.                         cbut(2,gy - 2,"Abgebrochen",nil,colors.orange) 
  821.                         disk.eject("left")
  822.                         sleep(2)           
  823.                         b = 1
  824.                     end
  825.  
  826.                    
  827.                    
  828.                    
  829.                    
  830.                     end
  831.                 end        
  832.             elseif einz == 1 then
  833.                 einz = 0
  834.                
  835.                 cbut(gx-9,gy - 2,"EINZAHLEN",colors.blue,colors.orange)
  836.                 clearMsgLine()
  837.                 cbut(2,gy - 2,"Disk einwerfen um Kontostand abzufragen",nil,colors.orange)
  838.             end
  839.         end
  840.     end
  841.        
  842.    
  843.     if evt == "rednet_message" then
  844.    
  845.         --print("ID: " .. id .. " send Msg: " .. msg)
  846.         sleep(1)
  847.         g = string.match(side,"Key")
  848.        
  849.         if g then
  850.             tab = textutils.unserialize(side)
  851.            
  852.             if tab.Key == "getItemCount" then
  853.                 wlan(colors.green)         
  854.             end
  855.             if tab.Key == "Create" then
  856.                 if fs.exists(tab.Name) then
  857.                     print("User found")
  858.                 else
  859.                     cUser = fs.open(tab.Name,"w")
  860.                     cUser.writeLine(tab.Money) -- Moneycount
  861.                     cUser.writeLine(tab.Time) -- Timecount
  862.                     cUser.writeLine(os.day()) -- Last logintime
  863.                     cUser.writeLine(tab.UID) -- UID
  864.                     cUser.close()
  865.                 end
  866.              end
  867.              
  868.              if tab.Key == "Update" then
  869.                 if fs.exists(tab.Name) then
  870.                     fs.delete(tab.Name)
  871.                     uUser = fs.open(tab.Name,"w")
  872.                     uUser.writeLine(tab.Money) -- Moneycount
  873.                     uUser.writeLine(tab.Time) -- Timecount
  874.                     uUser.writeLine(os.day()) -- Last logintime
  875.                     uUser.writeLine(tab.UID) -- UID
  876.                     uUser.close()
  877.                 else
  878.                     cUser = fs.open(tab.Name,"w")
  879.                     cUser.writeLine(tab.Money) -- Moneycount
  880.                     cUser.writeLine(tab.Time) -- Timecount
  881.                     cUser.writeLine(os.day()) -- Last logintime
  882.                     cUser.writeLine(tab.UID) -- UID
  883.                     cUser.close()
  884.                 end
  885.               end
  886.               if tab.Key == "Delete" then
  887.              
  888.                 if fs.exists(tab.Name) then
  889.                     fs.delete(tab.Name)
  890.                 end
  891.               end
  892.              
  893.              
  894.  
  895.              
  896.         end
  897.    
  898.         end
  899.    
  900.         bankTime = os.day()
  901.               cbut(36,1,"Day:                ",colors.red,colors.black)
  902.         cbut(36,1,"Day: " .. bankTime,colors.red,colors.black)
  903. end
Add Comment
Please, Sign In to add comment