protected override void OnReceivingError(string type, string errorMsg)
 {
     if (type == RECEIVE_FATAL_ERROR || type == outCreateGame || type == outJoinGame)
     {
         TimeLimitedOperationsServiceSingleton.RemoveOperation(SetStateGameQuery);
         context.game.OnReceivingError(RECEIVE_FATAL_ERROR, errorMsg);
     }
     else
     {
         context.game.OnReceivingError(type, errorMsg);
     }
 }
 public override void OnConnectionError(string type, string errorMsg)
 {
     if (bExiting)
     {
         int id = (context.gameCtrl.IsObserver || context.gameCtrl.IsGameFinished) ? -2 : -1;
         context.gameCtrl.FisishGame(id, string.Empty);
         TimeLimitedOperationsServiceSingleton.RemoveOperation(SetStateGameQuery);
         bExiting = false;
     }
     else
     {
         if (type == outCreateGame || type == outJoinGame)
         {
             context.game.OnConnectionError(errorMsg);
         }
         else
         {
             context.game.OnReceivingError(type, errorMsg);
         }
     }
 }
        public void SetExit(bool bAppExiting)
        {
            if (bExitSending || context.gameCtrl.IsGameFinished)
            {
                return;
            }
            bExitSending = true;
            bExiting     = true;
            Headers headers = new Headers();

            headers.Add("access_token", accessToken);
            headers.Add("game_creator", (context.gameCtrl.IsGameCreator ? 1 : 0).ToString());
            headers.Add("observer", (context.gameCtrl.IsObserver ? 1 : 0).ToString());
            JObject rss = new JObject();

            rss.Add("user_name", context.gameCtrl.UserName);
            rss.Add("exit", bAppExiting);
            if (context.gameCtrl.IsObserver)
            {
                TimeLimitedOperationsServiceSingleton.RemoveOperation(SetStateGameQuery);
            }
            SendJsonData("POST", "/exit", headers, rss.ToString());
            bExitSending = false;
        }
        private bool OnGameState(JObject jsonObject)
        {
            if (!bCheckGameState)
            {
                bCheckGameState = true;
                return(true);
            }

            bool   bMyMove      = (bool)jsonObject["you_turn"];
            long   timeDuration = (long)jsonObject["game_duration"];
            JArray jField       = (JArray)jsonObject["field"];
            string sdata        = string.Empty;

            foreach (var jRow in jField)
            {
                sdata += (string)jRow;
            }

            context.game.OnDuration(timeDuration);
            JToken winner = GameStateChecker.NONE;
            bool   bSucc  = jsonObject.TryGetValue("winner", out winner);

            if (!bSucc || (int)winner == GameStateChecker.NONE)
            {
                if (context.gameCtrl.IsGameCreator && context.gameCtrl.IsMyFirstMove())
                {
                    if (!bGameBeginEnabled && !bMyMove)
                    {
                        return(true);
                    }
                    if (bMyMove)
                    {
                        bGameBeginEnabled = true;
                    }
                }
                context.gameCtrl.SetYourMove(context.gameCtrl.IsMyFirstMove(), bMyMove);
                context.gameCtrl.SetGameState(sdata);
                return(true);
            }

            bCheckGameState = false;
            JToken jwinUserName;
            string winUserName = string.Empty;

            if (jsonObject.TryGetValue("winner_name", out jwinUserName))
            {
                winUserName = (string)jwinUserName;
            }
            int id = -1;

            switch ((int)winner)
            {
            case GameStateChecker.MATCH_DRAWN: {
                id = 0;
            }
            break;

            case GameStateChecker.WIN_X: {
                id = context.gameCtrl.MyCellValue == 'X' ? 1 : -1;
            }
            break;

            case GameStateChecker.WIN_0: {
                id = context.gameCtrl.MyCellValue == '0' ? 1 : -1;
            }
            break;
            }
            TimeLimitedOperationsServiceSingleton.RemoveOperation(SetStateGameQuery);
            context.gameCtrl.SetGameState(sdata);
            context.gameCtrl.FisishGame(id, winUserName);
            return(true);
        }