Skip to content

Commit

Permalink
still log admin commands if marked i n the config
Browse files Browse the repository at this point in the history
  • Loading branch information
negrifelipe committed Aug 23, 2022
1 parent 45d32af commit 03bb6d3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<AssemblyName>CommandLogger</AssemblyName>
<RootNamespace>Feli.RocketMod.CommandLogger</RootNamespace>

<AssemblyVersion>1.0.0</AssemblyVersion>
<Version>1.0.0</Version>
<AssemblyVersion>1.1.0</AssemblyVersion>
<Version>1.1.0</Version>

<Authors>Feli</Authors>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Feli.RocketMod.CommandLogger/Loggers/ChatCommandLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Log(IRocketPlayer caller, IRocketCommand command, string[] args)
{
var admins = Provider.clients
.Select(x => UnturnedPlayer.FromPlayer(x.player))
.Where(x => x.HasPermission(_plugin.Configuration.Instance.ViewChatLogPermission))
.Where(x => x.HasPermission(_plugin.Configuration.Instance.ViewChatLogPermission) && caller.Id != x.Id)
.ToList();

admins.ForEach(x => ChatManager.serverSendMessage(_plugin.Translate("ChatNotification", caller.DisplayName, command.Name, string.Join(" ", args)), Color.yellow, toPlayer: x.SteamPlayer(), useRichTextFormatting: true));
Expand Down
3 changes: 2 additions & 1 deletion Feli.RocketMod.CommandLogger/Models/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Rocket.API;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace Feli.RocketMod.CommandLogger.Models
{
public class Configuration : IRocketPluginConfiguration
{
public bool LogAllCommands { get; set; }
public bool ForeceLogAdminCommands { get; set; } = false;
public string BypassPermission { get; set; }
public bool LogToChat { get; set; }
public string ViewChatLogPermission { get; set; }
Expand All @@ -17,6 +17,7 @@ public class Configuration : IRocketPluginConfiguration
public void LoadDefaults()
{
LogAllCommands = true;
ForeceLogAdminCommands = false;
CommandsToLog = new()
{
new("ban"),
Expand Down
15 changes: 9 additions & 6 deletions Feli.RocketMod.CommandLogger/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override void Load()
new DiscordCommandLogger(Instance)
};

if(Configuration.Instance.LogToChat)
if (Configuration.Instance.LogToChat)
CommandLoggers.Add(new ChatCommandLogger(Instance));

Logger.Log($"{Name} plugin v{Assembly.GetName().Version} loaded !");
Expand All @@ -47,10 +47,14 @@ protected override void Load()

public void LogCommand(IRocketPlayer caller, IRocketCommand command, string[] args)
{
if (caller.HasPermission(Configuration.Instance.BypassPermission))
if (caller is ConsolePlayer)
return;

if (!Configuration.Instance.CommandsToLog.Any(x=> x.Name == command.Name) && !Configuration.Instance.LogAllCommands)
if (caller.HasPermission(Configuration.Instance.BypassPermission) &&
!(caller.IsAdmin && Configuration.Instance.ForeceLogAdminCommands))
return;

if (!Configuration.Instance.CommandsToLog.Any(x => x.Name == command.Name) && !Configuration.Instance.LogAllCommands)
return;

Logger.Log($"Processing execute request by {caller.DisplayName}");
Expand All @@ -62,7 +66,6 @@ public void LogCommand(IRocketPlayer caller, IRocketCommand command, string[] ar
try
{
logger.Log(caller, command, args);

}
catch (Exception ex)
{
Expand All @@ -75,9 +78,9 @@ protected override void Unload()
{
Harmony.UnpatchAll();

foreach(var logger in CommandLoggers)
foreach (var logger in CommandLoggers)
{
if(logger is IDisposable disposable)
if (logger is IDisposable disposable)
{
Logger.Log($"Disposing {logger.GetType().Name}..");
disposable.Dispose();
Expand Down

0 comments on commit 03bb6d3

Please sign in to comment.