Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Repeater
- function messageisnew()
- for ticn = 1, ticmemcounter do
- if timeandid == ticmem[ticn]
- then
- return false
- end
- end
- return true
- end
- function addtoticmem(newti)
- ticmemcounter = ticmemcounter + 1
- ticmem[ticmemcounter] = newti
- end
- function resetticmem()
- ticmemcounter = 0
- ticmem = {}
- os.setAlarm(0)
- end
- function skynetrepeater()
- resetticmem()
- while true do
- event, id, message = os.pullEvent()
- if event == "rednet_message"
- then
- if string.sub(message,1,8) == "[skynet]"
- then
- timeandid = string.sub(message,9,21) -- [TTTTTTIIIII]
- if messageisnew()
- then
- addtoticmem(timeandid)
- rednet.broadcast(message)
- end
- end
- elseif event == "alarm"
- then
- resetticmem()
- end
- end
- end
- --Sender
- function getticode()
- time = os.time()
- for n=1, 6 do
- if string.len(time) < n
- then time = time.."0"
- end
- end
- id = os.getComputerID()
- for n=1, 5 do
- if string.len(id) < n
- then id = "0"..id
- end
- end
- timeandidcode = ("["..time..id.."]")
- return timeandidcode
- end
- function gettargetid(targetidf)
- targetidf = tostring(targetidf)
- for tidlenc=1, 4 do
- if string.len(targetidf) == tidlenc
- then
- targetidf = ("0"..targetidf)
- end
- end
- targetidf = "["..targetidf.."]"
- return targetidf
- end
- function skynetsendmessage(message, targetid)
- if message and targetid then
- rednet.broadcast("[skynet]"..getticode()..gettargetid(targetid)..message) --[skynet][TTTTTTIIIII][IIIII]
- end
- end
- --Receiver
- function istargetid()
- targetid = tonumber(string.sub(skynettags,23,27))
- if targetid == os.getComputerID()
- then
- return true
- else
- return false
- end
- end
- function skynetreceivemessage()
- while true do
- event, id, message = os.pullEvent()
- if event == "rednet_message"
- then
- skynettags = string.sub(message,1,28)
- if string.sub(skynettags,1,8) == "[skynet]" then
- if istargetid() then
- message = string.sub(message,29)
- return message
- end
- end
- end
- end
- end
- function skyneteventmessage()
- while true do
- event, id, message = os.pullEvent()
- if event == "rednet_message"
- then
- skynettags = string.sub(message,1,28)
- if string.sub(skynettags,1,8) == "[skynet]" then
- if istargetid() then
- message = string.sub(message,29)
- return "skynet", message
- end
- end
- else
- return event, id, message
- end
- end
- end
Add Comment
Please, Sign In to add comment