Advertisement
jared314

Untitled

Aug 2nd, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. ----------------------------------------
  2. -- Base Monitor log to web
  3. -- by Demethan
  4. -- www.breakfastcraft.com
  5. ----------------------------------------
  6.  
  7. s=peripheral.wrap("top")
  8. allowedPlayerArray={["Topher"]=true,["nunley21"]=true,["Demethan"]=true,["waerloga"]=true}
  9. snapShot={}
  10. snapShot2={}
  11. flag={}
  12. baseName="Dem&Topher -"
  13.  
  14. function round(what, precision)
  15. if what==nil then return 0 end
  16. return math.floor(what*math.pow(10,precision)+0.5) / math.pow(10,precision)
  17. end
  18.  
  19. function record()
  20. term.setCursorPos(1,1)
  21. players=s.getPlayers()
  22. for num,player in pairs(players) do
  23. for p,ign in pairs(player) do
  24. if p=="name" then
  25. playerData=s.getPlayerByName(ign)
  26. data = playerData.all()
  27. inventory=data.player.inventory
  28. if not allowedPlayerArray[ign] then -- check the allow array
  29. flag[ign]=true -- set player flag for later processing
  30. print(ign.."is not on the allowed list")
  31. invArray={}
  32. for a,b in pairs(inventory) do --getting player inventory
  33. slot=b.all()
  34. --print(slot.name,slot.qty) -- debug
  35. invArray[a]=slot.name,slot.qty
  36. end
  37. if snapShot[ign]== nil then --recording first inventory scan
  38. snapShot[ign]= invArray
  39. print("Initial snapshot")
  40. post(baseName,ign," has entered your base")
  41. else
  42. if snapShot2[ign]~= nil then --recoding newer inventory until player leaves.
  43. snapShot2[ign]= nil
  44. end
  45. snapShot2[ign]= invArray
  46. print("updated snapshot")
  47. print("comparing Inventory")
  48. guilty,Items=compare(snapShot[ign],snapShot2[ign])
  49.  
  50. if guilty then
  51. for x=1,#Items do
  52. if Items[x] ~=nil then
  53. print("guilty:",guilty," ",Items[x])
  54. post(baseName,ign,Items[x])
  55. end
  56. end
  57. else
  58. print(ign," - No item found")
  59. end
  60. sleep(1)
  61. leaveCheck()
  62. end
  63.  
  64. end
  65.  
  66.  
  67. end
  68.  
  69. end
  70. end
  71. end
  72.  
  73. function post(one,two,three) --for posting offsite. Prevents log tempering
  74. http.post(
  75. "http://jaredeverett.ca/base_logger/logger.php",
  76. "one="..textutils.urlEncode(tostring(one)).."&"..
  77. "two="..textutils.urlEncode(tostring(two)).."&"..
  78. "three="..textutils.urlEncode(tostring(three))
  79. )
  80. end
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. function leaveCheck() --Check if player gone then compare both inventory.
  88. for ign,v in pairs(flag) do
  89. print("Did ",ign," leave?")
  90. local ok,msg=pcall(function ()s.getPlayerByName(ign) end)
  91. --print(msg) --debug
  92. if not ok and flag[ign] then
  93. print(ign," has left.")
  94. flag[ign]=false
  95. snapShot[ign]=nil
  96. snapShot2[ign]=nil
  97. post(baseName,ign," has left your base")
  98. end
  99.  
  100.  
  101.  
  102. end
  103.  
  104.  
  105.  
  106. end
  107.  
  108. function compare(t1,t2)
  109.  
  110. local ai = {}
  111. local r = {}
  112. for k,v in pairs(t2) do r[k] = v; ai[v]=true end
  113. for k,v in pairs(t1) do
  114. if ai[v]~=nil then r[k] = nil end
  115. end
  116. for k,v in pairs(r) do
  117. if v~=nil then
  118. return true,r
  119. end
  120. end
  121. return false
  122. end
  123.  
  124. function wheel()
  125. term.setCursorPos(1,10)
  126. heart=heart+1
  127. if heart==1 then
  128. print("Scanning | ")
  129. elseif heart==2 then
  130. print("Scanning / ")
  131. elseif heart==3 then
  132. print("Scanning - ")
  133. elseif heart==4 then
  134. print("Scanning \\ ")
  135. elseif heart==5 then
  136. print("Scanning | ")
  137. elseif heart==6 then
  138. print("Scanning / ")
  139. elseif heart==7 then
  140. print("Scanning - ")
  141. elseif heart==7 then
  142. print("Scanning \\ ")
  143. else
  144. heart=0
  145. end
  146. end
  147.  
  148.  
  149.  
  150.  
  151. --main thread
  152. heart=0
  153. term.clear()
  154. term.setCursorPos(1,1)
  155.  
  156. while true do
  157. ok,msg=pcall(record) --wrapped in case there are no players around.
  158. wheel()
  159. sleep(1)
  160. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement