Ejemplo n.º 1
0
        /// <summary>
        /// Leaves a tournament.
        /// </summary>
        /// <param name="tournament">The tournament.</param>
        public void LeaveTournament(LilaTournament tournament)
        {
            tournamentCons.TryRemove(tournament.Data.Id, out LilaTournament t);
            tournament.Dispose();

            if (!lobbyCon.IsConnected())
            {
                lobbyCon.Reconnect();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Joins a tournament.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        internal bool JoinTournament(TournamentData data)
        {
            if (_disposing)
            {
                return(false);
            }

            Uri host = new Uri("wss://socket.lichess.org");

            if (!Uri.TryCreate(string.Format("/tournament/{0}/socket/v2", data.Id), UriKind.Relative, out Uri relative))
            {
                return(false);
            }

            Uri absolute = new Uri(host, relative);

            if (random == null)
            {
                return(false);
            }

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

            LilaSocket tournamentCon = new LilaSocket("Tournament-Socket", ResourceType.Thread);

            tournamentCon.AddCookies(lobbyCon.GetCookies());

            if (tournamentCon.Connect(gameBldr.Uri) && !_disposing)
            {
                //Disconnect from lobby
                if (lobbyCon.IsConnected())
                {
                    lobbyCon.Disconnect();
                }

                LilaTournament lilaTournament = new LilaTournament(this, tournamentCon, data);
                tournamentCons.TryAdd(data.Id, lilaTournament);

                Events.FireEventAsync(Events._onTournamentEnter, new TournamentEvent(this, lilaTournament));
                return(true);
            }

            tournamentCon.Dispose();
            return(false);
        }