Skip to content

Commit

Permalink
заготовка спонорки
Browse files Browse the repository at this point in the history
  • Loading branch information
SpicyDarkFox committed Sep 1, 2024
1 parent c4ac178 commit ae70f49
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Content.Client/Entry/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public sealed class EntryPoint : GameClient
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly JoinQueueManager _joinQueue = default!;
[Dependency] private readonly DiscordAuthManager _discordAuth = default!;
#if LPP_Sponsors // _LostParadise-Sponsors
[Dependency] private readonly SponsorsManager _sponsorsManager = default!;
#endif

public override void Init()
{
Expand Down Expand Up @@ -165,6 +168,11 @@ public override void PostInit()
_voteManager.Initialize();
_userInterfaceManager.SetDefaultTheme("SS14DefaultTheme");
_userInterfaceManager.SetActiveTheme(_configManager.GetCVar(CVars.InterfaceTheme));

#if LPP_Sponsors
_sponsorsManager.Initialize(); // _LostParadise-Sponsors
#endif

_documentParsingManager.Initialize();
_joinQueue.Initialize();
_discordAuth.Initialize();
Expand Down
3 changes: 3 additions & 0 deletions Content.Client/IoC/ClientContentIoC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public static void Register()
collection.Register<ISharedPlaytimeManager, JobRequirementsManager>();
IoCManager.Register<JoinQueueManager>();
IoCManager.Register<DiscordAuthManager>();
#if LPP_Sponsors // _LostParadise-Sponsors
collection.Register<SponsorsManager>();
#endif
}
}
}
13 changes: 13 additions & 0 deletions Content.Client/Preferences/ClientPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
#if LPP_Sponsors // _LostParadise-Sponsors
using Content.Client._LostParadise.Sponsors;
#endif

namespace Content.Client.Preferences
{
Expand All @@ -24,6 +27,9 @@ public sealed class ClientPreferencesManager : IClientPreferencesManager
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IPrototypeManager _prototypes = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
#if LPP_Sponsors // _LostParadise-Sponsors
[Dependency] private readonly SponsorsManager _sponsorsManager = default!;
#endif

public event Action? OnServerDataLoaded;

Expand Down Expand Up @@ -67,6 +73,13 @@ public void SelectCharacter(int slot)
public void UpdateCharacter(ICharacterProfile profile, int slot)
{
var collection = IoCManager.Instance!;

#if LPP_Sponsors // _LostParadise-Sponsors
var allowedMarkings = _sponsorsManager.TryGetInfo(out var sponsor) ? sponsor.AllowedMarkings : [];
var session = _playerManager.LocalSession!;
profile.EnsureValid(session, collection, allowedMarkings);
#endif

profile.EnsureValid(_playerManager.LocalSession!, collection);
var characters = new Dictionary<int, ICharacterProfile>(Preferences.Characters) {[slot] = profile};
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor);
Expand Down
18 changes: 18 additions & 0 deletions Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,22 @@ private void UpdateUI()
Loc.GetString("character-setup-gui-create-new-character-button-tooltip",
("maxCharacters", _preferencesManager.Settings!.MaxCharacterSlots));

#if LPP_Sponsors
var isDisplayedMaxSlots = false; // _LostParadise-Sponsors возможно использование дополнительных слотов
#endif

foreach (var (slot, character) in _preferencesManager.Preferences!.Characters)
{
if (character is null)
{
continue;
}

#if LPP_SUBS // _LostParadise-Sponsors
isDisplayedMaxSlots = numberOfFullSlots >= _preferencesManager.Settings.MaxCharacterSlots;
if (isDisplayedMaxSlots) break;
#endif

numberOfFullSlots++;
var characterPickerButton = new CharacterPickerButton(_entityManager,
_preferencesManager,
Expand All @@ -133,8 +147,12 @@ private void UpdateUI()
};
}

#if LPP_Sponsors // _LostParadise-Sponsors
_createNewCharacterButton.Disabled = isDisplayedMaxSlots;
#else
_createNewCharacterButton.Disabled =
numberOfFullSlots >= _preferencesManager.Settings.MaxCharacterSlots;
#endif
Characters.AddChild(_createNewCharacterButton);
// TODO: Move this shit to the Lobby UI controller
}
Expand Down
14 changes: 14 additions & 0 deletions Content.Server.Database/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected ServerDbContext(DbContextOptions options) : base(options)
public DbSet<AdminNote> AdminNotes { get; set; } = null!;
public DbSet<AdminWatchlist> AdminWatchlists { get; set; } = null!;
public DbSet<AdminMessage> AdminMessages { get; set; } = null!;
public DbSet<Sponsor> Sponsors { get; set; } = null!; // _LostParadise-Sponsors

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down Expand Up @@ -1025,4 +1026,17 @@ public class AdminMessage : IAdminRemarksCommon
/// </summary>
public bool Dismissed { get; set; }
}

