Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Zone editable du programme--
- local blacklist = {PseudoExemple=true}
- local whitelist = {}
- local channel1 = 200
- local channel2 = 201
- --Ne pas toucher au programme apres cette ligne--
- local sensor = {}
- local prevsensor = {}
- local recent = {"","",""}
- function myperipheral(name)
- local function inlist(item,list)
- for n,m in pairs(list) do
- if m == item then
- return true
- end
- end
- return false
- end
- local side
- for k,v in pairs(peripheral.getNames()) do
- if string.find(v,name) then
- side = v
- elseif inlist(v,rs.getSides()) then
- if peripheral.getType(v) == name then
- side = v
- end
- end
- end
- if side ~= nil then
- print("Found "..name.." as "..side)
- return side
- else
- print("ERROR:"..name.." don't found")
- return nil
- end
- end
- function screen()
- x,y = m.getSize()
- local function enter()
- posx,posy = m.getCursorPos()
- m.setCursorPos(2,posy+1)
- end
- while true do
- m.setBackgroundColor(0x8000)
- m.clear()
- m.setCursorPos(2,2)
- for i,j in pairs(sensor) do
- m.setBackgroundColor(0x100)
- m.write(i.." :")
- enter()
- m.setBackgroundColor(0x8000)
- for o,p in pairs(j) do
- if blacklist[p] then
- m.setTextColor(0x4000)
- end
- m.write(" - "..p)
- enter()
- m.setTextColor(0x1)
- end
- end
- m.setCursorPos(2,y-3)
- m.setBackgroundColor(0x100)
- m.write("Intrusion recente :")
- m.setBackgroundColor(0x8000)
- enter()
- m.write(" - "..recent[1])
- enter()
- m.write(" - "..recent[2])
- enter()
- m.write(" - "..recent[3])
- sleep(2)
- end
- end
- function mylog(text)
- mydate = http.get("http://philipperydin.com/time2.php").readAll()
- mytime = http.get("http://philipperydin.com/time.php").readAll()
- if not fs.isDir("log") then
- fs.makeDir("log")
- end
- file = fs.open("log/"..mydate,"a")
- file.writeLine("["..mytime.."] "..text)
- file.close()
- end
- function event()
- while true do
- e, side, sender, reply, msg = os.pullEvent("modem_message")
- message = textutils.unserialize(msg)
- sensor[message.name] = message.players
- end
- end
- function check()
- while true do
- for sensorname,players in pairs(sensor) do
- if prevsensor[sensorname] then
- for nb,name in pairs(players) do
- if not whitelist[name] then
- local ok = false
- for o,prevname in pairs(prevsensor[sensorname]) do
- if name == prevname then
- ok = true
- end
- end
- if not ok then
- print(name.." entre dans la zone de "..sensorname)
- mylog(name.." entre dans la zone de "..sensorname)
- table.insert(recent,1,name)
- table.remove(recent,4)
- end
- end
- end
- end
- prevsensor[sensorname]=players
- end
- sleep(4)
- end
- end
- print("-------Check Peripheral-------")
- r = peripheral.wrap(myperipheral("modem"))
- m = peripheral.wrap(myperipheral("monitor"))
- print("-------End Check Peripheral-------")
- r.open(channel2)
- print("Wait for information")
- parallel.waitForAny(screen,event,check)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement