Advertisement
Guest User

Untitled

a guest
Mar 10th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. --requires
  2. local component = require("component")
  3. local event = require("event")
  4. local modem = component.modem
  5.  
  6. --port
  7. local chatPort = 312
  8.  
  9. modem.open(chatPort)
  10.  
  11. --listen
  12. function doListen(localAddress, remoteAddress, port, distance, message)
  13.     if(port ~= chatPort) then return end
  14.     print(message)
  15. end
  16.  
  17. --intro / input
  18. io.write("Welcome to GlobalChat!\nEnter a nickname: ")
  19. local nickname = io.read()
  20.  
  21. io.write("Welcome, "..nickname..", you are now chatting with everyone else running this program(type /quit to exit).\n")
  22.  
  23. event.listen("modem_message", doListen)
  24.  
  25. modem.broadcast(chatPort, nickname .." has joined!")
  26. while true do
  27.     local msg = io.read()
  28.     if(msg == "/quit") then
  29.         modem.broadcast(chatPort, nickname .." has quit!")
  30.         break
  31.     end
  32.     modem.broadcast(chatPort, nickname ..": "..msg)
  33. end
  34. event.ignore("modem_message", doListen)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement