Skip to content

Commit

Permalink
Support RunGameAsync method
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirKhil committed Feb 16, 2024
1 parent 34974e2 commit 2f6a2fd
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Common/SI.GameServer.Client/GameServerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public GameServerClient(IOptions<GameServerClientOptions> options, IUIThreadExec
};
}

public Task<RunGameResponse> RunGameAsync(RunGameRequest runGameRequest, CancellationToken cancellationToken = default) =>
Connection.InvokeAsync<RunGameResponse>("RunGame", runGameRequest, cancellationToken);

public Task<GameCreationResult> CreateGameAsync(
GameSettingsCore<AppSettingsCore> gameSettings,
PackageKey packageKey,
Expand Down
4 changes: 4 additions & 0 deletions src/Common/SI.GameServer.Client/IGameServerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public interface IGameServerClient : IGameClient

Task UploadPackageAsync(FileKey packageHash, Stream stream, CancellationToken cancellationToken = default);

Task<RunGameResponse> RunGameAsync(
RunGameRequest runGameRequest,
CancellationToken cancellationToken = default);

Task<GameCreationResult> CreateGameAsync(
GameSettingsCore<AppSettingsCore> gameSettings,
PackageKey packageKey,
Expand Down
14 changes: 14 additions & 0 deletions src/Common/SI.GameServer.Contract/RunGameRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using SIData;

namespace SI.GameServer.Contract;

/// <summary>
/// Defines a game run request.
/// </summary>
/// <param name="GameSettings">Game options.</param>
/// <param name="PackageInfo">Game package descriptor.</param>
/// <param name="ComputerAccounts">Custom computer accounts information.</param>
public sealed record RunGameRequest(
GameSettingsCore<AppSettingsCore> GameSettings,
PackageInfo PackageInfo,
ComputerAccount[] ComputerAccounts);
32 changes: 32 additions & 0 deletions src/Common/SI.GameServer.Contract/RunGameResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace SI.GameServer.Contract;

/// <summary>
/// Defines a run game response.
/// </summary>
public sealed class RunGameResponse
{
/// <summary>
/// Is run successfull.
/// </summary>
public bool IsSuccess { get; set; }

/// <summary>
/// Game host uri.
/// </summary>
public Uri? HostUri { get; set; }

/// <summary>
/// Game identifier.
/// </summary>
public int GameId { get; set; }

/// <summary>
/// Should the person be a game host.
/// </summary>
public bool IsHost { get; set; }

/// <summary>
/// Creation error code.
/// </summary>
public GameCreationResultCode ErrorType { get; set; }
}
12 changes: 11 additions & 1 deletion src/Common/SIPackages.Providers/PackageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@ public static Task<SIDocument> GenerateRandomPackageAsync(
{
var doc = SIDocument.Create(name, author, folder);

return GenerateCoreAsync(provider, roundsCount, themesCount, baseCost, doc, roundNameFormat, finalName, culture, maxPackageCount, cancellationToken);
return GenerateCoreAsync(
provider,
roundsCount,
themesCount,
baseCost,
doc,
roundNameFormat,
finalName,
culture,
maxPackageCount,
cancellationToken);
}

private static async Task<SIDocument> GenerateCoreAsync(
Expand Down
2 changes: 1 addition & 1 deletion src/SICore/SICore/Clients/Game/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2987,7 +2987,7 @@ private void SetPerson(string[] args, Account host)
}

var oldName = account.Name;
GamePersonAccount newAccount;
GamePersonAccount? newAccount;

if (!account.IsHuman)
{
Expand Down

0 comments on commit 2f6a2fd

Please sign in to comment.