Advertisement
Nikitos228

вышка инетная

Aug 26th, 2020
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local term = require("term")
  4. local modem = component.modem
  5.  
  6. local RECEIVE_PORT = 13
  7. local BROADCAST_STATION_PORT = 17
  8. local RAID_ID = "77e"
  9.  
  10. modem.open(RECEIVE_PORT)
  11. modem.open(BROADCAST_STATION_PORT)
  12.  
  13. term.clear()
  14.  
  15. print("[SERVER]: Сервер запущен.")
  16.  
  17. local function handler()
  18. local packet = {event.pull("modem_message")}
  19. if packet[4] == RECEIVE_PORT then
  20. print("[SERVER]: Получен запрос от клиента. IP: " .. packet[3] .. ".")
  21. local handle = io.open("/mnt/" .. RAID_ID .. "/connection.log", "a")
  22. handle:write("[TA]: " .. packet[6] .. " | [TP]: " .. packet[7] .. " | [SA]: " .. packet[3] .. " | [SP]: " .. packet[8] .. " | [DATA]: " .. packet[9] .. "\n")
  23. handle:flush()
  24. handle:close()
  25. modem.send(packet[6], packet[7], packet[3], packet[8], packet[9])
  26. modem.broadcast(BROADCAST_STATION_PORT, packet[6], packet[7], packet[3], packet[8], packet[9])
  27. end
  28. if packet[4] == BROADCAST_STATION_PORT then
  29. modem.send(packet[6], packet[7], packet[8], packet[9], packet[10])
  30. end
  31. end
  32.  
  33. while true do
  34. pcall(handler)
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement