Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Coded by LoneWolf with some help ]]--
- --[[ Chat PC ]]--
- shell.run("clear")
- if fs.exists("ChatSettings/Settings") then
- dofile("ChatSettings/Settings")
- else
- write("Your screen name: ")
- Person = io.read()
- fs.makeDir("ChatSettings")
- local WriteSettings = io.open("/ChatSettings/Settings","w")
- WriteSettings:write("\nPerson = "..[["]]..Person..[["]])
- WriteSettings:close()
- shell.run("clear")
- end
- X,Y = term.getSize()
- Host = "a"
- function openRednet()
- for _,side in ipairs(rs.getSides()) do
- if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
- rednet.open(side)
- return side
- end
- end
- error("No modem attached")
- end
- openRednet()
- function tag(tag)
- return "["..tag.."]"
- end
- function tagView(msg)
- local ReturnMsg = msg
- local ReturnTag = {}
- if string.find(ReturnMsg, "%[") and string.find(ReturnMsg, "%]") then
- while true do
- first = string.find(ReturnMsg, "%[", 1)
- last = string.find(ReturnMsg, "%]", 2)
- if first and last then ReturnTag[#ReturnTag+1] = string.sub(ReturnMsg, first+1, last-1)
- ReturnMsg = string.sub(ReturnMsg, last+1, string.len(msg))
- else
- break
- end
- end
- ReturnTag[#ReturnTag+1] = ReturnMsg
- return unpack(ReturnTag)
- else
- return false
- end
- end
- local ChatInput = ""
- function Clear()
- term.setCursorPos(1,1)
- term.clear()
- end
- Clear()
- print("Now searching for a IRC network")
- rednet.broadcast("Zero Zero Two Nine'r looking for network. Over")
- End = os.startTimer(1)
- Servers = {}
- n = 0
- function Same(para)
- for n=1,#Servers do
- if tagView(Servers[n]) == para then
- return true
- end
- end
- return false
- end
- while true do
- event,param1,param2 = os.pullEvent()
- if param2 then Name, Confirm = tagView(param2) end
- if not Confirm then
- Confirm = ""
- end
- if event == "rednet_message" and Confirm == "We receive and we confirm. Over" then
- if not Same(Name) then
- Servers[#Servers+1] = tag(Name)..param1
- n = n+1
- term.setCursorPos(1,2)
- print(n.." servers has been found")
- end
- elseif event == "timer" and param1 == End then
- break
- end
- end
- n=nil
- if Servers[1] then
- Clear()
- for n=1,#Servers do
- local x,y = term.getCursorPos()
- if y == Y then
- print("Press spacebar")
- while true do
- event,param1 = os.pullEvent()
- if event == "key" and param1 == 57 then
- term.clearLine()
- local Name, ID = Servers[n]
- print("Server: "..Name)
- break
- end
- end
- else
- local Name, ID = tagView(Servers[n])
- print("Server: "..Name)
- end
- end
- write("Choose server: ")
- ServerName = read()
- for n=1,#Servers do
- local Name, ID = tagView(Servers[n])
- if Name == ServerName then
- Host = tonumber(ID)
- elseif string.lower(Name) == string.lower(ServerName) then
- Host = tonumber(ID)
- end
- end
- if Host == "a" then
- Clear()
- print("Server name isnt found!")
- error()
- else
- rednet.send(Host, tag("You are the chosen one")..Person)
- end
- else
- print("Network cannot be found")
- error()
- end
- typex = 1
- Clear()
- print("** You are running LibChat 1.0")
- curx, cury = 1, 2
- term.setCursorPos(1, Y)
- term.setCursorBlink(true)
- Returned = true
- function Ping()
- if Returned == true then
- rednet.send(Host, "Ping")
- Returned = false
- Pingo = os.startTimer(1.5)
- return true
- else
- return false
- end
- end
- Ping()
- function Commands(commanda)
- command = string.lower(commanda)
- if command == "/ping" then
- rednet.send(Host, "Pinger!")
- elseif command == "/players" then
- rednet.send(Host, "Players?")
- elseif command == "/quit" then
- Clear()
- print("You have quit IRC")
- error()
- elseif string.sub(command, 1, 4) == "/me " then
- rednet.send(Host, tag(os.clock()..os.getComputerID())..tag("LibChatServer").."* "..Person.." "..string.sub(commanda, 5))
- elseif string.sub(command, 1, 6) == "/nick " and string.gsub(string.sub(commanda, 7), " ", "") ~= "" and string.len(string.gsub(string.sub(commanda, 7), " ", "")) < 15 then
- rednet.send(Host, tag(os.time()..os.getComputerID())..tag("NickChange")..tag(Person)..string.sub(commanda, 7))
- Person = string.sub(commanda, 7)
- local WriteSettings = io.open("/ChatSettings/Settings","w")
- WriteSettings:write("\nPerson = "..[["]]..Person..[["]])
- WriteSettings:close()
- elseif command == "/help" then
- Print("Commands: /nick <nick>, /quit, /ping, /players, /help")
- else
- Print("** Unknown command")
- end
- end
- function Print(thing)
- term.setCursorPos(curx, cury)
- thing = string.gsub(thing, "!LeftBracket!", "%]")
- thing = string.gsub(thing, "!RightBracket!", "%[")
- local x = "Derp"
- if cury <= Y then
- print(thing)
- x,cury = term.getCursorPos()
- else
- term.scroll(1)
- cury = cury-1
- term.setCursorPos(curx,cury)
- print(thing)
- end
- local x,y = term.getCursorPos()
- term.setCursorPos(typex,Y)
- end
- while true do
- event, param1, param2 = os.pullEvent()
- if event == "rednet_message" and param1 == Host then
- RedOne, RedTwo = tagView(param2)
- if RedOne == "LibChat" then -- Display MSG time!
- Print(RedTwo)
- elseif param2 == "Ping" then
- rednet.send(Host, "Pong")
- elseif param2 == "Pong" and param1 == Host then
- Returned = true
- end
- elseif event == "char" then -- Typing
- if string.len(ChatInput) < X-1 then
- local x,y = term.getCursorPos()
- term.setCursorPos(1,Y)
- ChatInput = ChatInput..param1
- term.clearLine()
- write(ChatInput)
- if typex < X then
- typex = typex+1
- end
- term.setCursorPos(typex,Y)
- end
- elseif event == "key" and param1 == 28 then -- Enter
- if string.gsub(ChatInput, " ", "") ~= "" then
- if string.sub(ChatInput, 1, 1) == "/" then
- Commands(ChatInput)
- else
- ChatInput = string.gsub(ChatInput, "%]", "!LeftBracket!")
- ChatInput = string.gsub(ChatInput, "%[", "!RightBracket!")
- rednet.send(Host, tag(os.clock()..os.getComputerID())..tag("LibChatServer")..Person..": "..ChatInput)
- end
- term.setCursorPos(curx, cury)
- local x,y = term.getCursorPos()
- term.setCursorPos(1,Y)
- term.clearLine()
- typex = 1
- ChatInput = ""
- term.setCursorPos(typex,Y)
- end
- elseif event == "key" and param1 == 14 then -- Backspace
- term.setCursorPos(curx, cury)
- ChatInput = string.sub(ChatInput, 1, -2)
- local x,y = term.getCursorPos()
- term.setCursorPos(1,Y)
- term.clearLine()
- write(ChatInput)
- if typex > 1 then
- typex = typex-1
- end
- term.setCursorPos(typex,Y)
- elseif event == "timer" and param1 == Pingo then
- if not Ping() then
- term.setCursorPos(curx, cury)
- print("Client has lost connection to the server")
- break
- end
- end
- end
Add Comment
Please, Sign In to add comment