mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-28 22:35:42 +00:00
clean up the connection a bit, add a keepalive, and extend the timeout (#3651)
* clean up connection * extend the timeout
This commit is contained in:
+3
-3
@@ -85,7 +85,7 @@ public class CustomBattleHandler : MonoBehaviour {
|
||||
bool youAreDefender = defenderToggle.isOn;
|
||||
|
||||
var yourSetupInfo = new Net.Eagle0.Common.PlayerSetupInfo {
|
||||
UserName = _eagleConnection.PlayerName,
|
||||
UserName = _eagleConnection.playerName,
|
||||
Defender = youAreDefender,
|
||||
EagleFactionId = 1,
|
||||
Food = 2000,
|
||||
@@ -180,7 +180,7 @@ public class CustomBattleHandler : MonoBehaviour {
|
||||
ecI: new RemoteEagleClient(
|
||||
gameId: newGameResponse.EagleGameId,
|
||||
client: _eagleConnection.EagleGrpcClient,
|
||||
creds: _eagleConnection.Credentials,
|
||||
creds: _eagleConnection.credentials,
|
||||
playerId: yourPid,
|
||||
token: EagleConnection.EagleCancellationToken),
|
||||
map: map,
|
||||
@@ -198,7 +198,7 @@ public class CustomBattleHandler : MonoBehaviour {
|
||||
_clientInterface = new RemoteEagleClient(
|
||||
newGameResponse.EagleGameId,
|
||||
_eagleConnection.EagleGrpcClient,
|
||||
_eagleConnection.Credentials,
|
||||
_eagleConnection.credentials,
|
||||
1,
|
||||
EagleConnection.EagleCancellationToken);
|
||||
Register();
|
||||
|
||||
@@ -6,7 +6,6 @@ using System.Collections.Generic;
|
||||
using common;
|
||||
using TMPro;
|
||||
using Net.Eagle0.Eagle.Api;
|
||||
using eagle0;
|
||||
using Net.Eagle0.Eagle.Common;
|
||||
using Shardok;
|
||||
#if UNITY_EDITOR
|
||||
@@ -162,7 +161,7 @@ namespace eagle {
|
||||
var oneGameClient = new RemoteEagleClient(
|
||||
gameId,
|
||||
eagleConnection.EagleGrpcClient,
|
||||
eagleConnection.Credentials,
|
||||
eagleConnection.credentials,
|
||||
playerId,
|
||||
EagleConnection.EagleCancellationToken);
|
||||
ModelUpdater = new GameModelUpdater(oneGameClient, rollPanelController);
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace eagle {
|
||||
using ProvinceId = Int32;
|
||||
|
||||
public class RemoteEagleClient : IEagleClientInterface {
|
||||
private const double TimeoutSeconds = 55.0;
|
||||
private const double TimeoutSeconds = 300.0;
|
||||
|
||||
private DateTime? GetDeadlineFromNow() {
|
||||
return DateTime.UtcNow.AddSeconds(TimeoutSeconds);
|
||||
|
||||
@@ -10,21 +10,17 @@ using eagle;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
public class EagleConnection : IDisposable {
|
||||
private static bool loggerSet = false;
|
||||
|
||||
public readonly string PlayerName;
|
||||
public readonly string Url;
|
||||
public readonly Metadata Credentials;
|
||||
public readonly string playerName;
|
||||
public readonly Metadata credentials;
|
||||
private const double KeepAliveSeconds = 45.0;
|
||||
|
||||
public static CancellationToken EagleCancellationToken =>
|
||||
ConnectionKiller.EagleCancellationToken;
|
||||
public static CancellationToken ShardokCancellationToken =>
|
||||
ConnectionKiller.ShardokCancellationToken;
|
||||
|
||||
public Eagle.EagleClient EagleGrpcClient { get; private set; }
|
||||
|
||||
private Action<GamesReply, StatusCode> repeatedCallback;
|
||||
private AsyncServerStreamingCall<GamesReply> streamingCall;
|
||||
private Action<GamesReply, StatusCode> _repeatedCallback;
|
||||
private AsyncServerStreamingCall<GamesReply> _streamingCall;
|
||||
|
||||
private CallInvoker MakeInvoker(string playerName, string password, string url) {
|
||||
var authInterceptor = new AuthInterceptor(playerName, password);
|
||||
@@ -35,11 +31,14 @@ public class EagleConnection : IDisposable {
|
||||
var channel = GrpcChannel.ForAddress(
|
||||
"https://" + url,
|
||||
new GrpcChannelOptions {
|
||||
HttpHandler = new YetAnotherHttpHandler { Http2Only = true },
|
||||
HttpHandler =
|
||||
new YetAnotherHttpHandler {
|
||||
Http2Only = true,
|
||||
Http2KeepAliveInterval = TimeSpan.FromSeconds(KeepAliveSeconds)
|
||||
},
|
||||
DisposeHttpClient = true,
|
||||
LoggerFactory = loggerFactory
|
||||
// Credentials = sslCreds,
|
||||
// MaxReceiveMessageSize = null
|
||||
LoggerFactory = loggerFactory,
|
||||
MaxReceiveMessageSize = null
|
||||
});
|
||||
|
||||
var invoker = channel.Intercept(authInterceptor);
|
||||
@@ -47,11 +46,8 @@ public class EagleConnection : IDisposable {
|
||||
}
|
||||
|
||||
public EagleConnection(string playerName, string password, string url) {
|
||||
PlayerName = playerName;
|
||||
Url = url;
|
||||
|
||||
Credentials = new Metadata();
|
||||
Credentials.Add("user", playerName);
|
||||
this.playerName = playerName;
|
||||
credentials = new Metadata { { "user", playerName } };
|
||||
|
||||
EagleGrpcClient = new Eagle.EagleClient(MakeInvoker(playerName, password, url));
|
||||
}
|
||||
@@ -66,21 +62,21 @@ public class EagleConnection : IDisposable {
|
||||
using (var call = EagleGrpcClient.EnterLobby(
|
||||
new GamesRequest { PregeneratedTextHash = pregeneratedTextHash },
|
||||
cancellationToken: EagleCancellationToken)) {
|
||||
repeatedCallback = rc;
|
||||
streamingCall = call;
|
||||
_repeatedCallback = rc;
|
||||
_streamingCall = call;
|
||||
|
||||
try {
|
||||
while (repeatedCallback != null &&
|
||||
await streamingCall.ResponseStream.MoveNext(
|
||||
while (_repeatedCallback != null &&
|
||||
await _streamingCall.ResponseStream.MoveNext(
|
||||
cancellationToken: EagleCancellationToken)) {
|
||||
if (repeatedCallback != null) {
|
||||
repeatedCallback.Invoke(
|
||||
streamingCall.ResponseStream.Current,
|
||||
if (_repeatedCallback != null) {
|
||||
_repeatedCallback.Invoke(
|
||||
_streamingCall.ResponseStream.Current,
|
||||
StatusCode.OK);
|
||||
} else {
|
||||
if (streamingCall != null) {
|
||||
streamingCall.Dispose();
|
||||
streamingCall = null;
|
||||
if (_streamingCall != null) {
|
||||
_streamingCall.Dispose();
|
||||
_streamingCall = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,8 +85,8 @@ public class EagleConnection : IDisposable {
|
||||
switch (e.StatusCode) {
|
||||
case StatusCode.Cancelled:
|
||||
case StatusCode.Internal:
|
||||
if (repeatedCallback != null) {
|
||||
repeatedCallback.Invoke(null, e.StatusCode);
|
||||
if (_repeatedCallback != null) {
|
||||
_repeatedCallback.Invoke(null, e.StatusCode);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -107,10 +103,10 @@ public class EagleConnection : IDisposable {
|
||||
}
|
||||
|
||||
public void LeaveLobby() {
|
||||
repeatedCallback = null;
|
||||
if (streamingCall != null) {
|
||||
streamingCall.Dispose();
|
||||
streamingCall = null;
|
||||
_repeatedCallback = null;
|
||||
if (_streamingCall != null) {
|
||||
_streamingCall.Dispose();
|
||||
_streamingCall = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user