Advertisement
1lann

Rednet Spam Monitor Node

Aug 10th, 2014
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | None | 0 0
  1. local pos = {5275, 69, 2162}
  2. local operatingChannel = 26743
  3.  
  4. local messageList = {}
  5.  
  6. local modem = nil
  7. for k,v in pairs(rs.getSides()) do
  8.     if peripheral.getType(v) == "modem" then
  9.         modem = peripheral.wrap(v)
  10.         break
  11.     end
  12. end
  13.  
  14. if not modem then
  15.     print("No modem found!")
  16.     return
  17. end
  18.  
  19. modem.open(operatingChannel)
  20. modem.open(rednet.CHANNEL_REPEAT)
  21. modem.open(gps.CHANNEL_GPS)
  22.  
  23. local getDistance = function(id)
  24.     for k,v in pairs(messageList) do
  25.         if v.id == id then
  26.             return v.dist
  27.         end
  28.     end
  29.     return false
  30. end
  31.  
  32. print("Running Rednet Spam Locator Node")
  33. print("At position: "..pos[1]..", "..pos[2]..", "..pos[3])
  34.  
  35. while true do
  36.     local event, side, channel, reply, message, dist = os.pullEvent()
  37.     if event == "modem_message" and channel == rednet.CHANNEL_REPEAT and type(message) == "table" then
  38.         if message.nMessageID and message.nRecipient and not getDistance(message.nMessageID) then
  39.             table.insert(messageList, {dist = dist, id = message.nMessageID})
  40.             if #messageList > 200 then
  41.                 table.remove(messageList, 1)
  42.             end
  43.         end
  44.     elseif event == "modem_message" and type(message) == "table" and message.ddosMonitor then
  45.         if message.ddosMonitor == "request" and message.messageID then
  46.             local dist = getDistance(message.messageID)
  47.             if dist then
  48.                 modem.transmit(operatingChannel, operatingChannel, {x = pos[1], y = pos[2], z = pos[3], dist = dist,
  49.                 id = message.messageID, ddosMonitor = "response"})
  50.             end
  51.         end
  52.     elseif event == "modem_message" and channel == gps.CHANNEL_GPS and message == "PING" then
  53.         modem.transmit(reply, gps.CHANNEL_GPS, {pos[1], pos[2], pos[3]})
  54.     end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement