37 lines
1.7 KiB
C#
37 lines
1.7 KiB
C#
using asap.core;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using game.Account;
|
|
var liveApi = GContext.container.Resolve<ICustomServerMgr>();
|
|
var liveUser = GContext.container.Resolve<game.IUserService>();
|
|
if (liveApi.ApiBaseUri.AbsoluteUri != "http://s101.local:18080/" || liveUser.ApiPlayerId != "101") return "Refused: baseline changed";
|
|
var endpoint = new Uri("http://127.0.0.1:62848/");
|
|
using var session = new S101AccountSession(endpoint);
|
|
var config = new Config(null);
|
|
config.Set(GConstant.K_Event_API_URL, endpoint.AbsoluteUri);
|
|
var mgr = new CustomServerMgr(config);
|
|
var rt = new SignalRService(mgr, config);
|
|
try
|
|
{
|
|
var login = await session.LoginAsync("102");
|
|
if (!login.Success) throw new Exception("Login failed " + login.Error);
|
|
mgr.UseAccountSession(session);
|
|
await rt.Connect();
|
|
if (!rt.IsConnected || await rt.Publish("Test", "acceptance", "before") != "OK") throw new Exception("First RPC failed");
|
|
bool sawDisconnected = false;
|
|
var until = DateTime.UtcNow.AddSeconds(32);
|
|
while (DateTime.UtcNow < until)
|
|
{
|
|
if (!rt.IsConnected) sawDisconnected = true;
|
|
if (sawDisconnected && rt.IsConnected) break;
|
|
await Task.Delay(100);
|
|
}
|
|
if (!sawDisconnected || !rt.IsConnected) throw new Exception("Automatic recovery missing");
|
|
if (await rt.Publish("Test", "acceptance", "after") != "OK") throw new Exception("Recovered RPC failed");
|
|
await rt.ReleaseAsync();
|
|
await Task.Delay(500);
|
|
await Task.Delay(2500);
|
|
return "SawDisconnected=" + sawDisconnected + "; AutoRecovered=True; BeforeRPC=OK; AfterRPC=OK; ReleaseConnected=" + rt.IsConnected;
|
|
}
|
|
finally { await rt.ReleaseAsync(); mgr.ClearAccountSession(); }
|