Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #207 from FireNameFN/MoneyAntiCheatLog
Browse files Browse the repository at this point in the history
Add logging for money anticheat
  • Loading branch information
Vonsant authored May 23, 2024
2 parents f41b226 + 1abf993 commit e60db94
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Content.Server/Preferences/Managers/ServerPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using System.Threading;
using System.Threading.Tasks;
using Content.Corvax.Interfaces.Server;
using Content.Server.Administration.Logs;
using Content.Server.Database;
using Content.Server.Humanoid;
using Content.Shared.CCVar;
using Content.Shared.Database;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Preferences;
using Content.Shared.Roles;
Expand All @@ -31,6 +33,7 @@ public sealed class ServerPreferencesManager : IServerPreferencesManager
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IDependencyCollection _dependencies = default!;
[Dependency] private readonly IPrototypeManager _protos = default!;
[Dependency] private readonly IAdminLogManager _log = default!;
private IServerSponsorsManager? _sponsors; // Corvax-Sponsors

// Cache player prefs on the server so we don't need as much async hell related to them.
Expand Down Expand Up @@ -111,10 +114,22 @@ private async void HandleUpdateCharacterMessage(MsgUpdateCharacter message)
if (curPrefs.Characters.TryGetValue(slot, out var storedProfile) && storedProfile is HumanoidCharacterProfile storedHumanoid)
{
if (humanoid.BankBalance != storedHumanoid.BankBalance)
{
_log.Add(LogType.UpdateCharacter, LogImpact.High,
$"Character update with wrong balance from {message.MsgChannel.UserName}, current balance: {storedHumanoid.BankBalance}, tried to set: {humanoid.BankBalance}");

return;
}
}
else if (humanoid.BankBalance != HumanoidCharacterProfile.DefaultBalance)
{
_log.Add(LogType.UpdateCharacter, LogImpact.High,
$"Character creation with wrong balance from {message.MsgChannel.UserName}, default balance: {HumanoidCharacterProfile.DefaultBalance}, tried to set: {humanoid.BankBalance}");

return;
}

_log.Add(LogType.UpdateCharacter, LogImpact.Low, $"Successful character update from {message.MsgChannel.UserName}");

// Corvax-Sponsors-Start: Ensure removing sponsor markings if client somehow bypassed client filtering
// WARN! It's not removing markings from DB!
Expand Down
5 changes: 5 additions & 0 deletions Content.Server/_NF/Bank/BankSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Content.Shared._NF.Bank.Events;
using Robust.Server.Player;
using Content.Shared.Preferences.Loadouts;
using Content.Shared.Database;

namespace Content.Server.Bank;

Expand Down Expand Up @@ -103,6 +104,8 @@ public bool TryBankWithdraw(EntityUid mobUid, int amount)
return false;
}

_adminLogger.Add(LogType.Balance, LogImpact.Medium, $"Balance change from {ToPrettyString(mobUid)}, old balance: {bank.Balance}, withdrew: {amount}");

bank.Balance -= amount;
_log.Info($"{mobUid} withdrew {amount}");
if (_playerManager.TryGetSessionByEntity(mobUid, out var player))
Expand Down Expand Up @@ -133,6 +136,8 @@ public bool TryBankDeposit(EntityUid mobUid, int amount)
return false;
}

_adminLogger.Add(LogType.Balance, LogImpact.Medium, $"Balance change from {ToPrettyString(mobUid)}, old balance: {bank.Balance}, deposited: {amount}");

bank.Balance += amount;
_log.Info($"{mobUid} deposited {amount}");
if (_playerManager.TryGetSessionByEntity(mobUid, out var player))
Expand Down
3 changes: 3 additions & 0 deletions Content.Shared.Database/LogType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@ public enum LogType
// Frontier Station Spesific
ATMUsage = 200,
ShipYardUsage = 201,

UpdateCharacter = 300,
Balance = 301
}

0 comments on commit e60db94

Please sign in to comment.