Skip to content

Commit

Permalink
sponsor slots fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MetalSage committed Dec 11, 2024
1 parent 7dbd395 commit f0cf40c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Content.Server/Preferences/Managers/ServerPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Content.Server._Corvax.Sponsors;
using Content.Server.Database;
using Content.Shared.CCVar;
using Content.Shared.Preferences;
Expand All @@ -26,14 +27,15 @@ public sealed class ServerPreferencesManager : IServerPreferencesManager, IPostI
[Dependency] private readonly IDependencyCollection _dependencies = default!;
[Dependency] private readonly ILogManager _log = default!;
[Dependency] private readonly UserDbDataManager _userDb = default!;
[Dependency] private readonly SponsorsManager _sponsors = default!;

// Cache player prefs on the server so we don't need as much async hell related to them.
private readonly Dictionary<NetUserId, PlayerPrefData> _cachedPlayerPrefs =
new();

private ISawmill _sawmill = default!;

private int MaxCharacterSlots => _cfg.GetCVar(CCVars.GameMaxCharacterSlots);
// private int MaxCharacterSlots => _cfg.GetCVar(CCVars.GameMaxCharacterSlots);

public void Init()
{
Expand All @@ -55,7 +57,7 @@ private async void HandleSelectCharacterMessage(MsgSelectCharacter message)
return;
}

if (index < 0 || index >= MaxCharacterSlots)
if (index < 0 || index >= GetMaxUserCharacterSlots(userId)) // Corvax-Sponsors
{
return;
}
Expand Down Expand Up @@ -95,7 +97,7 @@ public async Task SetProfile(NetUserId userId, int slot, ICharacterProfile profi
return;
}

if (slot < 0 || slot >= MaxCharacterSlots)
if (slot < 0 || slot >= GetMaxUserCharacterSlots(userId)) // Corvax-Sponsors
return;

var curPrefs = prefsData.Prefs!;
Expand Down Expand Up @@ -125,7 +127,7 @@ private async void HandleDeleteCharacterMessage(MsgDeleteCharacter message)
return;
}

if (slot < 0 || slot >= MaxCharacterSlots)
if (slot < 0 || slot >= GetMaxUserCharacterSlots(userId)) // Corvax-Sponsors
{
return;
}
Expand Down Expand Up @@ -213,7 +215,7 @@ public void FinishLoad(ICommonSession session)
msg.Preferences = prefsData.Prefs;
msg.Settings = new GameSettings
{
MaxCharacterSlots = MaxCharacterSlots
MaxCharacterSlots = GetMaxUserCharacterSlots(session.UserId), // Corvax-Sponsors
};
_netManager.ServerSendMessage(msg, session.Channel);
}
Expand All @@ -228,6 +230,14 @@ public bool HavePreferencesLoaded(ICommonSession session)
return _cachedPlayerPrefs.ContainsKey(session.UserId);
}

// Corvax-Sponsors-Start: Calculate total available users slots with sponsors
private int GetMaxUserCharacterSlots(NetUserId userId)
{
var maxSlots = _cfg.GetCVar(CCVars.GameMaxCharacterSlots);
var extraSlots = _sponsors.TryGetInfo(userId, out var sponsor) ? sponsor.ExtraSlots : 0;
return maxSlots + extraSlots;
}
// Corvax-Sponsors-End

/// <summary>
/// Tries to get the preferences from the cache
Expand Down

0 comments on commit f0cf40c

Please sign in to comment.