Marlingaming

Network Message Receiver

Apr 1st, 2022 (edited)
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. local modem = peripheral.find("modem") or error("No modem attached", 0)
  2. modem.open(8)
  3.  
  4. function Listen()
  5. while true do
  6. local event, a, b, c, d, e, f, g = os.pullEvent()
  7. local Res
  8. local MSG
  9. if event == "rednet_message" then
  10. Res = CheckProtocols(a)
  11. elseif event == "modem_message" then
  12. MSG = CheckAuthority(2)
  13. end
  14.  
  15. if Res ~= nil then ShareMessage(Res,b) elseif MSG ~= nil then SysMSG(d) else os.queueEvent("pass") end
  16. end
  17. end
  18.  
  19. function ShareMessages(Program,message)
  20. shell.run(Program,"message",message)
  21. end
  22.  
  23. function SysMSG(message)
  24. if string.find(message,"Alert.") then
  25. os.queueEvent("system_notification","network message",string.sub(message,7,string.len(message)))
  26. else
  27. shell.run(string.sub(message,1,string.find("_")-1),"direct_message",string.sub(message,string.find(message,"_")+1,string.len(message)))
  28. end
  29. end
  30.  
  31. function CheckProtocols(protocol)
  32. local Pro
  33. local Content
  34. local file = fs.open("os/Files/ProgramNetworkProtocols.txt","r")
  35. repeat
  36. Content = file.readLine()
  37. if Content ~= nil and string.find(Content,protocol) then Pro = string.sub(Content,1,string.find(Content,"=") - 1) end
  38. until Content == nil
  39. file.close()
  40. if Pro ~= nil then return Pro else return false end
  41. end
  42.  
  43. function CheckAuthority(channel)
  44. if channel == 8 then
  45. return true
  46. end
  47. end
  48.  
  49. Listen()
  50.  
Add Comment
Please, Sign In to add comment