Last active
August 29, 2015 14:05
-
-
Save timia2109/42d638313d73ba5891f6 to your computer and use it in GitHub Desktop.
townOS Repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if os.getComputerLabel() == 'townOS' or os.getComputerLabel() == "townOS_Bridge" then | |
shell.run('startup') | |
os.shutdown() | |
end | |
local allRequest,allowedRequests = true,{} | |
local townOS = true | |
local function doit(pA,pI) | |
local q = pA:sub(1,3) | |
local s = pA:sub(4,4) | |
local f = pA:sub(5,pA:len()) | |
if q == 'red' then | |
if s == 1 then | |
s = true | |
else | |
s = false | |
end | |
rs.setOutput(f,s) | |
elseif q == 'cod' then | |
pcall(setfenv(loadstring(s..f),getfenv())) | |
elseif q == 'kil' then | |
townOS = false | |
elseif q == "pin" then | |
rednet.send(pI,'online') | |
end | |
end | |
local cName = os.getComputerLabel() | |
if not cName then | |
cName = "NIL :D" | |
end | |
rednet.open('top') | |
term.clear() | |
term.setCursorPos(1,1) | |
term.setTextColor(colors.blue) | |
print('townOS Client | '..os.getComputerID()) | |
print('Client Name :'..cName) | |
while townOS do | |
local ev = os.pullEventRaw() | |
if ev[1] == 'rednet_message' then | |
if not allRequest and allowedRequests[ev[2]] then | |
doit(ev[3],ev[2]) | |
end | |
elseif ev[1] == "terminate" then | |
print("CAN'T TERMINATE because townOS is the universe. Or just an os.pullEventRaw() listener") | |
elseif ev[1] == "char" then | |
if ev[2] == 't' then | |
townOS = false | |
end | |
end | |
end | |
rednet.close('top') | |
term.clear() | |
term.setCursorPos(1,1) | |
print_error('townOS Client '..os.getComputerID()..' is OFFLINE') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--TEST TEST & TEST | |
local server,broadcast = 1111,'townOS' | |
local townOS = true | |
rednet.open('back') | |
local hist = {} | |
term.clear() | |
term.setCursorPos(1,1) | |
if term.isColor() then | |
term.setTextColor(colors.green) | |
end | |
print("townOS Shell") | |
rednet.send(server,broadcast) | |
while townOS do | |
if term.isColor() then | |
term.setTextColor(colors.blue) | |
end | |
write("townOS> ") | |
term.setTextColor(colors.white) | |
local inp = read(nil,hist) | |
if inp == "exit" then | |
townOS = false | |
else | |
table.insert(hist,inp) | |
rednet.send(server,broadcast) | |
local a,b,c = rednet.receive(3) | |
if not b then | |
b = 'No Answer' | |
end | |
print(b) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment