Here is the sourcecode for those who are interested:
IRCserver
SERVER = os.getComputerID()
nick = {}
channel = {}
--initialize names 1 to 128
for i=1,128 do
nick[i]="&new"
channel[i]="&new"
end
nick[SERVER] = "SERVER"
channel[SERVER] = "VIP LOUNGE"
function getUserId(str)
for i=1,128 do
if nick[i] == str then
return i
end
end
return nil
end
function listUsers(id)
p(id,"@ircOnline Users:")
for i=1,128 do
if nick[i]~="&new" and i~=SERVER then
p(id,"@irc -".. nick[i] .. " " .. channel[i])
end
end
end
function compare(str)
return string.find(message, str)
end
function newline()
mon.scroll(1)
mon.setCursorPos(1,20)
end
function post(str)
newline()
mon.write("<IRC>".. channel[senderId])
mon.setCursorPos(16,20)
mon.write(str)
chan = channel[senderId]
for i=1,128 do
if channel[i] == chan then
rednet.send(i,"@irc" .. str)
end
end
end
function addTime()
return "[" .. textutils.formatTime(os.time(),true) .. "]"
end
function postPrivate(receiver,str)
if getUserId(receiver) then
rednet.send(getUserId(receiver), "@irc".. addTime() .."<msg from ".. nick[senderId].. ">" .. str)
newline()
mon.write(addTime() .. "(msg " .. nick[senderId] .. " > " .. receiver .. ")" .. str)
else
rednet.send(senderId,"@ircUser " .. receiver .. " does not exist")
end
end
function p(i,str)
rednet.send(i,str)
end
function sendHelp(i)
p(i,"@irc--commands:------------")
p(i,"@irc /join channel -- joins the channel. example: /join #minecraft")
p(i,"@irc message -- sends plain text to the channel you're on")
p(i,"@irc /nick name -- changes your nickname. limited to 16 characters.")
--p(i,"@irc /msg receiver message -- sends a private message to 'receiver'")
p(i,"@irc /quit message -- quits IRC with a message")
end
rednet.open("left")
mon = peripheral.wrap("top")
mon.clear()
newline()
mon.write("IRC server software Alpha 1.0")
newline()
mon.write("Booting up server!")
rednet.announce()
repeat
senderId, message, distance = rednet.receive(1)
if senderId and string.len(message)>1 then
if nick[senderId]~="&new" or compare("/nick ")==1 then
if compare("/")==1 then
if compare("/join ")==1 and string.len(message)<=23 and string.len(message)>=1 and compare(" #")==6 then
channel[senderId]=string.sub(message, 7)
post(addTime() .. "*" .. nick[senderId] .. " has joined " .. channel[senderId])
elseif compare("/me ")==1 then
post(addTime() .. "*" .. nick[senderId] .. " " .. string.sub(message, 5) .. "*")
elseif compare("/nick ")==1 then
local oldnick= nick[senderId]
if string.sub(message,7,23)~="&new" then
nick[senderId] = string.sub(message, 7, 23)
if nick~=oldnick and oldnick~="&new" then
post(addTime() .. oldnick .. " changed his nickname to " .. nick[senderId])
end
end
elseif compare("/help")==1 then
sendHelp(senderId)
newline()
mon.write(addTime() .. nick[senderId] .. " requested help.")
elseif compare("/msg ")==1 then
msgStart = string.find(string.sub(message,6)," ")
if msgStart>1 then
postPrivate(string.sub(message,6,msgStart-1),string.sub(message,msgStart))
end
elseif compare("/quit ")==1 or compare("/quit") then
if nick[senderId]~="&new" then
post(addTime() .. "*".. nick[senderId] .. " has quit IRC (" .. string.sub(message,7) .. ")")
nick[senderId]="&new"
end
elseif compare("/who")==1 then
listUsers(userId)
end
else
post(addTime().. "<" .. nick[senderId] .. "> " .. message)
end
else
p(senderId,"@ircYou are not connected to IRC! type /join #irc")
end
end
until redstone.getInput("front")
rednet.close("left")
term.clear()
term.setCursorPos(1,1)
term.write("Closed Server!")
newline()
mon.write(addTime() .. "Closed Server!")
term.setCursorPos(1,2)
IRCclient
Note: Change SERVER = 29 to the ID of the server computer.
SERVER = 29
breakfree = false
function newline()
term.scroll(1)
term.setCursorPos(1,12)
end
function put(str)
newline()
term.write(str)
end
rednet.open("left")
rednet.announce()
function enterNick()
term.clear()
term.setCursorPos(1,1)
print("Enter nickname:")
username = read()
if string.len(username) and string.len(username)<=16 then
rednet.send(SERVER,"/nick " .. username)
rednet.send(SERVER,"/join #IRC")
return 0
else
return enterNick()
end
end
enterNick()
function1 = function()
while true do
local senderId, message, distance = rednet.receive(1)
if senderId and string.find(message,"@irc")==1 then
local x,y = term.getCursorPos()
put(string.sub(message,5))
term.setCursorPos(x,y)
end
if redstone.getInput("front") then
breakfree = true
return
end
end
end
function2 = function()
term.setCursorPos(1,14)
local message = read()
if string.find(message,"/quit")==1 then
breakfree=true
end
rednet.send(SERVER,message)
term.setCursorPos(1,14)
term.write(" ")
end
while not breakfree do
parallel.waitForAny(function1,function2)
end
rednet.send(SERVER, "/quit Client")
rednet.close("left")
I typed and debugged all of this using the ingame editor. It really sucks there are no linenumbers.
Edit: There is just one glitch: You can join with a name that is taken, so for instance when Keoni29 is on the IRC another guy can impersonate me by joining with the same nickname. It's probably quite easy to fix, but I leave that to someone else. I have had enough of the tekkit lua programming.