diff --git a/.gitignore b/.gitignore index 5aa7933..2e48831 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ .vs/ **/obj -**/bin \ No newline at end of file +**/bin + +# Ignore everything in BuildOutput directory +BuildOutput/ \ No newline at end of file diff --git a/TagsApi/TagsApi.cs b/TagsApi/TagsApi.cs index aa87090..7a9fbd8 100644 --- a/TagsApi/TagsApi.cs +++ b/TagsApi/TagsApi.cs @@ -9,6 +9,18 @@ public class Tag public string ChatColor { get; set; } = string.Empty; public string NameColor { get; set; } = string.Empty; public bool ChatSound { get; set; } = true; + + public Tag Clone() + { + return new Tag + { + ScoreTag = ScoreTag, + ChatTag = ChatTag, + ChatColor = ChatColor, + NameColor = NameColor, + ChatSound = ChatSound + }; + } } public enum Tags_Tags diff --git a/TagsApi/TagsApi.csproj b/TagsApi/TagsApi.csproj index 1206e86..e42e834 100644 --- a/TagsApi/TagsApi.csproj +++ b/TagsApi/TagsApi.csproj @@ -4,6 +4,8 @@ net8.0 enable enable + $(ProjectDir)..\BuildOutput\shared\TagsApi\ + false diff --git a/Tomlyn.dll b/Tomlyn.dll new file mode 100644 index 0000000..88d9d2a Binary files /dev/null and b/Tomlyn.dll differ diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..13996b1 --- /dev/null +++ b/config.toml @@ -0,0 +1,26 @@ +[Settings] +DeadName = "☠" +NoneName = "{White}(NONE)" +SpecName = "{Purple}(SPEC)" +TName = "{Yellow}(T)" +CTName = "{Blue}(CT)" + +[Default] +ScoreTag = "" +ChatTag = "{Grey}[Player]" +ChatColor = "{White}" +NameColor = "{TeamColor}" +ChatSound = true + +[76561199165718810] +ScoreTag = "" +ChatTag = "{Red}[schwarper] " +ChatColor = "{green}" +NameColor = "{TeamColor}" +ChatSound = false + +["#OWNER"] +ScoreTag = "" +ChatTag = "{Red}[OWNER] " +ChatColor = "{green}" +NameColor = "{TeamColor}" \ No newline at end of file diff --git a/cs2-tags/cs2-tags.csproj b/cs2-tags/cs2-tags.csproj index 6939e69..44ccb08 100644 --- a/cs2-tags/cs2-tags.csproj +++ b/cs2-tags/cs2-tags.csproj @@ -4,6 +4,8 @@ net8.0 enable enable + $(ProjectDir)..\BuildOutput\plugins\cs2-tags\ + false @@ -14,4 +16,20 @@ + + + + + + + + + + + + + + + + diff --git a/cs2-tags/src/config/config.cs b/cs2-tags/src/config/config.cs index b2f8b06..4e2dfbf 100644 --- a/cs2-tags/src/config/config.cs +++ b/cs2-tags/src/config/config.cs @@ -27,31 +27,26 @@ public class Cfg } public static Cfg Config { get; set; } = new Cfg(); - private static string? ConfigPath; + private static readonly string ConfigPath; - public static void Load() + static Config_Config() { - if (ConfigPath == null) + string assemblyName = Assembly.GetExecutingAssembly().GetName().Name ?? string.Empty; + + ConfigPath = Path.Combine(Server.GameDirectory, + "csgo", + "addons", + "counterstrikesharp", + "configs", + "plugins", + assemblyName, + "config.toml" + ); + + if (!File.Exists(ConfigPath)) { - string assemblyName = Assembly.GetExecutingAssembly().GetName().Name ?? string.Empty; - - ConfigPath = Path.Combine(Server.GameDirectory, - "csgo", - "addons", - "counterstrikesharp", - "configs", - "plugins", - assemblyName, - "config.toml" - ); - - if (!File.Exists(ConfigPath)) - { - throw new FileNotFoundException($"Configuration file not found: {ConfigPath}"); - } + throw new FileNotFoundException($"Configuration file not found: {ConfigPath}"); } - - LoadConfig(ConfigPath); } public static void Reload() @@ -73,9 +68,9 @@ public static void LoadPlayersTag() } } - private static void LoadConfig(string configPath) + public static void Load() { - string configText = File.ReadAllText(configPath); + string configText = File.ReadAllText(ConfigPath); TomlTable model = Toml.ToModel(configText); TomlTable table = (TomlTable)model["Settings"]; diff --git a/cs2-tags/src/cs2-tag.cs b/cs2-tags/src/cs2-tag.cs index c158035..2f7d812 100644 --- a/cs2-tags/src/cs2-tag.cs +++ b/cs2-tags/src/cs2-tag.cs @@ -17,7 +17,7 @@ namespace Tags; public partial class Tags : BasePlugin { public override string ModuleName => "Tags"; - public override string ModuleVersion => "0.0.9"; + public override string ModuleVersion => "1.0"; public override string ModuleAuthor => "schwarper"; public static ConcurrentDictionary PlayerTagsList { get; set; } = []; @@ -29,9 +29,11 @@ public override void Load(bool hotReload) Api = new TagsAPI(); Capabilities.RegisterPluginCapability(ITagApi.Capability, () => Api); + AddCommandListener("css_admins_reload", AdminsReload, HookMode.Pre); + HookUserMessage(118, OnMessage, HookMode.Pre); - AddTimer(5.0f, UpdateTags, TimerFlags.REPEAT); + AddTimer(10.0f, UpdateTags, TimerFlags.REPEAT); if (hotReload) { @@ -43,6 +45,17 @@ public override void Load(bool hotReload) } } + public override void Unload(bool hotReload) + { + RemoveCommandListener("css_admins_reload", AdminsReload, HookMode.Pre); + } + + public static HookResult AdminsReload(CCSPlayerController? player, CommandInfo info) + { + Reload(); + return HookResult.Continue; + } + [GameEventHandler] public HookResult OnPlayerConnect(EventPlayerConnectFull @event, GameEventInfo info) { @@ -155,7 +168,7 @@ public static void UpdateTags() foreach ((ulong steamid, Tag tag) in PlayerTagsList) { - if (players.FirstOrDefault(p => p.SteamID == steamid) is not CCSPlayerController player) + if (players.SingleOrDefault(p => p.SteamID == steamid) is not CCSPlayerController player) { continue; } diff --git a/cs2-tags/src/library/library.cs b/cs2-tags/src/library/library.cs index c06eff9..349eeb0 100644 --- a/cs2-tags/src/library/library.cs +++ b/cs2-tags/src/library/library.cs @@ -16,7 +16,8 @@ public static partial class TagsLibrary { public static void LoadTag(this CCSPlayerController player) { - PlayerTagsList.TryAdd(player.SteamID, player.GetTag()); + var tag = player.GetTag().Clone(); + PlayerTagsList.TryAdd(player.SteamID, tag); } public static Tag GetTag(this CCSPlayerController player) { @@ -27,21 +28,17 @@ public static Tag GetTag(this CCSPlayerController player) return steamidTag; } - foreach (KeyValuePair tag in tags.Where(tag => tag.Key.StartsWith('#'))) + foreach (var tag in tags) { - bool isInGroup = AdminManager.PlayerInGroup(player, tag.Key); - - if (isInGroup) + if (tag.Key[0] == '#' && AdminManager.PlayerInGroup(player, tag.Key)) { return tag.Value; } } - foreach (KeyValuePair tag in tags.Where(tag => tag.Key.StartsWith('@'))) + foreach (var tag in tags) { - bool hasPermission = AdminManager.PlayerHasPermissions(player, tag.Key); - - if (hasPermission) + if (tag.Key[0] == '@' && AdminManager.PlayerHasPermissions(player, tag.Key)) { return tag.Value; } @@ -84,7 +81,7 @@ public static void ResetTag(this CCSPlayerController player, Tags_Tags tag) { if (PlayerTagsList.TryGetValue(player.SteamID, out var playerData)) { - Tag defaultTag = GetTag(player); + Tag defaultTag = GetTag(player).Clone(); switch (tag) { case Tags_Tags.ScoreTag: @@ -132,7 +129,7 @@ public static void ResetColor(this CCSPlayerController player, Tags_Colors color { if (PlayerTagsList.TryGetValue(player.SteamID, out var playerData)) { - Tag defaultTag = GetTag(player); + Tag defaultTag = GetTag(player).Clone(); switch (color) { case Tags_Colors.NameColor: