Skip to content

Commit

Permalink
Move Locale from matchconfig to serverconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
TheR00st3r committed Nov 28, 2023
1 parent b4a10b7 commit e450616
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 74 deletions.
98 changes: 48 additions & 50 deletions Docs/source/admin/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Configuration

Introduction
----------------------------------------
There are three types of configurations that are relevant for PugSharp.
There are three types of configurations that are relevant for PugSharp.


PugSharp Configs
Expand All @@ -17,50 +17,48 @@ The matchconfig defines the current match. It is not loaded automatically, so yo

Matchconfig Fields
'''''''''''''''''''''
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| Field | DefaultValue | Description |
+==========================+=================+===========================================================================================+
| maplist | none (required) | List of available maps for the map vote |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| team1 | none (required) | Team declaration |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| team2 | none (required) | Team declaration |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| matchid | none (required) | Unique Identifier for the match |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| num_maps | 1 | Number of Maps to be played. This should be an odd number to determine a winner. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| players_per_team | 5 | Maximum possible number of players per team. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| min_players_to_ready | 5 | Number of players per team that have to be ready to start the game. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| max_rounds | 24 | Maximum number of rounds played for the main match. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| max_overtime_rounds | 6 | Maximum number of rounds played in overtime. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| vote_timeout | 60000 (60s) | Timeout in milliseconds. If a team does not complete the vote within this timeout, the |
| | | map with the most votes gets banned. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| eventula_apistats_url | (optional) | URL where the Game State has to be sent. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| eventula_apistats_token | (optional) | Optional AuthToken used to authenticate on apistats upload. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| eventula_demo_upload_url | (optional) | URL to upload the game demo to `eventula <https://github.com/Lan2Play/eventula-manager>`_ |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| g5_api_url | (optional) | URL to send the g5 events to. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| g5_api_header | (optional) | Header that should be set to access the g5 events API. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| g5_api_headervalue | (optional) | Header value that should be set to access the g5 events API. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| allow_suicide | true | Flag to determine if players are allowed to suicide. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| vote_map | de_dust2 | Map used during warm-up and voting. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| server_locale | en | This is the language that will be used for the messages that are printed to the users |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| Field | DefaultValue | Description |
+==========================+=================+===============================================================================================================================+
| maplist | none (required) | List of available maps for the map vote |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| team1 | none (required) | Team declaration |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| team2 | none (required) | Team declaration |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| matchid | none (required) | Unique Identifier for the match |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| num_maps | 1 | Number of Maps to be played. This should be an odd number to determine a winner. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| players_per_team | 5 | Maximum possible number of players per team. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| min_players_to_ready | 5 | Number of players per team that have to be ready to start the game. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| max_rounds | 24 | Maximum number of rounds played for the main match. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| max_overtime_rounds | 6 | Maximum number of rounds played in overtime. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| vote_timeout | 60000 (60s) | Timeout in milliseconds. If a team does not complete the vote within this timeout, the |
| | | map with the most votes gets banned. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| eventula_apistats_url | (optional) | URL where the Game State has to be sent. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| eventula_apistats_token | (optional) | Optional AuthToken used to authenticate on apistats upload. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| eventula_demo_upload_url | (optional) | URL to upload the game demo to `eventula <https://github.com/Lan2Play/eventula-manager>`_ |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| g5_api_url | (optional) | URL to send the g5 events to. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| g5_api_header | (optional) | Header that should be set to access the g5 events API. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| g5_api_headervalue | (optional) | Header value that should be set to access the g5 events API. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| allow_suicide | true | Flag to determine if players are allowed to suicide. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| vote_map | de_dust2 | Map used during warm-up and voting. |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+
| team_mode | 0 | Change how teams are defined. 0: Default (Teams are fix defined) 1: Scramble (Teams are scrambled when all players are ready) |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
+--------------------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------+

Matchconfig Example
'''''''''''''''''''''
Expand Down Expand Up @@ -107,11 +105,11 @@ The Serverconfig defines server wide PugSharp settings for your server. It is lo

Serverconfig Fields
'''''''''''''''''''''
+-------+-------------+
| Field | Description |
+=======+=============+
| none | none |
+-------+-------------+
+--------+---------+---------------------------------------------------------------------------------------+
| Field | Default | Description |
+========+=========+=======================================================================================+
| locale | en | This is the language that will be used for the messages that are printed to the users |
+--------+---------+---------------------------------------------------------------------------------------+

Serverconfig Example
'''''''''''''''''''''
Expand All @@ -127,7 +125,7 @@ CounterstrikeSharp Configs
----------------------------------------

For the administration permissions, we are using `the CounterstrikeSharp admin framework <https://docs.cssharp.dev/admin-framework/defining-admins/#adding-admins>`_ .
Currently all :ref:`admin/commands:Admin/Rcon Commands` are using the permission ``@pugsharp/matchadmin``
Currently all :ref:`admin/commands:Admin/Rcon Commands` are using the permission ``@pugsharp/matchadmin``


CS2 Server Configs
Expand Down
46 changes: 46 additions & 0 deletions PugSharp.Config/ConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ConfigProvider
private readonly ILogger<ConfigProvider> _Logger;

private string _ConfigDirectory = string.Empty;
private ServerConfig? _ServerConfig;

public ConfigProvider(HttpClient httpClient, ILogger<ConfigProvider> logger)
{
Expand Down Expand Up @@ -115,4 +116,49 @@ public async Task<OneOf<Error<string>, MatchConfig>> LoadMatchConfigFromUrlAsync
return new Error<string>($"Failed loading config from {url}.");
}
}

public OneOf<Error<string>, ServerConfig> LoadServerConfig()
{
try
{
if (_ServerConfig != null)
{
return _ServerConfig;
}

var configPath = Path.Join(_ConfigDirectory, "server.json");

if (!File.Exists(configPath))
{
var directoryName = Path.GetDirectoryName(configPath);
if (directoryName != null && !Directory.Exists(directoryName))
{
Directory.CreateDirectory(directoryName);
}

// Create default config
_ServerConfig = new ServerConfig();
using FileStream createStream = File.Create(configPath);
JsonSerializer.Serialize(createStream, _ServerConfig);
return _ServerConfig;
}

using var loadingStream = File.OpenRead(configPath);
_ServerConfig = JsonSerializer.Deserialize<ServerConfig>(loadingStream);

if (_ServerConfig == null)
{
_Logger.LogError("ServerConfig was deserialized to null");
return new Error<string>("ServerConfig couldn't be deserialized");
}

return _ServerConfig;
}
catch (Exception ex)
{
_Logger.LogError(ex, "Error loading server config");
return new Error<string>("Error loading server config");
}
}

}
3 changes: 0 additions & 3 deletions PugSharp.Config/MatchConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ public class MatchConfig
[JsonPropertyName("vote_map")]
public string VoteMap { get; init; } = "de_dust2";

[JsonPropertyName("server_locale")]
public string ServerLocale { get; init; } = "en";

[JsonPropertyName("team_mode")]
public TeamMode TeamMode { get; set; }
}
9 changes: 9 additions & 0 deletions PugSharp.Config/ServerConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Text.Json.Serialization;

namespace PugSharp.Config;

public class ServerConfig
{
[JsonPropertyName("locale")]
public string Locale { get; init; } = "en";
}
16 changes: 0 additions & 16 deletions PugSharp.Match/Match.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ private void Initialize(MatchInfo matchInfo)
throw new NotSupportedException($"Can not create Match without the required number of maps! At lease {matchInfo.Config.NumMaps} are required!");
}

SetServerCulture(matchInfo.Config.ServerLocale);
MatchInfo = matchInfo;
_VoteTimer.Interval = MatchInfo.Config.VoteTimeout;
_VoteTimer.Elapsed += VoteTimer_Elapsed;
Expand All @@ -107,21 +106,6 @@ private void Initialize(MatchInfo matchInfo)
}
}

private void SetServerCulture(string locale)
{
try
{
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.GetCultureInfo(locale);
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.DefaultThreadCurrentCulture;
CultureInfo.CurrentCulture = CultureInfo.DefaultThreadCurrentCulture;
CultureInfo.CurrentUICulture = CultureInfo.DefaultThreadCurrentCulture;
}
catch (Exception ex)
{
_Logger.LogError(ex, "Setting cultureInfo is not possible. Linux requires libicu-dev/libicu/icu-libs to support translations.");
}
}

#pragma warning disable MA0051 // Method is too long
private void InitializeStateMachine()
#pragma warning restore MA0051 // Method is too long
Expand Down
Loading

0 comments on commit e450616

Please sign in to comment.