Skip to content

Commit

Permalink
various xpevo fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
snixtho committed Sep 23, 2023
1 parent 6db3689 commit af17226
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 43 deletions.
12 changes: 9 additions & 3 deletions src/EvoSC.Common/Services/MapService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ public class MapService : IMapService
private readonly IEvoScBaseConfig _config;
private readonly IPlayerManagerService _playerService;
private readonly IServerClient _serverClient;
private readonly IMatchSettingsService _matchSettings;

public MapService(IMapRepository mapRepository, ILogger<MapService> logger, IEvoScBaseConfig config,
IPlayerManagerService playerService, IServerClient serverClient)
IPlayerManagerService playerService, IServerClient serverClient, IMatchSettingsService matchSettings)
{
_mapRepository = mapRepository;
_logger = logger;
_config = config;
_playerService = playerService;
_serverClient = serverClient;
_matchSettings = matchSettings;
}

public async Task<IMap?> GetMapByIdAsync(long id) => await _mapRepository.GetMapByIdAsync(id);
Expand Down Expand Up @@ -70,8 +72,12 @@ public async Task<IMap> AddMapAsync(MapStream mapStream)
map = await _mapRepository.AddMapAsync(mapMetadata, author, relativePath);
}

await _serverClient.Remote.InsertMapAsync($"EvoSC/{fileName}");
await _serverClient.Remote.SaveMatchSettingsAsync($"MatchSettings/{_config.Path.DefaultMatchSettings}");
await _matchSettings.EditMatchSettingsAsync(Path.GetFileNameWithoutExtension(_config.Path.DefaultMatchSettings),
builder => builder.AddMap($"EvoSC/{fileName}"));

/*await _serverClient.Remote.InsertMapAsync($"EvoSC/{fileName}");
await _serverClient.Remote.SaveMatchSettingsAsync($"MatchSettings/{_config.Path.DefaultMatchSettings}"); */

return map;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Modules/GeardownModule/GeardownModule.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@
<HintPath>..\..\..\..\..\..\.nuget\packages\hawf\1.0.3\lib\net6.0\Hawf.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Flurl" Version="3.0.7" />
<PackageReference Include="Flurl.Http" Version="3.2.4" />
</ItemGroup>

</Project>
101 changes: 62 additions & 39 deletions src/Modules/GeardownModule/Repositories/GeardownMatchApi.cs
Original file line number Diff line number Diff line change
@@ -1,51 +1,22 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using EvoSC.Common.Remote.EventArgsModels;
using EvoSC.Modules.Evo.GeardownModule.Interfaces.Repositories;
using EvoSC.Modules.Evo.GeardownModule.Models;
using EvoSC.Modules.Evo.GeardownModule.Models.API;
using EvoSC.Modules.Evo.GeardownModule.Settings;
using Hawf.Attributes;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Flurl;
using Flurl.Http;
using Flurl.Util;

namespace EvoSC.Modules.Evo.GeardownModule.Repositories;

