jaklsfjlsak

11/17/20 地狱火雷达网系统 S8tVp7Z8

Sep 5th, 2022
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.43 KB | None | 0 0
  1. --- WebSocket Address
  2. local WebSocket = "ws://139.99.165.106:1337"
  3. -- Node ID
  4. local nodeid = os.computerID()
  5. -- Script Version
  6. local version = "2.0"
  7. -- Pastebin Code
  8. local pbc = "S8tVp7Z8"
  9. -- Version Check Url
  10. local vcurl = "http://www.infaknox.space/hfgr-version"
  11. -- waittime between radar scans
  12. local intervalSec = 15
  13. -- range in blocks
  14. local radarRadius = 1000
  15. -- if something is closer than that then a warning sign will be prepended in discord
  16. local safetyDist = 400
  17.  
  18. term.clear()
  19. os.setComputerLabel("HFGR Node: "..nodeid)
  20. term.setBackgroundColor(colors.gray)
  21. term.setTextColor(colors.white)
  22. term.clear()
  23. term.setCursorPos(1,2)
  24. print(" _/ _/ _/_/_/_/ _/_/_/ _/_/_/ ")
  25. print(" _/ _/ _/ _/ _/ _/ ")
  26. print(" _/_/_/_/ _/_/_/ _/ _/_/ _/_/_/ ")
  27. print(" _/ _/ _/ _/ _/ _/ _/ ")
  28. print(" _/ _/ _/ _/_/_/ _/ _/ ")
  29. print(" ")
  30. term.setTextColor( colors.red )
  31. print(" By InfiniteBlock.")
  32. term.setTextColor( colors.green )
  33. print(" Node ID: " .. nodeid .. " Online.")
  34. term.setTextColor( colors.white )
  35. sleep(4)
  36. local checkUpdate = http.get(vcurl) --you have to enter your link
  37. if not checkUpdate then
  38. print("Update Fail Rebooting.")
  39. sleep(2)
  40. os.reboot()
  41. else
  42. local checkForUpdate = checkUpdate.readAll()
  43. if version ~= checkForUpdate then
  44. shell.run("rm", "startup")
  45. shell.run("pastebin", "get", pbc, "startup")
  46. os.reboot()
  47. else
  48. end
  49. end
  50. local radar = peripheral.find("warpdriveRadar")
  51. if radar == nil then
  52. error("No radar could be found!")
  53. end
  54. local ws, err = http.websocket(WebSocket)
  55. if not ws then
  56. else
  57. ws.send("HellFire Global Radar ID: " .. nodeid .. " Online.")
  58. ws.send("HellFire Global Radar ID: " .. nodeid .. " - Settings = Scan Interval: " .. intervalSec .. " sec Radius: " .. radarRadius .. " mtrs Safe Distance : " .. safetyDist .. " mtrs.")
  59. ws.close()
  60. end
  61. function tableHasValue(table, v)
  62. for i=1,#table do
  63. if table[i] == v then
  64. return true
  65. end
  66. end
  67. return false
  68. end
  69.  
  70. function getDst(x1,x2,y1,y2,z1,z2)
  71. local dx = x1-x2
  72. local dy = y1-y2
  73. local dz = z1-z2
  74. return math.floor(math.sqrt(dx*dx+dy*dy+dz*dz))
  75. end
  76.  
  77. function getRadarResults()
  78.  
  79. local dur = radar.getScanDuration(radarRadius)
  80. local first = true
  81. while true do
  82. local currPwr, maxPwr, unit = radar.getEnergyStatus()
  83. local _,reqPwr = radar.getEnergyRequired(radarRadius)
  84. if reqPwr <= currPwr then
  85. break
  86. else
  87. if first then
  88. first = false
  89. else
  90. local _,line=term.getCursorPos()
  91. term.setCursorPos(1,line-1)
  92. term.clearLine()
  93. end
  94. term.setCursorPos(1,11)
  95. term.clearLine()
  96. print("Waiting for energy.. ("..currPwr.."/"..reqPwr..")")
  97.  
  98. os.sleep(1)
  99. end
  100. end
  101. term.setCursorPos(1,11)
  102. term.clearLine()
  103. print("Scanning radius of "..radarRadius.." blocks. This will take "..tonumber(dur).."s.")
  104. radar.start()
  105. os.sleep(dur + 0.1) -- sleep for duration plus buffer
  106. radar.getResultsCount()
  107. local cnt = radar.getResultsCount()
  108. local ret = {}
  109. local dsts = {}
  110. local alreadySeen = {}
  111. local rPosOK,dim,rPosX,rPosY,rPosZ = radar.getGlobalPosition()
  112. for i=1,cnt do
  113. local result={radar.getResult(i-1)}
  114. -- identifier:
  115. local tv = result[2]..":"..result[3]..":"..result[4].."-"..result[5].."-"..result[6]..":"..result[7]
  116. if result[1] == true then -- [1] = successful or not
  117. table.insert(ret,result)
  118.  
  119. -- alreadySeen[#alreadySeen+1]=tv
  120. end
  121. end
  122. table.sort(ret, function(a,b) return getDst(rPosX,a[4],rPosY,a[5],rPosZ,a[6]) < getDst(rPosX,b[4],rPosY,b[5],rPosZ,b[6]) end)
  123. return ret
  124. end -- func
  125.  
  126. local oldShips = {}
  127. local goodChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"--,;:_-#'+~*?!??$%&/()={[]}^|<>"
  128. radar.radius(radarRadius)
  129. radar.enable()
  130. while true do
  131. local res = getRadarResults()
  132.  
  133. -- shell.run("clear")
  134. -- print("==== Ship Scanner ====")
  135.  
  136. local str = ""
  137. local newShips = {}
  138.  
  139. local firstMsgPart = true
  140. -- print("Currently tracked ships:")
  141. local rPosOK,dim,rPosX,rPosY,rPosZ = radar.getGlobalPosition()
  142. local rlPosX,rlPosY,rlPosZ = radar.getLocalPosition()
  143. -- print("Our pos: global xyz: ("..rPosX.." "..rPosY.." "..rPosZ..") local xyz: ("..rlPosX.." "..rlPosY.." "..rlPosZ..")")
  144. -- rlPosX = 0
  145. -- rlPosY = 0
  146. -- rlPosZ = 0
  147.  
  148. --print("ress:"..#res)
  149. os.sleep(1)
  150. for
  151. i=1,#res do
  152. local success, type, name, x, y, z, mass = table.unpack(res[i])
  153. if name ~= "" then
  154. local cdist = getDst(rPosX,x,rPosY,y,rPosZ,z)
  155. local so = ""
  156. if cdist < safetyDist then so = so .. " :warning: " end
  157.  
  158. so = so.. "**"..name.."** ["..type..", "..mass.."t] at Hyper XYZ: "..x.." "..y.." "..z.." Local XYZ: "
  159.  
  160. so = so..(x-rPosX+rlPosX).." "..(y-rPosY+rlPosY).." "..(z-rPosZ+rlPosZ).. " **Distance: "..cdist.."m**."
  161. table.insert(newShips,so)
  162. --print("added element "..#newShips)
  163. --os.sleep(1)
  164. if not tableHasValue(oldShips, so) then -- not already tracked
  165. if firstMsgPart then
  166. str = str.."**Newly tracked ships:**"
  167. firstMsgPart = false
  168. end
  169. str = str.."\n"..so
  170. end
  171. --print(so)
  172. --os.sleep(.5)
  173. --
  174. end
  175. end
  176.  
  177.  
  178. firstMsgPart = true
  179. for i=1,#oldShips do
  180. if not tableHasValue(newShips, oldShips[i]) then -- if a ship was removed
  181. if firstMsgPart then
  182. str = str.."Lost contact with ships:\n"
  183. firstMsgPart = false
  184. end
  185. str = str..oldShips[i].."\n"
  186. end
  187. end
  188. --print("\n\n")
  189. --print("l3:"..#newShips)
  190. if str ~= "" then
  191. str = "-------------------------------\n"..str
  192. --print("posting update to discord...")
  193. local sanitized = ""
  194. for j=1,str:len() do
  195. if string.find(str:sub(j,j), "\"") or str:sub(j,j):find("\\") then
  196. sanitized = sanitized .. "."
  197. -- print("removed "..str:sub(j,j))
  198. else
  199. sanitized = sanitized .. string.sub(str,j,j)
  200. end
  201. end
  202. --print(sanitized)
  203. term.setCursorPos(1,11)
  204. term.clearLine()
  205. print("Sent Results to HFGR Server.")
  206. if sanitized:len() > 1950 then
  207. sanitized = sanitized:sub(1,1951).."[..]"
  208. end
  209. local ws, err = http.websocket(WebSocket)
  210. if not ws then
  211. else
  212. ws.send(sanitized)
  213. ws.close()
  214. end
  215. end
  216. oldShips = newShips
  217. sleep(intervalSec)
  218. end
Add Comment
Please, Sign In to add comment