Skip to content

Commit

Permalink
Update Advertisement.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
partiusfabaa committed Dec 10, 2023
1 parent 7f54acf commit 0d9579c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Advertisement/Advertisement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,20 @@ public class Ads : BasePlugin
private int _panelCount;
private Config _config = null!;
private readonly List<Timer> _timers = new();
private readonly Dictionary<ulong, string> _playerIsoCode = new();

public override void Load(bool hotReload)
{
_config = LoadConfig();

RegisterListener<Listeners.OnClientAuthorized>((slot, id) =>
{
var player = Utilities.GetPlayerFromSlot(slot);
if (player.IpAddress != null)
_playerIsoCode.Add(id.SteamId64, GetPlayerIsoCode(player.IpAddress.Split(':')[0]));
});

RegisterEventHandler<EventCsWinPanelRound>(EventCsWinPanelRound, HookMode.Pre);
RegisterEventHandler<EventPlayerConnectFull>(EventPlayerConnectFull);

Expand Down Expand Up @@ -133,8 +143,8 @@ private void PrintWrappedLine(HudDestination destination, string message, string
foreach (var player in Utilities.GetPlayers().Where(u => u.IpAddress != null && u.IpAddress != "127.0.0.1"))
{
if (!_config.LanguageMessages.TryGetValue(message, out var language)) return;

var playerCountryIso = GetPlayerCountry(player.IpAddress?.Split(':')[0]!);
if (!_playerIsoCode.TryGetValue(player.SteamID, out var playerCountryIso)) return;

var msg = string.Empty;

if (!language.ContainsValue(playerCountryIso))
Expand Down Expand Up @@ -308,7 +318,7 @@ private Config CreateConfig(string configPath)
return config;
}

private string GetPlayerCountry(string ip)
private string GetPlayerIsoCode(string ip)
{
try
{
Expand Down

0 comments on commit 0d9579c

Please sign in to comment.