jimthenerd

PDATerm Client

Apr 19th, 2014
1,789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.69 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 connectToServer()
  41.     rednet.broadcast("$INFO");
  42.     id, msg = rednet.receive(5);
  43.    
  44.     if (msg == nil) then
  45.         showErrorMessage("No Carrier");
  46.         sleep(3);
  47.         os.reboot();
  48.     else
  49.         serverName = msg;
  50.         serverID = id;
  51.         connected = 1;
  52.     end
  53. end
  54.  
  55.  
  56. function showErrorMessage(message)
  57.     term.setBackgroundColor(colors.red);
  58.     term.setTextColor(colors.white);
  59.    
  60.     for i = 8, 13 do
  61.         term.setCursorPos(2, i);
  62.         for j = 1, 24 do
  63.             write(" ");
  64.         end
  65.         print();
  66.     end
  67.    
  68.     term.setCursorPos(11, 9);
  69.     write("Error");
  70.    
  71.    
  72.     term.setCursorPos(4, 11);
  73.     write(message);
  74. end
  75.  
  76. function showInformationMessage(line1, line2)
  77.     term.setBackgroundColor(colors.lightBlue);
  78.     term.setTextColor(colors.white);
  79.    
  80.     for i = 8, 13 do
  81.         term.setCursorPos(2, i);
  82.         for j = 1, 24 do
  83.             write(" ");
  84.         end
  85.         print();
  86.     end
  87.    
  88.     term.setCursorPos(11, 9);
  89.     write("Message");
  90.    
  91.    
  92.     term.setCursorPos(4, 11);
  93.     write(line1);
  94.     term.setCursorPos(4, 12);
  95.     write(line2);
  96. end
  97.  
  98. function showOSInformation()
  99.     term.setBackgroundColor(colors.white);
  100.     term.setTextColor(colors.lightGray);
  101.    
  102.     term.setCursorPos(4, 5);
  103.     write("PDATerm v0.1");
  104.     term.setCursorPos(4, 7);
  105.     write("A Free Mobile Terminal");
  106.     term.setCursorPos(4, 8);
  107.     write("for ComputerCraft");
  108. end
  109.  
  110. function lock()
  111.     term.setCursorPos(1, 1);
  112.     term.setBackgroundColor(colors.black);
  113.     term.setTextColor(colors.white);
  114.    
  115.     for i = 1, 20 do
  116.         for j = 1, 26 do
  117.             if (i == 1 or i == 20 or j == 1 or j == 26) then
  118.                 term.setBackgroundColor(colors.red);
  119.             end
  120.             write(" ");
  121.             term.setBackgroundColor(colors.black);
  122.         end
  123.         if (i ~= 20) then
  124.             print();
  125.         end
  126.     end
  127.    
  128.     term.setCursorPos(5, 3);
  129.     write("--Enter Passcode--");
  130.    
  131.     cpass = "1234";
  132.     pass = "";
  133.    
  134.     term.setTextColor(colors.white);
  135.    
  136.     while(pass ~= cpass) do
  137.    
  138.         pass = "";
  139.        
  140.         term.setCursorPos(5, 15);
  141.         write("   -  -  -  -   ");
  142.        
  143.         for i = 1, 4 do
  144.             term.setCursorPos(5 + i * 3, 15);
  145.             local event, key = os.pullEvent("char");
  146.             pass = pass .. key;
  147.             write("*");
  148.         end
  149.     end
  150.    
  151.    
  152. end
  153.  
  154.  
  155. function showInputDialog(message)
  156.     term.setBackgroundColor(colors.lightBlue);
  157.     term.setTextColor(colors.brown);
  158.    
  159.     for i = 4, 17 do
  160.         for j = 1, 24 do
  161.             write(" ");
  162.         end
  163.     end
  164.    
  165.     term.setCursorPos(4, 6);
  166.     write(message);
  167.    
  168.     term.setCursorPos(5, 14);
  169.     input = read();
  170.    
  171.     return input;
  172. end
  173.  
  174. function rednetControl()
  175.     term.setCursorPos(1, 1);
  176.     term.setBackgroundColor(colors.lightBlue);
  177.     term.setTextColor(colors.white);
  178.    
  179.     for i = 1, 20 do
  180.         for j = 1, 26 do
  181.             if (i == 1 or i == 20 or j == 1 or j == 26) then
  182.                 term.setBackgroundColor(colors.darkBlue);
  183.             end
  184.             write(" ");
  185.             term.setBackgroundColor(colors.lightBlue);
  186.         end
  187.         if (i ~= 20) then
  188.             print();
  189.         end
  190.     end
  191.    
  192.     term.setCursorPos(4, 3);
  193.     write("Advanced Rednet Console");
  194.    
  195.     term.setBackgroundColor(colors.orange);
  196.     term.setCursorPos(3, 6);
  197.     write("    OPEN Rednet       ");
  198.     term.setCursorPos(3, 8);
  199.     write("    CLOSE Rednet      ");
  200.     term.setCursorPos(3, 10);
  201.     write("  Rednet Broadcast    ");
  202.     term.setCursorPos(3, 12);
  203.     write("    Send Message      ");
  204.     term.setCursorPos(3, 14);
  205.     write("     Get Message      ");
  206.     term.setCursorPos(3, 16);
  207.     write("    Computer ID       ");
  208.     term.setCursorPos(3, 18);
  209.     write("        Exit          ");
  210.    
  211.     local event, button, x, y = os.pullEvent("mouse_click");
  212.    
  213.     if (button == 1) then
  214.         if (y == 6) then
  215.             rednet.open("back");
  216.             showInformationMessage("Rednet Turned On");
  217.             sleep(2);
  218.         end
  219.         if (y == 8) then
  220.             rednet.close("back");
  221.             showInformationMessage("Rednet Turned Off");
  222.             sleep(2);
  223.         end
  224.         if (y == 10) then
  225.             message = showInputDialog("Broadcast Message");
  226.             showInformationMessage("Broadcasting...", "");
  227.             rednet.broadcast(message);
  228.             sleep(2);
  229.         end
  230.         if (y == 12) then
  231.             id = tonumber(showInputDialog("Target ID"));
  232.             message = showInputDialog("Enter Message");
  233.             showInformationMessage("Sending Message...", "");
  234.             rednet.send(id, message);
  235.             sleep(2);
  236.         end
  237.         if (y == 14) then
  238.             timeout = tonumber(showInputDialog("Enter Timeout"));
  239.             showInformationMessage("Waiting for", "message");
  240.             id, msg = rednet.receive(timeout);
  241.             if (msg == nil) then
  242.                 showErrorMessage("Receive Timeout.");
  243.                 sleep(2);
  244.             else
  245.                 showInformationMessage(id, msg);
  246.                 sleep(5);
  247.             end
  248.         end
  249.         if (y == 16) then
  250.             showInformationMessage("Computer ID", os.getComputerID());
  251.             sleep(5);
  252.         end
  253.        
  254.         if (y == 18) then
  255.             return;
  256.         end
  257.         rednetControl();
  258.     end
  259. end
  260.  
  261. function displayMainMenu()
  262.     term.setBackgroundColor(colors.yellow);
  263.     term.setTextColor(colors.red);
  264.  
  265.     term.setCursorPos(2, 5);
  266.     write("  Current GPS Position  ");
  267.    
  268.     term.setCursorPos(2, 7);
  269.     write("       Mail System      ");
  270.    
  271.     term.setCursorPos(2, 9);
  272.     write("       Enter Chat       ");
  273.    
  274.     term.setCursorPos(2, 11);
  275.     write("    Rednet Console      ");
  276.    
  277.     term.setCursorPos(2, 13);
  278.     write("      Reconnect         ");
  279.    
  280.     term.setCursorPos(2, 15);
  281.     write("       Shutdown         ");
  282.    
  283.     local event, button, x, y = os.pullEvent("mouse_click");
  284.  
  285.     if (button == 1) then
  286.         if (y == 5) then
  287.             showInformationMessage("Getting Location", "");
  288.             if (gps.locate(5) == nil) then
  289.                 showErrorMessage("No GPS Signal.");
  290.                 sleep(2);
  291.             else
  292.                 x, y, z = gps.locate();
  293.                 showInformationMessage("Your Location: ", x .. ", " .. y .. ", " .. z);
  294.                 sleep(5);
  295.             end
  296.         end
  297.        
  298.         if (y == 7) then
  299.         end
  300.        
  301.         if (y == 9) then
  302.         end
  303.        
  304.         if (y == 11) then
  305.             showInformationMessage("Please Wait...", "");
  306.             sleep(2);
  307.             rednetControl();
  308.         end
  309.        
  310.         if (y == 13) then
  311.             showInformationMessage("Connecting...", "");
  312.             connected = 0;
  313.             connectToServer();
  314.            
  315.         end
  316.        
  317.         if (y == 15) then
  318.             showInformationMessage("Shutting Down...", "");
  319.             sleep(2);
  320.             os.shutdown();
  321.         end
  322.        
  323.     end
  324.    
  325.     repaint();
  326.     displayMainMenu();
  327.  
  328. end
  329.  
  330.  
  331.  
  332.  
  333. lock();
  334.  
  335. connectToServer();
  336. repaint();
  337. showOSInformation();
  338.  
  339. if (connected == 0) then
  340.     showErrorMessage("No Carrier");
  341.     sleep(5);
  342.     os.reboot();
  343. else
  344.     showInformationMessage("Connected to", serverName);
  345.     sleep(3);
  346. end
  347.  
  348.  
  349. repaint();
  350. displayMainMenu();
Advertisement
Add Comment
Please, Sign In to add comment