Browse Source

added files, dated 17/10/2015

master
Ben Savage 6 years ago
parent
commit
15e6a73475
  1. BIN
      bin/.test.swp
  2. 39
      bin/server/cntd
  3. 20
      bin/server/ftpd
  4. 159
      bin/turtle/layPipe
  5. 182
      bin/turtle/mine
  6. 200
      bin/turtle/secure
  7. 166
      bin/turtle/tunnel
  8. 33
      bin/utils/getFile
  9. 9
      bin/utils/setup
  10. 10
      bin/utils/turtleSetup
  11. 8
      bin/utils/whois
  12. 1
      etc/ftp.conf
  13. 1
      etc/resolv.conf
  14. BIN
      lib/.cnt.swp
  15. 15
      lib/cnt
  16. 37
      lib/icp
  17. 6
      misc/startup

BIN
bin/.test.swp

Binary file not shown.

39
bin/server/cntd

@ -0,0 +1,39 @@
local conf=fs.open('/etc/cnt.conf','r')
local cn_table = {}
line = conf.readLine()
while line ~= nil do
local name=string.sub(line,0,string.find(line, ' '))
address = tonumber(string.sub(line,string.find(line,' ')+1))
print(name..address)
cn_table[name]=address
line = conf.readLine()
end
print("Waiting for queries...")
while 1 do
local found=0
local senderId, message, distance = rednet.receive()
query=textutils.unserialize(message)
if query[1] == 'CNT' then
print("Query of "..query[2].." from "..senderId)
for key,value in pairs(cn_table) do
tmp=query[2]
if tonumber(tmp) ~= nil then
if tonumber(value) == tonumber(tmp) then
reply=textutils.serialize({"CNT",key})
found=1
end
else
if(string.find(key,tmp,0,true)) then
reply=textutils.serialize({"CNT",value})
found=1
end
end
end
if found ~= 1 then
reply=textutils.serialize({"CNT",-1})
end
rednet.send(senderId,reply)
end
end

20
bin/server/ftpd

@ -0,0 +1,20 @@
conf = fs.open('/etc/ftpd.conf','r')
export_path = conf.readLine()
while 1 do
local senderId, message, distance = rednet.receive()
query=textutils.unserialize(message)
if query[1] == 'FTP' then
print('Got request for '..query[2]..' from '..senderId)
if fs.exists(export_path..query[2]) then
local reply_file = fs.open(export_path..query[2],'r')
reply_file=reply_file.readAll()
reply = textutils.serialize({'FTP',1,reply_file})
rednet.send(senderId,reply)
else
reply=textutils.serialize({'FTP',0})
rednet.send(senderId,reply)
end
end
end

159
bin/turtle/layPipe

@ -0,0 +1,159 @@
local tArgs = { ... }
if #tArgs ~= 2 then
print( "Usage: layPipe <direction> <length>" )
return
end
-- Mine in a quarry pattern until we hit something we can't dig
local length = tonumber( tArgs[2] )
local direction = tostring( tArgs[1] )
if length < 1 then
print( "Tunnel length must be positive" )
return
end
local collected = 0
local function tryPlaceTorch()
turtle.select(2)
turtle.place()
end
local function collect()
collected = collected + 1
if math.fmod(collected, 25) == 0 then
print( "Mined "..collected.." items." )
end
end
local function tryDig()
while turtle.detect() do
if turtle.dig() then
collect()
sleep(0.5)
else
return false
end
end
return true
end
local function tryDigUp()
while turtle.detectUp() do
if turtle.digUp() then
collect()
sleep(0.5)
else
return false
end
end
return true
end
local function refuel()
local fuelLevel = turtle.getFuelLevel()
if fuelLevel == "unlimited" or fuelLevel > 0 then
return
end
local function tryRefuel()
for n=1,16 do
if turtle.getItemCount(n) > 0 then
turtle.select(n)
if turtle.refuel(1) then
turtle.select(1)
return true
end
end
end
turtle.select(1)
return false
end
if not tryRefuel() then
print( "Add more fuel to continue." )
while not tryRefuel() do
sleep(1)
end
print( "Resuming Tunnel." )
end
end
local function tryUp()
refuel()
while not turtle.up() do
if turtle.detectUp() then
if not tryDigUp() then
return false
end
elseif turtle.attackUp() then
collect()
else
sleep( 0.5 )
end
end
return true
end
local function tryDown()
refuel()
while not turtle.down() do
if turtle.detectDown() then
if not tryDigDown() then
return false
end
elseif turtle.attackDown() then
collect()
else
sleep( 0.5 )
end
end
return true
end
local function tryForward()
refuel()
while not turtle.forward() do
if turtle.detect() then
if not tryDig() then
return false
end
elseif turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
return true
end
for n=1,length do
if direction=="up" then
tryUp()
turtle.select(2)
turtle.placeDown()
end
if direction=="down" then
tryDown()
turtle.select(2)
turtle.placeUp()
end
if direction=="forward" then
tryForward()
turtle.select(2)
turtle.turnRight()
turtle.turnRight()
turtle.place()
turtle.turnRight()
turtle.turnRight()
end
end
print( "Tunnel complete." )

182
bin/turtle/mine

@ -0,0 +1,182 @@
local tArgs = { ... }
if #tArgs ~= 1 then
print( "Usage: tunnel <length>" )
return
end
-- Mine in a quarry pattern until we hit something we can't dig
local length = tonumber( tArgs[1] )
if length < 1 then
print( "Tunnel length must be positive" )
return
end
local depth = 0
local collected = 0
local function tryPlaceTorch()
turtle.select(2)
turtle.place()
end
local function collect()
collected = collected + 1
if math.fmod(collected, 25) == 0 then
print( "Mined "..collected.." items." )
end
end
local function tryDig()
while turtle.detect() do
if turtle.dig() then
collect()
sleep(0.5)
else
return false
end
end
return true
end
local function tryDigUp()
while turtle.detectUp() do
if turtle.digUp() then
collect()
sleep(0.5)
else
return false
end
end
return true
end
local function refuel()
local fuelLevel = turtle.getFuelLevel()
if fuelLevel == "unlimited" or fuelLevel > 0 then
return
end
local function tryRefuel()
for n=1,16 do
if turtle.getItemCount(n) > 0 then
turtle.select(n)
if turtle.refuel(1) then
turtle.select(1)
return true
end
end
end
turtle.select(1)
return false
end
if not tryRefuel() then
print( "Add more fuel to continue." )
while not tryRefuel() do
sleep(1)
end
print( "Resuming Tunnel." )
end
end
local function tryUp()
refuel()
while not turtle.up() do
if turtle.detectUp() then
if not tryDigUp() then
return false
end
elseif turtle.attackUp() then
collect()
else
sleep( 0.5 )
end
end
return true
end
local function tryDown()
refuel()
while not turtle.down() do
if turtle.detectDown() then
if not tryDigDown() then
return false
end
elseif turtle.attackDown() then
collect()
else
sleep( 0.5 )
end
end
return true
end
local function tryForward()
refuel()
while not turtle.forward() do
if turtle.detect() then
if not tryDig() then
return false
end
elseif turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
return true
end
print( "Tunnelling..." )
for n=1,length do
tryDigUp()
turtle.turnLeft()
tryDig()
tryUp()
tryDig()
turtle.turnRight()
turtle.turnRight()
tryDig()
tryDown()
tryDig()
turtle.turnLeft()
if n<length then
if n % 5 == 0 then
turtle.turnRight()
tryPlaceTorch()
turtle.turnLeft()
end
tryDig()
if not tryForward() then
print( "Aborting Tunnel." )
break
end
else
print( "Tunnel complete." )
end
end
print( "Returning to start..." )
-- Return to where we started
turtle.turnLeft()
turtle.turnLeft()
while length > 0 do
if tryForward() then
length = length - 1
else
turtle.dig()
end
end
turtle.turnRight()
turtle.turnRight()
print( "Tunnel complete." )
print( "Mined "..collected.." items total." )

200
bin/turtle/secure

