/// <summary> /// Gets the round. /// </summary> /// <param name="location">The location.</param> /// <returns></returns> private async Task <Round> GetRound(string location) { if (_disposing) { return(null); } LilaRequest roundReq = new LilaRequest(new Uri(location, UriKind.Relative), Culture); roundReq.Cookies.Add(lobbyCon.GetCookies()); if (anonymous) { roundReq.Cookies.Add(new Cookie("rk2", location.Substring(9), "/", "lichess.org")); //add anoncookie } LilaResponse roundRes = await roundReq.Get(LilaRequest.ContentType.Html); if (roundRes == null) { log.Error("Failed to join round at {0}", location); return(null); } string html = await roundRes.ReadAsync(); const string id = "LichessRound.boot("; int roundBootIndex = html.IndexOf(id); if (roundBootIndex == -1) { return(null); } string json = StringEngine.GetInside(html, roundBootIndex + id.Length); if (json == null) { log.Error("Failed to parse game json data."); return(null); } return(JsonConvert.DeserializeObject <Round>(json, jsonSettings)); }
/// <summary> /// Gets the tournament. /// </summary> /// <param name="tournamentId">The tournament identifier.</param> /// <returns></returns> private async Task <Tournament> GetTournament(string tournamentId) { if (_disposing) { return(null); } LilaRequest tournamentReq = new LilaRequest(new Uri(string.Format("/tournament/{0}", tournamentId), UriKind.Relative), Culture); tournamentReq.Cookies.Add(lobbyCon.GetCookies()); LilaResponse roundRes = await tournamentReq.Get(LilaRequest.ContentType.Html); if (roundRes == null) { log.Error("Failed to join tournament at {0}", tournamentId); return(null); } string html = await roundRes.ReadAsync(); const string id = "lichess.tournament = "; int roundBootIndex = html.IndexOf(id); if (roundBootIndex == -1) { return(null); } string json = StringEngine.GetInside(html, roundBootIndex + id.Length); if (json == null) { log.Error("Failed to parse tournament json data."); return(null); } return(JsonConvert.DeserializeObject <Tournament>(json, jsonSettings)); }