Skip to content

Commit

Permalink
Merge pull request #100 from Lan2Play/feature/G5Events
Browse files Browse the repository at this point in the history
Feature/g5 events
  • Loading branch information
TheR00st3r authored Dec 5, 2023
2 parents 39f4da4 + c811a5e commit 6037c84
Show file tree
Hide file tree
Showing 24 changed files with 287 additions and 132 deletions.
1 change: 1 addition & 0 deletions PugSharp.Api.Contract/IMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public interface IMap
IMapTeamInfo Team2 { get; }

public string WinnerTeamName { get; }
TeamSide WinnerTeamSide { get; init; }
}
2 changes: 1 addition & 1 deletion PugSharp.Api.Contract/IMapTeamInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public interface IMapTeamInfo
int Score { get; }
int ScoreCT { get; }
int ScoreT { get; }
StartingSide StartingSide { get; }
TeamSide StartingSide { get; }
}
2 changes: 2 additions & 0 deletions PugSharp.Api.Contract/ITeamInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

public interface ITeamInfo
{
string TeamId { get; }

string TeamName { get; }
}
2 changes: 1 addition & 1 deletion PugSharp.Api.Contract/RoundStatusUpdateParams.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace PugSharp.Api.Contract;

public record RoundStatusUpdateParams(string MatchId, int MapNumber, ITeamInfo TeamInfo1, ITeamInfo TeamInfo2, IMap CurrentMap);
public record RoundStatusUpdateParams(string MatchId, int MapNumber, ITeamInfo TeamInfo1, ITeamInfo TeamInfo2, IMap CurrentMap, int Reason, int RoundTime);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PugSharp.Api.Contract;

public enum StartingSide
public enum TeamSide
{
None,
T = 2,
Expand Down
1 change: 1 addition & 0 deletions PugSharp.Api.G5Api.Tests/Fixtures/G5ApiFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class G5ApiFixture : IAsyncLifetime
public G5ApiFixture()
{
_Network = new NetworkBuilder()
//.WithDriver(DotNet.Testcontainers.Configurations.NetworkDriver.Host)
.Build();

_DatabaseContainer = new MariaDbBuilder()
Expand Down
16 changes: 8 additions & 8 deletions PugSharp.Api.G5Api.Tests/G5ApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public async Task I_can_create_a_register_token()
// Arrange
var g5ApiClient = await Api.CreateClientAsync();



// Act
Assert.True(await g5ApiClient.SendEventAsync(new MapVetoedEvent() { Team = "team1", MapName = "de_dust2", MatchId = "1" }, CancellationToken.None));
Assert.True(await g5ApiClient.SendEventAsync(new MapVetoedEvent() { Team = "team2", MapName = "de_cache", MatchId = "1" }, CancellationToken.None));
Expand All @@ -29,13 +27,15 @@ public async Task I_can_create_a_register_token()
Assert.True(await g5ApiClient.SendEventAsync(new RoundMvpEvent() { MapNumber = 1, MatchId = "1", Player = new Player("76561198025644200", "3", 3, Side.T, isBot: false), Reason = 2, RoundNumber = 2 }, CancellationToken.None));
Assert.True(await g5ApiClient.SendEventAsync(new RoundMvpEvent() { MapNumber = 1, MatchId = "1", Player = new Player("76561198025644200", "3", 3, Side.T, isBot: false), Reason = 2, RoundNumber = 3 }, CancellationToken.None));

var statsTeam1 = new StatsTeam("1", "Kraddlers", 1, 0, 0, 0, new List<StatsPlayer> {
new() {},
new() {},
var statsTeam1 = new StatsTeam("1", "Kraddlers", 1, 0, 0, 0, new List<StatsPlayer>
{
new() { SteamId= "76561198025644200", Name = "3", Stats = new PlayerStats()},
new() {SteamId= "76561198025644200", Name = "3", Stats = new PlayerStats()},
});
var statsTeam2 = new StatsTeam("2", "Knaddles", 1, 3, 2, 1, new List<StatsPlayer> {
new() {},
new() {},
var statsTeam2 = new StatsTeam("2", "Knaddles", 1, 3, 2, 1, new List<StatsPlayer>
{
new() {SteamId= "76561198025644200", Name = "3", Stats = new PlayerStats()},
new() {SteamId= "76561198025644200", Name = "3", Stats = new PlayerStats()},
});
Assert.True(await g5ApiClient.SendEventAsync(new MapResultEvent() { MapNumber = 1, MatchId = "1", Winner = new Winner(Side.T, 0), StatsTeam1 = statsTeam1, StatsTeam2 = statsTeam2 }, CancellationToken.None));
Assert.True(await g5ApiClient.SendEventAsync(new SeriesResultEvent() { MatchId = "1", Winner = new Winner(Side.T, 0), Team1SeriesScore = 0, Team2SeriesScore = 1, TimeUntilRestore = 2 }, CancellationToken.None));
Expand Down
5 changes: 3 additions & 2 deletions PugSharp.Api.G5Api/G5ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@ public async Task<bool> SendEventAsync(EventBase eventToSend, CancellationToken

if (httpResponseMessage == null)
{
_Logger.LogError("G5 API request {event} failed. No HTTP status code available.", eventToSend.EventName);
return false;
}

if (httpResponseMessage.IsSuccessStatusCode)
{
_Logger.LogInformation("G5 API request was successful, HTTP status code = {statusCode}", httpResponseMessage.StatusCode);
_Logger.LogInformation("G5 API request {event} was successful, HTTP status code = {statusCode}", eventToSend.EventName, httpResponseMessage.StatusCode);
return true;
}

_Logger.LogError("G5 API request failed, HTTP status code = {statusCode} content: {content}", 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
107 changes: 107 additions & 0 deletions PugSharp.Api.G5Api/PlayerStats.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System.Text.Json.Serialization;

namespace PugSharp.Api.G5Api;

public class PlayerStats
{
[JsonPropertyName("kills")]
public int Kills { get; set; }

[JsonPropertyName("deaths")]
public int Deaths { get; set; }

[JsonPropertyName("assists")]
public int Assists { get; set; }

[JsonPropertyName("flash_assists")]
public int FlashAssists { get; set; }

[JsonPropertyName("team_kills")]
public int TeamKills { get; set; }

[JsonPropertyName("suicides")]
public int Suicides { get; set; }

[JsonPropertyName("damage")]
public int Damage { get; set; }

[JsonPropertyName("utility_damage")]
public int UtilityDamage { get; set; }

[JsonPropertyName("enemies_flashed")]
public int EnemiesFlashed { get; set; }

[JsonPropertyName("friendlies_flashed")]
public int FriendliesFlashed { get; set; }

[JsonPropertyName("knife_kills")]
public int KnifeKills { get; set; }

[JsonPropertyName("headshot_kills")]
public int HeadshotKills { get; set; }

[JsonPropertyName("rounds_played")]
public int RoundsPlayed { get; set; }

[JsonPropertyName("bomb_defuses")]
public int BombDefuses { get; set; }

[JsonPropertyName("bomb_plants")]
public int BombPlants { get; set; }

[JsonPropertyName("1k")]
public int Kills1 { get; set; }

[JsonPropertyName("2k")]
public int Kills2 { get; set; }

[JsonPropertyName("3k")]
public int Kills3 { get; set; }

[JsonPropertyName("4k")]
public int Kills4 { get; set; }

[JsonPropertyName("5k")]
public int Kills5 { get; set; }

#pragma warning disable S100 // Methods and properties should be named in PascalCase
[JsonPropertyName("1v1")]
public int OneV1s { get; set; }

[JsonPropertyName("1v2")]
public int OneV2s { get; set; }

[JsonPropertyName("1v3")]
public int OneV3s { get; set; }

[JsonPropertyName("1v4")]
public int OneV4s { get; set; }

[JsonPropertyName("1v5")]
public int OneV5s { get; set; }
#pragma warning restore S100 // Methods and properties should be named in PascalCase

[JsonPropertyName("first_kills_t")]
public int FirstKillsT { get; set; }

[JsonPropertyName("first_kills_ct")]
public int FirstKillsCT { get; set; }

[JsonPropertyName("first_deaths_t")]
public int FirstDeathsT { get; set; }

[JsonPropertyName("first_deaths_ct")]
public int FirstDeathsCT { get; set; }

[JsonPropertyName("trade_kills")]
public int TradeKills { get; set; }

[JsonPropertyName("kast")]
public int Kast { get; set; }

[JsonPropertyName("score")]
public int Score { get; set; }

[JsonPropertyName("mvp")]
public int Mvps { get; set; }
}
104 changes: 6 additions & 98 deletions PugSharp.Api.G5Api/StatsPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,104 +4,12 @@ namespace PugSharp.Api.G5Api;

public class StatsPlayer
{
[JsonPropertyName("kills")]
public int Kills { get; set; }
[JsonPropertyName("steamid")]
public required string SteamId { get; init; }

[JsonPropertyName("deaths")]
public int Deaths { get; set; }
[JsonPropertyName("name")]
public required string Name { get; init; }

[JsonPropertyName("assists")]
public int Assists { get; set; }

[JsonPropertyName("flash_assists")]
public int FlashAssists { get; set; }

[JsonPropertyName("team_kills")]
public int TeamKills { get; set; }

[JsonPropertyName("suicides")]
public int Suicides { get; set; }

[JsonPropertyName("damage")]
public int Damage { get; set; }

[JsonPropertyName("utility_damage")]
public int UtilityDamage { get; set; }

[JsonPropertyName("enemies_flashed")]
public int EnemiesFlashed { get; set; }

[JsonPropertyName("friendlies_flashed")]
public int FriendliesFlashed { get; set; }

[JsonPropertyName("knife_kills")]
public int KnifeKills { get; set; }

[JsonPropertyName("headshot_kills")]
public int HeadshotKills { get; set; }

[JsonPropertyName("rounds_played")]
public int RoundsPlayed { get; set; }

[JsonPropertyName("bomb_defuses")]
public int BombDefuses { get; set; }

[JsonPropertyName("bomb_plants")]
public int BombPlants { get; set; }

[JsonPropertyName("1k")]
public int Kills1 { get; set; }

[JsonPropertyName("2k")]
public int Kills2 { get; set; }

[JsonPropertyName("3k")]
public int Kills3 { get; set; }

[JsonPropertyName("4k")]
public int Kills4 { get; set; }

[JsonPropertyName("5k")]
public int Kills5 { get; set; }

#pragma warning disable S100 // Methods and properties should be named in PascalCase
[JsonPropertyName("1v1")]
public int OneV1s { get; set; }

[JsonPropertyName("1v2")]
public int OneV2s { get; set; }

[JsonPropertyName("1v3")]
public int OneV3s { get; set; }

[JsonPropertyName("1v4")]
public int OneV4s { get; set; }

[JsonPropertyName("1v5")]
public int OneV5s { get; set; }
#pragma warning restore S100 // Methods and properties should be named in PascalCase

[JsonPropertyName("first_kills_t")]
public int FirstKillsT { get; set; }

[JsonPropertyName("first_kills_ct")]
public int FirstKillsCT { get; set; }

[JsonPropertyName("first_deaths_t")]
public int FirstDeathsT { get; set; }

[JsonPropertyName("first_deaths_ct")]
public int FirstDeathsCT { get; set; }

[JsonPropertyName("trade_kills")]
public int TradeKills { get; set; }

[JsonPropertyName("kast")]
public int Kast { get; set; }

[JsonPropertyName("score")]
public int Score { get; set; }

[JsonPropertyName("mvp")]
public int Mvps { get; set; }
[JsonPropertyName("stats")]
public required PlayerStats Stats { get; init; }
}
2 changes: 2 additions & 0 deletions PugSharp.ApiStats/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class Map : IMap

public required string WinnerTeamName { get; init; }

public required TeamSide WinnerTeamSide { get; init; }

public required IMapTeamInfo Team1 { get; init; }

public required IMapTeamInfo Team2 { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion PugSharp.ApiStats/MapTeamInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public class MapTeamInfo : IMapTeamInfo

public int ScoreCT { get; set; }

public StartingSide StartingSide { get; set; }
public TeamSide StartingSide { get; set; }
}
2 changes: 2 additions & 0 deletions PugSharp.ApiStats/TeamInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ namespace PugSharp.ApiStats;

public class TeamInfo : ITeamInfo
{
public required string TeamId { get; init; }

public required string TeamName { get; init; }
}
2 changes: 2 additions & 0 deletions PugSharp.Config/ConfigCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ public ConfigCreator()
MatchId = "CustomMatch",
Team1 = new Team
{
Id = "1",
Name = "Team 1",
},
Team2 = new Team
{
Id = "2",
Name = "Team 2",
},
TeamMode = TeamMode.Scramble,
Expand Down
18 changes: 9 additions & 9 deletions PugSharp.Config/MatchConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ public class MatchConfig
[JsonPropertyName("eventula_demo_upload_url")]
public string? EventulaDemoUploadUrl { get; init; }

[JsonPropertyName("g5_api_url")]
public string? G5ApiUrl { get; init; }

[JsonPropertyName("g5_api_header")]
public string? G5ApiHeader { get; init; }

[JsonPropertyName("g5_api_headervalue")]
public string? G5ApiHeaderValue { get; init; }

[JsonPropertyName("allow_suicide")]
public bool AllowSuicide { get; init; } = true;

Expand All @@ -60,4 +51,13 @@ public class MatchConfig

[JsonPropertyName("team_mode")]
public TeamMode TeamMode { get; set; }

[JsonPropertyName("cvars")]
public IDictionary<string, string> CVars { get; init; } = new Dictionary<string, string>(StringComparer.Ordinal);

public string? G5ApiUrl => CVars.TryGetValue("get5_remote_log_url", out var value) ? value : null;

public string? G5ApiHeader => CVars.TryGetValue("get5_remote_log_header_key", out var value) ? value : null;

public string? G5ApiHeaderValue => CVars.TryGetValue("get5_remote_log_header_value", out var value) ? value : null;
}
3 changes: 3 additions & 0 deletions PugSharp.Config/Team.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ namespace PugSharp.Config;

public class Team
{
[JsonPropertyName("id")]
public required string Id { get; set; }

[JsonPropertyName("name")]
public required string Name { get; set; }

Expand Down
Loading

0 comments on commit 6037c84

Please sign in to comment.