@ -0,0 +1,200 @@
local tArgs = { ... }
if #tArgs ~= 1 then
print( "Usage: tunnel <length>" )
return
end
-- Mine in a quarry pattern until we hit something we can't dig
local length = tonumber( tArgs[1] )
if length < 1 then
print( "Tunnel length must be positive" )
return
end
local depth = 0
local collected = 0
local function tryPlaceTorch()
turtle.select(2)
turtle.place()
end
local function collect()
collected = collected + 1
if math.fmod(collected, 25) == 0 then
print( "Mined "..collected.." items." )
end
end
local function tryDig()
while turtle.detect() do
if turtle.dig() then
collect()
sleep(0.5)
else
return false
end
end
return true
end
local function tryDigUp()
while turtle.detectUp() do
if turtle.digUp() then
collect()
sleep(0.5)
else
return false
end
end
return true
end
local function refuel()
local fuelLevel = turtle.getFuelLevel()
if fuelLevel == "unlimited" or fuelLevel > 0 then
return
end
local function tryRefuel()
for n=1,16 do
if turtle.getItemCount(n) > 0 then
turtle.select(n)
if turtle.refuel(1) then
turtle.select(1)
return true
end
end
end
turtle.select(1)
return false
end
if not tryRefuel() then
print( "Add more fuel to continue." )
while not tryRefuel() do
sleep(1)
end
print( "Resuming Tunnel." )
end
end
local function tryUp()
refuel()
while not turtle.up() do
if turtle.detectUp() then
if not tryDigUp() then
return false
end
elseif turtle.attackUp() then
collect()
else
sleep( 0.5 )
end
end
return true
end
local function tryDown()
refuel()
while not turtle.down() do
if turtle.detectDown() then
if not tryDigDown() then
return false
end
elseif turtle.attackDown() then
collect()
else
sleep( 0.5 )
end
end
return true
end
local function tryForward()
refuel()
while not turtle.forward() do
if turtle.detect() then
if not tryDig() then
return false
end
elseif turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
return true
end
local function tryPlace(slot)
turtle.select(3)
turtle.place()
end
local function tryPlaceUp(slot)
turtle.select(3)
turtle.placeUp()
end
local function tryPlaceDown(slot)
turtle.select(3)
turtle.placeDown()
end
print( "Tunnelling..." )
local materialSlot = 3
for n=1,length do
tryForward()
tryPlaceDown()
turtle.turnLeft()
tryForward()
tryPlaceDown(3)
tryPlace(3)
tryUp()
tryPlace(3)
tryPlaceUp(3)
turtle.turnRight()
turtle.turnRight()
tryForward()
tryPlaceUp(3)
tryForward()
tryPlaceUp(3)
tryPlace(3)
tryDown()
tryPlace(3)
tryPlaceDown(3)
turtle.turnRight()
turtle.turnRight()
tryForward()
turtle.turnRight()
end
print( "Returning to start..." )
-- Return to where we started
turtle.turnLeft()
turtle.turnLeft()
while length > 0 do
if tryForward() then
length = length - 1
else
turtle.dig()
end
end
turtle.turnRight()
turtle.turnRight()
print( "Tunnel complete." )
print( "Mined "..collected.." items total." )

166
bin/turtle/tunnel

@ -0,0 +1,166 @@
local tArgs = { ... }
if #tArgs ~= 1 then
print( "Usage: tunnel <length>" )
return
end
-- Mine in a quarry pattern until we hit something we can't dig
local length = tonumber( tArgs[1] )
if length < 1 then
print( "Tunnel length must be positive" )
return
end
local depth = 0
local collected = 0
local function tryPlaceTorch()
turtle.select(2)
turtle.place()
end
local function collect()
collected = collected + 1
if math.fmod(collected, 25) == 0 then
print( "Mined "..collected.." items." )
end
end
local function tryDig()
while turtle.detect() do
if turtle.dig() then
collect()
sleep(0.5)
else
return false
end
end
return true
end
local function tryDigUp()
while turtle.detectUp() do
if turtle.digUp() then
collect()
sleep(0.5)
else
return false
end
end
return true
end
local function refuel()
local fuelLevel = turtle.getFuelLevel()
if fuelLevel == "unlimited" or fuelLevel > 0 then
return
end
local function tryRefuel()
for n=1,16 do
if turtle.getItemCount(n) > 0 then
turtle.select(n)
if turtle.refuel(1) then
turtle.select(1)
return true
end
end
end
turtle.select(1)
return false
end
if not tryRefuel() then
print( "Add more fuel to continue." )
while not tryRefuel() do
sleep(1)
end
print( "Resuming Tunnel." )
end
end
local function tryUp()
refuel()
while not turtle.up() do
if turtle.detectUp() then
if not tryDigUp() then
return false
end
elseif turtle.attackUp() then
collect()
else
sleep( 0.5 )
end
end
return true
end
local function tryDown()
refuel()
while not turtle.down() do
if turtle.detectDown() then
if not tryDigDown() then
return false
end
elseif turtle.attackDown() then
collect()
else
sleep( 0.5 )
end
end
return true
end
local function tryForward()
refuel()
while not turtle.forward() do
if turtle.detect() then
if not tryDig() then
return false
end
elseif turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
return true
end
print( "Tunnelling..." )
for n=1,length do
tryForward()
tryDigUp()
if n % 5 == 0 then
turtle.turnLeft()
turtle.turnLeft()
tryPlaceTorch()
turtle.turnLeft()
turtle.turnLeft()
end
end
print( "Returning to start..." )
-- Return to where we started
tryUp()
turtle.turnLeft()
turtle.turnLeft()
while length > 0 do
if tryForward() then
length = length - 1
else
turtle.dig()
end
end
turtle.turnRight()
turtle.turnRight()
tryDown()
print( "Tunnel complete." )
print( "Mined "..collected.." items total." )

