Advertisement
Guest User

startup

a guest
May 2nd, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.67 KB | None | 0 0
  1. rednet.open("back")
  2. User = nil
  3. function main()
  4. term.clear()
  5.   ScreenW,ScreenH = term.getSize()
  6.   UserName = ""
  7.   Password = ""
  8.   NewUserName = ""
  9.   NewPassword = ""
  10.   term.setBackgroundColor(colors.gray)
  11.   print("***************************************************")
  12.   print("*                                                 *")
  13.   print("*               Welcome to the ATM                *")
  14.   print("*                                                 *")
  15.   print("*                                                 *")
  16.   print("*                   |Register|                    *")
  17.   print("*                    |Log in|                     *")
  18.   print("*                                                 *")
  19.   print("*                                                 *")
  20.   print("*                                                 *")
  21.   print("*                                                 *")
  22.   print("*                                                 *")
  23.   print("*                                                 *")
  24.   print("*                                                 *")
  25.   print("*                                                 *")
  26.   print("*                                                 *")
  27.   print("***************************************************")
  28.     local event, MainButton, x, y = os.pullEvent("mouse_click")
  29.       if x >= 21 and x <= 30 and y == 7 then
  30.         Register()
  31.       elseif x >= 22 and x <= 29 and y == 8 then
  32.         Login()
  33.       else
  34.         main()
  35.       end
  36. end
  37.  
  38. function Register()
  39. term.clear()
  40. term.setCursorPos(1,1)
  41.   print("***************************************************")
  42.   print("*                 Create an Account               *")
  43.   print("*            UserName:                |           *")
  44.   print("*               (Max 16 Characters)               *")
  45.   print("*              |Type /exit to leave|              *")
  46.   print("***************************************************")
  47.     term.setCursorPos(23,3)
  48.     NewUserName = read()
  49.     if NewUserName == "/exit" then
  50.         main()
  51.     elseif string.len(NewUserName) > 16 then
  52.         term.clear()
  53.         term.setCursorPos(1,1)
  54.             print("***************************************************")
  55.             print("*                        !Error!                     *")
  56.             print("*                UserName must have               *")
  57.             print("*             less than 16 characters!            *")
  58.             print("***************************************************")
  59.                 sleep(3)
  60.                  Register()
  61.     else
  62.         PasswordReg()
  63.     end
  64. end
  65.  
  66. function PasswordReg()
  67.     term.clear()
  68.     term.setCursorPos(1,1)
  69.         print("***************************************************")
  70.         print("*                 Create an Account               *")
  71.         print("*            Password:                |           *")
  72.         print("*               (Max 16 Characters)               *")
  73.         print("*              |Type /exit to leave|              *")
  74.         print("***************************************************")
  75.             term.setCursorPos(23,3)
  76.             NewPassword = read("*")
  77.                 if NewPassword == "/exit" then
  78.                     main()
  79.                 elseif string.len(NewPassword) > 16 then
  80.                     term.clear()
  81.                     term.setCursorPos(1,1)
  82.                         print("***************************************************")
  83.                         print("*                        !Error!                     *")
  84.                         print("*                UserName must have               *")
  85.                         print("*             less than 16 characters!            *")
  86.                         print("***************************************************")
  87.                             sleep(3)
  88.                                 PasswordReg()
  89.                 else
  90.                     RegisterComplete()
  91.                 end
  92. end
  93.  
  94. function RegisterComplete()
  95. term.clear()
  96. term.setCursorPos(1,1)
  97.         print("***************************************************")
  98.         print("*                 Congratulations!                *")
  99.         print("*            You have finished creating           *")
  100.         print("*                your new account!                *")
  101.         print("***************************************************")
  102.             rednet.send(397,"$$register","$$eco")
  103.             local a,b = rednet.receive("$$eco",1)
  104.                 if b ~= true then
  105.                  ConnectError()
  106.                 end
  107.                     rednet.send(397,NewUserName,"$$eco")
  108.                             rednet.send(397,NewPassword,"$$eco")
  109.                                 local a,b = rednet.receive("$$eco",1)
  110.                                     if b == "$$userExists" then
  111.                                         UserNameError()
  112.                                     end
  113.                                         sleep(3)
  114.                                             main()
  115. end
  116.  
  117. function ConnectError()
  118. term.clear()
  119. term.setCursorPos(1,1)
  120.     print("***************************************************")
  121.     print("*                        !Error!                     *")
  122.     print("*             Connection to the sever             *")
  123.     print("*          was not made. Please try again         *")
  124.     print("***************************************************")
  125.         sleep(3)
  126.             main()
  127. end
  128.  
  129. function UserNameError()
  130. term.clear()
  131. term.setCursorPos(1,1)
  132.     print("***************************************************")
  133.     print("*                     !Error!                     *")
  134.     print("*            That UserName was already            *")
  135.     print("*             taken. Please try again             *")
  136.     print("***************************************************")
  137.         sleep(3)
  138.             main()
  139. end
  140.  
  141. function UserError()
  142. term.clear()
  143. term.setCursorPos(1,1)
  144.     print("***************************************************")
  145.     print("*                     !Error!                     *")
  146.     print("*             That UserName is Invalid            *")
  147.     print("*                Please try again                 *")
  148.     print("***************************************************")
  149.         sleep(3)
  150.             main()
  151. end
  152.  
  153. function IntError()
  154. term.clear()
  155. term.setCursorPos(1,1)
  156.     print("***************************************************")
  157.     print("*                     !Error!                     *")
  158.     print("*              Internal Server Error              *")
  159.     print("*                Please try again                 *")
  160.     print("***************************************************")
  161.         sleep(3)
  162.             main()
  163. end
  164.  
  165. function PassError()
  166. term.clear()
  167. term.setCursorPos(1,1)
  168.     print("***************************************************")
  169.     print("*                     !Error!                     *")
  170.     print("*              Password was Invalid               *")
  171.     print("*                Please try again                 *")
  172.     print("***************************************************")
  173.         sleep(3)
  174.             main()
  175. end
  176.  
  177. function DiskError()
  178. term.clear()
  179. term.setCursorPos(1,1)
  180.     print("***************************************************")
  181.     print("*                     !Error!                     *")
  182.     print("*              No Disk was Inserted               *")
  183.     print("*                Please try again                 *")
  184.     print("***************************************************")
  185.         sleep(3)
  186.             main()
  187. end
  188.  
  189. function ValidDiskError()
  190. term.clear()
  191. term.setCursorPos(1,1)
  192.     print("***************************************************")
  193.     print("*                     !Error!                     *")
  194.     print("*              The Disk is not valid              *")
  195.     print("*                Please try again                 *")
  196.     print("***************************************************")
  197.         sleep(3)
  198.             main()
  199. end
  200.  
  201. function TransferError()
  202. term.clear()
  203. term.setCursorPos(1,1)
  204.     print("***************************************************")
  205.     print("*                     !Error!                     *")
  206.     print("*           Transfer Was not Successful           *")
  207.     print("*                Please try again                 *")
  208.     print("***************************************************")
  209.         sleep(3)
  210.             main()
  211. end
  212.  
  213. function Login()
  214. term.clear()
  215. term.setCursorPos(1,1)
  216.   print("***************************************************")
  217.   print("*              Log In to an Account               *")
  218.   print("*            UserName:                |           *")
  219.   print("*              |Type /exit to leave|              *")
  220.   print("***************************************************")
  221.     term.setCursorPos(23,3)
  222.     UserName = read()
  223.     if UserName == "/exit" then
  224.         main()
  225.     elseif UserName == nil then
  226.         ConnectError()
  227.     elseif UserName == "" then
  228.         ConnectError()
  229.     else
  230.                 sleep(1)
  231.                  Login2()
  232.     end
  233. end
  234.  
  235. function Login2()
  236. term.clear()
  237. term.setCursorPos(1,1)
  238.   print("***************************************************")
  239.   print("*              Log In to an Account               *")
  240.   print("*            Password:                |           *")
  241.   print("*              |Type /exit to leave|              *")
  242.   print("***************************************************")
  243.     term.setCursorPos(23,3)
  244.     Password = read("*")
  245.     if Password == "/exit" then
  246.         main()
  247.     elseif Password == nil then
  248.         ConnectError()
  249.     elseif Password == "" then
  250.         ConnectError()
  251.     else
  252.                 sleep(1)
  253.                  Login3()
  254.     end
  255. end
  256.  
  257. function Login3()
  258. term.clear()
  259. term.setCursorPos(1,1)
  260.   print("***************************************************")
  261.   print("*              Log In to an Account               *")
  262.   print("*                 Logging In...                   *")
  263.   print("*                  Please Wait                    *")
  264.   print("***************************************************")
  265.     sleep(3)
  266.     rednet.send(397,"$$login","$$eco")
  267.         local a,b = rednet.receive("$$eco",1)
  268.             if b ~= true then
  269.                 ConnectError()
  270.             end
  271.                 rednet.send(397,UserName,"$$eco")
  272.                     local a,b = rednet.receive("$$eco",1)
  273.                         if b == "$$invUser" then
  274.                             UserError()
  275.                         elseif b ~= "$$getPass" then
  276.                             ConnectError()
  277.                         end
  278.                             rednet.send(397,Password,"$$eco")
  279.                                 local a,b = rednet.receive("$$eco",1)
  280.                                     if b == "$$invPass" then
  281.                                         PassError()
  282.                                     elseif b ~= "$$loginSuccess" then
  283.                                         ConnectError()
  284.                                     elseif b == "$$loginSuccess" then
  285.                                         User = UserName
  286.                                         a1,b1 = rednet.receive()
  287.                                         --a1,b1 = rednet.receive("$$HM",1)
  288.                                             MBalance = b1
  289.                                                     LoginSucess()  
  290.                                     end
  291.                                                                        
  292. end
  293.  
  294. function LoginSucess()
  295. term.clear()
  296. term.setCursorPos(1,1)
  297.   print("***************************************************")
  298.   print("*              Log In to an Account               *")
  299.   print("*             Logging In Successful!              *")
  300.   print("*                  Please Wait                    *")
  301.   print("***************************************************")
  302.     sleep(2)
  303.         Account()
  304. end
  305.  
  306. function Account()
  307. term.clear()
  308. term.setCursorPos(1,1)
  309.   print("***************************************************")
  310.   print("*                  Your Account                   *")
  311.   print("*                                                   *")
  312.   print("*                                                 *")
  313.   print("*                 |Check Balance|                 *")
  314.   print("*                                                   *")
  315.   print("*                        |Exit|                     *")
  316.   print("***************************************************")
  317.      local event, AccountButton, x, y = os.pullEvent("mouse_click")
  318.       if x >= 22 and x <= 30 and y == 4 then
  319.         Deposit()
  320.       elseif x >= 19 and x <= 33 and y == 5 then
  321.         BalanceDesplay()
  322.       elseif x >= 24 and x <= 29 and y == 7 then
  323.         main()
  324.       else
  325.         Account()
  326.       end
  327.  
  328. end
  329.  
  330.            
  331. function BalanceDesplay()                      
  332.     if MBalance == nil then
  333.         ConnectError()
  334.     else
  335. term.clear()
  336. term.setCursorPos(1,1)
  337.   print("***************************************************")
  338.   print("*                   Your Account                  *")
  339.   print("*   (Account will only update upon re-logging)    *")
  340.   print("*                                                   *")
  341.   print("   |Balance:"..tostring(MBalance).."|                     ")
  342.   print("*                                                   *")
  343.   print("*                      |Exit|                       *")
  344.   print("***************************************************")
  345.     local event, AccountBButton, x, y = os.pullEvent("mouse_click")
  346.       if x >= 22 and x <= 27 and y == 7 then
  347.         Account()
  348.       else
  349.         BalanceDesplay()
  350.       end
  351.     end
  352. end
  353.  
  354. function Deposit()                     
  355. term.clear()
  356. term.setCursorPos(1,1)
  357.   print("***************************************************")
  358.   print("*                     Deposit                     *")
  359.   print("*                                                   *")
  360.   print("*             Please Insert Valid Disk            *")
  361.   print("*                                                   *")
  362.   print("*                    |Confirm Disk|                 *")
  363.   print("*                        |Exit|                     *")
  364.   print("***************************************************")
  365.     local event, AccountBButton, x, y = os.pullEvent("mouse_click")
  366.       if x >= 22 and x <= 27 and y == 7 then
  367.         Account()
  368.       elseif x >= 18 and x <= 31 and y == 6 then
  369.             if fs.exists("disk") then
  370.                 ScanDisk()
  371.             else
  372.                 DiskError()
  373.             end
  374.       else
  375.         Deposit()
  376.       end
  377. end
  378.  
  379. function ScanDisk()                    
  380. term.clear()
  381. term.setCursorPos(1,1)
  382.   print("***************************************************")
  383.   print("*                     Deposit                     *")
  384.   print("*                    Scanning Disk...               *")
  385.   print("*                      Please wait                  *")
  386.   print("***************************************************")
  387.     if not fs.exists("disk/code") then
  388.         ValidDiskError()
  389.     else
  390.         local new = fs.open("disk/code",'r')
  391.             DiskCode = tostring(new.readAll())
  392.             new.close()
  393.             if DiskCode == nil then
  394.                 ValidDiskError()
  395.             elseif DiskCode == "" then
  396.                 ValidDiskError()
  397.             else
  398.             rednet.send(21,"$$checkCode","$$eco")
  399.                 local a,b = rednet.receive("$$eco",1)
  400.                     if b == true then
  401.                         rednet.send(397,DiskCode,"$$eco")
  402.                             local a,b = rednet.receive("$$eco",1)
  403.                                 if b == "$$falseDisk" then
  404.                                     ValidDiskError()
  405.                                 elseif b == "$$trueDisk" then
  406.                                     sleep(3)
  407.                                     ValidDisk()
  408.                                 end
  409.                     end
  410.             end
  411.     end
  412.                                
  413. end
  414.  
  415. function ValidDisk()   
  416. term.clear()
  417. term.setCursorPos(1,1)
  418.     rednet.send(397,"$$sendMoney","$$eco")
  419.         local a,b = rednet.receive("$$eco",1)
  420.                     if b == true then
  421.                         rednet.send(397,User,"$$eco")
  422.                             local a,b = rednet.receive("$$eco",1)
  423.                         if b ~= "$$transferDone" then
  424.                             TransferError()
  425.                         else
  426.                             rednet.send(397,DiskCode,"$$eco")
  427.                                 local a,b = rednet.receive("$$eco",1)
  428.                                     if b == "$$codeGone" then  
  429.                                         MoneyAdded()
  430.             end
  431.         end
  432.     end
  433. end
  434.  
  435.                            
  436. function MoneyAdded()
  437.   print("***************************************************")
  438.   print("*                     Deposit                     *")
  439.   print("*               Money Has been added              *")
  440.   print("*                 to your account!                *")
  441.   print("***************************************************")
  442. sleep(3)
  443. Account()
  444. end
  445.  
  446. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement