コード例 #1
0
ファイル: FICSConnection.cs プロジェクト: stschoof/Projects
        /// <summary>
        /// Start to observe a game
        /// </summary>
        /// <param name="game">                 Game to observe</param>
        /// <param name="chessBoardControl">    Chess board control to associate with the game</param>
        /// <param name="iTimeOut">             Command timeout in second</param>
        /// <param name="iMoveTimeOut">         Command timeout in second</param>
        /// <param name="actionGameFinished">   Action to call when game is finished or null if none</param>
        /// <param name="strError">             Error if any</param>
        /// <returns>
        /// true if succeed, false if game is already defined
        /// </returns>
        public bool ObserveGame(FICSGame game, SrcChess2.ChessBoardControl chessBoardControl, int iTimeOut, int?iMoveTimeOut, Action <GameIntf, TerminationE, string> actionGameFinished, out string strError)
        {
            bool              bRetVal;
            GameIntf          gameIntf;
            Action <GameIntf> actionMoveTimeOut;

            if (chessBoardControl == null)
            {
                throw new ArgumentNullException();
            }
            if (iMoveTimeOut == 0)
            {
                actionMoveTimeOut = null;
            }
            else
            {
                actionMoveTimeOut = GetTimeOutAction();
            }
            gameIntf = new GameIntf(game, chessBoardControl, iMoveTimeOut, actionMoveTimeOut, actionGameFinished);
#if DEBUG
            iTimeOut = 3600;
#endif
            bRetVal = ObserveGame(gameIntf, iTimeOut, out strError);
            return(bRetVal);
        }
コード例 #2
0
ファイル: FICSConnection.cs プロジェクト: stschoof/Projects
        /// <summary>
        /// Start observing a game using a predefined game interface
        /// </summary>
        /// <param name="gameIntf">             Game to observe</param>
        /// <param name="iTimeOut">             Command timeout in second</param>
        /// <param name="strError">             Error if any</param>
        /// <returns>
        /// true if succeed, false if game is already defined
        /// </returns>
        public bool ObserveGame(GameIntf gameIntf, int iTimeOut, out string strError)
        {
            bool bRetVal;
            int  iGameId;

            if (gameIntf.Game.IsPrivate)
            {
                throw new ArgumentException("Cannot listen to private game");
            }
            bRetVal = m_state.AddGameIntf(gameIntf);
            if (bRetVal)
            {
                iGameId = gameIntf.Game.GameId;
                m_state.SetCommand(CmdExecutingE.MoveList, gameIntf);
                m_connection.SendLine("observe " + iGameId.ToString());
                m_connection.SendLine("moves " + iGameId.ToString());
                if (m_state.CmdSignal.WaitOne(iTimeOut * 1000))
                {
                    strError = m_state.LastCmdError;
                    bRetVal  = (strError == null);
                }
                else
                {
                    m_state.ResetCommand();
                    strError = "Timeout";
                }
            }
            else
            {
                strError = "Already defined";
            }
            return(bRetVal);
        }
コード例 #3
0
ファイル: FICSConnection.cs プロジェクト: stschoof/Projects
            /// <summary>
            /// Find a game using its attached chess board control
            /// </summary>
            /// <param name="chessBoardControl">  Chess board control</param>
            /// <returns>
            /// Game or null if not found
            /// </returns>
            public GameIntf FindGameIntf(SrcChess2.ChessBoardControl chessBoardControl)
            {
                GameIntf gameIntfRetVal = null;

                lock (m_dictGameIntf) {
                    gameIntfRetVal = m_dictGameIntf.Values.FirstOrDefault(x => x.ChessBoardCtl == chessBoardControl);
                }
                return(gameIntfRetVal);
            }
コード例 #4
0
ファイル: FICSConnection.cs プロジェクト: stschoof/Projects
 /// <summary>
 /// Terminate a game
 /// </summary>
 /// <param name="gameIntf">                 Game interface</param>
 /// <param name="eTermination">             Termination code</param>
 /// <param name="strTerminationComment">    Termination comment</param>
 /// <param name="strError">                 Error if any</param>
 public void TerminateGame(GameIntf gameIntf, TerminationE eTermination, string strTerminationComment, string strError)
 {
     lock (m_dictGameIntf) {
         if (RemoveGameIntfInt(gameIntf.Game.GameId))
         {
             gameIntf.SetTermination(eTermination, strTerminationComment, strError);
         }
     }
 }
コード例 #5
0
ファイル: FICSConnection.cs プロジェクト: stschoof/Projects
 /// <summary>
 /// Set the current command or reset it to none
 /// </summary>
 /// <param name="eCmd">     Command</param>
 /// <param name="gameIntf"> Associated game interface if any</param>
 public void SetCommand(CmdExecutingE eCmd, GameIntf gameIntf)
 {
     if (eCmd == CmdExecutingE.None)
     {
         throw new ArgumentException("Use ResetCommand to set a command to none");
     }
     lock (this) {
         if (CmdExecuting != CmdExecutingE.None && CmdExecuting != CmdExecutingE.PreLogin)
         {
             throw new MethodAccessException("Cannot execute a command while another is executing");
         }
         CmdExecuting    = eCmd;
         TimeStarted     = DateTime.Now;
         CurrentGameIntf = gameIntf;
         Phase           = 0;
         LastCmdError    = null;
         CmdSignal.Reset();
     }
 }
コード例 #6
0
ファイル: FICSConnection.cs プロジェクト: stschoof/Projects
            /// <summary>
            /// Add a game interface
            /// </summary>
            /// <param name="gameIntf"> Game interface</param>
            /// <returns>
            /// true if succeed, false if game is already defined
            /// </returns>
            public bool AddGameIntf(GameIntf gameIntf)
            {
                bool bRetVal;
                int  iGameId;

                lock (m_dictGameIntf) {
                    iGameId = gameIntf.Game.GameId;
                    if (m_dictGameIntf.ContainsKey(iGameId))
                    {
                        bRetVal = false;
                    }
                    else
                    {
                        m_dictGameIntf.Add(iGameId, gameIntf);
                        bRetVal             = true;
                        SingleMoveListening = true;
                    }
                }
                return(bRetVal);
            }