SHOW:
|
|
- or go back to the newest paste.
| 1 | rednet.open("right")
| |
| 2 | rednet.open("left")
| |
| 3 | rednet.open("bottom")
| |
| 4 | rednet.open("top")
| |
| 5 | rednet.open("back")
| |
| 6 | rednet.open("front")
| |
| 7 | ||
| 8 | local channel = ""; | |
| 9 | local user = ""; | |
| 10 | local ip = os.computerID() | |
| 11 | local x2,y2 = term.getCursorPos() | |
| 12 | local channelID = 0; | |
| 13 | local chatHistory = "" | |
| 14 | local messages = 4; | |
| 15 | local function cPrint(text) | |
| 16 | local x,y = term.getSize() | |
| 17 | x2,y2 = term.getCursorPos() | |
| 18 | term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2) | |
| 19 | write(text) | |
| 20 | end | |
| 21 | ||
| 22 | term.clear() | |
| 23 | term.setCursorPos(1,1) | |
| 24 | ||
| 25 | function status() | |
| 26 | print("Status: " ..channel)
| |
| 27 | print("--------------------------------")
| |
| 28 | end | |
| 29 | ||
| 30 | function chatbox() | |
| 31 | term.clear() | |
| 32 | term.setCursorPos(1,1) | |
| 33 | status() | |
| 34 | print("[" ..channel.. "] "..user.." joined the server!")
| |
| 35 | while true do | |
| 36 | local e, pie = os.pullEvent() | |
| 37 | if e == "rednet_message" then | |
| 38 | if pie == channel then | |
| 39 | rednet.send(pie, "hehehoohoohaha") | |
| 40 | else | |
| 41 | term.setCursorPos(1, messages) | |
| 42 | messages = messages +1 | |
| 43 | end | |
| 44 | elseif e == "char" then | |
| 45 | local x,y = term.getSize() | |
| 46 | term.setCursorPos(1, y) | |
| 47 | chatHistory = chatHistory.. "" ..pie | |
| 48 | term.clearLine() | |
| 49 | write(chatHistory) | |
| 50 | elseif e == "key" and pie == 28 then | |
| 51 | rednet.send(channelID, "<" ..user.. "> " ..chatHistory) | |
| 52 | term.setCursorPos(1, messages) | |
| 53 | messages = messages +1 | |
| 54 | print("<" ..user.. "> " ..chatHistory)
| |
| 55 | chatHistory = "" | |
| 56 | local x,y = term.getSize() | |
| 57 | term.setCursorPos(1, y) | |
| 58 | term.clearLine() | |
| 59 | end | |
| 60 | end | |
| 61 | end | |
| 62 | ||
| 63 | function connector() | |
| 64 | term.clear() | |
| 65 | term.setCursorPos(1,1) | |
| 66 | status() | |
| 67 | print("Logging in...")
| |
| 68 | print(user.. " ["..ip.."] logged in to N-IRC!") | |
| 69 | print("Connecting to " ..channel.."...")
| |
| 70 | rednet.broadcast(channel) | |
| 71 | id, message = rednet.receive(1) | |
| 72 | print("Connected! Joining...")
| |
| 73 | rednet.send(id, "[" ..channel.. "] "..user.." joined the server!") | |
| 74 | sleep(0.5) | |
| 75 | channelID = id | |
| 76 | chatbox() | |
| 77 | end | |
| 78 | ||
| 79 | function login() | |
| 80 | term.clear() | |
| 81 | term.setCursorPos(1,1) | |
| 82 | cPrint("NeXuS IRC \n")
| |
| 83 | cPrint("Nickname: ")
| |
| 84 | nick = read() | |
| 85 | cPrint("Channel: #")
| |
| 86 | chan = read() | |
| 87 | ||
| 88 | channel = "#" ..chan | |
| 89 | user = nick | |
| 90 | connector() | |
| 91 | end | |
| 92 | ||
| 93 | login() |