[Table("sponsors")] // _LostParadise-Sponsors
public class Sponsor
{
[Required, Key] public Guid UserId { get; set; }
public int Tier { get; set; }
public string OOCColor { get; set; } = "#00FF00";
public bool HavePriorityJoin { get; set; }
public string AllowedMarkings { get; set; } = null!;
public int ExtraSlots { get; set; }
public DateTime ExpireDate {get;set;}
public bool AllowJob { get; set; } = false;
}
}
15 changes: 14 additions & 1 deletion Content.Server/Chat/Managers/ChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
using Robust.Shared.Replays;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
#if LPP_Sponsors // _LostParadise-Sponsors
using Content.Server._LostParadise.Sponsors;
#endif

namespace Content.Server.Chat.Managers
{
Expand Down Expand Up @@ -45,6 +48,9 @@ internal sealed partial class ChatManager : IChatManager
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
#if LPP_Sponsors // _LostParadise-Sponsors
[Dependency] private readonly SponsorsManager _sponsorsManager = default!;
#endif

/// <summary>
/// The maximum length a player-sent message can be sent
Expand Down Expand Up @@ -244,11 +250,18 @@ private void SendOOC(ICommonSession player, string message)
var prefs = _preferencesManager.GetPreferences(player.UserId);
colorOverride = prefs.AdminOOCColor;
}
if ( _netConfigManager.GetClientCVar(player.Channel, CCVars.ShowOocPatronColor) && player.Channel.UserData.PatronTier is { } patron && PatronOocColors.TryGetValue(patron, out var patronColor))
if (_netConfigManager.GetClientCVar(player.Channel, CCVars.ShowOocPatronColor) && player.Channel.UserData.PatronTier is { } patron && PatronOocColors.TryGetValue(patron, out var patronColor))
{
wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", patronColor),("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)));
}

#if LPP_Sponsors // _LostParadise-Sponsors
if (_sponsorsManager.TryGetInfo(player.UserId, out var sponsorData) && sponsorData.OOCColor != null)
{
wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", sponsorData.OOCColor),("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)));
}
#endif

//TODO: player.Name color, this will need to change the structure of the MsgChatMessage
ChatMessageToAll(ChatChannel.OOC, message, wrappedMessage, EntityUid.Invalid, hideChat: false, recordReplay: true, colorOverride: colorOverride, author: player.UserId);
_mommiLink.SendOOCMessage(player.Name, message);
Expand Down
25 changes: 23 additions & 2 deletions Content.Server/Connection/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
using Robust.Shared.Configuration;
using Robust.Shared.Network;
using Robust.Shared.Timing;
#if LPP_Sponsors // _LostParadise-Sponsors
using Content.Server._LostParadise.Sponsors;
using Content.Shared._LostParadise.CCVar;
#endif


namespace Content.Server.Connection
Expand Down Expand Up @@ -49,6 +53,9 @@ public sealed class ConnectionManager : IConnectionManager
[Dependency] private readonly ServerDbEntryManager _serverDbEntry = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly ILogManager _logManager = default!;
#if LPP_Sponsors // _LostParadise-Sponsors
[Dependency] private readonly SponsorsManager _sponsorsManager = default!;
#endif

private readonly Dictionary<NetUserId, TimeSpan> _temporaryBypasses = [];
private ISawmill _sawmill = default!;
Expand Down Expand Up @@ -157,7 +164,12 @@ private async Task NetMgrOnConnecting(NetConnectingArgs e)

var adminData = await _dbManager.GetAdminDataForAsync(e.UserId);

if (_cfg.GetCVar(CCVars.PanicBunkerEnabled) && adminData == null)
#if LPP_Sponsors // _LostParadise-Sponsors
var isPrivileged = await HavePrivilegedJoin(e.UserId);
if (_cfg.GetCVar(CCVars.PanicBunkerEnabled) && adminData == null && !isPrivileged)
#else
if (_cfg.GetCVar(CCVars.PanicBunkerEnabled) && adminData == null)
#endif
{
var showReason = _cfg.GetCVar(CCVars.PanicBunkerShowReason);
var customReason = _cfg.GetCVar(CCVars.PanicBunkerCustomReason);
Expand Down Expand Up @@ -310,7 +322,16 @@ public async Task<bool> HasPrivilegedJoin(NetUserId userId)
var wasInGame = EntitySystem.TryGet<GameTicker>(out var ticker) &&
ticker.PlayerGameStatuses.TryGetValue(userId, out var status) &&
status == PlayerGameStatus.JoinedGame;
return isAdmin || wasInGame;

#if LPP_Sponsors // _LostParadise-Sponsors
var havePriorityJoin = _sponsorsManager.TryGetInfo(userId, out var sponsor) && sponsor.HavePriorityJoin;
#endif

return isAdmin ||
#if LPP_Sponsors // _LostParadise-Sponsors
havePriorityJoin ||
#endif
wasInGame;
}
}
}
14 changes: 14 additions & 0 deletions Content.Server/Database/ServerDbBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1580,5 +1580,19 @@ protected abstract class DbGuard : IAsyncDisposable

public abstract ValueTask DisposeAsync();
}

#region Sponsors
public async Task<Sponsor?> GetSponsorInfo(NetUserId userId) // _LostParadise-Sponsors
{
await using var db = await GetDb();
return await db.DbContext.Sponsors.AsNoTracking().FirstOrDefaultAsync(x => x.UserId == userId.UserId);
}

