Ejemplo n.º 1
0
        /// <summary>
        /// Removes the specified game.
        /// </summary>
        /// <param name="game">The game.</param>
        /// <returns></returns>
        internal bool Remove(LilaGame game)
        {
            log.ConditionalDebug("Removing {0}", game.Data.Url.Socket);

            bool result = gameCons.TryRemove(game.Data.Url.Socket, out LilaGame s);

            game.Dispose();
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Joins a game.
        /// </summary>
        /// <param name="game">The game.</param>
        /// <returns></returns>
        internal bool JoinGame(GameData game)
        {
            if (_disposing)
            {
                return(false);
            }

            lock (joinLock)
            {
                Uri host = new Uri("wss://socket.lichess.org");
                if (!Uri.TryCreate(game.Url.Socket, 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 gameCon = new LilaSocket("Game-Socket", ResourceType.Thread);
                gameCon.AddCookies(lobbyCon.GetCookies());
                if (anonymous)
                {
                    gameCon.AddCookies(new Cookie("rk2", game.Url.Socket.Substring(9, 4), "/", "lichess.org")); //Add anoncookie
                }

                if (gameCons.Count == 0 && gameCon.Connect(gameBldr.Uri) && !_disposing)
                {
                    LilaGame lilaGame = new LilaGame(this, gameCon, game);
                    gameCons.TryAdd(game.Url.Socket, lilaGame);

                    Events.FireEventAsync(Events._onJoinGame, new JoinGameEvent(this, lilaGame));
                    return(true);
                }

                gameCon.Dispose();
                return(false);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Leaves a game.
 /// </summary>
 /// <param name="game">The game.</param>
 public void LeaveGame(LilaGame game)
 {
     Remove(game);
 }