コード例 #1
0
        /// <summary>
        /// Joins the tournament (starts playing).
        /// </summary>
        public async Task <bool> Join()
        {
            LilaRequest joinReq = new LilaRequest(new Uri(string.Format("/tournament/{0}/join", tournamentData.Id), UriKind.Relative));

            joinReq.Cookies.Add(socket.GetCookies());

            //p is password
            string       str     = "{\"p\":null}";
            LilaResponse joinRes = await joinReq.Post(LilaRequest.ContentType.Json, str);

            bool success = joinRes != null && joinRes.CheckStatus(HttpStatusCode.OK | HttpStatusCode.SeeOther);

            if (success)
            {
                Client.Events.FireEventAsync(Client.Events._onTournamentJoin, new TournamentEvent(Client, this));
                return(true);
            }

            return(false);
        }
コード例 #2
0
ファイル: LilaClient.cs プロジェクト: arbitre125/LilaSharp
        /// <summary>
        /// Challenges a player.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="form">The form.</param>
        /// <returns></returns>
        public async Task <bool> ChallengePlayer(string username, GameForm form)
        {
            if (_disposing || challengeCon == null)
            {
                return(false);
            }

            LilaRequest setupFriend = new LilaRequest(new Uri(string.Format("/setup/friend?user={0}", username.ToLower()), UriKind.Relative), Culture);

            setupFriend.Cookies.Add(lobbyCon.GetCookies());

            string[] keys   = new string[] { "variant", "fen", "timeMode", "time", "increment", "days", "mode", "color" };
            object[] values = new object[] { form.Variant, form.Fen, form.TimeMode, form.Time, form.Increment, form.Days, form.Mode, form.Color };

            LilaResponse res = await setupFriend.Post(LilaRequest.ContentType.Any, keys, values);

            if (res == null || !res.CheckStatus(HttpStatusCode.OK | HttpStatusCode.SeeOther))
            {
                return(false);
            }

            string loc = (challengeLocation = res.GetHeader("Location")).Trim('/');

            Uri host     = new Uri("wss://socket.lichess.org");
            Uri relative = new Uri(string.Format("/challenge/{0}/socket/v2", loc), UriKind.Relative);
            Uri absolute = new Uri(host, relative);

            UriBuilder challengeBldr = new UriBuilder(absolute)
            {
                Query = string.Format("sri={0}", random.NextSri())
            };

            //int port = LilaPing.PingServer(9025, 9029, 1);
            //challengeBldr.Port = port == -1 ? 9025 : port;

            challengeCon.AddCookies(lobbyCon.GetCookies());
            if (challengeCon.Connect(challengeBldr.Uri))
            {
                log.ConditionalDebug("Connected to challenge socket. Awaiting reload message.");
                return(true);
            }

            return(false);
        }