Advertisement
User9684

Evil silly cat turtle

Nov 24th, 2022 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. function string.starts(String, Start)
  2. return string.sub(String, 1, string.len(Start)) == Start
  3. end
  4.  
  5. local protoSub = 'STOP_SPYING_ON_REDNET_'
  6. local file = 'THECODE_'
  7. local id = os.getComputerID()
  8.  
  9. rednet.open('left')
  10.  
  11. function floodTraffic()
  12. rednet.broadcast('STOP_SPYING', protoSub..math.random(0,200000))
  13. end
  14.  
  15. local detector = peripheral.find('playerDetector')
  16. if not detector then
  17. error('Couldn\'t find the stalker thingie')
  18. end
  19.  
  20. local envDet = peripheral.find('environmentDetector')
  21.  
  22. local code
  23.  
  24. if not fs.exists(file) then
  25. print('ID?')
  26. code = read()
  27.  
  28. local newFile = fs.open(file, 'w')
  29. newFile.write(code)
  30.  
  31. newFile.close()
  32. else
  33. local filePass = fs.open(file, 'r')
  34. code = filePass.readAll()
  35. end
  36.  
  37. local prot = protoSub..code
  38.  
  39. term.clear()
  40.  
  41. if envDet == nil then
  42. print('Environment Detector could not be found.')
  43. end
  44.  
  45. local dim = (envDet and envDet.getDimension() or "UNKNOWN")
  46.  
  47. local cmds = {
  48. ['RESTART'] = function(...)
  49. os.reboot()
  50. end,
  51. ['EVAL'] = function(...)
  52. local luaStr = ...
  53. xpcall(function()
  54. loadstring(luaStr)()
  55. end, function(...)
  56. print(...)
  57. end)
  58. end,
  59. }
  60.  
  61. function commandSent(dataStr)
  62. if type(dataStr) ~= "string" then return end
  63. if not string.starts(tostring(dataStr), '{') then return end
  64.  
  65. xpcall(function()
  66. local data = textutils.unserialize(dataStr)
  67. cmds[data.cmd](data.txt)
  68. end, function(...)
  69. print(...)
  70. end)
  71. end
  72.  
  73. while true do
  74. local event,_,_, m, n, t = os.pullEvent()
  75. if event == "modem_message" then
  76. if n.sProtocol == prot and m == 1 then
  77. commandSent(n.message)
  78. end
  79. end
  80.  
  81. local playerPositions = {}
  82. local players = detector.getOnlinePlayers()
  83.  
  84. if players then
  85. for _, player in next, players do
  86. local position = detector.getPlayerPos(player)
  87. if position then
  88. playerPositions[player] = player..': X: '..position.x..' Y: '..position.y..' Z: '..position.z
  89. else
  90. playerPositions[player] = nil
  91. end
  92. end
  93.  
  94. local serialized = textutils.serialize({
  95. ['dem'] = dim,
  96. ['positions'] = playerPositions
  97. })
  98. if #serialized > 2 then
  99. rednet.send(1, serialized, prot)
  100. else
  101. rednet.send(1, 'NONE', prot)
  102. end
  103. end
  104. floodTraffic()
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement