ComputerCraft Archive

PDATerm - A Tele-Communication Terminal for Pocket Computers

computer networking unknown forum

Description

PDATerm v0.1A Tele-Communication Terminalfor Portable ComputersThis is a mobile terminal made for Portable Computers introduced in ComputerCraft 1.6. I was amused by the possibilities of what the port...

Installation

Copy one of these commands into your ComputerCraft terminal:

Pastebin:pastebin get aF9xrt9q pdaterm_-_a_tele-communication_terminal_for_pocket_computers
wget:wget https://pastebin.com/raw/aF9xrt9q pdaterm_-_a_tele-communication_terminal_for_pocket_computers
Archive:wget https://cc.shobie.xyz/cc/get/pb-aF9xrt9q pdaterm_-_a_tele-communication_terminal_for_pocket_computers
Quick Install: wget https://cc.shobie.xyz/cc/get/pb-aF9xrt9q PDATerm - A Tele-Communication Terminal for Pocket Computers

Usage

Run the program after downloading

Tags

networkingforumpocket-programs

Source

View Original Source

Code Preview

rednet.open("back");

local connected = 0;
local serverName = nil;
local serverID = 0;


function repaint()
	term.setCursorPos(1, 1);

	term.setBackgroundColor(colors.white);
	for i = 1, 20 do
		for j = 1, 26 do
			write(" ");
		end
		print();
	end
	
	if (connected == 0) then
		term.setBackgroundColor(colors.red);
	else
		term.setBackgroundColor(colors.green);
	end
	
	term.setTextColor(colors.white);
		
	term.setCursorPos(1, 1);
	write("                          ");
	
	term.setCursorPos(1, 20);
	write("                          ");
	
	
	term.setCursorPos(1, 1);
	write(serverName);
	
	
end

function connectToServer()
	rednet.broadcast("$INFO");
	id, msg = rednet.receive(5);
	
	if (msg == nil) then
		showErrorMessage("No Carrier");
		sleep(3);
		os.reboot();
	else
		serverName = msg;
		serverID = id;
		connected = 1;
	end
end


function showErrorMessage(message)
	term.setBackgroundColor(colors.red);
	term.setTextColor(colors.white);
	
	for i = 8, 13 do
		term.setCursorPos(2, i);
		for j = 1, 24 do
			write(" ");
		end 
		print();
	end
	
	term.setCursorPos(11, 9);
	write("Error");
	
	
	term.setCursorPos(4, 11);
	write(message);
end

function showInformationMessage(line1, line2)
	term.setBackgroundColor(colors.lightBlue);
	term.setTextColor(colors.white);
	
	for i = 8, 13 do
		term.setCursorPos(2, i);
		for j = 1, 24 do
			write(" ");
		end 
		print();
	end
	
	term.setCursorPos(11, 9);
	write("Message");
	
	
	term.setCursorPos(4, 11);
	write(line1);
	term.setCursorPos(4, 12);
	write(line2);
end

function showOSInformation()
	term.setBackgroundColor(colors.white);
	term.setTextColor(colors.lightGray);
	
	term.setCursorPos(4, 5);
	write("PDATerm v0.1");
	term.setCursorPos(4, 7);
	write("A Free Mobile Terminal");
	term.setCursorPos(4, 8);
	write("for ComputerCraft");
end

function lock()
	term.setCursorPos(1, 1);
	term.setBackgroundColor(colors.black);
	term.setTextColor(colors.white);
	
	for i = 1, 20 do
		for j = 1, 26 do
			if (i == 1 or i == 20 or j == 1 or j == 26) then
				term.setBackgroundColor(colors.red);
			end
			write(" ");
			term.setBackgroundColor(colors.black);
		end
		if (i ~= 20) then
			print();
		end
	end
	
	term.setCursorPos(5, 3);
	write("--Enter Passcode--");
	
	cpass = "1234";
	pass = "";
	
	term.setTextColor(colors.white);
	
	while(pass ~= cpass) do
	
		pass = "";
		
		term.setCursorPos(5, 15);
		write("   -  -  -  -   ");
		
		for i = 1, 4 do
			term.setCursorPos(5 + i * 3, 15);
			local event, key = os.pullEvent("char");
			pass = pass .. key;
			write("*");
		end
	end
	
	
end


function showInputDialog(message)
	term.setBackgroundColor(colors.lightBlue);
	term.setTextColor(colors.brown);
	
	for i = 4, 17 do
		for j = 1, 24 do
			write(" ");
		end
	end
	
	term.setCursorPos(4, 6);
	write(message);
	
	term.setCursorPos(5, 14);
	input = read();
	
	return input;
end

function rednetControl()
	term.setCursorPos(1, 1);
	term.setBackgroundColor(colors.lightBlue);
	term.setTextColor(colors.white);
	
	for i = 1, 20 do
		for j = 1, 26 do
			if (i == 1 or i == 20 or j == 1 or j == 26) then
				term.setBackgroundColor(colors.darkBlue);
			end
			write(" ");
			term.setBackgroundColor(colors.lightBlue);
		end
		if (i ~= 20) then
			print();
		end
	end
	
	term.setCursorPos(4, 3);
	write("Advanced Rednet Console");
	
	term.setBackgroundColor(colors.orange);
	term.setCursorPos(3, 6);
	write("    OPEN Rednet       ");
	term.setCursorPos(3, 8);
	write("    CLOSE Rednet      ");
	term.setCursorPos(3, 10);
	write("  Rednet Broadcast    ");
	term.setCursorPos(3, 12);
	write("    Send Message      ");
	term.setCursorPos(3, 14);
	write("     Get Message      ");
	term.setCursorPos(3, 16);
	write("    Computer ID       ");
	term.setCursorPos(3, 18);
	write("        Exit          ");
	
	local event, button, x, y = os.pullEvent("mouse_click");
	
	if (button == 1) then
		if (y == 6) then
			rednet.open("back");
			showInformationMessage("Rednet Turned On");
			sleep(2);
		end
		if (y == 8) then
			rednet.close("back");
			showInformationMessage("Rednet Turned Off");
			sleep(2);
		end
		if (y == 10) then
			message = showInputDialog("Broadcast Message");
			showInformationMessage("Broadcasting...", "");
			rednet.broadcast(message);
			sleep(2);
		end
		if (y == 12) then
			id = tonumber(showInputDialog("Target ID"));
			message = showInputDialog("Enter Message");
			showInformationMessage("Sending Message...", "");
			rednet.send(id, message);
			sleep(2);
		end
		if (y == 14) then
			timeout = tonumber(showInputDialog("Enter Timeout"));
			showInformationMessage("Waiting for", "message");
			id, msg = rednet.receive(timeout);
			if (msg == nil) then
				showErrorMessage("Receive Timeout.");
				sleep(2);
			else
				showInformationMessage(id, msg);
				sleep(5);
			end
		end
		if (y == 16) then
			showInformationMessage("Computer ID", os.getComputerID());
			sleep(5);
		end
		
		if (y == 18) then
			return;
		end
		rednetControl();
	end
end

function displayMainMenu()
	term.setBackgroundColor(colors.yellow);
	term.setTextColor(colors.red);

	term.setCursorPos(2, 5);
	write("  Current GPS Position  ");
	
	term.setCursorPos(2, 7);
	write("       Mail System      ");
	
	term.setCursorPos(2, 9);
	write("       Enter Chat       ");
	
	term.setCursorPos(2, 11);
	write("    Rednet Console      ");
	
	term.setCursorPos(2, 13);
	write("      Reconnect         ");
	
	term.setCursorPos(2, 15);
	write("       Shutdown         ");
	
	local event, button, x, y = os.pullEvent("mouse_click");

	if (button == 1) then
		if (y == 5) then
			showInformationMessage("Getting Location", "");
			if (gps.locate(5) == nil) then
				showErrorMessage("No GPS Signal.");
				sleep(2);
			else
				x, y, z = gps.locate();
				showInformationMessage("Your Location: ", x .. ", " .. y .. ", " .. z);
				sleep(5);
			end
		end
		
		if (y == 7) then
		end
		
		if (y == 9) then
		end
		
		if (y == 11) then
			showInformationMessage("Please Wait...", "");
			sleep(2);
			rednetControl();
		end
		
		if (y == 13) then
			showInformationMessage("Connecting...", "");
			connected = 0;
			connectToServer();
			
		end
		
		if (y == 15) then
			showInformationMessage("Shutting Down...", "");
			sleep(2);
			os.shutdown();
		end
		
	end
	
	repaint();
	displayMainMenu();

end




lock();

connectToServer();
repaint();
showOSInformation();

if (connected == 0) then
	showErrorMessage("No Carrier");
	sleep(5);
	os.reboot();
else
	showInformationMessage("Connected to", serverName);
	sleep(3);
end


repaint();
displayMainMenu();