View difference between Paste ID: p088CT3k and vzs3Fqxu
SHOW: | | - or go back to the newest paste.
1
function  giremu(inputstr, sep)
2
        if sep == nil then
3
                sep = "%s"
4
        end
5
        local t={}
6
        for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
7
                table.insert(t, str)
8
        end
9
        return t
10
end
11
12-
h.write("u='"..
12+
13
-- Aspetto la richiesta
14
while true do
15
modem.setListening(51, true)
16
local event, lato, sender, canale, msg = os.pullEvent("lan_message")
17
18
print("Richiesta da: 144.91.97."..sender.."\nContenuto: "..msg)
19
if msg == "1.x&o.g.gaugle.com" then
20
modem.sendChannel(51, "OK")
21
elseif msg == "1.x&o.g.gaugle.com/user" then
22
if fs.exists("o") == false  and fs.exists("x") == false then
23
   modem.sendChannel(51, "o&x")
24
elseif fs.exists("o") == true and fs.exists("x") == false then
25
   modem.sendChannel(51, " &x")
26
elseif fs.exists("o") == false and fs.exists("x") == true then
27
   modem.sendChannel(51, "o& ")
28
else
29
   modem.sendChannel(51, " &partita piena!")
30
end
31
elseif string.find(msg, "1.x&o.g.gaugle.com/check") ~= nil then
32
sus = giremu(msg, "$")
33
if sus[2] ~= "o" and sus[2] ~= "x" then
34
   modem.sendChannel(51, "NO")
35
else
36
  if fs.exists(sus[2]) == true then
37
    modem.sendChannel(51, "NI")
38
  else
39
    modem.sendChannel(51, "SI")
40
  end
41
end
42
elseif string.find(msg, "1.x&o.g.gaugle.com/new") ~= nil then
43
sus = giremu(msg, "$")
44
local h = fs.open("turn", "w")
45
h.write(sus[2])
46
h.flush()
47
h.close()
48
local h = fs.open(sus[2], "w")
49
h.write("reg")
50
h.flush()
51
h.close()
52
-- INIZIANO LE GRATE!!!
53
local h = fs.open("s1", "w")
54
h.write(" ")
55
h.flush()
56
h.close()
57
local h = fs.open("s2", "w")
58
h.write(" ")
59
h.flush()
60
h.close()
61
local h = fs.open("s3", "w")
62
h.write(" ")
63
h.flush()
64
h.close()
65
local h = fs.open("s4", "w")
66
h.write(" ")
67
h.flush()
68
h.close()
69
local h = fs.open("s5", "w")
70
h.write(" ")
71
h.flush()
72
h.close()
73
local h = fs.open("s6", "w")
74
h.write(" ")
75
h.flush()
76
h.close()
77
local h = fs.open("s7", "w")
78
h.write(" ")
79
h.flush()
80
h.close()
81
local h = fs.open("s8", "w")
82
h.write(" ")
83
h.flush()
84
h.close()
85
local h = fs.open("s9", "w")
86
h.write(" ")
87
h.flush()
88
h.close()
89
90
modem.sendChannel(51, "OK")
91
elseif msg == "1.x&o.g.gaugle.com/pick" then
92
-- Table: userOfTurn,cas1,cas2,cas3,cas4,cas5,cas6,cas7,cas8,cas9
93
local h = fs.open("turn", "r")
94
turnoa = h.readAll()
95
h.close()
96
local h = fs.open("s1", "r")
97
tu1 = h.readAll()
98
h.close()
99
local h = fs.open("s2", "r")
100
tu2 = h.readAll()
101
h.close()
102
local h = fs.open("s3", "r")
103
tu3 = h.readAll()
104
h.close()
105
local h = fs.open("s4", "r")
106
tu4 = h.readAll()
107
h.close()
108
local h = fs.open("s5", "r")
109
tu5 = h.readAll()
110
h.close()
111
local h = fs.open("s6", "r")
112
tu6 = h.readAll()
113
h.close()
114
local h = fs.open("s7", "r")
115
tu7 = h.readAll()
116
h.close()
117
local h = fs.open("s8", "r")
118
tu8 = h.readAll()
119
h.close()
120
local h = fs.open("s9", "r")
121
tu9 = h.readAll()
122
h.close()
123
modem.sendChannel(51, "isGrid$"..turnoa.."$"..tu1.."$"..tu2.."$"..tu3.."$"..tu4.."$"..tu5.."$"..tu6.."$"..tu7.."$"..tu8.."$"..tu9)
124
elseif string.find(msg, "1.x&o.g.gaugle.com/update") ~= nil then
125
susa = giremu(msg, "$")
126
-- Imposto che NON E' il turno del giocatore
127
local h = fs.open("turn", "w")
128
h.write(susa[2])
129
h.flush()
130
h.close()
131
-- Sistemo la casella scelta
132
local h = fs.open(susa[3], "w")
133
h.write(susa[2])
134
h.flush()
135
h.close()
136
modem.sendChannel(51, "OK")
137
elseif msg == "1.x&o.g.gaugle.com/stop" then
138
shell.run("rm x")
139
shell.run("rm o")
140
shell.run("rm turn")
141
modem.sendChannel(51, "stopped!")
142
shell.run("reboot")
143
end
144
sleep(0.1)
145
end