diff --git a/Content.Client/Humanoid/MarkingPicker.xaml.cs b/Content.Client/Humanoid/MarkingPicker.xaml.cs index 885403aa563..7adaf10c73b 100644 --- a/Content.Client/Humanoid/MarkingPicker.xaml.cs +++ b/Content.Client/Humanoid/MarkingPicker.xaml.cs @@ -1,5 +1,6 @@ using System.Linq; -using Content.Corvax.Interfaces.Shared; +using Robust.Client.Player; // A-13 Sponsor service +using Content.Shared.Andromeda.AndromedaSponsorService; // A-13 Sponsor service using Content.Shared.Humanoid; using Content.Shared.Humanoid.Markings; using Content.Shared.Humanoid.Prototypes; @@ -19,8 +20,8 @@ public sealed partial class MarkingPicker : Control { [Dependency] private readonly MarkingManager _markingManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; - private ISharedSponsorsManager? _sponsorsManager; // Corvax-Sponsors - + [Dependency] private readonly GetSponsorAllowedMarkingsMethod _getSponsorAllowedMarkingsMethod = default!; // A-13 Sponsor service + [Dependency] private readonly IPlayerManager _playerManager = default!; // A-13 Sponsor service public Action? OnMarkingAdded; public Action? OnMarkingRemoved; public Action? OnMarkingColorChange; @@ -227,10 +228,45 @@ public void Populate(string filter) var item = CMarkingsUnused.AddItem($"{GetMarkingName(marking)}", marking.Sprites[0].Frame0()); item.Metadata = marking; - // Corvax-Sponsors-Start - if (marking.SponsorOnly && _sponsorsManager != null) - item.Disabled = !_sponsorsManager.GetClientPrototypes().Contains(marking.ID); - // Corvax-Sponsors-End + + // A-13 Sponsor service start + var player = _playerManager.LocalSession; + var validatedFile = _getSponsorAllowedMarkingsMethod.FileIsValid(); + + if (player != null) + { + bool isSponsor = _getSponsorAllowedMarkingsMethod.IsSponsor(player.UserId); + if (validatedFile == true) + { + if (isSponsor == true) + { + bool allowedMarkings = _getSponsorAllowedMarkingsMethod.GetSponsorAllowedMarkings(player.UserId); + + if (marking.SponsorOnly) + { + item.Disabled = !allowedMarkings; + Logger.Info($"{player} is bad player, allowedMarking = {allowedMarkings}"); + } + } + else + { + if (marking.SponsorOnly) + { + item.Disabled = true; + Logger.Error($"Blocking all sponsor item, its doesn't sponsor"); + } + } + } + else + { + if (marking.SponsorOnly) + { + item.Disabled = true; + Logger.Error($"Blocking all sponsor item, file valid"); + } + } + } + // A-13 Sponsor service end } CMarkingPoints.Visible = _currentMarkings.PointsLeft(_selectedMarkingCategory) != -1; diff --git a/Content.Client/Humanoid/SingleMarkingPicker.xaml.cs b/Content.Client/Humanoid/SingleMarkingPicker.xaml.cs index a742d749f4c..03e96685f90 100644 --- a/Content.Client/Humanoid/SingleMarkingPicker.xaml.cs +++ b/Content.Client/Humanoid/SingleMarkingPicker.xaml.cs @@ -1,5 +1,6 @@ using System.Linq; -using Content.Corvax.Interfaces.Shared; +using Robust.Client.Player; // A-13 Sponsor service +using Content.Shared.Andromeda.AndromedaSponsorService; // A-13 Sponsor service using Content.Shared.Humanoid.Markings; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.Controls; @@ -12,7 +13,8 @@ namespace Content.Client.Humanoid; public sealed partial class SingleMarkingPicker : BoxContainer { [Dependency] private readonly MarkingManager _markingManager = default!; - private ISharedSponsorsManager? _sponsorsManager; // Corvax-Sponsors + [Dependency] private readonly GetSponsorAllowedMarkingsMethod _getSponsorAllowedMarkingsMethod = default!; // A-13 Sponsor service + [Dependency] private readonly IPlayerManager _playerManager = default!; // A-13 Sponsor service /// /// What happens if a marking is selected. @@ -193,10 +195,33 @@ public void PopulateList(string filter) { var item = MarkingList.AddItem(Loc.GetString($"marking-{id}"), marking.Sprites[0].Frame0()); item.Metadata = marking.ID; - // Corvax-Sponsors-Start - if (marking.SponsorOnly && _sponsorsManager != null) - item.Disabled = !_sponsorsManager.GetClientPrototypes().Contains(marking.ID); - // Corvax-Sponsors-End + + // A-13 Sponsor service start + var player = _playerManager.LocalSession; + var validatedFile = _getSponsorAllowedMarkingsMethod.FileIsValid(); + + if (validatedFile == true) + { + if (player != null) + { + bool allowedMarkings = _getSponsorAllowedMarkingsMethod.GetSponsorAllowedMarkings(player.UserId); + + if (marking.SponsorOnly) + { + item.Disabled = !allowedMarkings; + Logger.Info($"{player} is bad player, allowedMarking = {allowedMarkings}"); + } + } + } + else + { + if (marking.SponsorOnly) + { + item.Disabled = true; + Logger.Error($"Blocking all sponsor item, file valid"); + } + } + // A-13 Sponsor service end if (_markings[Slot].MarkingId == id) { diff --git a/Content.Server/Andromeda/AndromedaSponsorService/AndromedaSponsorManager.cs b/Content.Server/Andromeda/AndromedaSponsorService/AndromedaSponsorManager.cs new file mode 100644 index 00000000000..f153b490bae --- /dev/null +++ b/Content.Server/Andromeda/AndromedaSponsorService/AndromedaSponsorManager.cs @@ -0,0 +1,131 @@ +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; + +namespace Content.Server.Andromeda.AndromedaSponsorService; + +public sealed class AndromedaSponsorManager +{ + private readonly HashSet _sponsors = new HashSet(); + private readonly string _sponsorsFilePath = "Resources/Prototypes/Andromeda/sponsors.txt"; + + public void LoadSponsors() + { + if (!File.Exists(_sponsorsFilePath)) + { + File.WriteAllText(_sponsorsFilePath, string.Empty); + } + + _sponsors.Clear(); + + foreach (var line in File.ReadLines(_sponsorsFilePath)) + { + string[] parts = line.Split(';'); + + if (parts.Length >= 2 && Guid.TryParse(parts[0], out var guid)) + { + _sponsors.Add(guid); + } + } + } + + public void SaveSponsors(Guid userId, bool? allowedAntag = null, string? color = null, bool? allowedMarkings = null) + { + var lines = File.ReadAllLines(_sponsorsFilePath).ToList(); + var index = lines.FindIndex(line => line.StartsWith(userId.ToString())); + + if (index != -1) + { + lines[index] = $"{userId};{allowedAntag ?? false};{color ?? ""};{allowedMarkings ?? false}"; + } + else + { + lines.Add($"{userId};{allowedAntag ?? false};{color ?? ""};{allowedMarkings ?? false}"); + } + + File.WriteAllLines(_sponsorsFilePath, lines); + } + + public bool IsSponsor(Guid userId) + { + return _sponsors.Contains(userId); + } + + public List GetActiveSponsors() + { + return new List(_sponsors); + } + + public void AddSponsor(Guid userId, bool allowedAntag, string color, bool allowedMarkings) + { + _sponsors.Add(userId); + + SaveSponsors(userId, allowedAntag, color, allowedMarkings); + } + + public void RemoveSponsor(Guid userId) + { + _sponsors.Remove(userId); + + var lines = File.ReadAllLines(_sponsorsFilePath).ToList(); + var index = lines.FindIndex(line => line.StartsWith(userId.ToString())); + + if (index != -1) + { + lines.RemoveAt(index); + File.WriteAllLines(_sponsorsFilePath, lines); + } + } + + public bool GetSponsorAllowedAntag(Guid userId) + { + string[] lines = File.ReadAllLines(_sponsorsFilePath); + + foreach (string line in lines) + { + string[] parts = line.Split(';'); + + if (Guid.Parse(parts[0]) == userId) + { + bool allowedAntag; + if (bool.TryParse(parts[1], out allowedAntag)) + { + return allowedAntag; + } + } + } + + return false; + } + + public Color? GetSponsorOocColor(Guid userId) + { + string[] lines = File.ReadAllLines(_sponsorsFilePath); + + foreach (string line in lines) + { + string[] parts = line.Split(';'); + + if (Guid.Parse(parts[0]) == userId) + { + if (string.IsNullOrWhiteSpace(parts[2])) + { + return null; + } + + Color color; + if (Color.TryParse(parts[2], out color)) + { + return color; + } + } + } + + return null; + } + + public bool IsValidColor(string color) + { + return Regex.IsMatch(color, @"^#[0-9A-Fa-f]{6}$"); + } +} \ No newline at end of file diff --git a/Content.Server/Andromeda/Commands/SponsorManagerCommand/AddSponsor.cs b/Content.Server/Andromeda/Commands/SponsorManagerCommand/AddSponsor.cs new file mode 100644 index 00000000000..900d29bbb2a --- /dev/null +++ b/Content.Server/Andromeda/Commands/SponsorManagerCommand/AddSponsor.cs @@ -0,0 +1,74 @@ +using Content.Server.Administration; +using Content.Shared.Administration; +using Robust.Shared.Console; +using Content.Server.Andromeda.AndromedaSponsorService; + +namespace Content.Server.Andromeda.Commands.SponsorManagerCommand; + +[AdminCommand(AdminFlags.Host)] +public sealed class AddSponsorCommand : IConsoleCommand +{ + [Dependency] private readonly AndromedaSponsorManager _sponsorManager = default!; + + public string Command => "addsponsor"; + public string Description => "Adds a sponsor by their user ID."; + public string Help => $"Usage: {Command} [allowedAntag] [OOC color] [allowedMarkings]"; + + public void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length == 0) + { + shell.WriteLine(Help); + return; + } + + if (!Guid.TryParse(args[0], out var userId)) + { + shell.WriteLine($"Invalid user ID: {args[0]}"); + return; + } + + bool allowedAntag = false; + if (args.Length > 1) + { + if (!bool.TryParse(args[1], out allowedAntag)) + { + shell.WriteLine($"Invalid allowedAntag value: {args[1]}"); + return; + } + } + + string color = ""; + if (args.Length > 2) + { + color = args[2]; + + if (!_sponsorManager.IsValidColor(args[2])) + { + shell.WriteLine($"Invalid color: {args[2]}"); + return; + } + } + + bool allowedMarkings = false; + if (args.Length > 3) + { + if (!bool.TryParse(args[3], out allowedMarkings)) + { + shell.WriteLine($"Invalid allowedMarkings value: {args[3]}"); + return; + } + } + + if (_sponsorManager.IsSponsor(userId)) + { + _sponsorManager.SaveSponsors(userId, allowedAntag, color, allowedMarkings); + shell.WriteLine($"Sponsor data for user {userId} updated successfully."); + } + else + { + _sponsorManager.AddSponsor(userId, allowedAntag, color, allowedMarkings); + shell.WriteLine($"User {userId} added as a sponsor."); + } + } +} \ No newline at end of file diff --git a/Content.Server/Andromeda/Commands/SponsorManagerCommand/ListActiveSponsor.cs b/Content.Server/Andromeda/Commands/SponsorManagerCommand/ListActiveSponsor.cs new file mode 100644 index 00000000000..0a65729571f --- /dev/null +++ b/Content.Server/Andromeda/Commands/SponsorManagerCommand/ListActiveSponsor.cs @@ -0,0 +1,39 @@ +using Robust.Shared.Console; +using Content.Server.Andromeda.AndromedaSponsorService; +using Content.Server.Administration; +using Content.Shared.Administration; +using Robust.Shared.Network; +using Robust.Server.Player; + +namespace Content.Server.Andromeda.Commands.SponsorManagerCommand; + +[AdminCommand(AdminFlags.Admin)] +public sealed class ListActiveSponsorsCommand : IConsoleCommand +{ + [Dependency] private readonly IPlayerManager _playerManager = default!; + [Dependency] private readonly AndromedaSponsorManager _sponsorManager = default!; + + public string Command => "listsponsors"; + public string Description => "Lists all active sponsors."; + public string Help => $"Usage: {Command}"; + + public void Execute(IConsoleShell shell, string argStr, string[] args) + { + var activeSponsors = new List(); + + foreach (var session in _playerManager.Sessions) + { + if (_sponsorManager.IsSponsor(session.UserId)) + { + activeSponsors.Add(session.UserId); + } + } + + shell.WriteLine("Active sponsors:"); + foreach (var sponsor in activeSponsors) + { + var session = _playerManager.GetSessionById(new NetUserId(sponsor)); + shell.WriteLine($"- {session?.Name}"); + } + } +} \ No newline at end of file diff --git a/Content.Server/Andromeda/Commands/SponsorManagerCommand/RemoveSponsor.cs b/Content.Server/Andromeda/Commands/SponsorManagerCommand/RemoveSponsor.cs new file mode 100644 index 00000000000..4fce6a0cdf5 --- /dev/null +++ b/Content.Server/Andromeda/Commands/SponsorManagerCommand/RemoveSponsor.cs @@ -0,0 +1,40 @@ +using Content.Server.Administration; +using Content.Shared.Administration; +using Robust.Shared.Console; +using Content.Server.Andromeda.AndromedaSponsorService; + +namespace Content.Server.Andromeda.Commands.SponsorManagerCommand; + +[AdminCommand(AdminFlags.Host)] +public sealed class RemoveSponsorCommand : IConsoleCommand +{ + [Dependency] private readonly AndromedaSponsorManager _sponsorManager = default!; + + public string Command => "removesponsor"; + public string Description => "Removes a sponsor from the list."; + public string Help => $"Usage: {Command} "; + + public void Execute(IConsoleShell shell, string argStr, string[] args) + { + if (args.Length != 1) + { + shell.WriteLine(Help); + return; + } + + if (!Guid.TryParse(args[0], out var userId)) + { + shell.WriteLine($"Invalid user ID: {args[0]}"); + return; + } + + if (!_sponsorManager.IsSponsor(userId)) + { + shell.WriteLine($"User {userId} is not a sponsor."); + return; + } + + _sponsorManager.RemoveSponsor(userId); + shell.WriteLine($"Sponsor with user ID {userId} removed successfully."); + } +} \ No newline at end of file diff --git a/Content.Server/Antag/AntagSelectionSystem.cs b/Content.Server/Antag/AntagSelectionSystem.cs index 71ef3acbe3d..879e21c4ffd 100644 --- a/Content.Server/Antag/AntagSelectionSystem.cs +++ b/Content.Server/Antag/AntagSelectionSystem.cs @@ -24,7 +24,7 @@ using Robust.Shared.Map; using Robust.Shared.Player; using Robust.Shared.Random; -using Content.Shared.Chat; +using Content.Server.Andromeda.AndromedaSponsorService; //A-13 SponsorAntag using Content.Server.Andromeda.Roles; //A-13 SponsorAntag namespace Content.Server.Antag; @@ -41,6 +41,7 @@ public sealed partial class AntagSelectionSystem : GameRuleSystem en } // A-13 SponsorAntag start - if (session.UserId == new Guid("{d78ea958-8205-41a3-8ea1-8a650dabbf16}")) - //if (_sponsorsManager.TryGetInfo(session.UserId, out var sponsorData) && sponsorData.ExtraSlots >= 7) + if (_sponsorsManager.IsSponsor(session.UserId)) { - sponsorPrefList.Add(session); + bool allowedAntag = _sponsorsManager.GetSponsorAllowedAntag(session.UserId); + + if (allowedAntag == true) + { + sponsorPrefList.Add(session); + } } // A-13 SponsorAntag end diff --git a/Content.Server/Chat/Managers/ChatManager.cs b/Content.Server/Chat/Managers/ChatManager.cs index 8cb7e731510..0fd5e79d4f2 100644 --- a/Content.Server/Chat/Managers/ChatManager.cs +++ b/Content.Server/Chat/Managers/ChatManager.cs @@ -5,6 +5,7 @@ using Content.Server.Administration.Logs; using Content.Server.Administration.Managers; using Content.Server.Administration.Systems; +using Content.Server.Andromeda.AndromedaSponsorService; // A-13 Sponsor service using Content.Server.MoMMI; using Content.Server.Preferences.Managers; using Content.Shared.Administration; @@ -42,11 +43,11 @@ internal sealed partial class ChatManager : IChatManager [Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly IServerPreferencesManager _preferencesManager = default!; [Dependency] private readonly IConfigurationManager _configurationManager = default!; + [Dependency] private readonly AndromedaSponsorManager _sponsorsManager = default!; // A-13 Sponsor service [Dependency] private readonly INetConfigurationManager _netConfigManager = default!; [Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IPlayerManager _playerManager = default!; - private ISharedSponsorsManager? _sponsorsManager; // Corvax-Sponsors /// /// The maximum length a player-sent message can be sent @@ -249,23 +250,31 @@ private void SendOOC(ICommonSession player, string message) } Color? colorOverride = null; - var wrappedMessage = Loc.GetString("chat-manager-send-ooc-wrap-message", ("playerName",player.Name), ("message", FormattedMessage.EscapeText(message))); + var wrappedMessage = Loc.GetString("chat-manager-send-ooc-wrap-message", ("playerName", player.Name), ("message", FormattedMessage.EscapeText(message))); if (_adminManager.HasAdminFlag(player, AdminFlags.Admin)) { 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))); + wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", patronColor), ("playerName", player.Name), ("message", FormattedMessage.EscapeText(message))); } - // Corvax-Sponsors-Start - if (_sponsorsManager != null && _sponsorsManager.TryGetServerOocColor(player.UserId, out var oocColor)) + // A-13 Sponsor service start + if (_sponsorsManager.IsSponsor(player.UserId)) { - wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", oocColor),("playerName", player.Name), ("message", FormattedMessage.EscapeText(message))); + var color = _sponsorsManager.GetSponsorOocColor(player.UserId); + if (color != null) + { + wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", color), ("playerName", player.Name), ("message", FormattedMessage.EscapeText(message))); + } + else + { + wrappedMessage = Loc.GetString("chat-manager-send-ooc-wrap-message", ("playerName", player.Name), ("message", FormattedMessage.EscapeText(message))); + } } - // Corvax-Sponsors-End + // A-13 Sponsor service end //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); diff --git a/Content.Server/Connection/ConnectionManager.cs b/Content.Server/Connection/ConnectionManager.cs index 4c46324dfb7..3eeb2055536 100644 --- a/Content.Server/Connection/ConnectionManager.cs +++ b/Content.Server/Connection/ConnectionManager.cs @@ -1,8 +1,8 @@ using System.Collections.Immutable; using System.Runtime.InteropServices; using System.Threading.Tasks; -using Content.Corvax.Interfaces.Server; -using Content.Corvax.Interfaces.Shared; +using Content.Server.Andromeda.AndromedaSponsorService; // A-13 Sponsor service +using Content.Corvax.Interfaces.Server; // Corvax-VPNGuard using Content.Server.Database; using Content.Server.GameTicking; using Content.Server.Preferences.Managers; @@ -46,11 +46,11 @@ public sealed class ConnectionManager : IConnectionManager [Dependency] private readonly IServerNetManager _netMgr = default!; [Dependency] private readonly IServerDbManager _db = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; + [Dependency] private readonly AndromedaSponsorManager _sponsorsManager = default!; // A-13 Sponsor service [Dependency] private readonly ILocalizationManager _loc = default!; [Dependency] private readonly ServerDbEntryManager _serverDbEntry = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly ILogManager _logManager = default!; - private ISharedSponsorsManager? _sponsorsMgr; // Corvax-Sponsors private IServerVPNGuardManager? _vpnGuardMgr; // Corvax-VPNGuard private readonly Dictionary _temporaryBypasses = []; @@ -283,7 +283,7 @@ private bool HasTemporaryBypass(NetUserId user) public async Task HavePrivilegedJoin(NetUserId userId) { var adminBypass = _cfg.GetCVar(CCVars.AdminBypassMaxPlayers) && await _dbManager.GetAdminDataForAsync(userId) != null; - var havePriorityJoin = _sponsorsMgr != null && _sponsorsMgr.HaveServerPriorityJoin(userId); // Corvax-Sponsors + var havePriorityJoin = _sponsorsManager.IsSponsor(userId); // A-13 Sponsor service var wasInGame = EntitySystem.TryGet(out var ticker) && ticker.PlayerGameStatuses.TryGetValue(userId, out var status) && status == PlayerGameStatus.JoinedGame; diff --git a/Content.Server/Entry/EntryPoint.cs b/Content.Server/Entry/EntryPoint.cs index 422bb197efe..3b87c675a19 100644 --- a/Content.Server/Entry/EntryPoint.cs +++ b/Content.Server/Entry/EntryPoint.cs @@ -24,6 +24,7 @@ using Content.Shared.CCVar; using Content.Shared.Kitchen; using Content.Shared.Localizations; +using Content.Server.Andromeda.AndromedaSponsorService; // A-13 Sponsor service using Robust.Server; using Robust.Server.ServerStatus; using Robust.Shared.Configuration; @@ -104,6 +105,7 @@ public override void Init() IoCManager.Resolve().Initialize(); IoCManager.Resolve().Initialize(); IoCManager.Resolve().Initialize(); // Corvax-TTS + IoCManager.Resolve().LoadSponsors(); // A-13 Sponsor service IoCManager.Resolve().Initialize(); IoCManager.Resolve().Initialize(); diff --git a/Content.Server/GameTicking/Rules/TraitorRuleSystem.cs b/Content.Server/GameTicking/Rules/TraitorRuleSystem.cs index 67b188b62d3..36102230a68 100644 --- a/Content.Server/GameTicking/Rules/TraitorRuleSystem.cs +++ b/Content.Server/GameTicking/Rules/TraitorRuleSystem.cs @@ -17,6 +17,7 @@ using System.Text; using Content.Server.GameTicking.Components; using Robust.Server.Player; // A-13 SponsorAntag +using Content.Server.Andromeda.AndromedaSponsorService; //A-13 SponsorAntag namespace Content.Server.GameTicking.Rules; @@ -32,6 +33,7 @@ public sealed class TraitorRuleSystem : GameRuleSystem [Dependency] private readonly SharedJobSystem _jobs = default!; [Dependency] private readonly ObjectivesSystem _objectives = default!; [Dependency] private readonly IPlayerManager _playerSystem = default!; //A-13 SponsorAntag + [Dependency] private readonly AndromedaSponsorManager _sponsorsManager = default!; // A-13 SponsorAntag public const int MaxPicks = 20; @@ -54,14 +56,18 @@ protected override void Added(EntityUid uid, TraitorRuleComponent component, Gam private void AfterEntitySelected(Entity ent, ref AfterAntagEntitySelectedEvent args) { // A-13 SponsorAntag start - if (_playerSystem.TryGetSessionByEntity(args.EntityUid, out var session) && session.UserId == new Guid("{d78ea958-8205-41a3-8ea1-8a650dabbf16}")) - //if (_playerSystem.TryGetSessionByEntity(args.EntityUid, out var session) && _sponsorsManager.TryGetInfo(session.UserId, out var sponsorData) && sponsorData.ExtraSlots >= 7) + if (_playerSystem.TryGetSessionByEntity(args.EntityUid, out var session) && _sponsorsManager.IsSponsor(session.UserId)) { - MakeTraitor(args.EntityUid, ent, true, true); - } - else - { - MakeTraitor(args.EntityUid, ent); + bool allowedAntag = _sponsorsManager.GetSponsorAllowedAntag(session.UserId); + + if (allowedAntag == true) + { + MakeTraitor(args.EntityUid, ent, true, true); + } + else + { + MakeTraitor(args.EntityUid, ent); + } } // A-13 SponsorAntag end } diff --git a/Content.Server/IoC/ServerContentIoC.cs b/Content.Server/IoC/ServerContentIoC.cs index f5219e275a7..946aa69f265 100644 --- a/Content.Server/IoC/ServerContentIoC.cs +++ b/Content.Server/IoC/ServerContentIoC.cs @@ -24,6 +24,7 @@ using Content.Shared.Administration.Managers; using Content.Shared.Kitchen; using Content.Shared.Players.PlayTimeTracking; +using Content.Server.Andromeda.AndromedaSponsorService; // A-13 Sponsor service namespace Content.Server.IoC { @@ -57,6 +58,8 @@ public static void Register() IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); // Corvax-TTS + IoCManager.Register(); // Corvax-DiscordAuth + IoCManager.Register(); // A-13 Sponsor service IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); diff --git a/Content.Shared/Andromeda/AndromedaSponsorService/GetSponsorAllowedMarkingsMethod.cs b/Content.Shared/Andromeda/AndromedaSponsorService/GetSponsorAllowedMarkingsMethod.cs new file mode 100644 index 00000000000..0295be9a9ea --- /dev/null +++ b/Content.Shared/Andromeda/AndromedaSponsorService/GetSponsorAllowedMarkingsMethod.cs @@ -0,0 +1,69 @@ +using Robust.Shared.ContentPack; + +namespace Content.Shared.Andromeda.AndromedaSponsorService; + +public sealed class GetSponsorAllowedMarkingsMethod +{ + [Dependency] private readonly IResourceManager _resourceManager = default!; + private readonly string _sponsorsFilePath = "/Prototypes/Andromeda/sponsors.txt"; + + public bool FileIsValid() + { + string fileContent = _resourceManager.ContentFileReadAllText(_sponsorsFilePath); + + if (string.IsNullOrWhiteSpace(fileContent)) + { + return false; + } + else + { + return true; + } + } + + public bool IsSponsor(Guid userId) + { + string fileContent = _resourceManager.ContentFileReadAllText(_sponsorsFilePath); + string[] lines = fileContent.Split(new[] { Environment.NewLine }, StringSplitOptions.None); + + foreach (string line in lines) + { + string[] parts = line.Split(';'); + + if (Guid.TryParse(parts[0], out Guid userGuid) && userGuid == userId) + { + return true; + } + } + + return false; + } + + public bool GetSponsorAllowedMarkings(Guid userId) + { + string fileContent = _resourceManager.ContentFileReadAllText(_sponsorsFilePath); + string[] lines = fileContent.Split(new[] { Environment.NewLine }, StringSplitOptions.None); + + if (string.IsNullOrWhiteSpace(fileContent)) + { + return false; + } + + foreach (string line in lines) + { + string[] parts = line.Split(';'); + + if (Guid.TryParse(parts[0], out Guid userGuid) && userGuid == userId) + { + bool allowedMarkings; + + if (bool.TryParse(parts[3], out allowedMarkings)) + { + return allowedMarkings; + } + } + } + + return false; + } +} \ No newline at end of file diff --git a/Content.Shared/IoC/SharedContentIoC.cs b/Content.Shared/IoC/SharedContentIoC.cs index c20cdbc111e..728116dd5a7 100644 --- a/Content.Shared/IoC/SharedContentIoC.cs +++ b/Content.Shared/IoC/SharedContentIoC.cs @@ -1,4 +1,5 @@ -using Content.Shared.Humanoid.Markings; +using Content.Shared.Andromeda.AndromedaSponsorService; // A-13 Sponsor service +using Content.Shared.Humanoid.Markings; using Content.Shared.Localizations; namespace Content.Shared.IoC @@ -9,6 +10,7 @@ public static void Register() { IoCManager.Register(); IoCManager.Register(); + IoCManager.Register(); // A-13 Sponsor service } } }