Skip to content

Commit

Permalink
Merge pull request #80 from Lan2Play/feature/ConfigByCommand
Browse files Browse the repository at this point in the history
Feature/config by command
  • Loading branch information
TheR00st3r authored Nov 25, 2023
2 parents 5d9bd35 + bf45cce commit 532a17f
Show file tree
Hide file tree
Showing 34 changed files with 682 additions and 165 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"esbonio.sphinx.confDir": ""
}
8 changes: 8 additions & 0 deletions Docs/source/admin/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ These commands are available through rcon or to users with the required permissi
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| ``!ps_dumpmatch`` | Dumps the current matchstate and config to console |
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| ``!ps_creatematch`` | Creates a new match without preloaded configuration. |
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| ``!ps_startmatch`` | After match configuration is done with ``!ps_creatematch`` the match can be started. |
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| ``!ps_addmap`` | Add a map to the map pool during match creation. |
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
| ``!ps_removemap`` | Remove a map from the map pool during match creation. |
+----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------+
4 changes: 3 additions & 1 deletion Docs/source/admin/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ Matchconfig Fields
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+
| server_locale | en | This is the language that will be used for the messages that are printed to the users |
+--------------------------+-----------------+-------------------------------------------------------------------------------------------+

| 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
7 changes: 7 additions & 0 deletions PugSharp.Api.Contract/PugSharp.Api.Contract.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.14" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Meziantou.Analyzer" Version="2.0.110">
<PrivateAssets>all</PrivateAssets>
Expand Down
3 changes: 2 additions & 1 deletion PugSharp.Api.G5Api/PugSharp.Api.G5Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.14" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion PugSharp.Api.Json/PugSharp.Api.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.14" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions PugSharp.ApiStats/BaseApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ protected void InitializeBase(string? baseUrl, string? authKey)

HttpClient.BaseAddress = new Uri(baseUrl);

HttpClient.DefaultRequestHeaders.Remove(HeaderNames.Authorization);

if (!string.IsNullOrEmpty(authKey))
{
HttpClient.DefaultRequestHeaders.Add(HeaderNames.Authorization, authKey);
Expand Down
5 changes: 4 additions & 1 deletion PugSharp.ApiStats/PugSharp.ApiStats.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.14" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Update="Meziantou.Analyzer" Version="2.0.110">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
24 changes: 24 additions & 0 deletions PugSharp.Config/ConfigCreator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace PugSharp.Config;

public class ConfigCreator
{
public ConfigCreator()
{
Config = new MatchConfig
{
// TODO Maybe use guid for demo, ...

Check warning on line 9 in PugSharp.Config/ConfigCreator.cs

View workflow job for this annotation

GitHub Actions / test_linux_x64

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)

Check warning on line 9 in PugSharp.Config/ConfigCreator.cs

View workflow job for this annotation

GitHub Actions / test_linux_x64

MatchId = "CustomMatch",
Team1 = new Team
{
Name = "Team 1",
},
Team2 = new Team
{
Name = "Team 2",
},
TeamMode = TeamMode.Scramble,
};
}

public MatchConfig Config { get; }
}
13 changes: 8 additions & 5 deletions PugSharp.Config/MatchConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace PugSharp.Config;
public class MatchConfig
{
[JsonPropertyName("maplist")]
public required string[] Maplist { get; init; }
public IList<string> Maplist { get; init; } = new List<string>();

[JsonPropertyName("team1")]
public required Team Team1 { get; init; }
Expand All @@ -20,16 +20,16 @@ public class MatchConfig
public int NumMaps { get; init; } = 1;

[JsonPropertyName("players_per_team")]
public int PlayersPerTeam { get; init; } = 5;
public int PlayersPerTeam { get; set; } = 5;

[JsonPropertyName("min_players_to_ready")]
public int MinPlayersToReady { get; init; } = 5;
public int MinPlayersToReady { get; set; } = 5;

[JsonPropertyName("max_rounds")]
public int MaxRounds { get; init; } = 24;
public int MaxRounds { get; set; } = 24;

[JsonPropertyName("max_overtime_rounds")]
public int MaxOvertimeRounds { get; init; } = 6;
public int MaxOvertimeRounds { get; set; } = 6;

[JsonPropertyName("vote_timeout")]
public long VoteTimeout { get; init; } = 60000;
Expand Down Expand Up @@ -60,4 +60,7 @@ public class MatchConfig

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

[JsonPropertyName("team_mode")]
public TeamMode TeamMode { get; set; }
}
5 changes: 4 additions & 1 deletion PugSharp.Config/PugSharp.Config.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.14" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="OneOf" Version="3.0.263" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions PugSharp.Config/Team.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace PugSharp.Config;
public class Team
{
[JsonPropertyName("name")]
public required string Name { get; init; }
public required string Name { get; set; }

[JsonPropertyName("tag")]
public string Tag { get; init; } = string.Empty;
Expand All @@ -14,5 +14,5 @@ public class Team
public string Flag { get; init; } = string.Empty;

[JsonPropertyName("players")]
public required IDictionary<ulong, string> Players { get; init; }
public IDictionary<ulong, string> Players { get; init; } = new Dictionary<ulong, string>();
}
10 changes: 10 additions & 0 deletions PugSharp.Config/TeamMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace PugSharp.Config;

public enum TeamMode
{
// Take Teams as they are
Default,

// Scramble Teams afte all players are joined
Scramble,
}
5 changes: 5 additions & 0 deletions PugSharp.DebugDummy/PugSharp.DebugDummy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
<OutputPath>..\cs2\game\csgo\addons\counterstrikesharp\plugins\PugSharp\</OutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.14" />
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\PugSharp\PugSharp.csproj" />
Expand Down
1 change: 1 addition & 0 deletions PugSharp.Match.Contract/MatchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public enum MatchCommand
CompleteMap,
Pause,
Unpause,
TeamsDefined,
}
1 change: 1 addition & 0 deletions PugSharp.Match.Contract/MatchState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public enum MatchState
MapCompleted,
MatchCompleted,
RestoreMatch,
DefineTeams,
}
7 changes: 7 additions & 0 deletions PugSharp.Match.Contract/PugSharp.Match.Contract.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.14" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\PugSharp.Api.Contract\PugSharp.Api.Contract.csproj" />
</ItemGroup>
Expand Down
23 changes: 14 additions & 9 deletions PugSharp.Match.Tests/MatchTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

using NSubstitute;

Expand All @@ -23,7 +22,7 @@ private static IServiceProvider CreateTestProvider()
services.AddSingleton(Substitute.For<ICsServer>());
services.AddLogging(options =>
{
options.AddConsole();
//options.AddConsole();
});
services.AddSingleton<IApplication, Application>();

Expand Down Expand Up @@ -151,16 +150,16 @@ private static async Task VoteTeam(ICsServer csServer, MatchConfig config, Match
csServer.Received().SwitchMap(config.Maplist[^1]);

Assert.Equal(MatchState.WaitingForPlayersReady, match.CurrentState);
await match.TogglePlayerIsReadyAsync(player1).ConfigureAwait(false);
match.TogglePlayerIsReady(player1);
Assert.Equal(MatchState.WaitingForPlayersReady, match.CurrentState);
await match.TogglePlayerIsReadyAsync(player2).ConfigureAwait(false);
match.TogglePlayerIsReady(player2);

Assert.Equal(MatchState.MatchRunning, match.CurrentState);
}

private static IPlayer VoteForMap(MatchConfig config, Match match, IPlayer player1, IPlayer player2)
{
var matchCount = config.Maplist.Length;
var matchCount = config.Maplist.Count;
var votePlayer = player1;

Assert.False(match.BanMap(votePlayer, matchCount));
Expand All @@ -184,9 +183,9 @@ private static IPlayer VoteForMap(MatchConfig config, Match match, IPlayer playe

private static async Task SetPlayersReady(Match match, IPlayer player1, IPlayer player2, MatchState expectedMatchStateAfterReady)
{
await match.TogglePlayerIsReadyAsync(player1).ConfigureAwait(false);
match.TogglePlayerIsReady(player1);
Assert.Equal(MatchState.WaitingForPlayersConnectedReady, match.CurrentState);
await match.TogglePlayerIsReadyAsync(player2).ConfigureAwait(false);
match.TogglePlayerIsReady(player2);
Assert.Equal(expectedMatchStateAfterReady, match.CurrentState);
}

Expand All @@ -210,7 +209,7 @@ private static MatchConfig CreateExampleConfig(IEnumerable<string>? mapList = nu
mapListInternal = mapList;
}

return new MatchConfig
var matchConfig = new MatchConfig
{
MatchId = "1337",
PlayersPerTeam = 1,
Expand All @@ -232,8 +231,14 @@ private static MatchConfig CreateExampleConfig(IEnumerable<string>? mapList = nu
{ 1,"Def" },
},
},
Maplist = mapListInternal.ToArray(),
};

foreach (var map in mapListInternal)
{
matchConfig.Maplist.Add(map);
}

return matchConfig;
}

private static IPlayer CreatePlayerSub(ulong steamId, int playerId)
Expand Down
2 changes: 2 additions & 0 deletions PugSharp.Match.Tests/PugSharp.Match.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.14" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.6.2" />
Expand Down
Loading

0 comments on commit 532a17f

Please sign in to comment.