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

Commit

Permalink
Revert "add profile validation and async saving"
Browse files Browse the repository at this point in the history
  • Loading branch information
Vonsant authored Jul 18, 2024
1 parent 1604330 commit 3d3a938
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions Content.Server/_NF/Bank/BankSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading;
using System.Threading.Tasks;
using Content.Server.Database;
using Content.Server.Preferences.Managers;
using Content.Server.GameTicking;
Expand All @@ -9,6 +8,7 @@
using Robust.Shared.Network;
using Content.Shared._NF.Bank.Events;
using Robust.Server.Player;
using Content.Server.Cargo.Components;
using Content.Shared.Preferences.Loadouts;
using Robust.Shared.Prototypes;
using Content.Shared.Roles;
Expand All @@ -22,9 +22,6 @@ public sealed partial class BankSystem : EntitySystem
[Dependency] private readonly IServerPreferencesManager _prefsManager = default!;
[Dependency] private readonly IServerDbManager _dbManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

[Dependency] private readonly IDependencyCollection _dependencies = default!; // Corvax-Frontier-Changes

private ISawmill _log = default!;

public override void Initialize()
Expand All @@ -42,9 +39,6 @@ public override void Initialize()
// TODO: stop it from running 5 times every time
private void OnBankAccountChanged(EntityUid mobUid, BankAccountComponent bank, ref ComponentGetState args)
{
if (args.Player is null)
return;

var user = args.Player?.UserId;

if (user == null || args.Player?.AttachedEntity != mobUid)
Expand Down Expand Up @@ -77,29 +71,15 @@ private void OnBankAccountChanged(EntityUid mobUid, BankAccountComponent bank, r
new HashSet<ProtoId<TraitPrototype>>(profile.TraitPreferences), // Frontier Merge
new Dictionary<string, RoleLoadout>(profile.Loadouts));

newProfile.EnsureValid(args.Player, _dependencies, []);

args.State = new BankAccountComponentState
{
Balance = bank.Balance,
};
// idk if it works as i want
Task.Run(() => SaveCharSlot((NetUserId) user, profile, index)).Wait(300); // Corvax-Frontier-Changes

_dbManager.SaveCharacterSlotAsync((NetUserId) user, newProfile, index);
_log.Info($"Character {profile.Name} saved");
}
// Corvax-Frontier-Changes-Start
private async Task SaveCharSlot(NetUserId userId, HumanoidCharacterProfile profile, int index)
{
try
{
await _dbManager.SaveCharacterSlotAsync(userId, profile, index);
}
catch (Exception ex)
{
_log.Error($"Caught exception while saving bank account to database: {ex.Message}. Stack Trace: {ex.StackTrace}");
}
}
// Corvax-Frontier-Changes-End

/// <summary>
/// Attempts to remove money from a character's bank account. This should always be used instead of attempting to modify the bankaccountcomponent directly
/// </summary>
Expand Down

0 comments on commit 3d3a938

Please sign in to comment.