[ApiClient]
public class GeardownMatchApi : GeardownApiBase<GeardownMatchApi>, IGeardownMatchApi
public class GeardownMatchApi : IGeardownMatchApi
{
public GeardownMatchApi(IGeardownSettings settings) : base(settings)
private readonly IGeardownSettings _settings;

public GeardownMatchApi(IGeardownSettings settings)
{
_settings = settings;
}

public Task<IEnumerable<GdParticipant>?> GetParticipantsAsync(int matchId) =>
WithAccessToken()
.WithJsonBody(new { matchId })
.GetJsonAsync<IEnumerable<GdParticipant>>("/v1/matches/participants");

public Task UpdateStatusAsync(int matchId, MatchStatus statusId) =>
WithAccessToken()
.PutStringAsync("/v1/matches/{matchId}/status/{statusId}", matchId, statusId);

public Task<GdMatch?> UpdateParticipantsAsync(int matchId, IEnumerable<GdParticipant> participants) =>
WithAccessToken()
.WithJsonBody(new { matchId, participants })
.PutJsonAsync<GdMatch>("/v1/matches/participants");

public Task<GdMatchResult?> CreateMatchResultAsync(int matchId, bool isTotalResult, int participantId,
string result, bool pending) =>
WithAccessToken()
.WithJsonBody(new { matchId, isTotalResult, participantId, result, pending })
.PostJsonAsync<GdMatchResult>("/api/matches/results");

public Task<GdMatchResult?> CreateTimeResultAsync(int matchId, string result, string nickname, string mapId) =>
WithAccessToken()
.WithJsonBody(new { matchId, result, nickname, mapId })
.PostJsonAsync<GdMatchResult>("/api/matches/time_results");

public Task<GdMatchToken?> AssignServerAsync(int matchId, string name, string serverId, string? serverPassword) =>
/* public Task<GdMatchToken?> AssignServerAsync(int matchId, string name, string serverId, string? serverPassword) =>
WithAccessToken()
.WithJsonBody(new { serverId, password = serverPassword, name })
.PostJsonAsync<GdMatchToken>("/api/matches/game_server/{matchId}", matchId);
Expand All @@ -67,5 +38,57 @@ public Task OnStartMatchAsync(string matchToken) =>
public Task AddResultsAsync(int matchId, IEnumerable<GdResult> results) =>
WithAccessToken()
.WithJsonBody(new { matchId = matchId, results = results })
.PostStringAsync("/api/console/dedicated_controllers/results");
.PostStringAsync("/api/console/dedicated_controllers/results"); */
public Task<GdMatchToken?> AssignServerAsync(int matchId, string name, string serverId, string? serverPassword)
{
return $"https://tourneyapi.evoesports.gg/api/matches/game_server/{matchId}"
.SetQueryParam("token", _settings.ApiAccessToken)
.PostJsonAsync(new { serverId, password = serverPassword, name })
.ReceiveJson<GdMatchToken?>();
}

public Task<GdMatch?> GetMatchDataByTokenAsync(string matchToken)
{
return $"https://tourneyapi.evoesports.gg/api/matches/evo_token/{matchToken}"
.WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
.WithHeader("User-Agent", "EvoSC")
.WithHeader("Connection", "keep-alive")
.WithHeader("Accept-Encoding", "gzip, deflate, br")
.SetQueryParam("token", _settings.ApiAccessToken)
.GetAsync()
.ReceiveJson<GdMatch?>();
}

public Task OnEndMatchAsync(string matchToken)
{
return $"https://tourneyapi.evoesports.gg/v1/matches/on_end_match"
.WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
.WithHeader("User-Agent", "EvoSC")
.WithHeader("Connection", "keep-alive")
.WithHeader("Accept-Encoding", "gzip, deflate, br")
.SetQueryParam("token", _settings.ApiAccessToken)
.PostAsync();
}

public Task OnStartMatchAsync(string matchToken)
{
return $"https://tourneyapi.evoesports.gg/v1/matches/on_start_match"
.WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
.WithHeader("User-Agent", "EvoSC")
.WithHeader("Connection", "keep-alive")
.WithHeader("Accept-Encoding", "gzip, deflate, br")
.SetQueryParam("token", _settings.ApiAccessToken)
.PostAsync();
}

public Task AddResultsAsync(int matchId, IEnumerable<GdResult> results)
{
return $"https://tourneyapi.evoesports.gg/api/matches/game_server/{matchId}"
.WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
.WithHeader("User-Agent", "EvoSC")
.WithHeader("Connection", "keep-alive")
.WithHeader("Accept-Encoding", "gzip, deflate, br")
.SetQueryParam("token", _settings.ApiAccessToken)
.PostJsonAsync(new { matchId = matchId, results = results });
}
}
22 changes: 21 additions & 1 deletion src/Modules/GeardownModule/Services/GeardownSetupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,26 @@ private async Task<string> CreateMatchSettingsAsync(GdMatch match, IEnumerable<I

var format = match.formats.First();
var name = $"geardown_{format.id}";

var mapsToAdd = new List<IMap>();

foreach (var map in maps)
{
try
{
var serverMap = await _server.Remote.GetMapInfoAsync(map.FilePath);

if (serverMap != null)
{
mapsToAdd.Add(map);
}
}
catch (Exception)
{
// do nothing
}
}

await _matchSettings.CreateMatchSettingsAsync(name, builder =>
{
var mode = format.type_id switch
Expand Down Expand Up @@ -268,7 +288,7 @@ await _matchSettings.CreateMatchSettingsAsync(name, builder =>
}
});

builder.WithMaps(maps);
builder.WithMaps(mapsToAdd);
builder.WithFilter(f => f.AsRandomMapOrder(true));
});

Expand Down

0 comments on commit af17226

Please sign in to comment.