Advertisement
urielsalis

Untitled

Apr 1st, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. args = {...}
  2. function detectRedstone()
  3. while true do
  4. if rs.getInput(line) or rs.getInput(line2) then tr = "redstone" end
  5. sleep(0)
  6. end
  7. end
  8. function detectTimer()
  9. sleep(0)
  10. while true do
  11. os.pullEvent("key")
  12. tr = "timer"
  13. end
  14. end
  15. line = "back"
  16. line2 = "front"
  17. function send(filename)
  18. file = fs.open(filename, "rb")
  19. binary = ""
  20. while true do
  21. local a = file.read()
  22. if not a then break end
  23. binary = binary..a
  24. end
  25. file.close()
  26. for i=1, #binary do
  27. local str = binary:sub(i,i)
  28. if str=="1" then
  29. rs.setOutput(line, true)
  30. sleep(0.1)
  31. rs.setOutput(line, false)
  32. else
  33. rs.setOutput(line2, true)
  34. sleep(0.1)
  35. rs.setOutput(line2, false)
  36. end
  37. end
  38. end
  39. function mainreceive()
  40. file = ""
  41. while true do
  42. if tr=="" then
  43. sleep(0)
  44. else
  45. if tr=="timer" then break end
  46. if rs.getInput(line) then
  47. file = file.."1"
  48. print("1")
  49. end
  50. if rs.getInput(line2) then
  51. file = file.."0"
  52. print("0")
  53. end
  54. end
  55. tr = ""
  56. end
  57. end
  58. function receive(filename)
  59. print("Press any key to save the file")
  60. print("Receiving...")
  61. parallel.waitForAny(detectTimer, detectRedstone, mainreceive)
  62. print("breaked")
  63. f = fs.open(filename, "wb")
  64. print("Writing to file")
  65. for i=1, #file do
  66. print("x")
  67. local a = file:sub(i, i)
  68. f.write(tonumber(a))
  69. sleep(0)
  70. end
  71. f.close()
  72. end
  73. if #args==2 then
  74. if args[1]=="-send" then
  75. send(args[2])
  76. else
  77. receive(args[2])
  78. end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement