Advertisement
User9684

Evil silly cat console

Nov 24th, 2022 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. function string.split(inputstr, sep)
  2. if type(inputstr) ~= "string" then return end
  3. if sep == nil then
  4. sep = "%s"
  5. end
  6. local t = {}
  7. for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
  8. table.insert(t, str)
  9. end
  10. return t
  11. end
  12.  
  13. function string.starts(str, Start)
  14. return string.sub(tostring(str), 1, string.len(Start)) == Start
  15. end
  16.  
  17. local file = 'GO_AWAY_CODED'
  18.  
  19. local connectedDevices = {'3'}
  20. local protoSub = "STOP_SPYING_ON_REDNET_"
  21.  
  22. rednet.open("back")
  23.  
  24. local code
  25.  
  26. if not fs.exists(file) then
  27. print('ID?')
  28. code = read()
  29.  
  30. local newFile = fs.open(file, 'w')
  31. newFile.write(code)
  32.  
  33. newFile.close()
  34. else
  35. local filePass = fs.open(file, 'r')
  36. code = filePass.readAll()
  37. end
  38. term.clear()
  39.  
  40. local proto = protoSub .. code
  41.  
  42. local positions = {}
  43. local queue = {}
  44. local knownSenders = {}
  45.  
  46. local enabled = true
  47.  
  48. local cmds = {
  49. ['RESTART'] = function(...)
  50. os.reboot()
  51. end,
  52. ['TOGGLE'] = function()
  53. enabled = (not enabled)
  54. end,
  55. ['EVAL'] = function(...)
  56. local luaStr = ...
  57. xpcall(function()
  58. loadstring(luaStr)()
  59. end, function(...)
  60. print(...)
  61. end)
  62. end,
  63. }
  64.  
  65. function printQueue(str)
  66. table.insert(queue, str)
  67. end
  68. function flushQueue()
  69. term.clear()
  70. print(table.concat(queue, "\n"))
  71. queue = {}
  72. end
  73.  
  74. function checkSenders()
  75. for sender, lastSeen in next, knownSenders do
  76. if os.time() - lastSeen >= 5 then
  77. table.remove(knownSenders, sender)
  78. end
  79. end
  80. end
  81.  
  82. function floodTraffic()
  83. rednet.broadcast('STOP_SPYING', protoSub..math.random(0,200000))
  84. end
  85.  
  86. function commandSent(dataStr)
  87. if type(dataStr) ~= "string" then return end
  88. if not string.starts(tostring(dataStr), '{') then return end
  89.  
  90. xpcall(function()
  91. local data = textutils.unserialize(dataStr)
  92. local command = cmds[data.cmd]
  93. command(data.txt)
  94. end, function(...)
  95. print(...)
  96. end)
  97. end
  98.  
  99. while true do
  100. local event, m, n, t = os.pullEvent()
  101. if event == "rednet_message" and t == proto and string.starts(tostring(n), '{') then
  102. if m == 4 then
  103. for sender, _ in next, knownSenders do
  104. print(sender)
  105. rednet.send(tonumber(sender), n, proto)
  106. end
  107. commandSent(n)
  108. else
  109. local pos_ = textutils.unserialize(n)
  110. if pos_ then
  111. knownSenders[m] = os.time()
  112. if not positions[pos_.dem] then
  113. positions[pos_.dem] = {}
  114. end
  115. for player, playerString in next, pos_.positions or {} do
  116. positions[pos_.dem][player] = playerString
  117. end
  118. end
  119. end
  120. end
  121.  
  122. local finalStr = ''
  123.  
  124. for i, item in next, positions do
  125. local x = string.split(i, ':')
  126. table.remove(x, 1)
  127. local demStr = table.concat(x, ':')
  128. finalStr=finalStr..'-- '..demStr..' --\n'
  129. for _, posStr in next, positions[i] do
  130. finalStr=finalStr..posStr..'\n'
  131. end
  132. end
  133.  
  134. for _, device in next, connectedDevices do
  135. if enabled then
  136. rednet.send(tonumber(device), finalStr, 'uwu_publish')
  137. else
  138. rednet.send(tonumber(device), 'MONITOR DISABLED BY MANAGER', 'uwu_publish')
  139. end
  140. end
  141.  
  142. checkSenders()
  143. end
  144.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement