MtnMCG

mtnlabs uplink

Sep 6th, 2024 (edited)
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. -- Uplink Program (No Interference with Slot Machine)
  2.  
  3. local modem = peripheral.find("modem")
  4. if not modem then error("No modem found. Please attach a wireless modem.") end
  5.  
  6. -- Set uplink channels (different from slot machine)
  7. local uplinkChannel = 2 -- Uplink uses channel 2 for communication
  8. local serverChannel = 1 -- Server communication on channel 1
  9. modem.open(uplinkChannel)
  10.  
  11. -- Function to relay messages between server and client without interference
  12. local function relayMessage()
  13. while true do
  14. local event, side, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  15.  
  16. -- Ensure we only process messages on the uplink channel
  17. if senderChannel == uplinkChannel then
  18. -- Forward the message to the server (relay)
  19. modem.transmit(serverChannel, uplinkChannel, message)
  20. elseif senderChannel == serverChannel then
  21. -- Forward the message back to the client (uplink to client)
  22. modem.transmit(uplinkChannel, serverChannel, message)
  23. end
  24. end
  25. end
  26.  
  27. -- Start message relay
  28. print("Uplink is active and relaying messages.")
  29. relayMessage()
  30.  
Advertisement
Add Comment
Please, Sign In to add comment