View difference between Paste ID: 0s3EiBgk and epe5zAez
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()
36+
		local e, pie, test = 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
				print(test)
44
			end
45
		elseif e == "char" then
46
			local x,y = term.getSize()
47
			term.setCursorPos(1, y)
48
			chatHistory = chatHistory.. "" ..pie
49
			term.clearLine()
50
			write(chatHistory)
51
		elseif e == "key" and pie == 28 then
52
			rednet.send(channelID, "<" ..user.. "> " ..chatHistory)
53
			term.setCursorPos(1, messages)
54
			messages = messages +1
55
			print("<" ..user.. "> " ..chatHistory)
56
			chatHistory = ""
57
			local x,y = term.getSize()
58
			term.setCursorPos(1, y)
59
			term.clearLine()
60
		end
61
	end
62
end
63
64
function connector()
65
	term.clear()
66
	term.setCursorPos(1,1)
67
	status()
68
	print("Logging in...")
69
	print(user.. " ["..ip.."] logged in to N-IRC!")
70
	print("Connecting to " ..channel.."...")
71
	rednet.broadcast(channel)
72
	id, message = rednet.receive(1)
73
	print("Connected! Joining...")
74
	rednet.send(id, "[" ..channel.. "] "..user.." joined the server!")
75
	sleep(0.5)
76
	channelID = id
77
	chatbox()
78
end
79
80
function login()
81
	term.clear()
82
	term.setCursorPos(1,1)
83
	cPrint("NeXuS IRC \n")
84
	cPrint("Nickname: ")
85
	nick = read()
86
	cPrint("Channel: #")
87
	chan = read()
88
	
89
	channel = "#" ..chan
90
	user = nick
91
	connector()
92
end
93
94
login()