BendymelonCoding

PDATerm Client [New GUI] v0.2

Nov 29th, 2015
1,494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.18 KB | None | 0 0
  1. rednet.open("back");
  2.  
  3. local connected = 0;
  4. local serverName = nil;
  5. local serverID = 0;
  6.  
  7.  
  8. function repaint()
  9.     term.setCursorPos(1, 1);
  10.  
  11.     term.setBackgroundColor(colors.white);
  12.     for i = 1, 20 do
  13.         for j = 1, 26 do
  14.             write(" ");
  15.         end
  16.         print();
  17.     end
  18.    
  19.     if (connected == 0) then
  20.         term.setBackgroundColor(colors.red);
  21.     else
  22.         term.setBackgroundColor(colors.green);
  23.     end
  24.    
  25.     term.setTextColor(colors.white);
  26.        
  27.     term.setCursorPos(1, 1);
  28.     write("                          ");
  29.    
  30.     term.setCursorPos(1, 20);
  31.     write("                          ");
  32.    
  33.    
  34.     term.setCursorPos(1, 1);
  35.     write(serverName.."");
  36.    
  37.    
  38. end
  39.  
  40. function settings()
  41.    
  42. end
  43.  
  44. local function getSimInfo()
  45.     simID = os.computerID()
  46.     rednet.broadcast("$GETC",6942)
  47.     --This automatically detects a carrier that the user is registered on.
  48.     --6942 is by default the carrier frequency
  49.     id, msg = rednet.receive(5)
  50.     if msg ~= nil then
  51.         info = textutils.unserialize(msg)
  52.         info[1] = maxTexts
  53.         info[2] = maxSites
  54.         info[3] = pNumber
  55.     end
  56. end
  57.  
  58.  
  59. function connectToServer()
  60.     if fs.exists("/lock") then
  61.         local lockChk = assert(fs.open("lock","r"))
  62.         lock = lockChk.readLine()
  63.         if lock == "1" then
  64.             rednet.broadcast("$GETC",6942);
  65.             id, msg = rednet.receive(5);
  66.             planDetails = textutils.unserialize(msg)
  67.             id, msg = rednet.receive(5);
  68.              
  69.             showOSInformation();
  70.            
  71.             if (msg == nil) then
  72.                 showErrorMessage("No Carrier");
  73.                 serverName = "No Carrier"
  74.                 connected = 0;
  75.             else
  76.                 serverName = "Searching for Carrier..."
  77.                 store = msg;
  78.                 serverID = id;
  79.                 getSimInfo()
  80.                 connected = 1;
  81.             end
  82.         else
  83.             term.clear()
  84.             term.setCursorPos(1,1)
  85.             print("SIM card requires setup!")
  86.             print("Launching automated setup...")
  87.             sleep(0.1)
  88.             print("Preparing account...")
  89.             sleep(0.5)
  90.             rednet.broadcast("$REGISTER",6942)
  91.             id,msg = rednet.receive()
  92.             print("pass")
  93.             lockChk.close()
  94.             local lockChk = assert(fs.open("lock","w"))
  95.             lockChk.writeLine("1",1)
  96.             lockChk.close()
  97.             connectToServer()
  98.         end
  99.     else
  100.         shell.run("pastebin get YUZ9d1VN lock")
  101.     end
  102. end
  103.  
  104.  
  105. function showErrorMessage(message)
  106.     term.setBackgroundColor(16384);
  107.     term.setTextColor(1);
  108.    
  109.     for i = 8, 13 do
  110.         term.setCursorPos(2, i);
  111.         for j = 1, 24 do
  112.             write(" ");
  113.         end
  114.         print();
  115.     end
  116.    
  117.     term.setCursorPos(11, 9);
  118.     write("Error");
  119.    
  120.    
  121.     term.setCursorPos(4, 11);
  122.     write(message);
  123. end
  124.  
  125. function showInformationMessage(title, line1, line2)
  126.     term.setBackgroundColor(colors.lightBlue);
  127.     term.setTextColor(colors.white);
  128.    
  129.     for i = 8, 13 do
  130.         term.setCursorPos(2, i);
  131.         for j = 1, 24 do
  132.             write(" ");
  133.         end
  134.         print();
  135.     end
  136.    
  137.     if title == nil then
  138.         term.setCursorPos(3, 9);
  139.         write(title)
  140.     else
  141.         term.setCursorPos(3, 9);
  142.         write(title);
  143.     end
  144.    
  145.    
  146.     term.setCursorPos(4, 11);
  147.     write(line1);
  148.     term.setCursorPos(4, 12);
  149.     write(line2);
  150. end
  151.  
  152. function showOSInformation()
  153.     term.setBackgroundColor(1);
  154.     term.setTextColor(256);
  155.    
  156.     term.setCursorPos(4, 5);
  157.     write("PDATerm v0.2");
  158.     term.setCursorPos(4, 7);
  159.     write("A Free Mobile Terminal");
  160.     term.setCursorPos(4, 8);
  161.     write("for ComputerCraft");
  162. end
  163.  
  164. function lock()
  165.     term.setCursorPos(1, 1);
  166.     term.setBackgroundColor(32768);
  167.     term.setTextColor(1);
  168.    
  169.     for i = 1, 20 do
  170.         for j = 1, 26 do
  171.             if (i == 1 or i == 20 or j == 1 or j == 26) then
  172.                 term.setBackgroundColor(16384);
  173.             end
  174.             write(" ");
  175.             term.setBackgroundColor(32768);
  176.         end
  177.         if (i ~= 20) then
  178.             print();
  179.         end
  180.     end
  181.    
  182.     term.setCursorPos(5, 3);
  183.     write("--Enter Passcode--");
  184.    
  185.     cpass = "1234";
  186.     pass = "";
  187.    
  188.     term.setTextColor(1);
  189.    
  190.     while(pass ~= cpass) do
  191.    
  192.         pass = "";
  193.        
  194.         term.setCursorPos(5, 15);
  195.         write("   -  -  -  -   ");
  196.        
  197.         for i = 1, 4 do
  198.             term.setCursorPos(5 + i * 3, 15);
  199.             local event, key = os.pullEvent("char");
  200.             pass = pass .. key;
  201.             write("*");
  202.         end
  203.     end
  204.    
  205.    
  206. end
  207.  
  208.  
  209. function showInputDialog(message)
  210.     term.setBackgroundColor(512);
  211.     term.setTextColor(1);
  212.     for l = 6, 17 do
  213.         term.setCursorPos(2, l);
  214.         for k = 1, 24 do
  215.             write(" ");
  216.         end
  217.         print();
  218.     end
  219.     term.setCursorPos(4, 6);
  220.     io.write(message)
  221.     term.setCursorPos(5, 14);
  222.     input = io.read()
  223.     return input;
  224. end
  225.  
  226. function rednetControl()
  227.     term.setCursorPos(1, 1);
  228.     term.setBackgroundColor(8);
  229.     term.setTextColor(1);
  230.    
  231.     for i = 1, 20 do
  232.         for j = 1, 26 do
  233.             if (i == 1 or i == 20 or j == 1 or j == 26) then
  234.                 term.setBackgroundColor(2048);
  235.             end
  236.             write(" ");
  237.             term.setBackgroundColor(8);
  238.         end
  239.         if (i ~= 20) then
  240.             print();
  241.         end
  242.     end
  243.    
  244.     term.setCursorPos(3, 3);
  245.     write("Advanced Rednet Console");
  246.    
  247.     term.setBackgroundColor(colors.orange);
  248.     term.setCursorPos(3, 6);
  249.     write("    OPEN Rednet       ");
  250.     term.setCursorPos(3, 8);
  251.     write("    CLOSE Rednet      ");
  252.     term.setCursorPos(3, 10);
  253.     write("  Rednet Broadcast    ");
  254.     term.setCursorPos(3, 12);
  255.     write("    Send Message      ");
  256.     term.setCursorPos(3, 14);
  257.     write("     Get Message      ");
  258.     term.setCursorPos(3, 16);
  259.     write("    Computer ID       ");
  260.     term.setCursorPos(3, 18);
  261.     write("        Exit          ");
  262.    
  263.     local event, button, x, y = os.pullEvent("mouse_click");
  264.    
  265.     if (button == 1) then
  266.         if (y == 6) then
  267.             rednet.open("back");
  268.             showInformationMessage("Rednet Turned On");
  269.             sleep(2);
  270.         end
  271.         if (y == 8) then
  272.             rednet.close("back");
  273.             showInformationMessage("Rednet Turned Off");
  274.             sleep(2);
  275.         end
  276.         if (y == 10) then
  277.             message = showInputDialog("Broadcast Message");
  278.             showInformationMessage("Broadcast Sending...","Broadcasting...", "");
  279.             rednet.broadcast(message);
  280.             sleep(2);
  281.         end
  282.         if (y == 12) then
  283.             id = tonumber(showInputDialog("Target ID"));
  284.             message = showInputDialog("Enter Message");
  285.             showInformationMessage("Sending Message...", "");
  286.             rednet.send(id, message);
  287.             sleep(2);
  288.         end
  289.         if (y == 14) then
  290.             timeout = tonumber(showInputDialog("Enter Timeout"));
  291.             showInformationMessage("Rednet","Waiting for", "message");
  292.             id, msg = rednet.receive(timeout);
  293.             if (msg == nil) then
  294.                 showErrorMessage("Receive Timeout.");
  295.                 sleep(2);
  296.             else
  297.                 showInformationMessage("Data Received!",id, msg);
  298.                 sleep(5);
  299.             end
  300.         end
  301.         if (y == 16) then
  302.             showInformationMessage("Message","Computer ID", os.getComputerID());
  303.             sleep(5);
  304.         end
  305.        
  306.         if (y == 18) then
  307.             return;
  308.         end
  309.         rednetControl();
  310.     end
  311. end
  312.  
  313. function resetColor()
  314.     term.setBackgroundColor(colors.white)
  315.     term.clear()
  316.     repaint()
  317. end
  318.  
  319. function newMainMenu()
  320.     term.setCursorPos(1,3)
  321.     term.setTextColor(colors.red)
  322.     write("01230000012300000123000001230")
  323.     --gps
  324.     resetColor()
  325.     term.setCursorPos(3,3)
  326.     term.setBackgroundColor(colors.blue)
  327.     write("    ")
  328.     term.setCursorPos(3,4)
  329.     term.setTextColor(colors.black)
  330.     write("    ")
  331.     term.setCursorPos(3,5)
  332.     write("    ")
  333.     term.setCursorPos(3,7)
  334.     term.setBackgroundColor(colors.white)
  335.     write("GPS")
  336.    
  337.     --Browser
  338.     term.setCursorPos(12,3)
  339.     --term.setBackgroundColor(colors.lightBlue) --disabled
  340.     term.setBackgroundColor(colors.lightGray)
  341.     term.setTextColor(colors.green)
  342.     write(" _  ")
  343.     term.setCursorPos(12,4)
  344.     write("|O| ")
  345.     term.setCursorPos(12,5)
  346.     write(" -  ")
  347.     term.setBackgroundColor(colors.white)
  348.     term.setTextColor(colors.black)
  349.     term.setCursorPos(12,7)
  350.     write("Web")
  351.    
  352.     --sms
  353.     --term.setBackgroundColor(colors.yellow) --disabled
  354.     term.setBackgroundColor(colors.lightGray)
  355.     term.setCursorPos(21,3)
  356.     write("    ")
  357.     term.setCursorPos(21,4)
  358.     write("    ")
  359.     term.setCursorPos(21,5)
  360.     write("    ")
  361.     term.setCursorPos(21,7)
  362.     term.setBackgroundColor(colors.white)
  363.     write("SMS")
  364.    
  365.     --rednet console
  366.     term.setBackgroundColor(colors.red)
  367.     term.setTextColor(colors.white)
  368.     term.setCursorPos(3,8)
  369.     write(" R  ")
  370.     term.setCursorPos(3,9)
  371.     write("  N ")
  372.     term.setCursorPos(3,10)
  373.     write("    ")
  374.     term.setCursorPos(3,12)
  375.     term.setBackgroundColor(colors.white)
  376.     term.setTextColor(colors.black)
  377.     write("Rednet")
  378.    
  379.     --clock
  380.     term.setBackgroundColor(colors.black)
  381.     term.setTextColor(colors.white)
  382.     term.setCursorPos(12,8)
  383.     write(" 12 ")
  384.     term.setCursorPos(12,9)
  385.     write(" 45 ")
  386.     term.setCursorPos(12,10)
  387.     write(" PM ")
  388.     term.setCursorPos(12,12)
  389.     term.setBackgroundColor(colors.white)
  390.     term.setTextColor(colors.black)
  391.     write("Clock")
  392.     --app store
  393.     term.setBackgroundColor(colors.lightBlue)
  394.     term.setCursorPos(21,8)
  395.     write("    ")
  396.     term.setCursorPos(21,9)
  397.     write("APPS")
  398.     term.setCursorPos(21,10)
  399.     write("    ")
  400.     term.setCursorPos(21,12)
  401.     term.setBackgroundColor(colors.white)
  402.     write("Store")
  403.     --settings
  404.     term.setBackgroundColor(colors.gray)
  405.     term.setCursorPos(3,13)
  406.     write(" |  ")
  407.     term.setCursorPos(3,14)
  408.     write("-o- ")
  409.     term.setCursorPos(3,15)
  410.     write(" |  ")
  411.     term.setCursorPos(1,17)
  412.     term.setBackgroundColor(colors.white)
  413.     write("Settings")
  414.     --shutdown
  415.     term.setCursorPos(12,13)
  416.     term.setBackgroundColor(colors.red)
  417.     term.setTextColor(colors.white)
  418.     write("I   ")
  419.     term.setCursorPos(12,14)
  420.     write(" O  ")
  421.     term.setCursorPos(12,15)
  422.     write("    ")
  423.     term.setBackgroundColor(colors.white)
  424.     term.setCursorPos(12,17)
  425.     term.setTextColor(colors.black)
  426.     write("Power")
  427.     --return to old layout
  428.     term.setCursorPos(21,13)
  429.     term.setBackgroundColor(colors.red)
  430.     term.setTextColor(colors.white)
  431.     write("    ")
  432.     term.setCursorPos(21,14)
  433.     write(" <- ")
  434.     term.setCursorPos(21,15)
  435.     write("    ")
  436.     term.setCursorPos(20,17)
  437.     term.setTextColor(colors.black)
  438.     term.setBackgroundColor(colors.white)
  439.     write("Classic")
  440.  
  441.  
  442.     local event, button, x, y = os.pullEvent("mouse_click");
  443.    
  444.     --gps
  445.     if x >= 3 and x <= 6 then
  446.         if y >= 3 and y <= 5 then
  447.             showInformationMessage("Please wait...","Getting Location", " ");
  448.             if (gps.locate(2) == nil) then
  449.                 showErrorMessage("No GPS Signal.");
  450.                 sleep(2);
  451.             else
  452.                 x, y, z = gps.locate();
  453.                 showInformationMessage("GPS","Your Location: ", x .. ", " .. y .. ", " .. z);
  454.                 sleep(5);
  455.             end
  456.         end
  457.     end
  458.    
  459.     --web
  460.     --sms
  461.     if x >= 21 and x <= 24 then
  462.         if y >= 3 and y <= 5 then
  463.             test()
  464.         end
  465.     end
  466.     --rednet console
  467.     if x >= 3 and x <= 6 then
  468.         if y >= 8 and y <= 11 then
  469.             showInformationMessage("Loading...","Please Wait...", " ");
  470.             sleep(2);
  471.             rednetControl();
  472.         end
  473.     end
  474.            
  475.    
  476.     if x >= 12 and x <= 15 then
  477.         --web
  478.         if y >= 3 and y <= 5 then
  479.             test()
  480.         end
  481.         --clock
  482.         if y >= 8 and y <= 11 then
  483.             showInformationMessage("Time", textutils.formatTime(os.time(),false),"");
  484.             sleep(2)
  485.         end
  486.         --shutdown
  487.         if y >= 13 and y <= 15 then
  488.             showInformationMessage("Goodbye","Shutting Down..."," ");
  489.             sleep(2);
  490.             os.shutdown();
  491.         end
  492.     end
  493.     --app store
  494.     if x >= 21 and x <= 24 then
  495.         if y >= 8 and y <= 11 then
  496.             test()
  497.         end
  498.     end
  499.     --settings
  500.     if x >= 3 and x <= 6 then
  501.         if y >= 13 and y <= 15 then
  502.             test()
  503.         end
  504.     end
  505.     --shutdown
  506.     --if x >= 12 and x <= 15 then
  507.        
  508.     --end
  509.    
  510.     --revert to old    
  511.     if x >= 21 and x <= 24 then
  512.         if y >= 13 and y <= 15 then
  513.             repaint()
  514.             displayMainMenu()
  515.         end
  516.     end
  517.     newMainMenu()
  518. end
  519. function test()
  520.     showInformationMessage("Not Found", "Feature not","implemented!")
  521.     sleep(2)
  522. end
  523.  
  524. function displayMainMenu()
  525.    
  526.     term.setTextColor(colors.red);
  527.    
  528.     term.setCursorPos(2,3);
  529.     term.setBackgroundColor(colors.yellow);
  530.     write("     [BETA] New GUI     ");
  531.     term.setCursorPos(2, 5);
  532.     term.setBackgroundColor(colors.yellow);
  533.     write("  Current GPS Position  ");
  534.    
  535.     term.setCursorPos(2, 7);
  536.     term.setBackgroundColor(colors.lightGray);
  537.     write("    Internet Browser    ");
  538.    
  539.     term.setCursorPos(2, 9);
  540.     term.setBackgroundColor(colors.lightGray);
  541.     write("       Messaging        ");
  542.    
  543.     term.setCursorPos(2, 11);
  544.     term.setBackgroundColor(colors.yellow);
  545.     write("    Rednet Console      ");
  546.    
  547.     term.setCursorPos(2, 13);
  548.     term.setBackgroundColor(colors.lightGray);
  549.     write("       Settings         ");
  550.     term.setCursorPos(2, 15);
  551.     term.setBackgroundColor(colors.yellow);
  552.     write("       Reconnect        ");
  553.    
  554.     term.setCursorPos(2, 17);
  555.     term.setBackgroundColor(colors.yellow);
  556.     write("       Shutdown         ");
  557.     term.setCursorPos(1,19);
  558.    
  559.     local event, button, x, y = os.pullEvent("mouse_click");
  560.  
  561.     if (button == 1) then
  562.         if (y == 3) then
  563.             newMainMenu()
  564.         end
  565.         if (y == 5) then
  566.             showInformationMessage("Please wait...","Getting Location", "");
  567.             if (gps.locate(2) == nil) then
  568.                 showErrorMessage("No GPS Signal.");
  569.                 sleep(2);
  570.             else
  571.                 x, y, z = gps.locate();
  572.                 showInformationMessage("GPS","Your Location: ", x .. ", " .. y .. ", " .. z);
  573.                 sleep(5);
  574.             end
  575.         end
  576.        
  577.         if (y == 7) then
  578.         end
  579.        
  580.         if (y == 9) then
  581.         end
  582.        
  583.        
  584.         if (y == 11) then
  585.             showInformationMessage("Loading...","Please Wait...", "");
  586.             sleep(2);
  587.             rednetControl();
  588.         end
  589.        
  590.         if (y == 13) then
  591.         end
  592.        
  593.         if (y == 15) then
  594.             showInformationMessage("Loading...","Connecting...", "");
  595.             connected = 0;
  596.             connectToServer();
  597.            
  598.         end
  599.        
  600.         if (y == 17) then
  601.             showInformationMessage("Goodbye","Shutting Down...", "");
  602.             sleep(2);
  603.             os.shutdown();
  604.         end
  605.        
  606.     end
  607.    
  608.     repaint();
  609.     displayMainMenu();
  610.  
  611. end
  612.  
  613.  
  614.  
  615.  
  616. lock();
  617.  
  618. connectToServer();
  619. repaint();
  620. showOSInformation();
  621.  
  622. if (connected == 0) then
  623.     sleep(0.75)
  624.     showErrorMessage("No Carrier");
  625.    
  626. else
  627.    
  628.     sleep(0.75)
  629.     serverName = store
  630.     repaint();
  631.     showInformationMessage("Carrier Located","Connected to", serverName);
  632.     sleep(3);
  633. end
  634.  
  635.  
  636. repaint();
  637. displayMainMenu();
Advertisement
Add Comment
Please, Sign In to add comment