Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mod=peripheral.find("modem")
- local sg=peripheral.find("stargate")
- local _,addr=pcall(function() return dofile("addrs.lua") end)
- addr=addr or {}
- local _,password=pcall(function() return dofile("password.lua") end)
- password=password or {}
- local _,whitelist=pcall(function() return dofile("whitelist.lua") end)
- whitelist=whitelist or false
- local prevprevstate=""
- local knownaddrs={}
- dialout=false
- mod.open(555)
- while true do
- local event=table.pack(os.pullEvent())
- if event[1]=="modem_message" then
- local _,_,port,reply,packet=table.unpack(event)
- local msg=packet[1] or packet
- if port==555 then
- if msg=="disconnect" then
- worked,ret=sg.disconnect()
- elseif msg=="get_addr" then
- ret=sg.localAddress()
- elseif msg=="toggle" then
- if sg.irisState()=="Open" then
- worked,ret=sg.closeIris()
- else
- worked,ret=sg.openIris()
- end
- elseif msg=="open" then
- worked,ret=sg.openIris()
- elseif msg=="close" then
- sg.closeIris()
- elseif msg=="exit" then
- break
- elseif msg=="reboot" then
- mod.transmit(reply,555,"rebooting")
- shell.run("reboot")
- elseif msg=="update" then
- mod.transmit(reply,555,"updating")
- shell.run("rm dial_control.lua")
- shell.run("pastebin get Gigj4uj7 dial_control.lua")
- shell.run("reboot")
- elseif packet[1]=="auth" then
- sg.sendMessage(packet[2])
- else
- worked,ret=sg.dial(addr[msg] or msg)
- end
- if ret or worked~=nil then mod.transmit(reply,555,tostring(ret or worked)) end
- end
- elseif event[1]=="sgDialOut" then
- sg.closeIris()
- dialout=true
- elseif event[1]=="sgStargateStateChange" then
- local _,_,state,prevstate=table.unpack(event)
- if (state=="Connected" and prevprevstate=="Dialling" and dialout) or state=="idle" then
- sg.openIris()
- dialout=false
- end
- prevprevstate=prevstate
- elseif event[1]=="sgDialIn" then
- if not knownaddrs[event[3]] then
- io.open("addrlog.txt","a"):write(event[3].."\n"):close()
- knownaddrs[event[3]]=true
- end
- if whitelist then
- if whitelist[event[3]] then
- sg.openIris()
- else
- if whitelist.strict then
- sg.disconnect()
- else
- sg.closeIris()
- end
- end
- end
- elseif event[1]=="sgMessageReceived" then
- if password[event[3]] or password[sg.remoteAddress()] then
- sg.openIris()
- end
- end
- end
- mod.close(555)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement