Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Unnamed message forwarding
- --This is WTFPL, just change the name, OK?
- --Version 1.0 - this means it's the most broken yet
- --I commented out all they annoying text outputs. You people love me.
- local component = require "component"
- local event = require "event"
- local text = require "text"
- local shell = require "shell"
- local modem = component.modem
- tape = component.tape_drive
- local modemPower = 100
- local nodeAddr = "derp" -- Change this. This is what other nodes will address you as
- local storedMessages = 0
- local function tape_rezero()
- tape.seek(0-tape.getSize())
- end
- local function extractPath(path)
- return path:sub(1,path:find("!")-1), path:sub(path:find("!")+1,path:len())
- end
- local function idCheck(addr) -- I don't even use this... I should probably remove it
- local n = 0
- repeat
- n = n + 1
- --print(tConnections[n])
- until tConnections[n] == addr or tConnections[n] == nil
- if tConnections[n] == addr then
- --print(n..":"..addr)
- return true
- end
- end
- function recvMsg(name,user,message) --This is what happens when you get a message for a user on your system
- end
- local function sks_send(path,retPath,name,user,message)
- local toAddr, contPath = extractPath(path)
- modem.broadcast(42,toAddr,contPath,retPath,name,user,message)
- end
- local function store(path,retPath,name,user,message)
- tape.write(path:len())
- tape.write(path)
- --print(path)
- tape.write(retPath:len())
- tape.write(retPath)
- --print(retPath)
- tape.write(name:len())
- tape.write(name)
- --print(name)
- tape.write(user:len())
- tape.write(user)
- --print(user)
- tape.write(message:len())
- tape.write(message)
- --print(message)
- storedMessages = storedMessages + 1
- --print "Message stored! Will be sent soon." --This function really hurt to look at...
- end
- function msgListener(_,_,from,port,_,toAddr,path,retPath,name,user,message)
- print(from)
- if port == 42 and path ~= nodeAddr and toAddr == nodeAddr then
- store(path,retPath,name,user,message)
- elseif port == 42 and path == nodeAddr and toAddr == nodeAddr then
- recvMsg(name,user,message)
- end
- end
- local function sendTimer()
- tape_rezero()
- --print "Send timer activated"
- if storedMessages > 0 then
- repeat
- local path = tape.read(tape.read())
- local retPath = tape.read(tape.read())
- local name = tape.read(tape.read())
- local user = tape.read(tape.read())
- local message = tape.read(tape.read())
- sks_send(path,retPath,name,user,message)
- storedMessages = storedMessages - 1
- until storedMessages == 0
- --print "Messages sent!"
- else
- --print "No messages sent!"
- end
- end
- local function setup()
- modem.open(42)
- modem.setStrength(100)
- event.listen("modem_message",msgListener)
- event.timer(30,sendTimer,math.huge) --Changing the 30 will change the delay between buffer cleaning, short time was for testing,
- sendTimer() -- You'd get away with once every few days on a low traffic node, but on a big node, you'd have to do it every few
- end -- seconds or you'd lose messages. I doubt one will ever get to that point though. Prove me wrong!
- setup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement