Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Copyright 2015 Max Thor <thormax5@gmail.com>
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ]]--
- for k,v in ipairs(rs.getSides()) do
- if(peripheral.getType(v) == "modem") then
- modem = peripheral.wrap(v)
- end
- end
- local msg = ""
- local name = ""
- local cmd = ""
- local args
- local w,h = term.getSize()
- local debug = true
- local channel = 1
- local chans = {"1", "2", "3"}
- local cmds = {
- ["me"] = {
- ["does"] = function(args)
- send('* '..name..' '..args)
- end
- },
- ["nick"] = {
- ["does"] = function(nc)
- send(name..' is now known as '..nc)
- name=nc
- end
- },
- ["server"] = {
- ["does"] = function(args)
- term.setCursorPos(1, 5)
- print(args)
- channel = tonumber(args[1])
- for k, v in pairs(chans) do
- if v == args[1] then
- else
- table.insert(chans, args[1])
- end
- end
- --term.clear()
- --line()
- end
- },
- ["debug"] = {
- ["does"] = function(args)
- if debug then
- print(loadstring(args))
- end
- end
- }
- }
- local history = {}
- function gui()
- term.clear()
- term.setCursorPos(1,1)
- paintutils.drawLine(1, 1, w, 1, colors.red)
- term.setCursorPos(1,1)
- print(name)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1, h);
- end
- function line()
- x = name:len()+1
- term.setCursorPos(1,1)
- paintutils.drawLine(1, 1, w, 1, colors.red)
- term.setCursorPos(1,1)
- print(name)
- term.setBackgroundColor(colors.red)
- term.setCursorPos(1, h)
- for k, v in pairs(chans) do
- x = x+2
- term.setCursorPos(x, 1)
- if(tonumber(v) == channel) then
- term.setBackgroundColor(colors.cyan)
- write(v)
- term.setBackgroundColor(colors.red)
- else
- write(v)
- end
- end
- term.setBackgroundColor(colors.black)
- end
- function initConf()
- modem.open(channel)
- gui()
- end
- function send(msg)
- modem.transmit(channel,channel,msg)
- end
- function input()
- while true do
- _, p1 = os.pullEvent("key")
- if(p1 == 28) then
- local inp = read()
- line()
- term.setCursorPos(1, h-1)
- term.clearLine()
- local cmd,args = inp:match("^/(%w+)%s*(.-)$")
- if cmd then
- if(cmds[cmd]) then
- cmds[cmd]['does'](args)
- else
- print("Unknown command: "..cmd)
- end
- else
- send("<"..name.."> "..inp)
- term.clearLine()
- print("<"..name.."> "..inp)
- end
- end
- end
- end
- function chat()
- while true do
- e, p1, p2, p3, p4 = os.pullEventRaw()
- if(e == "modem_message") then
- if(p2 == channel) then
- --line()
- print(p4)
- line()
- end
- elseif(e == "terminate") then
- send(name.." has left")
- end
- end
- end
- function init()
- term.clear()
- term.setCursorPos(1,1)
- print("Chatty")
- write("Name > ")
- name = read()
- initConf()
- send(name.." has joined!")
- parallel.waitForAny(chat,input)
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement