Skip to content

Commit

Permalink
Warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
TheR00st3r committed Sep 19, 2024
1 parent 6fb9ba4 commit f0ca51d
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 73 deletions.
2 changes: 1 addition & 1 deletion PugSharp.Api.G5Api/G5ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task<bool> SendEventAsync(EventBase eventToSend, CancellationToken
return true;
}

_Logger.LogError("G5 API request {Event} failed. HTTP status code = {statusCode} content: {Content}", eventToSend.EventName, httpResponseMessage.StatusCode, httpResponseMessage.Content.ToString());
_Logger.LogError("G5 API request {Event} failed. HTTP status code = {StatusCode} content: {Content}", eventToSend.EventName, httpResponseMessage.StatusCode, httpResponseMessage.Content.ToString());

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion PugSharp.ApiStats/Series.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Series

public Map GetMap(int mapNumber)
{
var mapNumberString = $"map{mapNumber}";
var mapNumberString = string.Create(CultureInfo.CurrentUICulture, $"map{mapNumber}");

return Maps[mapNumberString];
}
Expand Down
2 changes: 1 addition & 1 deletion PugSharp.Config/ConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<OneOf<Error<string>, MatchConfig>> LoadMatchConfigFromFileAsyn
return new Error<string>("Config couldn't be deserialized");
}

_Logger.LogInformation("Successfully loaded config for match {matchId}", config.MatchId);
_Logger.LogInformation("Successfully loaded config for match {MatchId}", config.MatchId);
return config;
}
}
Expand Down
2 changes: 1 addition & 1 deletion PugSharp.Config/TeamMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public enum TeamMode
Scramble,

// Player Selects which Team to join
PlayerSelect
PlayerSelect,
}
4 changes: 2 additions & 2 deletions PugSharp.Match.Tests/MatchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace PugSharp.Match.Tests;

public class MatchTests
{
private static IServiceProvider CreateTestProvider()
private static ServiceProvider CreateTestProvider()
{
var services = new ServiceCollection();

Expand Down Expand Up @@ -45,7 +45,7 @@ public void CreateDotGraphTest()
var match = matchFactory.CreateMatch(config);

var dotGraphString = match.CreateDotGraph();
Assert.True(!string.IsNullOrEmpty(dotGraphString));
Assert.False(string.IsNullOrEmpty(dotGraphString));
}

[Fact]
Expand Down
93 changes: 50 additions & 43 deletions PugSharp.Match/Match.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void Initialize(MatchInfo matchInfo)

if (matchInfo.Config.Maplist.Count < matchInfo.Config.NumMaps)
{
throw new NotSupportedException($"Can not create Match without the required number of maps! At lease {matchInfo.Config.NumMaps} are required!");
throw new NotSupportedException(string.Create(CultureInfo.InvariantCulture, $"Can not create Match without the required number of maps! At lease {matchInfo.Config.NumMaps} are required!"));
}

MatchInfo = matchInfo;
Expand Down Expand Up @@ -442,54 +442,63 @@ private void UpdateStats(IReadOnlyDictionary<ulong, IPlayerRoundResults> playerR
// Score is the overall value, not reported per round
matchStats.ContributionScore = playerResult.ContributionScore;

switch (playerResult.Kills)
UpdateKills(playerResult, matchStats);
UpdateClutchKills(playerResult, matchStats);

// TODO Kast

Check warning on line 448 in PugSharp.Match/Match.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)
}
}

private static void UpdateKills(IPlayerRoundResults playerResult, PlayerMatchStatistics matchStats)
{
switch (playerResult.Kills)
{
case _Kill1:
matchStats.Count1K++;
break;
case _Kill2:
matchStats.Count2K++;
break;
case _Kill3:
matchStats.Count3K++;
break;
case _Kill4:
matchStats.Count4K++;
break;
case _Kill5:
matchStats.Count5K++;
break;
default:
// Do nothing
break;
}
}

private static void UpdateClutchKills(IPlayerRoundResults playerResult, PlayerMatchStatistics matchStats)
{
if (playerResult.Clutched)
{
switch (playerResult.ClutchKills)
{
case _Kill1:
matchStats.Count1K++;
matchStats.V1++;
break;
case _Kill2:
matchStats.Count2K++;
matchStats.V2++;
break;
case _Kill3:
matchStats.Count3K++;
matchStats.V3++;
break;
case _Kill4:
matchStats.Count4K++;
matchStats.V4++;
break;
case _Kill5:
matchStats.Count5K++;
matchStats.V5++;
break;
default:
// Do nothing
break;
}

if (playerResult.Clutched)
{
switch (playerResult.ClutchKills)
{
case _Kill1:
matchStats.V1++;
break;
case _Kill2:
matchStats.V2++;
break;
case _Kill3:
matchStats.V3++;
break;
case _Kill4:
matchStats.V4++;
break;
case _Kill5:
matchStats.V5++;
break;
default:
// Do nothing
break;
}
}

// TODO Kast
}
}

Expand Down Expand Up @@ -670,13 +679,13 @@ private void ReadyReminderTimer_Elapsed(object? sender, System.Timers.ElapsedEve
if (MatchInfo.Config.TeamMode == Config.TeamMode.PlayerSelect)
{
_Logger.LogInformation("TeamReminder Elapsed");
foreach (var player in AllMatchPlayers)
foreach (var player in AllMatchPlayers.Select(p => p.Player))
{
var matchTeam = GetMatchTeam(player.Player.Team);
if (player.Player.Team == Team.Terrorist || player.Player.Team == Team.CounterTerrorist)
var matchTeam = GetMatchTeam(player.Team);
if (player.Team == Team.Terrorist || player.Team == Team.CounterTerrorist)
{
var teamMessage = _TextHelper.GetText(nameof(Resources.PugSharp_Match_TeamReminder), matchTeam?.TeamConfig.Name);
player.Player.PrintToChat(teamMessage);
player.PrintToChat(teamMessage);
}
}
}
Expand Down Expand Up @@ -808,7 +817,7 @@ private void SetSelectedTeamSide()
_VoteTimer.Stop();

var startTeam = _TeamVotes.MaxBy(m => m.Votes.Count)!.Name.Equals("T", StringComparison.OrdinalIgnoreCase) ? Team.Terrorist : Team.CounterTerrorist;
_Logger.LogInformation("Set selected teamsite to {startTeam}. Voted by {team}", startTeam, _CurrentMatchTeamToVote!.TeamConfig.Name);
_Logger.LogInformation("Set selected teamsite to {StartTeam}. Voted by {Team}", startTeam, _CurrentMatchTeamToVote!.TeamConfig.Name);

if (_CurrentMatchTeamToVote!.CurrentTeamSide != startTeam)
{
Expand All @@ -818,8 +827,8 @@ private void SetSelectedTeamSide()
otherTeam.StartingTeamSide = startTeam == Team.Terrorist ? Team.CounterTerrorist : Team.Terrorist;
otherTeam.CurrentTeamSide = otherTeam.StartingTeamSide;

_Logger.LogInformation("{team} starts as Team {startTeam}", _CurrentMatchTeamToVote.TeamConfig.Name, _CurrentMatchTeamToVote!.CurrentTeamSide.ToString());
_Logger.LogInformation("{team} starts as Team {startTeam}", otherTeam.TeamConfig.Name, otherTeam!.CurrentTeamSide.ToString());
_Logger.LogInformation("{Team} starts as Team {StartTeam}", _CurrentMatchTeamToVote.TeamConfig.Name, _CurrentMatchTeamToVote!.CurrentTeamSide.ToString());
_Logger.LogInformation("{Team} starts as Team {StartTeam}", otherTeam.TeamConfig.Name, otherTeam!.CurrentTeamSide.ToString());
}

_CsServer.PrintToChatAll(_TextHelper.GetText(nameof(Resources.PugSharp_Match_SelectedTeam), _CurrentMatchTeamToVote!.TeamConfig.Name, startTeam));
Expand Down Expand Up @@ -865,8 +874,6 @@ private bool AllPlayersAreReady()
var readyPlayers = AllMatchPlayers.Where(p => p.IsReady);
var requiredPlayers = MatchInfo.Config.PlayersPerTeam * 2;

//_Logger.LogInformation("Match has {readyPlayers} of {requiredPlayers} ready players: {readyPlayers}", readyPlayers.Count(), requiredPlayers, string.Join("; ", readyPlayers.Select(a => $"{a.Player.PlayerName}[{a.IsReady}]").ToList()));

return readyPlayers.Take(requiredPlayers + 1).Count() == requiredPlayers;
}

