Help is always appreciated. Right now the main thing I need help with is getting people to use it. I've gotten a lot of people saying it looks great, but only a few have actually put their scripts on the site.
Once I have a few more things worked out I will probably put the whole website/cc-get program on GitHub. If you're looking to contribute in the way of code it will be best to wait until it's on GitHub. I expect everything to be on there in the next day or two.
That works for me. I will probably only add scripts that are posted after this so people know what's happening.
I'll also wait a day after people post here to put the script on the website so they have time to add it themselves (if they want). It would be helpful if when people post a script on this thread if they mention whether they have/will add it to cc-get.
Great! I'm happy to see more people are starting to use it.
i was just looking at your site saying, "woah it should be tons of script on here" the site looks good and you put alot of work into it, and the program. I will advertise this alot and it will get the attention it deserves. When i finish my programs(had to rewrite for update) i'll definitely look out for you. Just made an account there is well : )
A new program i created is a program to tell the computer which redpower wire to activate / deactivate trough bundled wire.
for example you write red then the red wire which connects to the bundled wire which connects to the computer will be on. Write red again and it is off
commands:
colors such as : red,cyan,blue,lightgray,yellow etc.
reset- turn all the wires off
all - turn all the wires on
Note: the output is only to the back of the computer
function light(color,j)
if color=="red" then
return colors.red,1,"Red"
end
if color=="white" then
return colors.white,2,"White"
end
if color=="blue" then
return colors.blue,3,"Blue"
end
if color=="green" then
return colors.green,4,"Green"
end
if color=="pink" then
return colors.pink,5,"Pink"
end
if color=="orange" then
return colors.orange,6,"Orange"
end
if color=="magenta" then
return colors.magenta,7,"Magenta"
end
if color=="lightblue" then
return 8,8,"Light Blue"
end
if color=="yellow" then
return colors.yellow,9,"Yellow"
end
if color=="lime" then
return colors.lime,10,"Lime"
end
if color=="gray" then
return colors.gray,11,"Gray"
end
if color=="break" then
j=1
return (redstone.getBundledOutput("back")*(-1)),1,"Error",j
end
if color=="lightgray" then
return 256,12,"Light Gray"
end
if color=="cyan" then
return colors.cyan,13,"Cyan"
end
if color=="purple" then
return colors.purple,14,"Purple"
end
if color=="brown" then
return colors.brown,15,"Brown"
end
if color=="black" then
return colors.black,16,"Black"
end
if color=="reset" then
return (redstone.getBundledOutput("back")*(-1))
end
if color=="all" then
return (65535)
end
return 0
end
l={}
for i=1, 16 do
l[i]=0
end
term.clear()
term.setCursorPos(1,1)
write("All Colors Are Off")
print(newline)
write("------------")
print(newline)
j=nill
while j==nill do
write("Enter Color ")
a=read()
num,place,b,j=light(a,l)
if num==redstone.getBundledOutput("back")*(-1) then
redstone.setBundledOutput("back", 0)
term.clear()
term.setCursorPos(1,1)
print("All The Colors Are Off")
write("------------")
print(newline)
for i=1, 16 do
l[i]=0
end
else
if num==65535 then
redstone.setBundledOutput("back", 65535)
term.clear()
term.setCursorPos(1,1)
print("All The Colors Are On")
write("------------")
print(newline)
for i=1, 16 do
l[i]=1
end
else
if num~=0 then
if l[place]==0 then
l[place]=1
else
l[place]=0
end
if l[place]==0 then
redstone.setBundledOutput("back", redstone.getBundledOutput("back")-num)
term.clear()
term.setCursorPos(1,1)
print(b.." Is Off")
write("------------")
print(newline)
else
redstone.setBundledOutput("back", redstone.getBundledOutput("back")+num)
term.clear()
term.setCursorPos(1,1)
print(b.." Is On")
write("------------")
print(newline)
end
else
term.clear()
term.setCursorPos(1,1)
write("Wrong Color ")
print(newline)
write("------------")
print(newline)
end
end
end
end
term.clear()
term.setCursorPos(1,1)
write("CraftOS 1.1")
print(newline)
Edit:
Fixed a the lightgray + gray lights which didnt work properly togheter
local tArgs = { ... }
local First = tArgs[1]
if not First then
error("Usage: BlockPC <First pass> <Second pass>")
end
local Second = tArgs[2] or "000"
print("Yor PC block now for exit enter First or Second pass")
repeat
local inp=io.read()
if inp==First or inp==Second then
else
print("Invalid password")
end
until inp==First or inp==Second
print("Yor computer unblock now")
local tArgs = { ... }
local sSide = tArgs[1]
if not sSide then
error("Usage: Password <side> <First Pass> <Second Pass> <Delay> <Inverse>")
end
local First = tArgs[2]
local Second = tArgs[3]
local Del=tonumber(tArgs[4]) or 5
local Inv=tArgs[5]
local Inv1=true
local Inv2=false
if Inv==true or Inv==1 then
local Inv1=false
local Inv2=true
else
local Inv1=true
local Inv2=false
end
print("Start Pass program for use enter right First pass")
print("For off enter Second Pass")
repeat
print("Enter password")
local inp=io.read()
if inp==First then
redstone.setOutput( sSide, Inv1 )
sleep(Del)
redstone.setOutput( sSide, Inv2 )
end
term.clear()
term.setCursorPos( 1, 1 )
until inp==Second
Here is my network code using bundled cables. This uses cables 0-9 leaving 7 other cables still useable in the same bundle.
--[[
Network API by XLilCasper. Original idea from D0han
All API can be accessed directly or though network.
Basic useage is
network.sendStr(0xFF,"Hello World")
Will send Hello World to all connected computers that are listening
To set your computer to listen use
local data = network.waitForData()
You can set your computers network ID with
network.setid(XXX) where XXX is a number 0-254, computers default to an ID of 0.
Finaly by default data is sent out the back. You can change this with
network.setDataSide(side)
--]]
sDataSide = "back"
computerid = 0x00
fThrottle = 0.2 --This was the fastest that worked for me. This gives us 5 Bps or 40 bps
Dec2BinTable = {}
b = {}
packetHeaders = {
['trans'] = {0x1, 0x11},
}
------------borrowed code------------------------
for n=1,8 do
table.insert(b, 0)
end
for n=0,255 do
table.insert(Dec2BinTable, 0)
Dec2BinTable[n] = b[1] .. b[2] .. b[3] .. b[4] .. b[5] .. b[6] .. b[7] .. b[8]
b[8] = b[8] + 1
for n2=1,7 do
if b[9-n2] == 2 then
b[9-n2] = 0
b[8-n2] = b[8-n2] + 1
end
end
end
------------end of borrowed code------------------
function getDataClock()
return rs.testBundledInput(sDataSide,256)
end
function networkReady()
os.startTimer(3*fThrottle)
event = os.pullEvent()
if event == "redstone" and getDataClock() then
return false
elseif event =="timer" then
return true
end
end
function sendByte(byte)
local bits = Dec2BinTable[byte]
local wires=0
for n=0,7 do
if (string.sub(bits,n+1,n+1) == "1") then
wires = wires + (2^(7-n))
end
end
rs.setBundledOutput(sDataSide,wires+256)
sleep(fThrottle)
rs.setBundledOutput(sDataSide,0)
sleep(fThrottle)
end
function readByte(timeout)
if (timeout) then
timeStarted = false
os.startTimer(timeout/2)
end
while true do
event, param = os.pullEvent()
if event == "key" and param == 197 then --Exit on pause/break
return "Exited"
elseif event == "redstone" then
--print("Redstone - " .. rs.getBundledOutput(sDataSide))
if getDataClock() then --Clock fired
--print("clock fired")
local byte=0
for n=0,7 do
if rs.testBundledInput(sDataSide,2^n) then byte=byte+(2^n) end
--print("Bit " .. n .. "= " .. tostring(rs.testBundledInput(sDataSide,2^n)))
end
return tonumber(byte);
end
elseif event =="timer" and timeStarted and timeout then
break
elseif event =="timer" and timeout then
timeStarted=true
os.startTimer(timeout/2)
end
end
return nil
end
function sendStr(addr, data, tries)
tries = tries or 3
while not networkReady() do
sleep(3*fThrottle)
end
sendByte(0x01)
sendByte(0x11)
sendByte(addr)
sendByte(#data)
sendByte(0x02)
for n=1,#data do
sendByte(string.byte(string.sub(data, n,n)))
end
sendByte(0x04)
--print("Data sent, wait for ack")
local ack = readByte(10*fThrottle)
if ack then
if ack == 0x06 then
--print("Got ack")
return true
elseif ack == 0x15 then -- failed, try a resend
--print("Got failed")
tries=tries-1
if (tries <=0) then
return false
else --We still have tries left, retry
return sendStr(addr,data,tries)
end
else --Unknown error, abort.
--print("Got unknown " .. ack)
return false
end
else
--We timed out
return false
end
end
function waitForData()
local bExit = false
local packs = { 0x00, 0x00}
while not bExit do
event, param = os.pullEvent()
if event == "key" and param == 197 then --Exit on pause/break
bExit = true
end
newByte = readByte()
--print("got byte " .. tostring(newByte))
if newByte then
table.remove(packs, 1)
table.insert(packs, newByte)
for index, val in pairs(packetHeaders) do
if (packs[1] == val[1]) and (packs[2] == val[2]) then
newByte = readByte()
if (newByte == computerid) or (newByte == 0xff) then --It is our id or it is a broadcast
if (val[2] == packetHeaders["trans"][2]) then --Incomeing trasnmition
--print("Incoming data")
local str = readPacket()
return str
end
end
end
end
end
sleep(0.1)
end
end
function readPacket(len)
local failed = 0
if not len then
len = readByte() -- if we don't have a lenght it should be the next byte
end
--verify that the next byte is 0x02 and that our text is starting. This is here so we can have larger then 255 packets later
if (readByte() == 0x02) then
packet = {}
for n=1, len do
table.insert(packet, readByte())
end
--we are done getting our string next byte should be the end transmition
endByte = readByte()
if endByte and endByte == 0x04 then
sleep(3*fThrottle)
sendByte(0x06)
--Convert back to a string
local str = ""
for index, val in ipairs(packet) do
str = str .. string.char(val)
end
return str
else
sendByte(0x15) --send transmition failed.
return false
end
else
return nil
end
end
This mod is just really awesome, but I got a problem:
I've made a program that's an infinite loop. It's something like this:
while true do
print("password: ")
pass = read()
if (password matches then door opens, if not dispensers shoot etc.)
end
end
Now to the problem: I want to edit my code. How can I do that? The program is never terminating itself as it's an infinite loop, and I cannot find any other way to exit the program than destroying the machine, which will delete my program :/
This mod is really really awesome, and it'll be really good if anyone could help me fix my problem :sad.gif:
This mod is just really awesome, but I got a problem:
I've made a program that's an infinite loop. It's something like this:
while true do
print("password: ")
pass = read()
if (password matches then door opens, if not dispensers shoot etc.)
end
end
Now to the problem: I want to edit my code. How can I do that? The program is never terminating itself as it's an infinite loop, and I cannot find any other way to exit the program than destroying the machine, which will delete my program :/
This mod is really really awesome, and it'll be really good if anyone could help me fix my problem :sad.gif:
You should always be careful with while loops, before your program is finished do something like this to give yourself a way to kill the loop...
while redstone.getInput( "left" ) ~= true do
Don't worry though, you can edit the programs on any computer by closing Minecraft then finding the save directory. It'll be in a sub directory under computer or something. This is obviously also a better way to use a real code editor to build complex programs too.
Here is my network code using bundled cables. This uses cables 0-9 leaving 7 other cables still useable in the same bundle.
--[[
Network API by XLilCasper. Original idea from D0han
All API can be accessed directly or though network.
Basic useage is
network.sendStr(0xFF,"Hello World")
Will send Hello World to all connected computers that are listening
To set your computer to listen use
local data = network.waitForData()
You can set your computers network ID with
network.setid(XXX) where XXX is a number 0-254, computers default to an ID of 0.
Finaly by default data is sent out the back. You can change this with
network.setDataSide(side)
--]]
sDataSide = "back"
computerid = 0x00
fThrottle = 0.2 --This was the fastest that worked for me. This gives us 5 Bps or 40 bps
Dec2BinTable = {}
b = {}
packetHeaders = {
['trans'] = {0x1, 0x11},
}
------------borrowed code------------------------
for n=1,8 do
table.insert(b, 0)
end
for n=0,255 do
table.insert(Dec2BinTable, 0)
Dec2BinTable[n] = b[1] .. b[2] .. b[3] .. b[4] .. b[5] .. b[6] .. b[7] .. b[8]
b[8] = b[8] + 1
for n2=1,7 do
if b[9-n2] == 2 then
b[9-n2] = 0
b[8-n2] = b[8-n2] + 1
end
end
end
------------end of borrowed code------------------
function getDataClock()
return rs.testBundledInput(sDataSide,256)
end
function networkReady()
os.startTimer(3*fThrottle)
event = os.pullEvent()
if event == "redstone" and getDataClock() then
return false
elseif event =="timer" then
return true
end
end
function sendByte(byte)
local bits = Dec2BinTable[byte]
local wires=0
for n=0,7 do
if (string.sub(bits,n+1,n+1) == "1") then
wires = wires + (2^(7-n))
end
end
rs.setBundledOutput(sDataSide,wires+256)
sleep(fThrottle)
rs.setBundledOutput(sDataSide,0)
sleep(fThrottle)
end
function readByte(timeout)
if (timeout) then
timeStarted = false
os.startTimer(timeout/2)
end
while true do
event, param = os.pullEvent()
if event == "key" and param == 197 then --Exit on pause/break
return "Exited"
elseif event == "redstone" then
--print("Redstone - " .. rs.getBundledOutput(sDataSide))
if getDataClock() then --Clock fired
--print("clock fired")
local byte=0
for n=0,7 do
if rs.testBundledInput(sDataSide,2^n) then byte=byte+(2^n) end
--print("Bit " .. n .. "= " .. tostring(rs.testBundledInput(sDataSide,2^n)))
end
return tonumber(byte);
end
elseif event =="timer" and timeStarted and timeout then
break
elseif event =="timer" and timeout then
timeStarted=true
os.startTimer(timeout/2)
end
end
return nil
end
function sendStr(addr, data, tries)
tries = tries or 3
while not networkReady() do
sleep(3*fThrottle)
end
sendByte(0x01)
sendByte(0x11)
sendByte(addr)
sendByte(#data)
sendByte(0x02)
for n=1,#data do
sendByte(string.byte(string.sub(data, n,n)))
end
sendByte(0x04)
--print("Data sent, wait for ack")
local ack = readByte(10*fThrottle)
if ack then
if ack == 0x06 then
--print("Got ack")
return true
elseif ack == 0x15 then -- failed, try a resend
--print("Got failed")
tries=tries-1
if (tries <=0) then
return false
else --We still have tries left, retry
return sendStr(addr,data,tries)
end
else --Unknown error, abort.
--print("Got unknown " .. ack)
return false
end
else
--We timed out
return false
end
end
function waitForData()
local bExit = false
local packs = { 0x00, 0x00}
while not bExit do
event, param = os.pullEvent()
if event == "key" and param == 197 then --Exit on pause/break
bExit = true
end
newByte = readByte()
--print("got byte " .. tostring(newByte))
if newByte then
table.remove(packs, 1)
table.insert(packs, newByte)
for index, val in pairs(packetHeaders) do
if (packs[1] == val[1]) and (packs[2] == val[2]) then
newByte = readByte()
if (newByte == computerid) or (newByte == 0xff) then --It is our id or it is a broadcast
if (val[2] == packetHeaders["trans"][2]) then --Incomeing trasnmition
--print("Incoming data")
local str = readPacket()
return str
end
end
end
end
end
sleep(0.1)
end
end
function readPacket(len)
local failed = 0
if not len then
len = readByte() -- if we don't have a lenght it should be the next byte
end
--verify that the next byte is 0x02 and that our text is starting. This is here so we can have larger then 255 packets later
if (readByte() == 0x02) then
packet = {}
for n=1, len do
table.insert(packet, readByte())
end
--we are done getting our string next byte should be the end transmition
endByte = readByte()
if endByte and endByte == 0x04 then
sleep(3*fThrottle)
sendByte(0x06)
--Convert back to a string
local str = ""
for index, val in ipairs(packet) do
str = str .. string.char(val)
end
return str
else
sendByte(0x15) --send transmition failed.
return false
end
else
return nil
end
end
Wow thats really cool...
So from what i understand the computer send a packet to all the computers on "waitForData" mode. And the first packet tells the computer to start recording the packets and stop when it gets packet which ==0x02 then it creates a sentence from all the packets the computer recieved?
A new program i created is a program to tell the computer which redpower wire to activate / deactivate trough bundled wire.
for example you write red then the red wire which connects to the bundled wire which connects to the computer will be on. Write red again and it is off
commands:
colors such as : red,cyan,blue,lightgray,yellow etc.
reset- turn all the wires off
all - turn all the wires on
Note: the output is only to the back of the computer
function light(color)
if color=="red" then
return colors.red,1
end
if color=="white" then
return colors.white,2
end
if color=="blue" then
return colors.blue,3
end
if color=="green" then
return colors.green,4
end
if color=="pink" then
return colors.pink,5
end
if color=="orange" then
return colors.orange,6
end
if color=="magenta" then
return colors.magenta,7
end
if color=="lightblue" then
return 8,8
end
if color=="yellow" then
return colors.yellow,9
end
if color=="lime" then
return colors.lime,10
end
if color=="gray" then
return colors.gray,11
end
if color=="break" then
os.shutdown()
end
if color=="lightgray" then
return 128,12
end
if color=="cyan" then
return colors.cyan,13
end
if color=="purple" then
return colors.purple,14
end
if color=="brown" then
return colors.brown,15
end
if color=="black" then
return colors.black,16
end
if color=="reset" then
return (redstone.getBundledOutput("back")*(-1))
end
if color=="all" then
return (65535)
end
return 0
end
l={}
for i=1, 16 do
l[i]=0
end
term.clear()
term.setCursorPos(1,1)
while true do
write("Enter Color ")
a=read()
num,place=light(a,l)
if num==redstone.getBundledOutput("back")*(-1) then
redstone.setBundledOutput("back", 0)
term.clear()
term.setCursorPos(1,1)
print("All the colors are off")
for i=1, 16 do
l[i]=0
end
else
if num==65535 then
redstone.setBundledOutput("back", 65535)
term.clear()
term.setCursorPos(1,1)
print("All the colors are on")
for i=1, 16 do
l[i]=1
end
else
if num~=0 then
if l[place]==0 then
l[place]=1
else
l[place]=0
end
if l[place]==0 then
redstone.setBundledOutput("back", redstone.getBundledOutput("back")-num)
term.clear()
term.setCursorPos(1,1)
print(a.." is off")
else
redstone.setBundledOutput("back", redstone.getBundledOutput("back")+num)
term.clear()
term.setCursorPos(1,1)
print(a.." is on")
end
else
write("Wrong Color ")
print(newline)
end
end
end
end
Here is my network code using bundled cables. This uses cables 0-9 leaving 7 other cables still useable in the same bundle.
--[[
Network API by XLilCasper. Original idea from D0han
All API can be accessed directly or though network.
Basic useage is
network.sendStr(0xFF,"Hello World")
Will send Hello World to all connected computers that are listening
To set your computer to listen use
local data = network.waitForData()
You can set your computers network ID with
network.setid(XXX) where XXX is a number 0-254, computers default to an ID of 0.
Finaly by default data is sent out the back. You can change this with
network.setDataSide(side)
--]]
sDataSide = "back"
computerid = 0x00
fThrottle = 0.2 --This was the fastest that worked for me. This gives us 5 Bps or 40 bps
Dec2BinTable = {}
b = {}
packetHeaders = {
['trans'] = {0x1, 0x11},
}
------------borrowed code------------------------
for n=1,8 do
table.insert(b, 0)
end
for n=0,255 do
table.insert(Dec2BinTable, 0)
Dec2BinTable[n] = b[1] .. b[2] .. b[3] .. b[4] .. b[5] .. b[6] .. b[7] .. b[8]
b[8] = b[8] + 1
for n2=1,7 do
if b[9-n2] == 2 then
b[9-n2] = 0
b[8-n2] = b[8-n2] + 1
end
end
end
------------end of borrowed code------------------
function getDataClock()
return rs.testBundledInput(sDataSide,256)
end
function networkReady()
os.startTimer(3*fThrottle)
event = os.pullEvent()
if event == "redstone" and getDataClock() then
return false
elseif event =="timer" then
return true
end
end
function sendByte(byte)
local bits = Dec2BinTable[byte]
local wires=0
for n=0,7 do
if (string.sub(bits,n+1,n+1) == "1") then
wires = wires + (2^(7-n))
end
end
rs.setBundledOutput(sDataSide,wires+256)
sleep(fThrottle)
rs.setBundledOutput(sDataSide,0)
sleep(fThrottle)
end
function readByte(timeout)
if (timeout) then
timeStarted = false
os.startTimer(timeout/2)
end
while true do
event, param = os.pullEvent()
if event == "key" and param == 197 then --Exit on pause/break
return "Exited"
elseif event == "redstone" then
--print("Redstone - " .. rs.getBundledOutput(sDataSide))
if getDataClock() then --Clock fired
--print("clock fired")
local byte=0
for n=0,7 do
if rs.testBundledInput(sDataSide,2^n) then byte=byte+(2^n) end
--print("Bit " .. n .. "= " .. tostring(rs.testBundledInput(sDataSide,2^n)))
end
return tonumber(byte);
end
elseif event =="timer" and timeStarted and timeout then
break
elseif event =="timer" and timeout then
timeStarted=true
os.startTimer(timeout/2)
end
end
return nil
end
function sendStr(addr, data, tries)
tries = tries or 3
while not networkReady() do
sleep(3*fThrottle)
end
sendByte(0x01)
sendByte(0x11)
sendByte(addr)
sendByte(#data)
sendByte(0x02)
for n=1,#data do
sendByte(string.byte(string.sub(data, n,n)))
end
sendByte(0x04)
--print("Data sent, wait for ack")
local ack = readByte(10*fThrottle)
if ack then
if ack == 0x06 then
--print("Got ack")
return true
elseif ack == 0x15 then -- failed, try a resend
--print("Got failed")
tries=tries-1
if (tries <=0) then
return false
else --We still have tries left, retry
return sendStr(addr,data,tries)
end
else --Unknown error, abort.
--print("Got unknown " .. ack)
return false
end
else
--We timed out
return false
end
end
function waitForData()
local bExit = false
local packs = { 0x00, 0x00}
while not bExit do
event, param = os.pullEvent()
if event == "key" and param == 197 then --Exit on pause/break
bExit = true
end
newByte = readByte()
--print("got byte " .. tostring(newByte))
if newByte then
table.remove(packs, 1)
table.insert(packs, newByte)
for index, val in pairs(packetHeaders) do
if (packs[1] == val[1]) and (packs[2] == val[2]) then
newByte = readByte()
if (newByte == computerid) or (newByte == 0xff) then --It is our id or it is a broadcast
if (val[2] == packetHeaders["trans"][2]) then --Incomeing trasnmition
--print("Incoming data")
local str = readPacket()
return str
end
end
end
end
end
sleep(0.1)
end
end
function readPacket(len)
local failed = 0
if not len then
len = readByte() -- if we don't have a lenght it should be the next byte
end
--verify that the next byte is 0x02 and that our text is starting. This is here so we can have larger then 255 packets later
if (readByte() == 0x02) then
packet = {}
for n=1, len do
table.insert(packet, readByte())
end
--we are done getting our string next byte should be the end transmition
endByte = readByte()
if endByte and endByte == 0x04 then
sleep(3*fThrottle)
sendByte(0x06)
--Convert back to a string
local str = ""
for index, val in ipairs(packet) do
str = str .. string.char(val)
end
return str
else
sendByte(0x15) --send transmition failed.
return false
end
else
return nil
end
end
Here is my network code using bundled cables. This uses cables 0-9 leaving 7 other cables still useable in the same bundle.
--[[
Network API by XLilCasper. Original idea from D0han
All API can be accessed directly or though network.
Basic useage is
network.sendStr(0xFF,"Hello World")
Will send Hello World to all connected computers that are listening
To set your computer to listen use
local data = network.waitForData()
You can set your computers network ID with
network.setid(XXX) where XXX is a number 0-254, computers default to an ID of 0.
Finaly by default data is sent out the back. You can change this with
network.setDataSide(side)
--]]
sDataSide = "back"
computerid = 0x00
fThrottle = 0.2 --This was the fastest that worked for me. This gives us 5 Bps or 40 bps
Dec2BinTable = {}
b = {}
packetHeaders = {
['trans'] = {0x1, 0x11},
}
------------borrowed code------------------------
for n=1,8 do
table.insert(b, 0)
end
for n=0,255 do
table.insert(Dec2BinTable, 0)
Dec2BinTable[n] = b[1] .. b[2] .. b[3] .. b[4] .. b[5] .. b[6] .. b[7] .. b[8]
b[8] = b[8] + 1
for n2=1,7 do
if b[9-n2] == 2 then
b[9-n2] = 0
b[8-n2] = b[8-n2] + 1
end
end
end
------------end of borrowed code------------------
function getDataClock()
return rs.testBundledInput(sDataSide,256)
end
function networkReady()
os.startTimer(3*fThrottle)
event = os.pullEvent()
if event == "redstone" and getDataClock() then
return false
elseif event =="timer" then
return true
end
end
function sendByte(byte)
local bits = Dec2BinTable[byte]
local wires=0
for n=0,7 do
if (string.sub(bits,n+1,n+1) == "1") then
wires = wires + (2^(7-n))
end
end
rs.setBundledOutput(sDataSide,wires+256)
sleep(fThrottle)
rs.setBundledOutput(sDataSide,0)
sleep(fThrottle)
end
function readByte(timeout)
if (timeout) then
timeStarted = false
os.startTimer(timeout/2)
end
while true do
event, param = os.pullEvent()
if event == "key" and param == 197 then --Exit on pause/break
return "Exited"
elseif event == "redstone" then
--print("Redstone - " .. rs.getBundledOutput(sDataSide))
if getDataClock() then --Clock fired
--print("clock fired")
local byte=0
for n=0,7 do
if rs.testBundledInput(sDataSide,2^n) then byte=byte+(2^n) end
--print("Bit " .. n .. "= " .. tostring(rs.testBundledInput(sDataSide,2^n)))
end
return tonumber(byte);
end
elseif event =="timer" and timeStarted and timeout then
break
elseif event =="timer" and timeout then
timeStarted=true
os.startTimer(timeout/2)
end
end
return nil
end
function sendStr(addr, data, tries)
tries = tries or 3
while not networkReady() do
sleep(3*fThrottle)
end
sendByte(0x01)
sendByte(0x11)
sendByte(addr)
sendByte(#data)
sendByte(0x02)
for n=1,#data do
sendByte(string.byte(string.sub(data, n,n)))
end
sendByte(0x04)
--print("Data sent, wait for ack")
local ack = readByte(10*fThrottle)
if ack then
if ack == 0x06 then
--print("Got ack")
return true
elseif ack == 0x15 then -- failed, try a resend
--print("Got failed")
tries=tries-1
if (tries <=0) then
return false
else --We still have tries left, retry
return sendStr(addr,data,tries)
end
else --Unknown error, abort.
--print("Got unknown " .. ack)
return false
end
else
--We timed out
return false
end
end
function waitForData()
local bExit = false
local packs = { 0x00, 0x00}
while not bExit do
event, param = os.pullEvent()
if event == "key" and param == 197 then --Exit on pause/break
bExit = true
end
newByte = readByte()
--print("got byte " .. tostring(newByte))
if newByte then
table.remove(packs, 1)
table.insert(packs, newByte)
for index, val in pairs(packetHeaders) do
if (packs[1] == val[1]) and (packs[2] == val[2]) then
newByte = readByte()
if (newByte == computerid) or (newByte == 0xff) then --It is our id or it is a broadcast
if (val[2] == packetHeaders["trans"][2]) then --Incomeing trasnmition
--print("Incoming data")
local str = readPacket()
return str
end
end
end
end
end
sleep(0.1)
end
end
function readPacket(len)
local failed = 0
if not len then
len = readByte() -- if we don't have a lenght it should be the next byte
end
--verify that the next byte is 0x02 and that our text is starting. This is here so we can have larger then 255 packets later
if (readByte() == 0x02) then
packet = {}
for n=1, len do
table.insert(packet, readByte())
end
--we are done getting our string next byte should be the end transmition
endByte = readByte()
if endByte and endByte == 0x04 then
sleep(3*fThrottle)
sendByte(0x06)
--Convert back to a string
local str = ""
for index, val in ipairs(packet) do
str = str .. string.char(val)
end
return str
else
sendByte(0x15) --send transmition failed.
return false
end
else
return nil
end
end
Anyway of doing this using observer patter, or and event type system, where the program can still recieve input while waiting for incoming data???
Rollback Post to RevisionRollBack
Knock her out, and have her wake up in an endless hallway of minecraft blocks, and the only way she can get out is by finding a pickaxe and digging out. That's the way it's done.
Name of program: DoorOS Functions: Secure a door Download link/Copy of code:
shell.run("clear")
currentUsername = ("user")
currentPass = ("pass")
loggedIn = false
while true do
shell.run("clear")
print("Default username is 'user'.")
print("Default password is 'pass'.")
print("")
print ("username: ")
username = read()
print("")
print ("password: ")
pass = read()
if pass == (currentPass) and username == (currentUsername) then
print ("correct password. Access granted.")
sleep (1.5)
loggedIn = true
else
print ("Username and password don't match.")
sleep (0.7)
print ("goodbye :biggrin.gif:")
sleep (0.2)
oneShot()
oneShot()
oneShot()
end
while loggedIn == true do
shell.run("clear")
print(" what do you want to do?")
print(",----------------------,")
print("|[1] open door |")
print("|[2] change username |")
print("|[3] change password |")
print("|[0] log off |")
print("| |")
print("'----------------------'")
func = read()
if func == "1" then
redstone.setOutput ("back", true)
sleep (4)
redstone.setOutput ("back", false)
sleep (0.3)
end
if func == "2" then
print("Password: ")
pass = read()
if pass == (currentPass) then
print("Correct password.")
print("What do you want the new username to be?")
username = read()
print("Username changed.")
currentUsername = (username)
print("")
print("Your new username is now")
print(currentUsername)
sleep (2)
else
print("wrong password.")
sleep (2)
end
end
if func == "3" then
print("Old password: ")
pass = read()
if pass == (currentPass) then
print("Correct password.")
print("What do you want the new password to be?")
pass = read()
print("Password changed.")
currentPass = (pass)
print("")
print("Your password is now")
print(currentPass)
sleep (2)
else
print("wrong password.")
sleep (2)
end
end
if func == "0" then
loggedIn = false
print("logging off.")
sleep (0.7)
print("logging off. .")
sleep (0.7)
print("logging off. . .")
sleep (0.6)
end
end
function oneShot ()
redstone.setOutput("bottom", true)
sleep (0.2)
redstone.setOutput("bottom", false)
sleep (0.2)
end
end
A description (Optional): A user interface where you must log in with user name and password. You are able to change the username and password.
Name of program: DoorOS Functions: Secure a door Download link/Copy of code:
shell.run("clear")
currentUsername = ("user")
currentPass = ("pass")
loggedIn = false
while true do
shell.run("clear")
print("Default username is 'user'.")
print("Default password is 'pass'.")
print("")
print ("username: ")
username = read()
print("")
print ("password: ")
pass = read()
if pass == (currentPass) and username == (currentUsername) then
print ("correct password. Access granted.")
sleep (1.5)
loggedIn = true
else
print ("Username and password don't match.")
sleep (0.7)
print ("goodbye :biggrin.gif:")
sleep (0.2)
oneShot()
oneShot()
oneShot()
end
while loggedIn == true do
shell.run("clear")
print(" what do you want to do?")
print(",----------------------,")
print("|[1] open door |")
print("|[2] change username |")
print("|[3] change password |")
print("|[0] log off |")
print("| |")
print("'----------------------'")
func = read()
if func == "1" then
redstone.setOutput ("back", true)
sleep (4)
redstone.setOutput ("back", false)
sleep (0.3)
end
if func == "2" then
print("Password: ")
pass = read()
if pass == (currentPass) then
print("Correct password.")
print("What do you want the new username to be?")
username = read()
print("Username changed.")
currentUsername = (username)
print("")
print("Your new username is now")
print(currentUsername)
sleep (2)
else
print("wrong password.")
sleep (2)
end
end
if func == "3" then
print("Old password: ")
pass = read()
if pass == (currentPass) then
print("Correct password.")
print("What do you want the new password to be?")
pass = read()
print("Password changed.")
currentPass = (pass)
print("")
print("Your password is now")
print(currentPass)
sleep (2)
else
print("wrong password.")
sleep (2)
end
end
if func == "0" then
loggedIn = false
print("logging off.")
sleep (0.7)
print("logging off. .")
sleep (0.7)
print("logging off. . .")
sleep (0.6)
end
end
function oneShot ()
redstone.setOutput("bottom", true)
sleep (0.2)
redstone.setOutput("bottom", false)
sleep (0.2)
end
end
A description (Optional): A user interface where you must log in with user name and password. You are able to change the username and password.
phone friendly version
Its kinda like the other "LockedDoors with password" programs only with user or at least that what its look like.
My first ever proper lua program. Yes, I know the code is messy but I hope you like it! :biggrin.gif:
Name of program: SCAL - Secure Computer Authorised Lock Functions:
Lock your vaults/safes safely and securely
Obfuscated Password Prompt - Evasdroppers can't see what your password is.
Easy to use interface with menus
Change your password in-game
Change the number of login attempts in-game
Disable/enable login attempts in-game
All your data is saved when you quit the game. When you load the world again, all your settings will be back.
System Lockdown Mode when you run out of login attempts
Download link/Copy of code:
function readyToLock(n)
write("Ready? ")
command = read()
if command == "lock" then
print "Ok, locking your safe!"
redstone.setOutput("right", false)
lockSafe()
end
print "Sorry I don't understand what you said, try again"
readyToLock()
end
function doLock(n)
num = 0
file = io.open("attempts.dat", "w")
file:write(num)
file:close()
redstone.setOutput("right", false)
redstone.setOutput("back", true)
print "[SYSTEM LOCKDOWN]"
nothing = read()
doLock()
end
function lockSafe(n)
term.clear()
file = io.open("password.dat", "w")
file:write(password)
file:close()
file = io.open("attemptset.dat", "w")
file:write(numset)
file:close()
file = io.open("attempts.dat", "w")
file:write(num)
file:close()
if attemptEnabled == true then aten = "true"
end
if attemptEnabled == false then aten = "false"
end
file = io.open("attempten.dat", "w")
file:write(aten)
file:close()
redstone.setOutput("right", false)
print " [SAFE LOCKED]"
print " [PRESS ENTER TO UNLOCK]"
print " SCAL v.1"
enter = read()
passwordAuth()
end
function passwordAuth(n)
if num < 0.1 then
doLock()
end
print "Enter your password to unlock your safe"
if attemptEnabled == true then
print ("You have " .. num .. " attempts remaining")
end
write "Password: "
entry = read("*")
if entry == password then
print "Password Accepted!"
sleep(2)
num = numset
file = io.open("attempts.dat", "w")
file:write(num)
file:close()
redstone.setOutput("right", true)
launchMenu()
end
print "Password Incorrect!"
sleep(2)
if attemptEnabled == true then
numb = num
num = numb - 1
if num < 0.1 then
doLock()
end
end
lockSafe()
end
function changePassword(n)
term.clear()
print "Please enter you current password"
print "Or type back to go back"
write "Current Password: "
cpassword = read("*")
if cpassword == password then
term.clear()
write "New password: "
password = read()
print "New password set!"
file = io.open("password.dat", "w")
file:write(password)
file:close()
sleep(2)
launchMenu()
end
if cpassword == "back" then
launchMenu()
end
print "Password Incorrect! Locking safe"
sleep(3)
lockSafe()
end
function changeAttempts(n)
term.clear()
if attemptEnabled == true then
result = "enabled"
end
if attemptEnabled == false then
result = "disabled"
end
print ("Currently, attempts are " .. result)
print ("and you can do " .. numset .. " login attempts")
print "\nType toggle to enable/disable attempts."
print "\nType set to set the number of login attempts one can do"
print "\nType back to go back"
cattempts = read()
if cattempts == "toggle" then
if attemptEnabled == true then
attemptEnabled = false
print "Attempts are now disabled!"
if attemptEnabled == true then aten = "true"
end
if attemptEnabled == false then aten = "false"
end
file = io.open("attempten.dat", "w")
file:write(aten)
file:close()
sleep(3)
launchMenu()
end
if attemptEnabled == false then
attemptEnabled = true
print "Attempts are now enabled!"
if attemptEnabled == true then aten = "true"
end
if attemptEnabled == false then aten = "false"
end
file = io.open("attempten.dat", "w")
file:write(aten)
file:close()
sleep(3)
launchMenu()
end
end
if cattempts == "back" then
launchMenu()
end
if cattempts == "set" then
setAttempts()
end
print "Not a valid option!"
sleep(3)
changeAttempts()
end
function setAttempts(n)
term.clear()
print "Enter a number above 0 to set the number of login attempts"
print "Type anything else to go back"
nmbr = read()
entern = tonumber(nmbr)
if entern == nil then
changeAttempts()
end
if entern > 0 then
numset = entern
num = entern
print ("You can now only do " .. numset .. " attempts")
file = io.open("attemptset.dat", "w")
file:write(numset)
file:close()
file = io.open("attempts.dat", "w")
file:write(num)
file:close()
sleep(4)
launchMenu()
end
print "The number must be above 0"
sleep(3)
changeAttempts()
end
function lockdown(n)
term.clear()
print "This will lockdown your safe and you will have"
print "to break it down. This would also stop the"
print "computer from operating, if you are sure,"
print "enter your password"
print "or type back to go back"
write "Password: "
cpassword = read("*")
if cpassword == password then
term.clear()
doLock()
end
if cpassword == "back" then
launchMenu()
end
print "Password Incorrect! Locking safe"
sleep(3)
lockSafe()
end
function launchMenu(n)
term.clear()
file = io.open("password.dat", "w")
file:write(password)
file:close()
file = io.open("attemptset.dat", "w")
file:write(numset)
file:close()
file = io.open("attempts.dat", "w")
file:write(num)
file:close()
if attemptEnabled == true then aten = "true"
end
if attemptEnabled == false then aten = "false"
end
file = io.open("attempten.dat", "w")
file:write(aten)
file:close()
print "Welcome! The actions you can do are:"
print "changepassword - Change your current password"
print "changeattempts - Change the number of login"
print "attempts you can do"
print "lockdown - WARNING: Does a system lockdown"
print "lock - locks your safe"
write "Action: "
action = read()
if action == "lock" then
print "Locking safe..."
sleep(2)
lockSafe()
end
if action == "changepassword" then
changePassword()
end
if action == "changeattempts" then
changeAttempts()
end
if action == "lockdown" then
lockdown()
end
print "Not a valid option!"
sleep(3)
launchMenu()
end
passwordexist = false
if fs.exists("password.dat") then
passwordexist = true
file = io.open("password.dat", "r")
password = file:read()
file:close()
file = io.open("attemptset.dat", "r")
numsetz = file:read()
file:close()
numset = tonumber(numsetz)
file = io.open("attempts.dat", "r")
numz = file:read()
file:close()
num = tonumber(numz)
file = io.open("attempten.dat", "r")
aten = file:read()
file:close()
if aten == "true" then attemptEnabled = true
end
if aten == "false" then attemptEnabled = false
end
end
if passwordexist == false then
attemptEnabled = true
num = 4
numset = 4
redstone.setOutput("right", true)
redstone.setOutput("back", false)
print "Oh hey there, I'm SCAL, which means"
print "Secure Computer Authorized Lock"
print "I see you're new here, go ahead and set a new"
write "Password: "
password = read ()
term.clear()
print "Ok you better remember that!"
print "Go ahead and type in \"lock\" when you're ready"
print "to lock your safe"
readyToLock()
end
redstone.setOutput("right", false)
redstone.setOutput("back", false)
passwordAuth()
A description (Optional):
This program is designed for locking vaults/safes/chests. Not doors. This program also requires *no* programming experience at all or editing the file. Everything can be controlled from the computer.
Setting Up:
1. Make sure you set the program as the startup program
2. The current configuration is that the right of the computer will control the vault/safe lock, while the back will control what will happen if a person runs out of login attempts. Guide: When the left side is on, it will open the vault. When the back is on, it will activate the what will happen if a person runs out of login attempts.
Setting up the lock:
1. Run startup
2. Set a password at prompt
3. Put stuff in your vault, then lock it
Images (Coming Soon!)
FAQ:
Q: So what will happen if a person runs of login attempts or when I use the lockdown action from the menu?
Q: Tell me about Lockdown Mode
A: The computer will enter System Lockdown mode where no-one can gain access to the vault unless you break it down. It will also transmit a redstone signal at the back of the computer. Even when you exit and re-join the game, it will still be in lockdown mode. To get out of lockdown mode, you must locate your .minecraft files, then saves, the the world, then computers, then find which folder is the one with SCAL in it. Once you find it, open attempts.dat with notepad and change it to something like 4. Just make sure it's above 0. Re-run the program and you will be back at the password prompt and the system should be out of lockdown mode.
Q: What do you mean by Obfuscated Password Prompt?
A: When the computer asks you to enter your password (Apart form the times of creating a new password), it will show up like this when you type:
Password: ****
Cool, eh?
Got any more questions or suggestions? Feel free to ask me.
The Meaning of Life, the Universe, and Everything.
Join Date:
1/1/2012
Posts:
45
Minecraft:
elrond1369
Member Details
Password door with note block alarm
Programs: startup, vault
Startup
------------------------------------------------------------------------------------------------------------------------------------------
correct = "password" States the password
write("Password:") Displays Password: on the screen
password = read(). Tells the program that password equals what's typed on screen
if password == (correct) States if what is typed in matches the text at the top
then Then
shell.run("clear") Clear the screen
redstone.setOutput("bottom", false) Turns off the output below the computer, silencing the alarm
write("Access Granted") Displays Access Granted on the screen
else else
shell.run("clear") clears the screen
write("Incorrect Password!"). Displays Incorrect Password!
redstone.setOutput("bottom", true. Turns bottom output and alarm on
sleep(2) Waits 2 seconds
shell.run("clear") Clears the screen
shell.run("startup") Restarts startup
end Ends the IF
-------------------------------------------------------------------------------------------------------------------------------------------------
vault (manuly started)
--------------------------------------------------------------------------------------------------------------------------------
redstone.setOutput("top", true) Door opens
sleep(5) For 5 seconds
redstone.setOutput("top", false) Door closes
shell.run("startup"). run startup will ask for password again
---------------------------------------------------------------------------------------------------------------------------------
Name of program: DoorOS Functions: Secure a door Download link/Copy of code:
shell.run("clear")
currentUsername = ("user")
currentPass = ("pass")
loggedIn = false
while true do
shell.run("clear")
print("Default username is 'user'.")
print("Default password is 'pass'.")
print("")
print ("username: ")
username = read()
print("")
print ("password: ")
pass = read()
if pass == (currentPass) and username == (currentUsername) then
print ("correct password. Access granted.")
sleep (1.5)
loggedIn = true
else
print ("Username and password don't match.")
sleep (0.7)
print ("goodbye :biggrin.gif:")
sleep (0.2)
oneShot()
oneShot()
oneShot()
end
while loggedIn == true do
shell.run("clear")
print(" what do you want to do?")
print(",----------------------,")
print("|[1] open door |")
print("|[2] change username |")
print("|[3] change password |")
print("|[0] log off |")
print("| |")
print("'----------------------'")
func = read()
if func == "1" then
redstone.setOutput ("back", true)
sleep (4)
redstone.setOutput ("back", false)
sleep (0.3)
end
if func == "2" then
print("Password: ")
pass = read()
if pass == (currentPass) then
print("Correct password.")
print("What do you want the new username to be?")
username = read()
print("Username changed.")
currentUsername = (username)
print("")
print("Your new username is now")
print(currentUsername)
sleep (2)
else
print("wrong password.")
sleep (2)
end
end
if func == "3" then
print("Old password: ")
pass = read()
if pass == (currentPass) then
print("Correct password.")
print("What do you want the new password to be?")
pass = read()
print("Password changed.")
currentPass = (pass)
print("")
print("Your password is now")
print(currentPass)
sleep (2)
else
print("wrong password.")
sleep (2)
end
end
if func == "0" then
loggedIn = false
print("logging off.")
sleep (0.7)
print("logging off. .")
sleep (0.7)
print("logging off. . .")
sleep (0.6)
end
end
function oneShot ()
redstone.setOutput("bottom", true)
sleep (0.2)
redstone.setOutput("bottom", false)
sleep (0.2)
end
end
A description (Optional): A user interface where you must log in with user name and password. You are able to change the username and password.
phone friendly version
I was messing around with this but the stuff entered doesn't change the file. So when I leave the map and come back to it the passwds were reset. Do you know a way to fix this? Other than that the code works perfectly.
I was messing around with this but the stuff entered doesn't change the file. So when I leave the map and come back to it the passwds were reset. Do you know a way to fix this? Other than that the code works perfectly.
Reading the data at startup:
if fs.exists("password.dat") then
file = io.open("password.dat", "r")
currentPassword = file:read()
file:close()
file = io.open("username.dat", "r")
currentUsername = file:read()
file:close()
end
Writing the data at changing your username/password
Add them to the correct parts of the code and it should work. Also if you're planning to lock a safe/vault, try my program which also saves your data and has many features (2 posts above you!)
i was just looking at your site saying, "woah it should be tons of script on here" the site looks good and you put alot of work into it, and the program. I will advertise this alot and it will get the attention it deserves. When i finish my programs(had to rewrite for update) i'll definitely look out for you. Just made an account there is well : )
for example you write red then the red wire which connects to the bundled wire which connects to the computer will be on. Write red again and it is off
commands:
colors such as : red,cyan,blue,lightgray,yellow etc.
reset- turn all the wires off
all - turn all the wires on
Note: the output is only to the back of the computer
if color=="red" then
return colors.red,1,"Red"
end
if color=="white" then
return colors.white,2,"White"
end
if color=="blue" then
return colors.blue,3,"Blue"
end
if color=="green" then
return colors.green,4,"Green"
end
if color=="pink" then
return colors.pink,5,"Pink"
end
if color=="orange" then
return colors.orange,6,"Orange"
end
if color=="magenta" then
return colors.magenta,7,"Magenta"
end
if color=="lightblue" then
return 8,8,"Light Blue"
end
if color=="yellow" then
return colors.yellow,9,"Yellow"
end
if color=="lime" then
return colors.lime,10,"Lime"
end
if color=="gray" then
return colors.gray,11,"Gray"
end
if color=="break" then
j=1
return (redstone.getBundledOutput("back")*(-1)),1,"Error",j
end
if color=="lightgray" then
return 256,12,"Light Gray"
end
if color=="cyan" then
return colors.cyan,13,"Cyan"
end
if color=="purple" then
return colors.purple,14,"Purple"
end
if color=="brown" then
return colors.brown,15,"Brown"
end
if color=="black" then
return colors.black,16,"Black"
end
if color=="reset" then
return (redstone.getBundledOutput("back")*(-1))
end
if color=="all" then
return (65535)
end
return 0
end
l={}
for i=1, 16 do
l[i]=0
end
term.clear()
term.setCursorPos(1,1)
write("All Colors Are Off")
print(newline)
write("------------")
print(newline)
j=nill
while j==nill do
write("Enter Color ")
a=read()
num,place,b,j=light(a,l)
if num==redstone.getBundledOutput("back")*(-1) then
redstone.setBundledOutput("back", 0)
term.clear()
term.setCursorPos(1,1)
print("All The Colors Are Off")
write("------------")
print(newline)
for i=1, 16 do
l[i]=0
end
else
if num==65535 then
redstone.setBundledOutput("back", 65535)
term.clear()
term.setCursorPos(1,1)
print("All The Colors Are On")
write("------------")
print(newline)
for i=1, 16 do
l[i]=1
end
else
if num~=0 then
if l[place]==0 then
l[place]=1
else
l[place]=0
end
if l[place]==0 then
redstone.setBundledOutput("back", redstone.getBundledOutput("back")-num)
term.clear()
term.setCursorPos(1,1)
print(b.." Is Off")
write("------------")
print(newline)
else
redstone.setBundledOutput("back", redstone.getBundledOutput("back")+num)
term.clear()
term.setCursorPos(1,1)
print(b.." Is On")
write("------------")
print(newline)
end
else
term.clear()
term.setCursorPos(1,1)
write("Wrong Color ")
print(newline)
write("------------")
print(newline)
end
end
end
end
term.clear()
term.setCursorPos(1,1)
write("CraftOS 1.1")
print(newline)
Edit:
Fixed a the lightgray + gray lights which didnt work properly togheter
My Os lock
Download
My redstone password program
Download
--[[
Network API by XLilCasper. Original idea from D0han
All API can be accessed directly or though network.
Basic useage is
network.sendStr(0xFF,"Hello World")
Will send Hello World to all connected computers that are listening
To set your computer to listen use
local data = network.waitForData()
You can set your computers network ID with
network.setid(XXX) where XXX is a number 0-254, computers default to an ID of 0.
Finaly by default data is sent out the back. You can change this with
network.setDataSide(side)
--]]
sDataSide = "back"
computerid = 0x00
fThrottle = 0.2 --This was the fastest that worked for me. This gives us 5 Bps or 40 bps
Dec2BinTable = {}
b = {}
packetHeaders = {
['trans'] = {0x1, 0x11},
}
------------borrowed code------------------------
for n=1,8 do
table.insert(b, 0)
end
for n=0,255 do
table.insert(Dec2BinTable, 0)
Dec2BinTable[n] = b[1] .. b[2] .. b[3] .. b[4] .. b[5] .. b[6] .. b[7] .. b[8]
b[8] = b[8] + 1
for n2=1,7 do
if b[9-n2] == 2 then
b[9-n2] = 0
b[8-n2] = b[8-n2] + 1
end
end
end
------------end of borrowed code------------------
function getDataClock()
return rs.testBundledInput(sDataSide,256)
end
function networkReady()
os.startTimer(3*fThrottle)
event = os.pullEvent()
if event == "redstone" and getDataClock() then
return false
elseif event =="timer" then
return true
end
end
function sendByte(byte)
local bits = Dec2BinTable[byte]
local wires=0
for n=0,7 do
if (string.sub(bits,n+1,n+1) == "1") then
wires = wires + (2^(7-n))
end
end
rs.setBundledOutput(sDataSide,wires+256)
sleep(fThrottle)
rs.setBundledOutput(sDataSide,0)
sleep(fThrottle)
end
function readByte(timeout)
if (timeout) then
timeStarted = false
os.startTimer(timeout/2)
end
while true do
event, param = os.pullEvent()
if event == "key" and param == 197 then --Exit on pause/break
return "Exited"
elseif event == "redstone" then
--print("Redstone - " .. rs.getBundledOutput(sDataSide))
if getDataClock() then --Clock fired
--print("clock fired")
local byte=0
for n=0,7 do
if rs.testBundledInput(sDataSide,2^n) then byte=byte+(2^n) end
--print("Bit " .. n .. "= " .. tostring(rs.testBundledInput(sDataSide,2^n)))
end
return tonumber(byte);
end
elseif event =="timer" and timeStarted and timeout then
break
elseif event =="timer" and timeout then
timeStarted=true
os.startTimer(timeout/2)
end
end
return nil
end
function sendStr(addr, data, tries)
tries = tries or 3
while not networkReady() do
sleep(3*fThrottle)
end
sendByte(0x01)
sendByte(0x11)
sendByte(addr)
sendByte(#data)
sendByte(0x02)
for n=1,#data do
sendByte(string.byte(string.sub(data, n,n)))
end
sendByte(0x04)
--print("Data sent, wait for ack")
local ack = readByte(10*fThrottle)
if ack then
if ack == 0x06 then
--print("Got ack")
return true
elseif ack == 0x15 then -- failed, try a resend
--print("Got failed")
tries=tries-1
if (tries <=0) then
return false
else --We still have tries left, retry
return sendStr(addr,data,tries)
end
else --Unknown error, abort.
--print("Got unknown " .. ack)
return false
end
else
--We timed out
return false
end
end
function waitForData()
local bExit = false
local packs = { 0x00, 0x00}
while not bExit do
event, param = os.pullEvent()
if event == "key" and param == 197 then --Exit on pause/break
bExit = true
end
newByte = readByte()
--print("got byte " .. tostring(newByte))
if newByte then
table.remove(packs, 1)
table.insert(packs, newByte)
for index, val in pairs(packetHeaders) do
if (packs[1] == val[1]) and (packs[2] == val[2]) then
newByte = readByte()
if (newByte == computerid) or (newByte == 0xff) then --It is our id or it is a broadcast
if (val[2] == packetHeaders["trans"][2]) then --Incomeing trasnmition
--print("Incoming data")
local str = readPacket()
return str
end
end
end
end
end
sleep(0.1)
end
end
function readPacket(len)
local failed = 0
if not len then
len = readByte() -- if we don't have a lenght it should be the next byte
end
--verify that the next byte is 0x02 and that our text is starting. This is here so we can have larger then 255 packets later
if (readByte() == 0x02) then
packet = {}
for n=1, len do
table.insert(packet, readByte())
end
--we are done getting our string next byte should be the end transmition
endByte = readByte()
if endByte and endByte == 0x04 then
sleep(3*fThrottle)
sendByte(0x06)
--Convert back to a string
local str = ""
for index, val in ipairs(packet) do
str = str .. string.char(val)
end
return str
else
sendByte(0x15) --send transmition failed.
return false
end
else
return nil
end
end
--Create API
network = {
["setid"] = function( _id )
computerid=tonumber(_id)
end,
["getid"] = function( )
return computerid
end,
["sendStr"] = function( _addr, _data, _tries )
return sendStr(_addr, _data, _tries)
end,
["waitForData"] = function( )
return waitForData()
end,
["sendByte"] = function( _byte )
return sendByte(_byte)
end,
["readByte"] = function( _timeOut )
return readByte( _timeOut )
end,
["getDataSide"] = function( )
return sDataSide
end,
["setDataSide"] = function( _side )
sDataSide = _side
end,
}
I've made a program that's an infinite loop. It's something like this:
Now to the problem: I want to edit my code. How can I do that? The program is never terminating itself as it's an infinite loop, and I cannot find any other way to exit the program than destroying the machine, which will delete my program :/
This mod is really really awesome, and it'll be really good if anyone could help me fix my problem :sad.gif:
I'm new in the forum, and I just made a fast login script... with password asterisk masking! Hope it'll be useful :biggrin.gif:
You should always be careful with while loops, before your program is finished do something like this to give yourself a way to kill the loop...
Don't worry though, you can edit the programs on any computer by closing Minecraft then finding the save directory. It'll be in a sub directory under computer or something. This is obviously also a better way to use a real code editor to build complex programs too.
Wow thats really cool...
So from what i understand the computer send a packet to all the computers on "waitForData" mode. And the first packet tells the computer to start recording the packets and stop when it gets packet which ==0x02 then it creates a sentence from all the packets the computer recieved?
This is very helpful - supports all 16 colors?
yes,
red,blue,cyan,lightblue and etc
Thanks for the code. I had started my own, but never finished it. Your code is cleaner than mine.
Anyway of doing this using observer patter, or and event type system, where the program can still recieve input while waiting for incoming data???
Knock her out, and have her wake up in an endless hallway of minecraft blocks, and the only way she can get out is by finding a pickaxe and digging out. That's the way it's done.
I just made a small program:
Name of program: DoorOS
Functions: Secure a door
Download link/Copy of code:
A description (Optional): A user interface where you must log in with user name and password. You are able to change the username and password.
phone friendly version
Its kinda like the other "LockedDoors with password" programs only with user or at least that what its look like.
Name of program: SCAL - Secure Computer Authorised Lock
Functions:
Lock your vaults/safes safely and securely
Obfuscated Password Prompt - Evasdroppers can't see what your password is.
Easy to use interface with menus
Change your password in-game
Change the number of login attempts in-game
Disable/enable login attempts in-game
All your data is saved when you quit the game. When you load the world again, all your settings will be back.
System Lockdown Mode when you run out of login attempts
Download link/Copy of code:
A description (Optional):
This program is designed for locking vaults/safes/chests. Not doors. This program also requires *no* programming experience at all or editing the file. Everything can be controlled from the computer.
Setting Up:
1. Make sure you set the program as the startup program
2. The current configuration is that the right of the computer will control the vault/safe lock, while the back will control what will happen if a person runs out of login attempts. Guide: When the left side is on, it will open the vault. When the back is on, it will activate the what will happen if a person runs out of login attempts.
Setting up the lock:
1. Run startup
2. Set a password at prompt
3. Put stuff in your vault, then lock it
Images (Coming Soon!)
FAQ:
Q: So what will happen if a person runs of login attempts or when I use the lockdown action from the menu?
Q: Tell me about Lockdown Mode
A: The computer will enter System Lockdown mode where no-one can gain access to the vault unless you break it down. It will also transmit a redstone signal at the back of the computer. Even when you exit and re-join the game, it will still be in lockdown mode. To get out of lockdown mode, you must locate your .minecraft files, then saves, the the world, then computers, then find which folder is the one with SCAL in it. Once you find it, open attempts.dat with notepad and change it to something like 4. Just make sure it's above 0. Re-run the program and you will be back at the password prompt and the system should be out of lockdown mode.
Q: What do you mean by Obfuscated Password Prompt?
A: When the computer asks you to enter your password (Apart form the times of creating a new password), it will show up like this when you type:
Password: ****
Cool, eh?
Got any more questions or suggestions? Feel free to ask me.
:3
Programs: startup, vault
Startup
------------------------------------------------------------------------------------------------------------------------------------------
correct = "password" States the password
write("Password:") Displays Password: on the screen
password = read(). Tells the program that password equals what's typed on screen
if password == (correct) States if what is typed in matches the text at the top
then Then
shell.run("clear") Clear the screen
redstone.setOutput("bottom", false) Turns off the output below the computer, silencing the alarm
write("Access Granted") Displays Access Granted on the screen
else else
shell.run("clear") clears the screen
write("Incorrect Password!"). Displays Incorrect Password!
redstone.setOutput("bottom", true. Turns bottom output and alarm on
sleep(2) Waits 2 seconds
shell.run("clear") Clears the screen
shell.run("startup") Restarts startup
end Ends the IF
-------------------------------------------------------------------------------------------------------------------------------------------------
vault (manuly started)
--------------------------------------------------------------------------------------------------------------------------------
redstone.setOutput("top", true) Door opens
sleep(5) For 5 seconds
redstone.setOutput("top", false) Door closes
shell.run("startup"). run startup will ask for password again
---------------------------------------------------------------------------------------------------------------------------------
I was messing around with this but the stuff entered doesn't change the file. So when I leave the map and come back to it the passwds were reset. Do you know a way to fix this? Other than that the code works perfectly.
Reading the data at startup:
Writing the data at changing your username/password
Add them to the correct parts of the code and it should work. Also if you're planning to lock a safe/vault, try my program which also saves your data and has many features (2 posts above you!)
:3