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