Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function giremu(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- local modem = peripheral.wrap("top")
- -- Aspetto la richiesta
- while true do
- modem.setListening(70, true)
- local event, lato, sender, canale, msg = os.pullEvent("lan_message")
- print("Richiesta da: 144.91.97."..sender.."\nContenuto: "..msg)
- if msg == "server.chat.gaugle.com" then
- modem.sendChannel(80, "Pong!")
- elseif string.find(msg, "server.chat.gaugle.com/register") ~= nil then
- sus = giremu(msg, "$")
- if fs.exists("u/"..sus[2]) == true then
- modem.sendChannel(70, "NO")
- else
- local h = fs.open("u/"..sus[2], "w")
- h.write(sus[3])
- h.flush()
- h.close()
- modem.sendChannel(70, "SI")
- end
- elseif string.find(msg, "server.chat.gaugle.com/checkUsername") ~= nil then
- sua = giremu(msg, "$")
- if fs.exists("u/"..sua[2]) == true then
- modem.sendChannel(70, "SI")
- else
- modem.sendChannel(70, "NO")
- end
- elseif string.find(msg, "server.chat.gaugle.com/login") ~= nil then
- sao = giremu(msg, "$")
- local h = fs.open("u/"..sao[2], "r")
- pass = h.readAll()
- if sao[3] ~= pass then
- modem.sendChannel(70, "NO")
- else
- modem.sendChannel(70, "SI")
- end
- elseif string.find(msg, "server.chat.gaugle.com/get") ~= nil then
- sen = giremu(msg, "$")
- if fs.exists("c/"..sen[2]) == false then
- local h = fs.open("c/"..sen[2], "w")
- h.write("Chat iniziata!")
- h.flush()
- h.close()
- modem.sendChannel(70, "Ho appena creato la chat!")
- else
- local h = fs.open("c/"..sen[2], "r")
- chat = h.readAll()
- h.close()
- modem.sendChannel(70, chat)
- end
- elseif string.find(msg, "server.chat.gaugle.com/sendMessage") ~= nil then
- sar = giremu(msg, "$")
- local h = fs.open("c/"..sar[2], "w")
- h.writeLine(sar[3])
- h.flush()
- h.close()
- modem.sendChannel(70, "OK")
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement