Skip to content

Commit

Permalink
Additional refactoring and removal of old code
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirKhil committed Jan 2, 2025
1 parent baa3cc5 commit 214c67f
Show file tree
Hide file tree
Showing 33 changed files with 352 additions and 434 deletions.
31 changes: 2 additions & 29 deletions src/Common/SI.GameServer.Client/GameServerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -20,8 +19,6 @@ public sealed class GameServerClient : IGameServerClient

private readonly GameServerClientOptions _options;

private readonly CookieContainer _cookieContainer;
private readonly HttpClientHandler _httpClientHandler;
private readonly HttpClient _client;

private HubConnection? _connection;
Expand Down Expand Up @@ -59,10 +56,7 @@ public GameServerClient(IOptions<GameServerClientOptions> options, IUIThreadExec
_options = options.Value;
_uIThreadExecutor = uIThreadExecutor;

_cookieContainer = new CookieContainer();
_httpClientHandler = new HttpClientHandler { CookieContainer = _cookieContainer };

_client = new HttpClient(_httpClientHandler)
_client = new HttpClient
{
BaseAddress = new Uri(ServiceUri),
Timeout = _options.Timeout,
Expand All @@ -84,7 +78,6 @@ public async ValueTask DisposeAsync()
}

_client?.Dispose();
_httpClientHandler?.Dispose();
}

public Task JoinLobbyAsync(CancellationToken cancellationToken = default) =>
Expand All @@ -99,18 +92,6 @@ public Task<Slice<GameInfo>> GetGamesAsync(int fromId, CancellationToken cancell
public Task<HostInfo> GetGamesHostInfoAsync(CancellationToken cancellationToken = default) =>
Connection.InvokeAsync<HostInfo>("GetGamesHostInfoNew", Thread.CurrentThread.CurrentUICulture.Name, cancellationToken);

public Task<string> GetNewsAsync(CancellationToken cancellationToken = default) =>
Connection.InvokeAsync<string>("GetNews", cancellationToken);

public Task<string> GetNewsNewAsync(CancellationToken cancellationToken = default) =>
Connection.InvokeAsync<string>("GetNewsNew", cancellationToken);

public Task<ChatMessage[]> GetLatestChatMessagesAsync(CancellationToken cancellationToken = default) =>
Connection.InvokeAsync<ChatMessage[]>("GetLatestChatMessages", cancellationToken);

public Task<string[]> GetUsersAsync(CancellationToken cancellationToken = default) =>
Connection.InvokeAsync<string[]>("GetUsers", cancellationToken);

public async Task OpenAsync(string userName, CancellationToken cancellationToken = default)
{
if (_isOpened)
Expand All @@ -119,13 +100,7 @@ public async Task OpenAsync(string userName, CancellationToken cancellationToken
}

_connection = new HubConnectionBuilder()
.WithUrl(
$"{ServiceUri}sionline",
options =>
{
options.AccessTokenProvider = () => Task.FromResult<string?>(Convert.ToBase64String(Encoding.UTF8.GetBytes(userName)));
options.Cookies = _cookieContainer;
})
.WithUrl($"{ServiceUri}sionline")
.WithAutomaticReconnect(new ReconnectPolicy())
.AddMessagePackProtocol()
.Build();
Expand Down Expand Up @@ -167,8 +142,6 @@ public async Task OpenAsync(string userName, CancellationToken cancellationToken
_isOpened = true;
}

public Task SayAsync(string message) => Connection.InvokeAsync("Say", message);

private Task OnConnectionClosedAsync(Exception? exc) => Closed != null ? Closed(exc) : Task.CompletedTask;

private void OnUI(Action action)
Expand Down
10 changes: 0 additions & 10 deletions src/Common/SI.GameServer.Client/IGameServerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,7 @@ public interface IGameServerClient : IAsyncDisposable
/// <param name="cancellationToken">Cancellation token.</param>
Task LeaveLobbyAsync(CancellationToken cancellationToken = default);

Task<string> GetNewsAsync(CancellationToken cancellationToken = default);

Task<string> GetNewsNewAsync(CancellationToken cancellationToken = default);

Task<ChatMessage[]> GetLatestChatMessagesAsync(CancellationToken cancellationToken = default);

Task<string[]> GetUsersAsync(CancellationToken cancellationToken = default);

Task<Slice<GameInfo>> GetGamesAsync(int fromId, CancellationToken cancellationToken = default);

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

Task SayAsync(string message);
}
1 change: 0 additions & 1 deletion src/Common/SI.GameServer.Client/SIHostClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public SIHostClient(HubConnection connection, SIHostClientOptions options)
_connection.On(nameof(ISIHostClient.Disconnect), async () =>
{
IncomingMessage?.Invoke(new Message(Resources.YourWereKicked, "@", isSystem: false));

await _connection.StopAsync();
});

Expand Down
3 changes: 0 additions & 3 deletions src/Common/SI.GameServer.Contract/HostInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ public sealed class HostInfo
/// </summary>
public string Name { get; set; } = "";

[Obsolete]
public string PackagesPublicBaseUrl { get; set; } = "";

/// <summary>
/// Base Urls that are considered valid for in-game content files.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/Common/SIEngine.Core/IQuestionEngine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SIEngine.Core;

public interface IQuestionEngine
{
string QuestionTypeName { get; }

bool PlayNext();

void MoveToAnswer();
}
8 changes: 8 additions & 0 deletions src/Common/SIEngine.Core/IQuestionEngineFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using SIPackages;

namespace SIEngine.Core;

public interface IQuestionEngineFactory
{
IQuestionEngine CreateEngine(Question question, QuestionEngineOptions questionEngineOptions);
}
2 changes: 1 addition & 1 deletion src/Common/SIEngine.Core/QuestionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SIEngine.Core;
/// <summary>
/// Performs SI question playing.
/// </summary>
public sealed class QuestionEngine
public sealed class QuestionEngine : IQuestionEngine
{
private readonly Question _question;
private readonly QuestionEngineOptions _options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SIEngine;
/// <summary>
/// Allows to create question engine for a question.
/// </summary>
public sealed class QuestionEngineFactory
public sealed class QuestionEngineFactory : IQuestionEngineFactory
{
private readonly IQuestionEnginePlayHandler _playHandler;

Expand All @@ -18,6 +18,6 @@ public sealed class QuestionEngineFactory
/// <param name="question">Question being played.</param>
/// <param name="questionEngineOptions">Engine options.</param>
/// <returns>Created engine.</returns>
public QuestionEngine CreateEngine(Question question, QuestionEngineOptions questionEngineOptions) =>
new(question, questionEngineOptions, _playHandler);
public IQuestionEngine CreateEngine(Question question, QuestionEngineOptions questionEngineOptions) =>
new QuestionEngine(question, questionEngineOptions, _playHandler);
}
Loading

0 comments on commit 214c67f

Please sign in to comment.