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 channel = 1
- local cmds = {
- ["me"] = {
- ["does"] = function(args)
- send('* '..name..' '..args)
- end
- },
- ["nick"] = {
- ["does"] = function(nc)
- send(name..' is now known as '..nc)
- name=nc
- end
- }
- }
- local history = {}
- function initConf()
- --modem.open(channel)
- 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()
- 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)
- end
- end
- end
- end
- function chat()
- while true do
- e, p1, p2, p3, p4 = os.pullEventRaw()
- if(e == "modem_message") then
- print(p4)
- elseif(e == "terminate") then
- send(name.." has left")
- end
- end
- end
- function init()
- term.clear()
- 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