View difference between Paste ID: 7rqrwmCv and 8FYU6mX3
SHOW: | | - or go back to the newest paste.
1
function split(str, pat)
2
   local t = {}  -- NOTE: use {n = 0} in Lua-5.0
3
   local fpat = "(.-)" .. pat
4
   local last_end = 1
5
   local s, e, cap = str:find(fpat, 1)
6
   while s do
7
      if s ~= 1 or cap ~= "" then
8
	 table.insert(t,cap)
9
      end
10
      last_end = e+1
11
      s, e, cap = str:find(fpat, last_end)
12
   end
13
   if last_end <= #str then
14
      cap = str:sub(last_end)
15
      table.insert(t, cap)
16
   end
17
   return t
18
end
19
adress={}
20
adr=http.get("http://imgood.hostoi.com/otherstuff/stargates")
21
src=adr.readAll()
22
adress=textutils.unserialize(src)
23
sg=peripheral.wrap("front")
24
p=peripheral.wrap("right")
25
while true do
26
ev,usr,msg=os.pullEvent("chat")
27
args=split(msg," ")
28
if usr=="justync7" or usr=="Imgoodisher" or usr=="wired2coffee" and args[1]==".sg" then
29
if args[2]=="dial" then
30
if sg.isConnected() then sg.disconnect() end
31
if adress[args[3]] then
32
dial=sg.connect(adress[args[3]].add)
33
else
34
dial=sg.connect(args[3])
35
end
36
if dial=="true" then
37
p.say("Dialing...")
38
else
39
p.say("Failed.")
40
end
41
elseif args[2]=="disconnect" then
42
sg.disconnect()
43
end
44
end
45
end