Expand Down
9 changes: 4 additions & 5 deletions PugSharp.Shared/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ public static class EnumerableExtensions
{
public static IEnumerable<T> Randomize<T>(this IEnumerable<T> source)
{
if (source == null) throw new ArgumentNullException(nameof(source));

return source.RandomizeInternal();
return source == null
? throw new ArgumentNullException(nameof(source))
: source.RandomizeInternal();
}

private static IEnumerable<T> RandomizeInternal<T>(
this IEnumerable<T> source)
private static IEnumerable<T> RandomizeInternal<T>(this IEnumerable<T> source)
{
var buffer = source.ToList();
for (int i = 0; i < buffer.Count; i++)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using Microsoft.Extensions.DependencyInjection;

using NSubstitute;
Expand All @@ -11,9 +10,9 @@

namespace PugSharp.Tests;

public class UnitTest1
public class ApplicationTests
{
private static IServiceProvider CreateTestProvider()
private static ServiceProvider CreateTestProvider()
{
var services = new ServiceCollection();

Expand All @@ -22,10 +21,7 @@ private static IServiceProvider CreateTestProvider()

services.AddSingleton(Substitute.For<ICssDispatcher>());
services.AddSingleton(Substitute.For<ICsServer>());
services.AddLogging(options =>
{
//options.AddConsole();
});
services.AddLogging();
services.AddSingleton<IApplication, Application>();

services.AddSingleton<ConfigProvider>();
Expand All @@ -39,6 +35,7 @@ private static IServiceProvider CreateTestProvider()
// Build service provider
return services.BuildServiceProvider();
}

[Fact]
public void InitializeApplicationTest()
{
Expand Down
4 changes: 2 additions & 2 deletions PugSharp.Translation/TextHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public string GetTranslatedText(string key, CultureInfo cultureInfo, bool withCo
}
catch (Exception ex)
{
_Logger.LogError(ex, "Error formatting text {text}", text);
_Logger.LogError(ex, "Error formatting text {Text}", text);
}
}

Expand Down Expand Up @@ -86,7 +86,7 @@ public string GetTranslatedText(string key, CultureInfo cultureInfo, bool withCo

public string GetText(string key, params object?[] arguments) => GetTranslatedText(key, CultureInfo.CurrentUICulture, arguments);

private string GetArgumentString(object? value)
private static string GetArgumentString(object? value)
{
return value switch
{
Expand Down
2 changes: 1 addition & 1 deletion PugSharp/CsServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public void SwitchMap(string selectedMap)
return;
}

_Logger.LogInformation("Switch map to: \"{electedMap}\"!", selectedMap);
_Logger.LogInformation("Switch map to: \"{SelectedMap}\"!", selectedMap);
ExecuteCommand($"changelevel {selectedMap}");
});
}
Expand Down
2 changes: 1 addition & 1 deletion PugSharp/Extensions/CommandInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void ReplyToCommand(this CommandInfo commandInfo, ITextHelper text
string translatedText;
if (commandInfo.CallingPlayer == null)
{
translatedText = textHelper.GetTranslatedText(textKey, CultureInfo.InvariantCulture, false, arguments);
translatedText = textHelper.GetTranslatedText(textKey, CultureInfo.InvariantCulture, withColors: false, arguments);
}
else
{
Expand Down
9 changes: 1 addition & 8 deletions PugSharp/G5ApiProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public Task RoundMvpAsync(RoundMvpParams roundMvpParams, CancellationToken cance
MatchId = roundMvpParams.MatchId,
Reason = roundMvpParams.Reason,
RoundNumber = roundMvpParams.RoundNumber,
Player = new Player(player.SteamId.ToString(CultureInfo.InvariantCulture), player.Name, player.UserId, (Side)player.Side, player.IsBot)
Player = new Player(player.SteamId.ToString(CultureInfo.InvariantCulture), player.Name, player.UserId, (Side)player.Side, player.IsBot),
};

return _G5Stats.SendEventAsync(roundMvpEvent, cancellationToken);
Expand Down Expand Up @@ -183,12 +183,5 @@ public Task FreeServerAsync(CancellationToken cancellationToken)
return Task.CompletedTask;
}



#endregion

#region Get5Api Commands


#endregion
}

0 comments on commit f0ca51d

Please sign in to comment.