Advertisement
Guest User

chat

a guest
Oct 31st, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.16 KB | None | 0 0
  1. local args = {...}
  2. local m = peripheral.find("modem") -- Yay for CC1.6
  3. local flines = {}
  4. local   nick = "Luca"
  5. local x, y = term.getSize()
  6.  
  7. local f = fs.open(args[1],"r")
  8.  
  9. for fline in f.readLine do
  10.   flines[#flines+1] = fline
  11. end
  12.  
  13. term.clear()
  14. term.setCursorPos(1,1)
  15.  
  16. print("Welcome to Chat!")
  17. print("IDs im Chatraum:")
  18.  
  19. for i = 1,#flines do
  20.     print(flines[i])
  21.     m.open(tonumber(flines[i]))
  22. end
  23.  
  24. sleep(3)
  25. term.clear()
  26. local line = 1
  27. local msg = ""
  28.  
  29. while true do
  30.     term.setCursorPos(1, y)
  31.     term.clearLine()
  32.     write("Message:"..msg)
  33.  
  34.     local e = {os.pullEvent()}
  35.     if e[1] == "char" then
  36.         msg = msg..e[2]
  37.  
  38.     elseif e[1] == "modem_message" then
  39.         if line == y -1 then
  40.             term.clear()
  41.             line = 1
  42.         end
  43.         term.setCursorPos(1, line)
  44.         print(e[5])
  45.         line = line + 1
  46.  
  47.     elseif e[1] == "key" then
  48.         if e[2] == 14 then
  49.             term.setCursorPos(1,1)
  50.             msg = msg:sub(0,#msg-1)
  51.         end
  52.         if e[2] == 28 then
  53.             msg = "<"..nick..">"..msg
  54.             if line == y -1 then
  55.                 term.clear()
  56.                 line = 1
  57.             end
  58.             term.setCursorPos(1, line)
  59.             print(msg)
  60.             line = line + 1
  61.             m.transmit(os.getComputerID(),os.getComputerID(),msg)
  62.             msg = ""
  63.         end
  64.     end
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement