示例#1
0
        /// <summary>
        /// Called when seeks are reloaded.
        /// </summary>
        /// <param name="ws">The websocket.</param>
        /// <param name="message">The message.</param>
        private void OnReloadSeeks(WebSocketBase ws, MReloadSeeks message)
        {
            LilaRequest lr = new LilaRequest(new Uri(LilaRoutes.LobbySeeks, UriKind.Relative), Culture);

            lr.Cookies.Add(lobbyCon.GetCookies());
            lr.Get(LilaRequest.ContentType.Json).ContinueWith(SetHooks);
        }
示例#2
0
        /// <summary>
        /// Logs in as anonymous player.
        /// </summary>
        public void Login()
        {
            anonymous = true;
            LilaRequest         req    = new LilaRequest(new Uri(LilaRoutes.Lobby, UriKind.Relative), Culture);
            Task <LilaResponse> result = req.Get(LilaRequest.ContentType.Html);

            result.ContinueWith(HandleAuth);
        }
示例#3
0
        /// <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));
        }
示例#4
0
        /// <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));
        }
示例#5
0
        /// <summary>
        /// Logs in as the specified username.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        public void Login(string username, string password)
        {
            if (_disposing)
            {
                return;
            }

            anonymous = false;
            LilaRequest         hpReq     = new LilaRequest(new Uri(LilaRoutes.Lobby, UriKind.Relative), Culture);
            Task <LilaResponse> hpResTask = hpReq.Get(LilaRequest.ContentType.Any);

            hpResTask.Wait();

            LilaRequest req = new LilaRequest(new Uri(LilaRoutes.Login, UriKind.Relative), Culture);

            if (hpResTask.Result != null)
            {
                req.Cookies.Add(hpResTask.Result.GetCookies());
            }

            Task <LilaResponse> result = req.Post(LilaRequest.ContentType.Html, new string[] { "username", "password" }, new string[] { username, password });

            result.ContinueWith(HandleAuth);
        }