Esempio n. 1
0
        public override void Process(KgsConnection connection)
        {
            KgsGameInfo info = KgsGameInfo.FromGameJoin(this);

            if (info == null)
            {
                return;
            }
            var channel = connection.Data.GetChannel(this.ChannelId);

            if (channel == null)
            {
                channel = connection.Data.CreateGame(KgsTrueGameChannel.FromGameInfo(info, this.ChannelId));
            }


            var blackPlayer = new KgsPlayerBuilder(Game.StoneColor.Black, connection)
                              .Name(info.Black.Name)
                              .Rank(info.Black.Rank)
                              .Build();

            if (info.Black.Name == connection.Username)
            {
                blackPlayer =
                    new HumanPlayerBuilder(Game.StoneColor.Black).Name(info.Black.Name).Rank(info.Black.Rank).Build();
            }
            var whitePlayer = new KgsPlayerBuilder(Game.StoneColor.White, connection)
                              .Name(info.White.Name)
                              .Rank(info.White.Rank)
                              .Build();

            if (info.White.Name == connection.Username)
            {
                whitePlayer =
                    new HumanPlayerBuilder(Game.StoneColor.White).Name(info.White.Name).Rank(info.White.Rank).Build();
            }
            var ongame = new KgsGameBuilder(info, connection)
                         .BlackPlayer(blackPlayer)
                         .WhitePlayer(whitePlayer)
                         .Build();

            connection.Data.JoinGame(ongame, channel as KgsTrueGameChannel);
            foreach (var ev in SgfEvents)
            {
                ev.ExecuteAsIncoming(connection, ongame);
            }
            connection.Events.RaiseGameJoined(ongame);
        }
Esempio n. 2
0
 /// <summary>
 /// Adds a game to the list of channels we know but haven't joined yet, and returns it.
 /// </summary>
 /// <param name="game">The game.</param>
 public KgsTrueGameChannel CreateGame(KgsTrueGameChannel game)
 {
     Channels[game.ChannelId] = game;
     return(game);
 }
Esempio n. 3
0
 /// <summary>
 /// Joins the game channel and opens the given game so it can be referenced by other messages.
 /// </summary>
 /// <param name="ongame">The KGS game that will be referenced later.</param>
 /// <param name="kgsTrueGameChannel">The game channel that we are joining.</param>
 public void JoinGame(KgsGame ongame, KgsTrueGameChannel kgsTrueGameChannel)
 {
     _joinedGames[ongame.Info.ChannelId] = ongame;
     JoinChannel(kgsTrueGameChannel);
 }