rednet.open("right")
rednet.open("left")
rednet.open("bottom")
rednet.open("top")
rednet.open("back")
rednet.open("front")
local channel = "";
local user = "";
local ip = os.computerID()
local x2,y2 = term.getCursorPos()
local channelID = 0;
local chatHistory = ""
local messages = 4;
local opmode = false;
local kkmode = false;
local isChatter = false;
local deopmode = false;
local oldUser = ""
local function cPrint(text)
local x,y = term.getSize()
x2,y2 = term.getCursorPos()
term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
write(text)
end
term.clear()
term.setCursorPos(1,1)
function status()
print("Status: " ..channel)
print("--------------------------------")
end
function chatbox()
local sizeX, sizeY = term.getSize()
term.clear()
term.setCursorPos(1,1)
status()
print("[" ..channel.. "] "..user.." joined the server!")
term.setCursorPos(1, sizeY)
term.setCursorBlink( true )
while true do
local e, pie, test = os.pullEvent()
if e == "rednet_message" then
if test == "pinged " ..channel then
rednet.send(pie, "hehehoohoohaha")
else
if(test == "["..channel.."] /op " ..user)then
oldUser = user
user = "@" .. user
isChatter = true
rednet.broadcast("*" ..user.. " is now OP!")
term.setCursorPos(1, messages)
messages = messages +1
print("You are now OP!")
elseif(test == "["..channel.."] /deop " ..user)then
rednet.broadcast("*" ..user.. " is no longer OP!")
user = oldUser
isChatter = false
term.setCursorPos(1, messages)
messages = messages +1
print("You are no longer OP!")
elseif(test == "["..channel.."] /kick " ..user)then
rednet.broadcast("*" ..user.. " left.")
menu()
elseif(test == "["..channel.."] /ls")then
rednet.send(pie, "[List:] " ..user)
end
local x,y = term.getSize()
if messages < y then
term.setCursorPos(1, messages)
messages = messages +1
print(test)
else
term.clear()
term.setCursorPos(1,1)
status()
messages = 3
term.setCursorPos(1, messages)
messages = messages +1
print(test)
end
end
elseif e == "char" then
local x,y = term.getSize()
term.setCursorPos(1, y)
chatHistory = chatHistory.. "" ..pie
term.clearLine()
write(chatHistory)
elseif e == "key" and pie == 28 or pie == 14 then
if pie == 14 then
chatHistory = string.sub( chatHistory, 1, 1 ) .. string.sub( chatHistory, 1 )
else
if pie == 28 then
if chatHistory == "/exit" then
rednet.broadcast("*" ..user.. " left.")
chatHistory = ""
menu()
elseif chatHistory == "/ping" then
term.setCursorPos(1, messages)
messages = messages +1
print("[" ..channel.. "] Pong")
elseif chatHistory == "/help" then
term.setCursorPos(1, messages)
messages = messages +1
if isChatter == true then
print("[" ..channel.. "] Commands: /help, /ping, /exit, /op, /kick, /ls")
else
print("[" ..channel.. "] Commands: /help, /ping, /exit, /ls")
end
else
if isChatter == true then
if opmode == true then
rednet.broadcast("["..channel.."] " ..chatHistory)
term.setCursorPos(1, messages)
messages = messages +1
print("["..channel.."] " ..chatHistory)
elseif kkmode == true then
rednet.broadcast("["..channel.."] " ..chatHistory)
term.setCursorPos(1, messages)
messages = messages +1
print("["..channel.."] " ..chatHistory)
elseif deopmode == true then
rednet.broadcast("["..channel.."] " ..chatHistory)
term.setCursorPos(1, messages)
messages = messages +1
print("["..channel.."] " ..chatHistory)
else
rednet.broadcast("[" ..user.. "] " ..chatHistory)
term.setCursorPos(1, messages)
messages = messages +1
print("[" ..user.. "] " ..chatHistory)
end
else
rednet.broadcast("<" ..user.. "> " ..chatHistory)
term.setCursorPos(1, messages)
messages = messages +1
print("<" ..user.. "> " ..chatHistory)
end
end
end
end
if chatHistory == "/ls" then
term.setCursorPos(1, messages)
messages = messages +1
print("[List:] " ..user)
rednet.broadcast("["..channel.."] /ls")
end
chatHistory = ""
local x,y = term.getSize()
term.setCursorPos(1, y)
term.clearLine()
opmode = false
kkmode = false
deopmode = false
elseif e == "key" and pie == 57 then
if chatHistory == "/op" or chatHistory == "/op " then
opmode = true
elseif chatHistory == "/kick" or chatHistory == "/kick " then
kkmode = true
elseif chatHistory == "/deop" or chatHistory == "/deop " then
deopmode = true
end
end
end
end
function connector()
term.clear()
term.setCursorPos(1,1)
status()
print("Logging in...")
print(user.. " ["..ip.."] logged in to N-IRC!")
print("Connecting to " ..channel.."...")
rednet.broadcast("pinged " ..channel)
id, message = rednet.receive(1)
if message == "hehehoohoohaha" then
print("Connected! Joining...")
rednet.broadcast("[" ..channel.. "] "..user.." joined the server!")
sleep(0.5)
channelID = id
chatbox()
else
print("Server not existing... Hosting")
print("Connected! Joining...")
isChatter = true
user = "@" ..user
rednet.broadcast("[" ..channel.. "] "..user.." joined the server!")
sleep(0.5)
channelID = id
chatbox()
end
end
function login()
term.clear()
term.setCursorPos(1,1)
cPrint("NeXuS IRC n")
cPrint("Nickname: ")
nick = read()
cPrint("Channel: #")
chan = read()
channel = "#" ..chan
user = nick
connector()
end
function menu()
term.clear()
term.setCursorPos(1,1)
cPrint("NeXuS IRC n n")
cPrint("1:) Loginn")
cPrint("2:) Exit n n")
cPrint("Selection: ")
input = read()
if input == "1" then
login()
elseif input == "2" then
else
menu()
end
end
menu()
Added a blinking cursor