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