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(51, true)
- local event, lato, sender, canale, msg = os.pullEvent("lan_message")
- print("Richiesta da: 144.91.97."..sender.."\nContenuto: "..msg)
- if msg == "1.x&o.g.gaugle.com" then
- modem.sendChannel(51, "OK")
- elseif msg == "1.x&o.g.gaugle.com/user" then
- if fs.exists("o") == false and fs.exists("x") == false then
- modem.sendChannel(51, "o&x")
- elseif fs.exists("o") == true and fs.exists("x") == false then
- modem.sendChannel(51, " &x")
- elseif fs.exists("o") == false and fs.exists("x") == true then
- modem.sendChannel(51, "o& ")
- else
- modem.sendChannel(51, " &partita piena!")
- end
- elseif string.find(msg, "1.x&o.g.gaugle.com/check") ~= nil then
- sus = giremu(msg, "$")
- if sus[2] ~= "o" and sus[2] ~= "x" then
- modem.sendChannel(51, "NO")
- else
- if fs.exists(sus[2]) == true then
- modem.sendChannel(51, "NI")
- else
- modem.sendChannel(51, "SI")
- end
- end
- elseif string.find(msg, "1.x&o.g.gaugle.com/new") ~= nil then
- sus = giremu(msg, "$")
- local h = fs.open("turn", "w")
- h.write(sus[2])
- h.flush()
- h.close()
- local h = fs.open(sus[2], "w")
- h.write("reg")
- h.flush()
- h.close()
- -- INIZIANO LE GRATE!!!
- local h = fs.open("s1", "w")
- h.write(" ")
- h.flush()
- h.close()
- local h = fs.open("s2", "w")
- h.write(" ")
- h.flush()
- h.close()
- local h = fs.open("s3", "w")
- h.write(" ")
- h.flush()
- h.close()
- local h = fs.open("s4", "w")
- h.write(" ")
- h.flush()
- h.close()
- local h = fs.open("s5", "w")
- h.write(" ")
- h.flush()
- h.close()
- local h = fs.open("s6", "w")
- h.write(" ")
- h.flush()
- h.close()
- local h = fs.open("s7", "w")
- h.write(" ")
- h.flush()
- h.close()
- local h = fs.open("s8", "w")
- h.write(" ")
- h.flush()
- h.close()
- local h = fs.open("s9", "w")
- h.write(" ")
- h.flush()
- h.close()
- modem.sendChannel(51, "OK")
- elseif msg == "1.x&o.g.gaugle.com/pick" then
- -- Table: userOfTurn,cas1,cas2,cas3,cas4,cas5,cas6,cas7,cas8,cas9
- local h = fs.open("turn", "r")
- turnoa = h.readAll()
- h.close()
- local h = fs.open("s1", "r")
- tu1 = h.readAll()
- h.close()
- local h = fs.open("s2", "r")
- tu2 = h.readAll()
- h.close()
- local h = fs.open("s3", "r")
- tu3 = h.readAll()
- h.close()
- local h = fs.open("s4", "r")
- tu4 = h.readAll()
- h.close()
- local h = fs.open("s5", "r")
- tu5 = h.readAll()
- h.close()
- local h = fs.open("s6", "r")
- tu6 = h.readAll()
- h.close()
- local h = fs.open("s7", "r")
- tu7 = h.readAll()
- h.close()
- local h = fs.open("s8", "r")
- tu8 = h.readAll()
- h.close()
- local h = fs.open("s9", "r")
- tu9 = h.readAll()
- h.close()
- modem.sendChannel(51, "isGrid$"..turnoa.."$"..tu1.."$"..tu2.."$"..tu3.."$"..tu4.."$"..tu5.."$"..tu6.."$"..tu7.."$"..tu8.."$"..tu9)
- elseif string.find(msg, "1.x&o.g.gaugle.com/update") ~= nil then
- susa = giremu(msg, "$")
- -- Imposto che NON E' il turno del giocatore
- local h = fs.open("turn", "w")
- h.write(susa[2])
- h.flush()
- h.close()
- -- Sistemo la casella scelta
- local h = fs.open(susa[3], "w")
- h.write(susa[2])
- h.flush()
- h.close()
- modem.sendChannel(51, "OK")
- elseif msg == "1.x&o.g.gaugle.com/stop" then
- shell.run("rm x")
- shell.run("rm o")
- shell.run("rm turn")
- modem.sendChannel(51, "stopped!")
- shell.run("reboot")
- end
- sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement