Skip to content

Commit

Permalink
sponsor slots fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MetalSage committed Dec 16, 2024
1 parent 69e6f0c commit 03cea71
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
22 changes: 6 additions & 16 deletions Content.Server/Preferences/Managers/ServerPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
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 @@ -27,15 +26,14 @@ 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 @@ -57,7 +55,7 @@ private async void HandleSelectCharacterMessage(MsgSelectCharacter message)
return;
}

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

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

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

if (slot < 0 || slot >= GetMaxUserCharacterSlots(userId)) // Corvax-Sponsors
if (slot < 0 || slot >= MaxCharacterSlots)
{
return;
}
Expand Down Expand Up @@ -178,7 +176,7 @@ public async Task LoadData(ICommonSession session, CancellationToken cancel)
{
PrefsLoaded = true,
Prefs = new PlayerPreferences(
new[] { new KeyValuePair<int, ICharacterProfile>(0, HumanoidCharacterProfile.Random()) },
new[] {new KeyValuePair<int, ICharacterProfile>(0, HumanoidCharacterProfile.Random())},
0, Color.Transparent)
};

Expand Down Expand Up @@ -215,7 +213,7 @@ public void FinishLoad(ICommonSession session)
msg.Preferences = prefsData.Prefs;
msg.Settings = new GameSettings
{
MaxCharacterSlots = GetMaxUserCharacterSlots(session.UserId), // Corvax-Sponsors
MaxCharacterSlots = MaxCharacterSlots
};
_netManager.ServerSendMessage(msg, session.Channel);
}
Expand All @@ -230,14 +228,6 @@ 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
3 changes: 0 additions & 3 deletions Content.Shared/_Corvax/Sponsors/MsgSponsorInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public sealed class SponsorInfo
[JsonPropertyName("priorityJoin")]
public bool HavePriorityJoin { get; set; } = false;

[JsonPropertyName("extraSlots")]
public int ExtraSlots { get; set; }

[JsonPropertyName("allowedMarkings")] // TODO: Rename API field in separate PR as breaking change!
public string[] AllowedMarkings { get; set; } = Array.Empty<string>();

Expand Down
1 change: 0 additions & 1 deletion Resources/ConfigPresets/Stories/stories.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ desc = """
📚 Присоединяйтесь к нашему дружному сообществу 📚"""
map_pool = "StoriesDefaultMapPool"
lobbyduration = 210
maxcharacterslots = 2
round_restart_time = 120
contraband_examine = false

Expand Down

0 comments on commit 03cea71

Please sign in to comment.