Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sides = {"top", "bottom", "left", "right", "front", "back"}
- local cons = {}
- local serv = 0
- local hosting = false
- local tArgs = {...}
- local w, h = term.getSize()
- local input = ""
- local nick = ""
- local pinging = false
- pinged = {}
- local config = textutils.unserialize(tArgs[1])
- local function cprint(txt)
- term.setTextColor(config.colors.main)
- print(txt)
- term.setTextColor(config.colors.second)
- end
- local function cwrite(txt)
- term.setTextColor(config.colors.main)
- write(txt)
- term.setTextColor(config.colors.second)
- end
- local function loadInput()
- local cinp = input
- local limit = w-4
- if #cinp > limit then
- cinp = string.sub(cinp, #cinp-limit, #cinp)
- end
- term.setCursorPos(1, h)
- term.clearLine()
- cwrite("> ")
- write(cinp)
- end
- local function ports()
- for i,v in pairs(sides) do
- rednet.open(v)
- end
- end
- local function dot(name, txt)
- term.clearLine()
- term.scroll(1)
- term.setCursorPos(1, h-2)
- cwrite("["..name.."] ")
- write(txt)
- local x, y = term.getCursorPos()
- if y > h-2 then
- term.scroll(y-(h-2))
- end
- loadInput()
- end
- local function senda(name, txt)
- for i,v in pairs(cons) do
- rednet.send(i, textutils.serialize({name, txt}))
- end
- if txt ~= "PINGONONONPINGONONPINGONONPING2424523523" then
- dot(name, txt)
- end
- end
- local function sendp(vic, txt)
- if vic == os.getComputerID() then
- dot("Server", txt)
- else
- rednet.send(vic, textutils.serialize({"Server", txt}))
- end
- end
- local cmds = {
- ["nick"] = function(id, msg)
- cons[id] = msg
- sendp(id, "Changed nickname to '"..msg.."'")
- end;
- }
- local function checkc(id)
- local isf = nil
- for i,v in pairs(cons) do
- if v[1] == id then
- isf = v[2]
- end
- end
- return isf
- end
- local function doh(p1, p2)
- if string.sub(p2, 1, 4) == "IRC:" then
- p2 = string.sub(p2, 5)
- if not checkc(p1) then
- if string.sub(p2, 1, 5) == "JOIN:" then
- table.insert(cons, {p1, string.sub(p2, 6)})
- senda("Server", string.sub(p2, 6).." has joined.")
- end
- elseif string.sub(p2, 1, 1) == "/" then
- local dead = #p2+1
- for i = 1, #p2 do
- if string.sub(p2, i, i) == " " then
- dead = i
- end
- end
- for i,v in pairs(cmds) do
- if string.sub(p2, 2, dead-1) == i then
- v(p1, string.sub(p2, dead+1))
- end
- end
- elseif p2 == "PINGRESPONSE11234234BIDSFBsofnskifn(S*9e-r94thtrebgd" then
- table.insert(pinged, p1)
- else
- senda(checkc(p1), p2)
- end
- end
- end
- local function sendt(txt)
- if hosting == true then
- doh(os.getComputerID(), "IRC:"..txt)
- end
- rednet.send(serv, "IRC:"..txt)
- end
- local function pinga()
- senda("Server", "PINGONONONPINGONONPINGONONPING2424523523")
- pinging = true
- pinged = {os.getComputerID()}
- os.startTimer(1)
- end
- local rtbl = function(tbl, ind)
- for i = ind+1, #tbl do
- tbl[i-1] = tbl[i]
- end
- tbl[#tbl] = nil
- end
- local function getPings()
- pinging = false
- local i = 0
- for dsfsf = 1, #cons do
- i = i + 1
- local v = cons[i]
- local isp = false
- local lot = 0
- for tdgdfhdfh = 1, #pinged do
- lot = lot + 1
- if v[1] == pinged[lot] then
- isp = true
- rtbl(pinged, lot)
- lot = lot - 1
- end
- end
- if isp == false then
- senda("Server", v[2].." has left the server")
- rtbl(cons, i)
- i = i - 1
- end
- end
- pinged = {}
- end
- term.setBackgroundColor(config.colors.bg)
- term.clear()
- term.setCursorPos(1, 1)
- ports()
- cwrite("Server: ")
- serv = tonumber(read())
- if not serv then
- cprint("Invalid")
- return
- end
- if serv == os.getComputerID() then
- hosting = true
- cprint("Hosting")
- end
- cwrite("Nickame: ")
- nick = read()
- if hosting == true then
- table.insert(cons, {os.getComputerID(), nick})
- else
- sendt("JOIN:"..nick)
- end
- term.clear()
- term.setCursorPos(1, 1)
- loadInput()
- if hosting == true then
- pinga()
- end
- while true do
- term.setCursorBlink(true)
- local e, p1, p2 = os.pullEvent()
- if e == "char" then
- input = input..p1
- loadInput()
- elseif e == "key" then
- if p1 == keys.backspace then
- input = string.sub(input, 1, #input-1)
- loadInput()
- elseif p1 == keys.enter then
- sendt(input)
- input = ""
- loadInput()
- end
- elseif e == "rednet_message" then
- if p1 == serv then
- local tp = textutils.unserialize(p2)
- if tp[2] == "PINGONONONPINGONONPINGONONPING2424523523" then
- sendt("PINGRESPONSE11234234BIDSFBsofnskifn(S*9e-r94thtrebgd")
- else
- dot(tp[1], tp[2])
- end
- end
- if hosting == true then
- doh(p1, p2)
- end
- elseif e == "timer" then
- -- getPings()
- -- pinga()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement