BendymelonCoding

PDATerm Client Bugfix

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