Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- charlist = {}
- function init()
- print("Name?")
- name = io.read()
- serverId = rednet.lookup("chatServ","chatServer")
- if serverId ~= nil then
- rednet.send(serverId,"PING","chatServ")
- print("Getting PONG")
- id, msg = rednet.receive("chatServ")
- if msg == "PONG" then
- print("Got PONG from id "..id.." server id is "..serverId..".")
- if id == serverId then
- rednet.send(id,name,"chatServ")
- return serverId, true
- else
- error("An unknown computer sent a message during handshake... aborting!")
- end
- else
- error("Handshake interrupted for some reason... Aborting!")
- end
- else
- error("You need a server to connect to, silly!")
- end
- end
- function send(charlist,id)
- msg = " "
- for k,v in pairs(charlist) do
- msg = msg..tostring(charlist[k])
- end
- rednet.send(id,msg,"chatServ")
- end
- function main(serverid)
- event, idKey, msg = os.pullEvent()
- if event == "rednet_message" then
- elseif event == "char" then
- term.write(idKey)
- table.insert(charlist,m,idKey)
- m=m+1
- elseif event == "key_up" then
- if idKey == 28 then
- x, y = term.getCursorPos()
- newY = y+1
- term.setCursorPos(1,newY)
- send(charlist,serverid)
- charlist = {}
- m=0
- end
- end
- end
- --------
- m=0
- if textutils.serialize(peripheral.getNames()) ~= "{}" then
- rednet.open("back")
- else
- error("you need to put a wireless modem above this, dingbat")
- end
- serverId, status = init()
- if status then
- while true do
- main(serverId)
- end
- else
- error("Unknown error occured! Aborting...")
- end
Add Comment
Please, Sign In to add comment