Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions AutomaticAds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using AutomaticAds.Config;
using AutomaticAds.Config.Models;
using AutomaticAds.Services;
using AutomaticAds.Managers;
using AutomaticAds.Utils;
Expand All @@ -14,7 +15,7 @@ namespace AutomaticAds;
public class AutomaticAdsBase : BasePlugin, IPluginConfig<BaseConfigs>
{
public override string ModuleName => "AutomaticAds";
public override string ModuleVersion => "1.2.1";
public override string ModuleVersion => "1.2.2";
public override string ModuleAuthor => "luca.uy";
public override string ModuleDescription => "Send automatic messages to the chat and play a sound alert for users to see the message.";

Expand Down Expand Up @@ -64,7 +65,7 @@ public void OnConfigParsed(BaseConfigs config)

private void InitializeServices()
{
_messageFormatter = new MessageFormatter();
_messageFormatter = new MessageFormatter(Config);
_timerManager = new TimerManager(this);
_playerManager = new PlayerManager(this);
_ipQueryService = new IPQueryService();
Expand Down Expand Up @@ -143,7 +144,7 @@ private void RegisterTriggerCommands()
}
}

private void HandleTriggerCommand(CCSPlayerController? player, BaseConfigs.AdConfig ad)
private void HandleTriggerCommand(CCSPlayerController? player, AdConfig ad)
{
if (!player.IsValidPlayer())
return;
Expand Down
3 changes: 2 additions & 1 deletion AutomaticAds.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.290" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<None Update="lang\**\*.*" CopyToOutputDirectory="PreserveNewest" />
<None Update="Newtonsoft.Json.dll" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
70 changes: 4 additions & 66 deletions Config/BaseConfigs.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CounterStrikeSharp.API.Core;
using System.Text.Json.Serialization;
using AutomaticAds.Config.Models;

namespace AutomaticAds.Config;

Expand All @@ -11,6 +12,9 @@ public class BaseConfigs : BasePluginConfig
[JsonPropertyName("GlobalPlaySound")]
public string? GlobalPlaySound { get; set; } = "ui/panorama/popup_reveal_01";

[JsonPropertyName("AdminFlag")]
public string? AdminFlag { get; set; } = "@css/generic";

[JsonPropertyName("sendAdsInOrder")]
public bool SendAdsInOrder { get; set; } = true;

Expand Down Expand Up @@ -94,70 +98,4 @@ public class BaseConfigs : BasePluginConfig
onDead = true
}
};

public class AdConfig
{
[JsonPropertyName("message")]
public string Message { get; set; } = string.Empty;

[JsonPropertyName("viewFlag")]
public string? ViewFlag { get; set; } = "all";

[JsonPropertyName("excludeFlag")]
public string? ExcludeFlag { get; set; } = "";

[JsonPropertyName("map")]
public string Map { get; set; } = "all";

[JsonPropertyName("interval")]
public float Interval { get; set; } = 30;

[JsonPropertyName("disableSound")]
public bool DisableSound { get; set; } = false;

[JsonPropertyName("onlyInWarmup")]
public bool OnlyInWarmup { get; set; } = false;

[JsonPropertyName("onlySpec")]
public bool onlySpec { get; set; } = false;

[JsonPropertyName("onDead")]
public bool onDead { get; set; } = false;

[JsonPropertyName("triggerAd")]
public List<string>? TriggerAd { get; set; } = new();

[JsonPropertyName("Disableinterval")]
public bool DisableInterval { get; set; } = false;

[JsonPropertyName("playSoundName")]
public string? PlaySoundName { get; set; } = null;

[JsonPropertyName("displayType")]
public DisplayType DisplayType { get; set; } = DisplayType.Chat;
}

public class WelcomeConfig
{
[JsonPropertyName("WelcomeMessage")]
public string WelcomeMessage { get; set; } = string.Empty;

[JsonPropertyName("viewFlag")]
public string? ViewFlag { get; set; } = "all";

[JsonPropertyName("excludeFlag")]
public string? ExcludeFlag { get; set; } = "";

[JsonPropertyName("disableSound")]
public bool DisableSound { get; set; } = false;
}

public class JoinLeaveConfig
{
[JsonPropertyName("JoinMessage")]
public string JoinMessage { get; set; } = string.Empty;

[JsonPropertyName("LeaveMessage")]
public string LeaveMessage { get; set; } = string.Empty;
}
}
8 changes: 4 additions & 4 deletions Config/ConfigValidator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AutomaticAds.Utils;
using AutomaticAds.Config.Models;

namespace AutomaticAds.Config;

Expand All @@ -12,7 +13,7 @@ public static void ValidateConfig(BaseConfigs config)
ValidateCenterHtmlDisplayTime(config);
}

private static void ValidateAds(List<BaseConfigs.AdConfig> ads)
private static void ValidateAds(List<AdConfig> ads)
{
foreach (var ad in ads)
{
Expand All @@ -21,7 +22,7 @@ private static void ValidateAds(List<BaseConfigs.AdConfig> ads)
}
}

private static void ValidateAdInterval(BaseConfigs.AdConfig ad)
private static void ValidateAdInterval(AdConfig ad)
{
if (ad.Interval > Constants.MaxInterval)
{
Expand All @@ -34,7 +35,7 @@ private static void ValidateAdInterval(BaseConfigs.AdConfig ad)
}
}

private static void ValidateTriggerAd(BaseConfigs.AdConfig ad)
private static void ValidateTriggerAd(AdConfig ad)
{
if (ad.TriggerAd != null)
{
Expand Down Expand Up @@ -65,5 +66,4 @@ private static void ValidateCenterHtmlDisplayTime(BaseConfigs config)
config.centerHtmlDisplayTime = 5.0f;
}
}

}
45 changes: 45 additions & 0 deletions Config/Models/AdConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Text.Json.Serialization;

namespace AutomaticAds.Config.Models;

public class AdConfig
{
[JsonPropertyName("message")]
public string Message { get; set; } = string.Empty;

[JsonPropertyName("viewFlag")]
public string? ViewFlag { get; set; } = "all";

[JsonPropertyName("excludeFlag")]
public string? ExcludeFlag { get; set; } = "";

[JsonPropertyName("map")]
public string Map { get; set; } = "all";

[JsonPropertyName("interval")]
public float Interval { get; set; } = 30;

[JsonPropertyName("disableSound")]
public bool DisableSound { get; set; } = false;

[JsonPropertyName("onlyInWarmup")]
public bool OnlyInWarmup { get; set; } = false;

[JsonPropertyName("onlySpec")]
public bool onlySpec { get; set; } = false;

[JsonPropertyName("onDead")]
public bool onDead { get; set; } = false;

[JsonPropertyName("triggerAd")]
public List<string>? TriggerAd { get; set; } = new();

[JsonPropertyName("Disableinterval")]
public bool DisableInterval { get; set; } = false;

[JsonPropertyName("playSoundName")]
public string? PlaySoundName { get; set; } = null;

[JsonPropertyName("displayType")]
public DisplayType DisplayType { get; set; } = DisplayType.Chat;
}
12 changes: 12 additions & 0 deletions Config/Models/JoinLeaveConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;

namespace AutomaticAds.Config.Models;

public class JoinLeaveConfig
{
[JsonPropertyName("JoinMessage")]
public string JoinMessage { get; set; } = string.Empty;

[JsonPropertyName("LeaveMessage")]
public string LeaveMessage { get; set; } = string.Empty;
}
18 changes: 18 additions & 0 deletions Config/Models/WelcomeConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.Json.Serialization;

namespace AutomaticAds.Config.Models;

public class WelcomeConfig
{
[JsonPropertyName("WelcomeMessage")]
public string WelcomeMessage { get; set; } = string.Empty;

[JsonPropertyName("viewFlag")]
public string? ViewFlag { get; set; } = "all";

[JsonPropertyName("excludeFlag")]
public string? ExcludeFlag { get; set; } = "";

[JsonPropertyName("disableSound")]
public bool DisableSound { get; set; } = false;
}
18 changes: 17 additions & 1 deletion Managers/TimerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class TimerManager
private readonly List<CounterStrikeSharp.API.Modules.Timers.Timer> _timers = new();
private CounterStrikeSharp.API.Modules.Timers.Timer? _adTimer;
private CounterStrikeSharp.API.Modules.Timers.Timer? _specAdTimer;
private CounterStrikeSharp.API.Modules.Timers.Timer? _onDeadAdTimer;
private readonly BasePlugin _plugin;

public TimerManager(BasePlugin plugin)
Expand All @@ -34,6 +35,12 @@ public void SetSpecAdTimer(CounterStrikeSharp.API.Modules.Timers.Timer timer)
_specAdTimer = timer;
}

public void SetOnDeadAdTimer(CounterStrikeSharp.API.Modules.Timers.Timer timer)
{
_onDeadAdTimer?.Kill();
_onDeadAdTimer = timer;
}

public void KillAdTimer()
{
_adTimer?.Kill();
Expand All @@ -46,6 +53,12 @@ public void KillSpecAdTimer()
_specAdTimer = null;
}

public void KillOnDeadAdTimer()
{
_onDeadAdTimer?.Kill();
_onDeadAdTimer = null;
}

public void KillAllTimers()
{
_adTimer?.Kill();
Expand All @@ -54,9 +67,12 @@ public void KillAllTimers()
_specAdTimer?.Kill();
_specAdTimer = null;

_onDeadAdTimer?.Kill();
_onDeadAdTimer = null;

foreach (var timer in _timers)
{
timer.Kill();
timer?.Kill();
}
_timers.Clear();
}
Expand Down
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The configuration file will be automatically generated when the plugin is first
|----------------------|---------------------------------------------------------------------------------------------------|----------|
| `ChatPrefix` | The prefix displayed in the chat before each announcement. Supports colors. To use it, include `{prefix}` inside the `message` field in the ads configuration. | **YES** |
| `GlobalPlaySound` | Sound that is played when an announcement is sent in case `playSoundName` is not set in the announcement and `disableSound` is not `true`. Leave it blank to disable it. | **YES** |
| `AdminFlag` | The permission flag required for a player to be considered an admin in `{admincount}` and `{adminnames}`. | **YES** |
| `sendAdsInOrder` | Send announcements in an orderly manner, respecting the intervals. | **YES** |
| `UseWelcomeMessage` | Set to `true` to enable the welcome message. Set to `false` to disable it. | **YES** |
| `JoinLeaveMessages` | Set `true` to enable custom connection and disconnection messages. Set `false` to disable it. | **YES** |
Expand Down Expand Up @@ -125,18 +126,20 @@ Here is an example configuration file:

### List of Available Variables:
You can use the following placeholders in your announcements:
| Variable | Description |
|--------------|---------------------------------------------------------------|
| `{prefix}` | A dynamic variable replaced with the value of ChatPrefix in each message. Enables optional inclusion or exclusion of the prefix. |
| `{ip}` | The server's IP address. |
| `{port}` | The server's port. |
| `{hostname}` | The server's hostname. |
| `{map}` | The current map being played. |
| `{time}` | The current time in the server's timezone. |
| `{date}` | The current date. |
| `{playername}` | The name the player has on Steam |
| `{players}` | The current number of players online. |
| `{maxplayers}`| The maximum number of players the server can hold. |
| Variable | Description |
|----------------|---------------------------------------------------------------|
| `{prefix}` | A dynamic variable replaced with the value of ChatPrefix in each message. Enables optional inclusion or exclusion of the prefix. |
| `{ip}` | The server's IP address. |
| `{port}` | The server's port. |
| `{hostname}` | The server's hostname. |
| `{map}` | The current map being played. |
| `{time}` | The current time in the server's timezone. |
| `{date}` | The current date. |
| `{playername}` | The name the player has on Steam. |
| `{players}` | The current number of players online. |
| `{maxplayers}` | The maximum number of players the server can hold. |
| `{admincount}` | The number of administrators currently online. |
| `{adminnames}` | A comma-separated list of the names of online administrators. |

## TO-DO
The list of upcoming tasks and features has been moved to a dedicated file. You can find it here: [TO-DO.md](TODO.md)
Expand Down
Loading