Advertisement
Guest User

Untitled

a guest
Oct 1st, 2015
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. PLUGIN.Title = "Logger"
  2. PLUGIN.Version = V(0, 2, 8)
  3. PLUGIN.Description = "Logs all chat commands used by players with auth level to the server log and/or chat."
  4. PLUGIN.Author = "Wulfspider"
  5. PLUGIN.Url = "http://forum.rustoxide.com/plugins/670/"
  6. PLUGIN.ResourceId = 670
  7. PLUGIN.HasConfig = true
  8.  
  9. local debug = false
  10.  
  11. local compatible = true
  12. function PLUGIN:Init()
  13. self:LoadDefaultConfig()
  14. if plugins.Exists("chathandler") then compatible = false end
  15.  
  16. if not permission.PermissionExists( "logger.see" ) then
  17. permission.RegisterPermission( "logger.see", self.Object )
  18. end
  19. end
  20.  
  21. function PLUGIN:OnRunCommand(arg)
  22. if not arg then return end
  23. if not arg.connection then return end
  24. if not arg.connection.player then return end
  25. if not arg.cmd then return end
  26. if not arg.cmd.namefull then return end
  27. local player = arg.connection.player
  28. local console = arg.cmd.namefull
  29. local chat = arg:GetString(0, "text")
  30. if self.Config.Settings.CommandLogging ~= "false" then
  31. if self:PermissionsCheck(player) then
  32. local excluded
  33. for key, value in pairs(self.Config.Settings.Exclusions) do if value == console then excluded = true; break end end
  34. if not excluded then
  35. print("[" .. self.Title .. "] " .. player.displayName .. " ran console command: " .. console)
  36. if self.Config.Settings.Broadcast ~= "false" then
  37. rust.BroadcastChat(self.Config.Settings.ChatName, player.displayName .. " ran console command: " .. console)
  38. end
  39. elseif chat:sub(1, 1) == "/" then
  40. print("[" .. self.Title .. "] " .. player.displayName .. " ran chat command: " .. chat)
  41. if self.Config.Settings.Broadcast ~= "false" then
  42. self:sendToAdmins( self.Config.Settings.ChatName, player.displayName .. " ran chat command: " .. chat )
  43. end
  44. end
  45. end
  46. end
  47. end
  48.  
  49. function PLUGIN:sendToAdmins(cn, msg)
  50. itPlayerList = global.BasePlayer.activePlayerList:GetEnumerator()
  51. playerList = {}
  52. while itPlayerList:MoveNext() do
  53. if( itPlayerList.Current:GetComponent("BaseNetworkable").net.connection.authLevel > 0 ) then
  54. rust.SendChatMessage( itPlayerList.Current, cn, msg )
  55. end
  56. end
  57. end
  58.  
  59. function PLUGIN:OnPlayerChat(arg)
  60. if not arg then return end
  61. if not arg.connection then return end
  62. if not arg.connection.player then return end
  63. local player = arg.connection.player
  64. local chat = arg:GetString(0, "text")
  65. if not chat or chat == "" or chat:sub(1, 1) == "/" then return end
  66. if self.Config.Settings.ChatLogging ~= "false" and compatible ~= "false" then
  67. print(player.displayName .. ": " .. chat)
  68. end
  69. end
  70.  
  71. function PLUGIN:PermissionsCheck(player)
  72. local authLevel
  73. if player then authLevel = player.net.connection.authLevel else authLevel = 2 end
  74. local neededLevel = tonumber(self.Config.Settings.AuthLevel) or 2
  75. if debug then print(player.displayName .. " has auth level: " .. tostring(authLevel)) end
  76. if authLevel and authLevel >= neededLevel then return true else return false end
  77. end
  78.  
  79. function PLUGIN:LoadDefaultConfig()
  80. self.Config.Settings = self.Config.Settings or {}
  81. self.Config.Settings.AuthLevel = tonumber(self.Config.Settings.AuthLevel) or 2
  82. self.Config.Settings.Broadcast = self.Config.Settings.Broadcast or "true"
  83. self.Config.Settings.ChatName = self.Config.Settings.ChatName or "LOGGER"
  84. self.Config.Settings.ChatLogging = self.Config.Settings.ChatLogging or "false"
  85. self.Config.Settings.CommandLogging = self.Config.Settings.CommandLogging or "true"
  86. self.Config.Settings.Exclusions = self.Config.Settings.Exclusions or {
  87. "chat.say", "craft.add", "craft.cancel", "global.kill", "global.respawn", "global.respawn_sleepingbag", "global.status", "global.wakeup", "inventory.endloot"
  88. }
  89. self:SaveConfig()
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement