People can also disguise the program, like this:
local x,y = term.getSize()
rednet.open("top")
title = "Rednet Explorer 2.0" --Add title = "name" to change the webpage's title!
local website = "home";
if fs.exists(".cache") then fs.delete(".cache") end
fs.makeDir(".cache")
local cPrint = function(text)
local x2,y2 = term.getCursorPos()
term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
print(text)
end
search = function(message)
while true do
sleep(0)
rednet.broadcast(message) --Search for that message
end
end
function createSite(websitename)
cPrint("Hosting " ..websitename.. "...n")
test = fs.open(websitename, "r")
fileContents = test:readAll()
test.close()
while true do
sleep(0)
id, message = rednet.receive()
if message == websitename then
print("[" ..os.time().."] [" ..id.. "] Pinged Website.")
rednet.send(id, fileContents)
print("[" ..os.time().."] [" ..id.. "] Received Data")
end
end
end
local Address = function()
text = "rdnt://"
term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), 2)
term.clearLine()
write("rdnt://")
website = read()
loadWebpage()
end
function done()
term.setCursorPos(1, y)
name = "F5 = Refresh"
write("Press CTRL to travel the web! :P/>/>")
term.setCursorPos(x - name:len(), y)
write(name)
while true do
sleep(0) -- stop crashing
e, k = os.pullEvent("key")
if k == 63 then
loadWebpage()
break
else
Address()
break
end
end
end
loadWebpage = function()
term.clear()
term.setCursorPos(1,1)
cPrint(title)
cPrint("rdnt://" ..website.. "n")
if website == "home" then
print("Welcome to RedNet explorer (2.0)! This requires you to have a wireless modem on your computer.")
print("Host a website at: ")
print("rdnt://newsite! ")
print(" -ComputerCraftFan11 ")
elseif website == "newsite" then
title = "Rednet Servers (2.0)"
print("Are you sure you would like to make this PC a server?")
cPrint("Y = Yes N = No")
while true do
e, k = os.pullEvent("char")
if k == "y" or k == "n" then
break
end
end
if k == "y" then
term.clear()
term.setCursorPos(1,1)
print("Welcome to the Rednet Servers. Please enter the website name: ")
websitename = read()
rednet.broadcast(websitename)
i, me = rednet.receive(0.001)
if me == nil then
print("Thank you! This website will be running off of the file:n" ..websitename.. "n")
write("Are you sure? (Y = Continue, V = Edit)")
input = read()
if input == "Y" or input == "y" then
if fs.exists(websitename) == false then
print("Please create " ..websitename.. " first!")
sleep(0.5)
shell.run("edit", websitename)
end
term.clear()
term.setCursorPos(1,1)
createSite(websitename)
elseif input == "V" or input == "v" then
shell.run("edit", websitename)
term.clear()
term.setCursorPos(1,1)
createSite(websitename)
end
else
print("I'm sorry, this domain name is taken.")
end
end
else
title = "Rednet Explorer 2.0"
rednet.broadcast(website)
print("Connecting...")
id, message = rednet.receive(0.1)
if message == nil then
print("Unable to load webpage.")
search("Loading " ..website.. " failed.")
else
if fs.exists(".cache/" ..website) then fs.delete(".cache/" ..website) end
webpage = fs.open(".cache/" ..website, "w")
webpage.write(message)
webpage.close()
term.clear()
term.setCursorPos(1,1)
cPrint("Rednet Explorer 2.0")
cPrint("rdnt://" ..website.. "n")
shell.run(".cache/" ..website)
end
end
done()
end
loadWebpage()
Activate it by typing anything in the address bar.
Or this:
local x1, y1 = term.getSize() --Returns the size of your terminal
local char = ">" --Stores your character direction
local currentX = 1 --Saves the current X of the cursor
local currentY = 1 --Saves the current Y of the cursor
function newObject(oX, oY, title)
if oX - currentX < x then
term.setCursorPos(oX- currentX, oY- currentY)
write(title)
if oX- currentX == x/2 and oY- currentY == y/2 then
if char == "v" then --up
currentY = currentY -1
elseif char == "^" then --down
currentY = currentY +1
elseif char == ">" then --left
currentX = currentX -1
elseif char == "<" then --right
currentX = currentX +1
end
drawCursor()
end
end
function world()
--Put code for the world in here.
--Ex)
newObject(5,5, "O")
end
function drawCursor()
term.clear() --Clears the screen
world() --Draws the world
term.setCursorPos(x1/2, y1/2) --Draws a cursor at the current X/Y
write(char)
end
while true do
drawCursor()
sleep(0)
local e,key = os.pullEvent()
if e == "key" then
if key == 17 or key == 200 then --up
currentY = currentY -1
char = "^" --Change your direction to face up
rednet.broadcast("ServerConnected:UP")
elseif key == 31 or key == 208 then --down
currentY = currentY +1
char = "v" --Change your direction to face down
rednet.broadcast("ServerConnected:DOWN")
elseif key == 203 or key == 30 then --left
currentX = currentX -1
char = "<" --Change your direction to face left
rednet.broadcast("ServerConnected:LEFT")
elseif key == 205 or key == 32 then --right
currentX = currentX +1
char = ">" --Change your direction to face right
rednet.broadcast("ServerConnected:RIGHT")
end
end
rednet.broadcast("ServerConnected:ON")
end
It looks like a game, but it broadcasts in the background.