public async Task<Sponsor[]?> GetSponsorList() // _LostParadise-Sponsors
{
await using var db = await GetDb();
return await db.DbContext.Sponsors.AsNoTracking().ToArrayAsync();
}
#endregion
}
}
18 changes: 18 additions & 0 deletions Content.Server/Database/ServerDbManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ Task<int> AddConnectionLogAsync(
Task MarkMessageAsSeen(int id, bool dismissedToo);

#endregion

#region Sponsors
Task<Sponsor?> GetSponsorInfo(NetUserId userId, CancellationToken cancel = default); //_LostParadise-Sponsors
Task<Sponsor[]?> GetSponsorList(CancellationToken cancel = default);
#endregion
}

public sealed class ServerDbManager : IServerDbManager
Expand Down Expand Up @@ -916,6 +921,19 @@ private IAsyncEnumerable<T> RunDbCommand<T>(Func<IAsyncEnumerable<T>> command)
return enumerable;
}

// _LostParadise-Sponsors
public async Task<Sponsor?> GetSponsorInfo(NetUserId userId, CancellationToken cancel = default)
{
DbWriteOpsMetric.Inc();
return await _db.GetSponsorInfo(userId);
}

public async Task<Sponsor[]?> GetSponsorList(CancellationToken cancel = default)
{
DbWriteOpsMetric.Inc();
return await _db.GetSponsorList();
}

private DbContextOptions<PostgresServerDbContext> CreatePostgresOptions()
{
var host = _cfg.GetCVar(CCVars.DatabasePgHost);
Expand Down
6 changes: 6 additions & 0 deletions Content.Server/Entry/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
#if LPP_Sponsors // _LostParadise-Sponsors
using Content.Server._LostParadise.Sponsors;
#endif

namespace Content.Server.Entry
{
Expand Down Expand Up @@ -109,6 +112,9 @@ public override void Init()
IoCManager.Resolve<JoinQueueManager>().Initialize();
IoCManager.Resolve<DiscordAuthManager>().Initialize();
IoCManager.Resolve<ServerApi>().Initialize();
#if LPP_Sponsors // _LostParadise-Sponsors
IoCManager.Resolve<SponsorsManager>().Initialize();
#endif

_voteManager.Initialize();
_updateManager.Initialize();
Expand Down
21 changes: 21 additions & 0 deletions Content.Shared/Humanoid/HumanoidCharacterAppearance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,29 @@ public static HumanoidCharacterAppearance EnsureValid(HumanoidCharacterAppearanc
hairStyleId = HairStyles.DefaultHairStyle;
}

#if LPP_Sponsors // _LostParadise-Sponsors
if (proto.TryIndex(hairStyleId, out MarkingPrototype? hairProto) &&
hairProto.SponsorOnly &&
!sponsorPrototypes.Contains(hairStyleId))
{
hairStyleId = HairStyles.DefaultHairStyle;
}
#endif

if (!markingManager.MarkingsByCategory(MarkingCategories.FacialHair).ContainsKey(facialHairStyleId))
{
facialHairStyleId = HairStyles.DefaultFacialHairStyle;
}

#if LPP_Sponsors // _LostParadise-Sponsors
if (proto.TryIndex(facialHairStyleId, out MarkingPrototype? facialHairProto) &&
facialHairProto.SponsorOnly &&
!sponsorPrototypes.Contains(facialHairStyleId))
{
facialHairStyleId = HairStyles.DefaultFacialHairStyle;
}
#endif

var markingSet = new MarkingSet();
var skinColor = appearance.SkinColor;
if (proto.TryIndex(species, out SpeciesPrototype? speciesProto))
Expand All @@ -238,6 +256,9 @@ public static HumanoidCharacterAppearance EnsureValid(HumanoidCharacterAppearanc

markingSet.EnsureSpecies(species, skinColor, markingManager);
markingSet.EnsureSexes(sex, markingManager);
#if LPP_Sponsors // _LostParadise-Sponsors
markingSet.FilterSponsor(sponsorPrototypes, markingManager);
#endif
}

return new HumanoidCharacterAppearance(
Expand Down
16 changes: 16 additions & 0 deletions Content.Shared/_LostParadise/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,20 @@ public sealed partial class AccVars
{
public static readonly CVarDef<string> DiscordBanWebhook =
CVarDef.Create("discord.ban_webhook", "", CVar.SERVERONLY);

/// <summary>
/// URL of the sponsors server API.
/// </summary>
public static readonly CVarDef<string> SponsorsApiUrl =
CVarDef.Create("sponsor.api_url", "", CVar.SERVERONLY);

/*
* Queue
*/

/// <summary>
/// Controls if the connections queue is enabled. If enabled stop kicking new players after `SoftMaxPlayers` cap and instead add them to queue.
/// </summary>
public static readonly CVarDef<bool>
QueueEnabled = CVarDef.Create("queue.enabled", false, CVar.SERVERONLY);
}

0 comments on commit ae70f49

Please sign in to comment.