33
bin/utils/getFile

@ -0,0 +1,33 @@
os.loadAPI('/lib/cnt')
local tArgs = { ... }
if #tArgs < 1 then
print( "Usage: getFile <remote_file> [local_file]" )
return
end
local r_filename = tArgs[1]
local l_filename = shell.resolve(fs.getName(r_filename))
print(l_filename)
tmp = fs.open('/etc/ftp.conf','r')
local fileserver = tostring(tmp.readLine())
fs_id = cnt.lookup(fileserver)
message=textutils.serialize({'FTP',r_filename})
rednet.send(fs_id,message)
local senderId, reply, distance = rednet.receive()
reply = textutils.unserialize(reply)
while senderId ~= fs_id and reply[1] ~= 'FTP' do
local senderId, reply, distance = rednet.receive()
reply = textutils.unserialize(reply)
end
if reply[2] > 0 then
l_file=fs.open(l_filename,'w')
l_file.write(reply[3])
l_file.close()
else
print("File not found: "..r_filename)
end

9
bin/utils/setup

@ -0,0 +1,9 @@
fs.makeDir('/etc')
fs.makeDir('/lib')
fs.makeDir('/bin')
fs.copy('/disk/misc/startup','/startup')
fs.copy('/disk/etc/resolv.conf','/etc/resolv.conf')
fs.copy('/disk/etc/ftp.conf','/etc/ftp.conf')
fs.copy('/disk/lib/cnt','/lib/cnt')
fs.copy('/disk/bin/utils','/bin/utils')

10
bin/utils/turtleSetup

@ -0,0 +1,10 @@
fs.makeDir('/etc')
fs.makeDir('/lib')
fs.makeDir('/bin')
fs.copy('/disk/misc/startup','/startup')
fs.copy('/disk/etc/resolv.conf','/etc/resolv.conf')
fs.copy('/disk/etc/ftp.conf','/etc/ftp.conf')
fs.copy('/disk/lib/cnt','/lib/cnt')
fs.copy('/disk/bin/utils','/bin/utils')
fs.copy('/disk/bin/turtle','/bin/turtle')

8
bin/utils/whois

@ -0,0 +1,8 @@
local tArgs = { ... }
if #tArgs < 1 then
print("Usage: whois <name/id>")
return
end
os.loadAPI('/lib/cnt')
print(cnt.lookup(tArgs[1]))

1
etc/ftp.conf

@ -0,0 +1 @@
test

1
etc/resolv.conf

@ -0,0 +1 @@
3

BIN
lib/.cnt.swp

Binary file not shown.

15
lib/cnt

@ -0,0 +1,15 @@
function lookup (name)
local resolv = fs.open('/etc/resolv.conf','r')
local ns=tonumber(resolv.readLine())
local message=textutils.serialize({"CNT",name})
rednet.send(ns,message)
local senderId, reply, distance = rednet.receive()
local count = 0
while senderId ~= ns do
local senderId, reply, distance = rednet.receive()
end
local address=textutils.unserialize(reply)
return address[2]
end

37
lib/icp

@ -0,0 +1,37 @@
function send(dest, message)
if ~isnumber(dest) then
cnt.lookup(dest)
end
message=textUtil.serialize(os.getComputerId(),dest,message)
route(message)
end
rednet.send(
end
function syn
function acksyn
function ack
function receive
function join
function broadcast
function locate(host_id)
function route(message)
tmp=textUtil.unserialize(message)
dest = tmp[2]
next_hop=locate(dest)

6
misc/startup

@ -0,0 +1,6 @@
tSides = { "top","bottom","back","left","right","front" }
for i = 1,#tSides do
if peripheral.getType( tSides[i] ) == "modem" then
rednet.open( tSides[i] )
end
end
Loading…
Cancel
Save