Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------
- -- Base Monitor log to web
- -- by Demethan
- -- www.breakfastcraft.com
- ----------------------------------------
- s=peripheral.wrap("top")
- allowedPlayerArray={["Topher"]=true,["nunley21"]=true,["Demethan"]=true,["waerloga"]=true}
- snapShot={}
- snapShot2={}
- flag={}
- baseName="Dem&Topher -"
- function round(what, precision)
- if what==nil then return 0 end
- return math.floor(what*math.pow(10,precision)+0.5) / math.pow(10,precision)
- end
- function record()
- term.setCursorPos(1,1)
- players=s.getPlayers()
- for num,player in pairs(players) do
- for p,ign in pairs(player) do
- if p=="name" then
- playerData=s.getPlayerByName(ign)
- data = playerData.all()
- inventory=data.player.inventory
- if not allowedPlayerArray[ign] then -- check the allow array
- flag[ign]=true -- set player flag for later processing
- print(ign.."is not on the allowed list")
- invArray={}
- for a,b in pairs(inventory) do --getting player inventory
- slot=b.all()
- --print(slot.name,slot.qty) -- debug
- invArray[a]=slot.name,slot.qty
- end
- if snapShot[ign]== nil then --recording first inventory scan
- snapShot[ign]= invArray
- print("Initial snapshot")
- post(baseName,ign," has entered your base")
- else
- if snapShot2[ign]~= nil then --recoding newer inventory until player leaves.
- snapShot2[ign]= nil
- end
- snapShot2[ign]= invArray
- print("updated snapshot")
- print("comparing Inventory")
- guilty,Items=compare(snapShot[ign],snapShot2[ign])
- if guilty then
- for x=1,#Items do
- if Items[x] ~=nil then
- print("guilty:",guilty," ",Items[x])
- post(baseName,ign,Items[x])
- end
- end
- else
- print(ign," - No item found")
- end
- sleep(1)
- leaveCheck()
- end
- end
- end
- end
- end
- end
- function post(one,two,three) --for posting offsite. Prevents log tempering
- http.post(
- "http://jaredeverett.ca/base_logger/logger.php",
- "one="..textutils.urlEncode(tostring(one)).."&"..
- "two="..textutils.urlEncode(tostring(two)).."&"..
- "three="..textutils.urlEncode(tostring(three))
- )
- end
- function leaveCheck() --Check if player gone then compare both inventory.
- for ign,v in pairs(flag) do
- print("Did ",ign," leave?")
- local ok,msg=pcall(function ()s.getPlayerByName(ign) end)
- --print(msg) --debug
- if not ok and flag[ign] then
- print(ign," has left.")
- flag[ign]=false
- snapShot[ign]=nil
- snapShot2[ign]=nil
- post(baseName,ign," has left your base")
- end
- end
- end
- function compare(t1,t2)
- local ai = {}
- local r = {}
- for k,v in pairs(t2) do r[k] = v; ai[v]=true end
- for k,v in pairs(t1) do
- if ai[v]~=nil then r[k] = nil end
- end
- for k,v in pairs(r) do
- if v~=nil then
- return true,r
- end
- end
- return false
- end
- function wheel()
- term.setCursorPos(1,10)
- heart=heart+1
- if heart==1 then
- print("Scanning | ")
- elseif heart==2 then
- print("Scanning / ")
- elseif heart==3 then
- print("Scanning - ")
- elseif heart==4 then
- print("Scanning \\ ")
- elseif heart==5 then
- print("Scanning | ")
- elseif heart==6 then
- print("Scanning / ")
- elseif heart==7 then
- print("Scanning - ")
- elseif heart==7 then
- print("Scanning \\ ")
- else
- heart=0
- end
- end
- --main thread
- heart=0
- term.clear()
- term.setCursorPos(1,1)
- while true do
- ok,msg=pcall(record) --wrapped in case there are no players around.
- wheel()
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement