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
23 changes: 23 additions & 0 deletions configs/addons/counterstrikesharp/lang/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"menu.button.previous": "Prev",
"menu.button.next": "Next",
"menu.button.close": "Close",

"all": "all players",
"bots": "bots",
"humans": "humans",
"alive": "alive players",
"dead": "dead players",
"notme": "all players except self",
"ct": "ct players",
"t": "t players",
"spec": "spec players",

"No matching client": "No matching client was found.",
"No matching clients": "No matching clients were found.",
"Target must be alive": "This command can only be used on alive players.",
"Target must be dead": "This command can only be used on dead players.",
"Unable to target": "You cannot target this player.",
"Cannot target bot": "Unable to perform this command on a bot.",
"More than one client matched": "More than one client matched the given pattern."
}
23 changes: 23 additions & 0 deletions configs/addons/counterstrikesharp/lang/tr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"menu.button.previous": "Geri",
"menu.button.next": "İleri",
"menu.button.close": "Çıkış",

"all": "tüm oyuncular",
"bots": "botlar",
"humans": "insanlar",
"alive": "hayatta olan oyuncular",
"dead": "ölü oyuncular",
"notme": "kendi hariç tüm oyuncular",
"ct": "CT oyuncular",
"t": "T oyuncular",
"spec": "izleyici oyuncular",

"No matching client": "{white}Eşleşen bir istemci bulunamadı.",
"No matching clients": "{white}Eşleşen istemciler bulunamadı.",
"Target must be alive": "{white}Bu komut yalnızca hayatta olan oyunculara uygulanabilir.",
"Target must be dead": "{white}Bu komut yalnızca ölü oyunculara uygulanabilir.",
"Unable to target": "{white}Bu oyuncu hedeflenemez.",
"Cannot target bot": "{white}Bu komut bir bota uygulanamaz.",
"More than one client matched": "{white}Verilen kalıba birden fazla istemci eşleşti."
}
14 changes: 10 additions & 4 deletions managed/CounterStrikeSharp.API/Bootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
using CounterStrikeSharp.API.Core.Plugin.Host;
using CounterStrikeSharp.API.Core.Translations;
using CounterStrikeSharp.API.Modules.Admin;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Serilog;

Expand All @@ -27,7 +29,7 @@
try
{
// Path to /game/csgo/addons/counterstrikesharp
var contentRoot = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.Parent.FullName;

Check warning on line 32 in managed/CounterStrikeSharp.API/Bootstrap.cs

View workflow job for this annotation

GitHub Actions / build_managed

Dereference of a possibly null reference.

Check warning on line 32 in managed/CounterStrikeSharp.API/Bootstrap.cs

View workflow job for this annotation

GitHub Actions / build_managed

Dereference of a possibly null reference.

Check warning on line 32 in managed/CounterStrikeSharp.API/Bootstrap.cs

View workflow job for this annotation

GitHub Actions / build_managed

Dereference of a possibly null reference.

Check warning on line 32 in managed/CounterStrikeSharp.API/Bootstrap.cs

View workflow job for this annotation

GitHub Actions / build_managed

Dereference of a possibly null reference.

using var host = Host.CreateDefaultBuilder()
.UseContentRoot(contentRoot)
Expand All @@ -44,7 +46,11 @@
services.AddSingleton<IPluginManager, PluginManager>();
services.AddSingleton<IPlayerLanguageManager, PlayerLanguageManager>();
services.AddScoped<IPluginContextQueryHandler, PluginContextQueryHandler>();
services.AddSingleton<ICommandManager, CommandManager>();
services.AddSingleton<ICommandManager, CommandManager>();

services.TryAddSingleton<IStringLocalizerFactory, CoreJsonStringLocalizerFactory>();
services.TryAddTransient(typeof(IStringLocalizer<>), typeof(StringLocalizer<>));
services.TryAddTransient(typeof(IStringLocalizer), typeof(StringLocalizer));

services.Scan(i => i.FromCallingAssembly()
.AddClasses(c => c.AssignableTo<IStartupService>())
Expand All @@ -71,4 +77,4 @@
return 0;
}
}
}
}
7 changes: 6 additions & 1 deletion managed/CounterStrikeSharp.API/Core/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
using CounterStrikeSharp.API.Modules.Menu;
using CounterStrikeSharp.API.Modules.Utils;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;

namespace CounterStrikeSharp.API.Core
{
public sealed class Application
{
private static Application _instance = null!;
public static IStringLocalizer Localizer => Instance._localizer;

public ILogger Logger { get; }

public static Application Instance => _instance!;
Expand All @@ -48,11 +51,12 @@ public sealed class Application
private readonly IPluginContextQueryHandler _pluginContextQueryHandler;
private readonly IPlayerLanguageManager _playerLanguageManager;
private readonly ICommandManager _commandManager;
private readonly IStringLocalizer _localizer;

public Application(ILoggerFactory loggerFactory, IScriptHostConfiguration scriptHostConfiguration,
GameDataProvider gameDataProvider, CoreConfig coreConfig, IPluginManager pluginManager,
IPluginContextQueryHandler pluginContextQueryHandler, IPlayerLanguageManager playerLanguageManager,
ICommandManager commandManager)
ICommandManager commandManager, IStringLocalizer localizer)
{
Logger = loggerFactory.CreateLogger("Core");
_scriptHostConfiguration = scriptHostConfiguration;
Expand All @@ -62,6 +66,7 @@ public Application(ILoggerFactory loggerFactory, IScriptHostConfiguration script
_pluginContextQueryHandler = pluginContextQueryHandler;
_playerLanguageManager = playerLanguageManager;
_commandManager = commandManager;
_localizer = localizer;
_instance = this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,11 @@ public interface IScriptHostConfiguration
/// Gets the absolute path to the directory that contains CounterStrikeSharp game data.
/// e.g. /game/csgo/addons/counterstrikesharp/gamedata
/// </summary>
string GameDataPath { get; }
}
string GameDataPath { get; }

/// <summary>
/// Gets the absolute path to the directory that contains CounterStrikeSharp translation files.
/// e.g. /game/csgo/addons/counterstrikesharp/lang
/// </summary>
string LanguagePath { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ internal sealed class ScriptHostConfiguration : IScriptHostConfiguration
public string PluginPath { get; }
public string SharedPath { get; }
public string ConfigsPath { get; }
public string GameDataPath { get; }
public string GameDataPath { get; }
public string LanguagePath { get; }

public ScriptHostConfiguration(IHostEnvironment hostEnvironment)
{
RootPath = Path.Join(new[] { hostEnvironment.ContentRootPath });
SharedPath = Path.Join(new[] { hostEnvironment.ContentRootPath, "shared" });
PluginPath = Path.Join(new[] { hostEnvironment.ContentRootPath, "plugins" });
ConfigsPath = Path.Join(new[] { hostEnvironment.ContentRootPath, "configs" });
GameDataPath = Path.Join(new[] { hostEnvironment.ContentRootPath, "gamedata" });
GameDataPath = Path.Join(new[] { hostEnvironment.ContentRootPath, "gamedata" });
LanguagePath = Path.Join(new[] { hostEnvironment.ContentRootPath, "lang" });
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using CounterStrikeSharp.API.Core.Hosting;
using Microsoft.Extensions.Localization;

namespace CounterStrikeSharp.API.Core.Translations;

public class CoreJsonStringLocalizerFactory : IStringLocalizerFactory
{
private IScriptHostConfiguration _scriptHostConfiguration;

public CoreJsonStringLocalizerFactory(IScriptHostConfiguration scriptHostConfiguration)
{
_scriptHostConfiguration = scriptHostConfiguration;
}

public IStringLocalizer Create(Type resourceSource)
{
return new JsonStringLocalizer(_scriptHostConfiguration.LanguagePath);
}

public IStringLocalizer Create(string baseName, string location)
{
return new JsonStringLocalizer(_scriptHostConfiguration.LanguagePath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public LocalizedString this[string name]
result = _resourceManager.GetFallbackString(name);
}

// Fallback to the default culture (en-US) if the resource is not found for the current culture.
// Fallback to the default culture (whatever is in core.json) if the resource is not found for the current culture.
if (result == null && !culture.Equals(CultureInfo.DefaultThreadCurrentUICulture))
{
result = _resourceManager.GetString(name, CultureInfo.DefaultThreadCurrentUICulture!);
Expand Down Expand Up @@ -119,4 +119,4 @@ private IEnumerable<string> GetResourceNamesFromCultureHierarchy(CultureInfo sta

return resourceNames;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* This file is part of CounterStrikeSharp.
* CounterStrikeSharp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CounterStrikeSharp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/

namespace CounterStrikeSharp.API.Modules.Commands.Targeting;

/// <summary>
/// Specifies filters for processing command targets.
/// </summary>
[Flags]
public enum ProcessTargetFilterFlag
{
/// <summary>
/// No filter applied.
/// </summary>
None = 0,

/// <summary>
/// Only allow alive players as targets.
/// </summary>
FilterAlive = 1 << 0,

/// <summary>
/// Only allow dead players as targets.
/// </summary>
FilterDead = 1 << 1,

/// <summary>
/// Filter out targets that the command issuer cannot target due to immunity rules.
/// </summary>
FilterNoImmunity = 1 << 2,

/// <summary>
/// Do not allow multiple target patterns like @all, @ct, etc.
/// </summary>
FilterNoMulti = 1 << 3,

/// <summary>
/// Do not allow bots to be targeted.
/// </summary>
FilterNoBots = 1 << 4
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* This file is part of CounterStrikeSharp.
* CounterStrikeSharp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CounterStrikeSharp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CounterStrikeSharp. If not, see <https://www.gnu.org/licenses/>. *
*/

namespace CounterStrikeSharp.API.Modules.Commands.Targeting;

/// <summary>
/// Represents the result of a target processing operation.
/// </summary>
public enum ProcessTargetResultFlag
{
/// <summary>
/// Target(s) were successfully found and filtered.
/// </summary>
TargetFound,

/// <summary>
/// No target was found matching the initial pattern.
/// </summary>
TargetNone,

/// <summary>
/// A single target was found, but they were not alive as required by the filter.
/// Or a multi-target filter resulted in no alive players.
/// </summary>
TargetNotAlive,

/// <summary>
/// A single target was found, but they were not dead as required by the filter.
/// Or a multi-target filter resulted in no dead players.
/// </summary>
TargetNotDead,

/// <summary>
/// The target is immune and cannot be targeted by the command issuer.
/// </summary>
TargetImmune,

/// <summary>
/// A multi-target filter (like @all) resulted in no players after filtering.
/// </summary>
TargetEmptyFilter,

/// <summary>
/// The target was found, but it was not a human player as required by the filter.
/// </summary>
TargetNotHuman,

/// <summary>
/// The target string was ambiguous and matched more than one player when a single target was expected.
/// </summary>
TargetAmbiguous
}
Loading
Loading