Ejemplo n.º 1
0
        public override async void Process(KgsConnection connection)
        {
            Debug.WriteLine("Success. Now getting info.");
            var roomsArray = new int[this.Rooms.Length];

            for (int i = 0; i < this.Rooms.Length; i++)
            {
                roomsArray[i] = this.Rooms[i].ChannelId;
            }
            connection.Events.RaisePersonalInformationUpdate(this.You);
            connection.Events.RaiseSystemMessage("Requesting room names...");
            connection.Events.RaiseLoginPhaseChanged(KgsLoginPhase.RequestingRoomNames);
            await connection.MakeUnattendedRequestAsync("ROOM_NAMES_REQUEST", new
            {
                Rooms = roomsArray
            });

            connection.Events.RaiseSystemMessage("Joining global lists...");
            connection.Events.RaiseLoginPhaseChanged(KgsLoginPhase.JoiningGlobalLists);
            await connection.Commands.GlobalListJoinRequestAsync("CHALLENGES");

            await connection.Commands.GlobalListJoinRequestAsync("ACTIVES");

            await connection.Commands.GlobalListJoinRequestAsync("FANS");

            connection.Events.RaiseSystemMessage("On-login outgoing message burst complete.");
            connection.LoggedIn  = true;
            connection.LoggingIn = false;
            connection.Events.RaiseLoginPhaseChanged(KgsLoginPhase.Done);
            connection.Events.RaiseLoginComplete(LoginResult.Success);
        }
Ejemplo n.º 2
0
        public override void Process(KgsConnection connection)
        {
            connection.Events.RaiseErrorNotification("CHALLENGE_DECLINE");
#pragma warning disable 4014
            connection.Commands.GenericUnjoinAsync(this.ChannelId);
#pragma warning restore 4014
        }
Ejemplo n.º 3
0
 public override void Process(KgsConnection connection)
 {
     foreach (var ev in SgfEvents)
     {
         ev.ExecuteAsIncoming(connection, connection.Data.GetGame(ChannelId));
     }
 }
Ejemplo n.º 4
0
 public override void Process(KgsConnection connection)
 {
     foreach (var info in Rooms)
     {
         connection.Data.SetRoomName(info.ChannelId, info.Name);
     }
 }
Ejemplo n.º 5
0
        public override void Process(KgsConnection connection)
        {
            // Yeah, we cannot await here. I don't think it's a big deal. We'll see.
#pragma warning disable 4014
            connection.Commands.GameTimeExpiredAsync(this.ChannelId);
#pragma warning restore 4014
        }
Ejemplo n.º 6
0
 public override void Process(KgsConnection connection)
 {
     connection.Data.UnjoinChannel(ChannelId);
     // TODO (future expansion): If this is a room, it can be removed from the list of rooms.
     // However, it is also possible that a different downstream message is responsible for this.
     // Research needed.
 }
Ejemplo n.º 7
0
 public override void Process(KgsConnection connection)
 {
     connection.Data.JoinGlobalChannel(ChannelId, ContainerType);
     foreach (var channel in Games)
     {
         connection.Data.GetChannel <KgsGameContainer>(ChannelId)?.AddChannel(channel, connection);
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes the KGS connection
 /// </summary>
 /// <returns></returns>
 private static void InitKgsConnection()
 {
     _kgsConnection = new KgsConnection();
     _kgsConnection.Events.PersonalInformationUpdate += KgsUserUpdate;
     _kgsConnection.Events.GameJoined += Kgs_GameJoined;
     _kgsConnection.Events.NotificationErrorMessage += KgsNotificationErrorMessage;
     _kgsConnection.Events.ChallengeJoined          += Kgs_ChallengeJoined;
     Mvx.Resolve <ITimerService>()
     .StartTimer(TimeSpan.FromSeconds(10), async() => { await _kgsConnection.Commands.WakeUpAsync(); });
 }
Ejemplo n.º 9
0
 public ChallengeForm(KgsChallenge challenge, KgsConnection connection)
 {
     InitializeComponent();
     this.challenge            = challenge;
     this._connection          = connection;
     this.lblInfo.Text         = challenge.ToString();
     connection.Events.Unjoin += Events_Unjoin;
     challenge.StatusChanged  += ChallengeStatusChanged;
     RefreshEvents();
 }
Ejemplo n.º 10
0
 public KgsGameBuilder(KgsGameInfo info, KgsConnection connection)
 {
     this._info = info;
     this.BoardSize(info.BoardSize);
     this.CountingType(Rules.CountingType.Territory);
     this.HandicapPlacementType(Phases.HandicapPlacement.HandicapPlacementType.Fixed);
     this.Komi(info.Komi);
     this._connection = connection;
     this.Handicap(info.NumberOfHandicapStones);
 }
Ejemplo n.º 11
0
        public override void Process(KgsConnection connection)
        {
            var challenge = connection.Data.GetChannel <KgsChallenge>(this.ChannelId);

            if (challenge != null)
            {
                challenge.IncomingChallenge = this.Proposal;
                challenge.Events.Add("RECEIVED A CHALLENGE");
                challenge.RaiseStatusChanged();
            }
        }
Ejemplo n.º 12
0
        public override void Process(KgsConnection connection)
        {
            KgsChallenge createdChallenge = KgsChallenge.FromChannel(Game);

            if (createdChallenge != null)
            {
                createdChallenge.OwnedByUs = true;
                connection.Data.JoinChallenge(createdChallenge);
            }
            createdChallenge.RaiseStatusChanged();
        }
Ejemplo n.º 13
0
        public override void Process(KgsConnection connection)
        {
            var challenge = connection.Data.GetChannel <KgsChallenge>(this.ChannelId);

            if (challenge != null)
            {
                challenge.Events.Add(this.Type);
                challenge.Acceptable          = true;
                challenge.CreatorsNewProposal = Proposal;
                challenge.RaiseStatusChanged();
            }
        }
Ejemplo n.º 14
0
 public override void Process(KgsConnection connection)
 {
     connection.Data.JoinRoom(this.ChannelId);
     if (Games != null)
     {
         connection.Data.GetChannel <KgsRoom>(ChannelId)?.UpdateGames(Games, connection);
     }
     (connection.Data.GetChannel(this.ChannelId) as KgsRoom).Users.Clear();
     foreach (var user in Users)
     {
         connection.Data.AddUserToChannel(this.ChannelId, user);
     }
 }
Ejemplo n.º 15
0
        public override void Process(KgsConnection connection)
        {
            var challenge = connection.Data.GetChannel <KgsChallenge>(this.ChannelId);

            if (challenge != null)
            {
                connection.Data.JoinChallenge(challenge);
            }
            foreach (var user in Users)
            {
                connection.Data.AddUserToChannel(this.ChannelId, user);
            }
        }
Ejemplo n.º 16
0
 public KgsGameController(
     KgsGameInfo kgsGameInfo,
     IRuleset ruleset,
     PlayerPair players,
     KgsConnection serverConnection) :
     base(kgsGameInfo, ruleset, players, serverConnection)
 {
     Info         = kgsGameInfo;
     KgsConnector = new KgsConnector(this, serverConnection);
     Chat         = new ChatService(KgsConnector);
     Server       = serverConnection;
     RegisterConnector(KgsConnector);
     KgsConnector.GameEndedByServer += KgsConnector_GameEndedByServer;
 }
        public override void Process(KgsConnection connection)
        {
            var          channel   = connection.Data.GetChannel(this.ChannelId);
            KgsChallenge challenge = channel as KgsChallenge;

            if (challenge != null)
            {
                challenge.Events.Add(this.Type);
            }
            else
            {
                Debug.WriteLine("That was supposed to be a challenge.");
            }
        }
Ejemplo n.º 18
0
 public void UpdateGames(GameChannel[] games, KgsConnection connection)
 {
     foreach (var g in games)
     {
         var existingGame = AllChannelsCollection.FirstOrDefault(kgc => kgc.ChannelId == g.ChannelId);
         if (existingGame != null)
         {
             existingGame.UpdateFrom(g);
         }
         else
         {
             AddChannel(g, connection);
         }
     }
 }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
        public void AddChannel(GameChannel channel, KgsConnection connection)
        {
            var kChallenge = KgsChallenge.FromChannel(channel);

            if (kChallenge != null)
            {
                connection.Data.EnsureChannelExists(kChallenge);
                Challenges.Add(kChallenge);
                AllChannelsCollection.Add(kChallenge);
                return;
            }
            var kGame = KgsTrueGameChannel.FromChannel(channel);

            if (kGame != null)
            {
                connection.Data.EnsureChannelExists(kGame);
                Games.Add(kGame);
                AllChannelsCollection.Add(kGame);
                return;
            }
        }
Ejemplo n.º 21
0
        public override void Process(KgsConnection connection)
        {
            KgsGame game = connection.Data.GetGame(ChannelId);

            if (game != null)
            {
                if (this.Clocks != null)
                {
                    if (this.Clocks[Role.White] != null)
                    {
                        game.Controller.Players.White.Clock.UpdateFromClock(this.Clocks[Role.White]);
                    }
                    if (this.Clocks[Role.Black] != null)
                    {
                        game.Controller.Players.Black.Clock.UpdateFromClock(this.Clocks[Role.Black]);
                    }
                }
                game.Controller.DoneId = DoneId;
                if (this.Actions != null)
                {
                    if (this.Actions.Any(action => action.Action == "SCORE"))
                    {
                        if (game.Controller.Phase.Type != Modes.LiveGame.Phases.GamePhaseType.LifeDeathDetermination)
                        {
                            game.Controller.SetPhase(Modes.LiveGame.Phases.GamePhaseType.LifeDeathDetermination);
                        }
                    }
                }
                if (this.BlackDoneSent && !game.Controller.BlackDoneReceived)
                {
                    game.Controller.BlackDoneReceived = true;
                    game.Controller.KgsConnector.RaiseDoneReceived(game.Controller.Players.Black);
                }
                if (this.WhiteDoneSent && !game.Controller.WhiteDoneReceived)
                {
                    game.Controller.WhiteDoneReceived = true;
                    game.Controller.KgsConnector.RaiseDoneReceived(game.Controller.Players.White);
                }
            }
        }
Ejemplo n.º 22
0
 public override void Process(KgsConnection connection)
 {
     var myGame = connection.Data.GetGame(this.ChannelId);
     connection.Events.RaiseUndoRequestReceived(myGame);
 }
Ejemplo n.º 23
0
 public KgsPlayerBuilder(StoneColor color, KgsConnection connection) : base(color)
 {
     this._connection = connection;
 }
Ejemplo n.º 24
0
 public override void Process(KgsConnection connection)
 {
     connection.LogoutAndDisconnect(Text ?? "");
 }
Ejemplo n.º 25
0
 public KgsAgent(StoneColor color, KgsConnection pandanet) : base(color)
 {
     this._connection = pandanet;
 }
Ejemplo n.º 26
0
 public override void Process(KgsConnection connection)
 {
     connection.Data.GetChannel <KgsGameContainer>(ChannelId)?.RemoveGame(GameId);
 }
Ejemplo n.º 27
0
 public override void Process(KgsConnection connection)
 {
     connection.Data.GetChannel <KgsGameContainer>(ChannelId)?.UpdateGames(Games, connection);
 }
Ejemplo n.º 28
0
 public override void Process(KgsConnection connection)
 {
     connection.LoggingIn = false;
     connection.Events.RaiseLoginComplete(LoginResult.FailureWrongPassword);
 }
Ejemplo n.º 29
0
 public override void Process(KgsConnection connection)
 {
     connection.Data.UnjoinChannel(ChannelId);
 }
Ejemplo n.º 30
0
 public override void Process(KgsConnection connection)
 {
 }