From 6ea8607285a0a69decc1506241956c3bd7960102 Mon Sep 17 00:00:00 2001 From: Lemirda <142801986+Lemirda@users.noreply.github.com> Date: Wed, 5 Jun 2024 18:28:54 +0300 Subject: [PATCH] New manager by Lemird v1 --- Content.Client/Humanoid/MarkingPicker.xaml.cs | 48 +++++-- .../Humanoid/SingleMarkingPicker.xaml.cs | 35 +++-- .../AndromedaSponsorManager.cs | 131 ++++++++++++++++++ .../SponsorManagerCommand/AddSponsor.cs | 74 ++++++++++ .../ListActiveSponsor.cs | 39 ++++++ .../SponsorManagerCommand/RemoveSponsor.cs | 40 ++++++ Content.Server/Antag/AntagSelectionSystem.cs | 16 ++- Content.Server/Chat/Managers/ChatManager.cs | 26 ++-- .../Connection/ConnectionManager.cs | 6 +- Content.Server/Entry/EntryPoint.cs | 2 + .../GameTicking/Rules/TraitorRuleSystem.cs | 22 +-- Content.Server/IoC/ServerContentIoC.cs | 4 +- .../GetSponsorAllowedMarkingsMethod.cs | 69 +++++++++ Content.Shared/IoC/SharedContentIoC.cs | 4 +- 14 files changed, 468 insertions(+), 48 deletions(-) create mode 100644 Content.Server/Andromeda/AndromedaSponsorService/AndromedaSponsorManager.cs create mode 100644 Content.Server/Andromeda/Commands/SponsorManagerCommand/AddSponsor.cs create mode 100644 Content.Server/Andromeda/Commands/SponsorManagerCommand/ListActiveSponsor.cs create mode 100644 Content.Server/Andromeda/Commands/SponsorManagerCommand/RemoveSponsor.cs create mode 100644 Content.Shared/Andromeda/AndromedaSponsorService/GetSponsorAllowedMarkingsMethod.cs diff --git a/Content.Client/Humanoid/MarkingPicker.xaml.cs b/Content.Client/Humanoid/MarkingPicker.xaml.cs index 8e331bed02d..4cf9c3c49f4 100644 --- a/Content.Client/Humanoid/MarkingPicker.xaml.cs +++ b/Content.Client/Humanoid/MarkingPicker.xaml.cs @@ -1,5 +1,6 @@ using System.Linq; -using Content.Client.Corvax.Sponsors; +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!; - [Dependency] private readonly SponsorsManager _sponsorsManager = default!; // 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; @@ -226,16 +227,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) + + // A-13 Sponsor service start + var player = _playerManager.LocalSession; + var validatedFile = _getSponsorAllowedMarkingsMethod.FileIsValid(); + + if (player != null) { - item.Disabled = true; - if (_sponsorsManager.TryGetInfo(out var sponsor)) + 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 { - item.Disabled = !sponsor.AllowedMarkings.Contains(marking.ID); + if (marking.SponsorOnly) + { + item.Disabled = true; + Logger.Error($"Blocking all sponsor item, file valid"); + } } } - // Corvax-Sponsors-End + // 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 c6f9f0b0481..8d192851776 100644 --- a/Content.Client/Humanoid/SingleMarkingPicker.xaml.cs +++ b/Content.Client/Humanoid/SingleMarkingPicker.xaml.cs @@ -1,5 +1,6 @@ using System.Linq; -using Content.Client.Corvax.Sponsors; +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!; - [Dependency] private readonly SponsorsManager _sponsorsManager = default!; // 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. @@ -192,16 +194,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) + + // 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 { - item.Disabled = true; - if (_sponsorsManager.TryGetInfo(out var sponsor)) + if (marking.SponsorOnly) { - item.Disabled = !sponsor.AllowedMarkings.Contains(marking.ID); + item.Disabled = true; + Logger.Error($"Blocking all sponsor item, file valid"); } } - // Corvax-Sponsors-End + // 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 3c0f231ef5c..a3aefd98173 100644 --- a/Content.Server/Antag/AntagSelectionSystem.cs +++ b/Content.Server/Antag/AntagSelectionSystem.cs @@ -24,9 +24,7 @@ using Robust.Shared.Map; using Robust.Shared.Player; using Robust.Shared.Random; -using Content.Shared.Chat; -using Content.Server.Corvax.Sponsors; //A-13 SponsorAntag -using Content.Server.Andromeda.Roles; //A-13 SponsorAntag +using Content.Server.Andromeda.AndromedaSponsorService; //A-13 SponsorAntag namespace Content.Server.Antag; @@ -42,7 +40,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 5cbcb6dae85..c89ae76b61b 100644 --- a/Content.Server/Chat/Managers/ChatManager.cs +++ b/Content.Server/Chat/Managers/ChatManager.cs @@ -4,7 +4,7 @@ using Content.Server.Administration.Logs; using Content.Server.Administration.Managers; using Content.Server.Administration.Systems; -using Content.Server.Corvax.Sponsors; +using Content.Server.Andromeda.AndromedaSponsorService; // A-13 Sponsor service using Content.Server.MoMMI; using Content.Server.Preferences.Managers; using Content.Shared.Administration; @@ -42,7 +42,7 @@ 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 SponsorsManager _sponsorsManager = default!; // Corvax-Sponsors + [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 IPlayerManager _playerManager = default!; @@ -241,23 +241,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.TryGetInfo(player.UserId, out var sponsorData) && sponsorData.OOCColor != null) + // A-13 Sponsor service start + if (_sponsorsManager.IsSponsor(player.UserId)) { - wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", sponsorData.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 cdcabb54703..4dd16779b96 100644 --- a/Content.Server/Connection/ConnectionManager.cs +++ b/Content.Server/Connection/ConnectionManager.cs @@ -1,7 +1,7 @@ using System.Collections.Immutable; using System.Runtime.InteropServices; using System.Threading.Tasks; -using Content.Server.Corvax.Sponsors; +using Content.Server.Andromeda.AndromedaSponsorService; // A-13 Sponsor service using Content.Server.Database; using Content.Server.GameTicking; using Content.Server.Preferences.Managers; @@ -45,7 +45,7 @@ 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 SponsorsManager _sponsorsManager = default!; // Corvax-Sponsors + [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!; @@ -263,7 +263,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 = _sponsorsManager.TryGetInfo(userId, out var sponsor) && sponsor.HavePriorityJoin; // 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 7c5601c4282..cb72f5849be 100644 --- a/Content.Server/Entry/EntryPoint.cs +++ b/Content.Server/Entry/EntryPoint.cs @@ -27,6 +27,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; @@ -110,6 +111,7 @@ public override void Init() IoCManager.Resolve().Initialize(); // Corvax-Sponsors IoCManager.Resolve().Initialize(); // Corvax-Queue 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 67a0afffd8b..36102230a68 100644 --- a/Content.Server/GameTicking/Rules/TraitorRuleSystem.cs +++ b/Content.Server/GameTicking/Rules/TraitorRuleSystem.cs @@ -17,7 +17,7 @@ using System.Text; using Content.Server.GameTicking.Components; using Robust.Server.Player; // A-13 SponsorAntag -using Content.Server.Corvax.Sponsors; // A-13 SponsorAntag +using Content.Server.Andromeda.AndromedaSponsorService; //A-13 SponsorAntag namespace Content.Server.GameTicking.Rules; @@ -33,7 +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 SponsorsManager _sponsorsManager = default!; // A-13 SponsorAntag + [Dependency] private readonly AndromedaSponsorManager _sponsorsManager = default!; // A-13 SponsorAntag public const int MaxPicks = 20; @@ -56,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 f8617826209..3593910242b 100644 --- a/Content.Server/IoC/ServerContentIoC.cs +++ b/Content.Server/IoC/ServerContentIoC.cs @@ -3,7 +3,6 @@ using Content.Server.Administration.Managers; using Content.Server.Administration.Notes; using Content.Server.Afk; -using Content.Server.Andromeda; using Content.Server.Chat.Managers; using Content.Server.Connection; using Content.Server.Corvax.DiscordAuth; @@ -28,6 +27,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 { @@ -64,8 +64,8 @@ public static void Register() IoCManager.Register(); // Corvax-Queue IoCManager.Register(); // Corvax-TTS IoCManager.Register(); // Corvax-DiscordAuth + IoCManager.Register(); // A-13 Sponsor service IoCManager.Register(); - //IoCManager.Register(); // Andromeda BanNotification 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 } } }