private void StartGame(JToken data, bool continued) { gameStarted = false; Task.Factory.StartNew(() => { InvokeOnUnknownEvent("Game found. Connecting..."); while (!gameStarted) { var host = getServerHost(string.Format(gameServerListUrlTemplate, data["location"])); var url = "wss://" + host; if (url.EndsWith(":443")) { url += "/game-gateway"; } wsGameNode = new WebSocketNode(url, OnMessage, OnError); Send(wsGameNode, ".lq.FastTest.authGame", new { account_id = accountId, token = data["connect_token"], game_uuid = data["game_uuid"] }).Wait(); Thread.Sleep(3000); if (!gameStarted) { InvokeOnUnknownEvent("Failed to connect. Retrying..."); } } }); SaveReplay((string)data["game_uuid"]); }
public MajsoulClient(Config config) : base(config) { var host = getServerHost(serverListUrl); var url = "wss://" + host; if (url.EndsWith(":443")) { url += "/gateway"; } wsNode = new WebSocketNode(url, OnMessage, OnError); username = config.MajsoulUsername; password = config.MajsoulPassword; }
private async Task Send(WebSocketNode wsNode, string methodName, object data) { byte[] buffer = majsoulHelper.encode(new MajsoulMessage { Type = MajsoulMessageType.REQUEST, MethodName = methodName, Data = data, }); try { wsNode.Send(buffer, gameEnded); } catch (Exception ex) { Trace.TraceError(ex.ToString()); Close(true); } }
public override void Bye() { wsNode.Close(); wsGameNode = null; }