Example #1
0
        internal unsafe int GetByteCount(char[] chars, int index, int count, UTF8Encoder encoder) {
            if (chars == null) {
                throw new ArgumentNullException("chars", 
                    Environment.GetResourceString("ArgumentNull_Array"));
            }
            if (index < 0 || count < 0) {
                throw new ArgumentOutOfRangeException((index<0 ? "index" : "count"),
                    Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (chars.Length - index < count) {
                throw new ArgumentOutOfRangeException("chars",
                      Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
            }
            
            int retVal = -1;
            if (chars.Length == 0) {
                return 0;
            }

            fixed (char *p = chars) {
                retVal = GetByteCount(p, index, count, encoder);
            }
            BCLDebug.Assert(retVal!=-1, "[UTF8Encoding.GetByteCount]retVal!=-1");
            return retVal;
        }
Example #2
0
        private string EncodeDecode(string original)
        {
            ByteBuffer encoded = UTF8Encoder.fastestAvailableEncoder().encode(original);

            sbyte[] b = new sbyte[encoded.remaining()];
            encoded.get(b);
            return(StringHelper.NewString(b, StandardCharsets.UTF_8));
        }
Example #3
0
        private unsafe int GetBytes(char *chars, int charIndex, int charCount, byte[] bytes, int byteIndex, UTF8Encoder encoder) {
            BCLDebug.Assert(chars!=null, "[UTF8Encoding.GetBytes]chars!=null");

            int charEnd = charIndex + charCount;
            int byteStart = byteIndex;

            int surrogateChar;
            if (encoder == null || !encoder.storedSurrogate) {
                surrogateChar = -1;
            }
            else {
                surrogateChar = encoder.surrogateChar;
                encoder.storedSurrogate = false;
            }

            try {
                while (charIndex < charEnd) {
                    char ch = chars[charIndex++];
                    //
                    // In previous byte, we encounter a high surrogate, so we are expecting a low surrogate here.
                    //
                    if (surrogateChar > 0) {
                        if (StringInfo.IsLowSurrogate(ch)) {
                            // We have a complete surrogate pair.
                            surrogateChar = (surrogateChar - CharacterInfo.HIGH_SURROGATE_START) << 10;    // (ch - 0xd800) * 0x400
                            surrogateChar += (ch - CharacterInfo.LOW_SURROGATE_START);
                            surrogateChar += 0x10000;
                            bytes[byteIndex++] = (byte)(0xF0 | (surrogateChar >> 18) & 0x07);    
                            bytes[byteIndex++] = (byte)(0x80 | (surrogateChar >> 12) & 0x3F);    
                            bytes[byteIndex++] = (byte)(0x80 | (surrogateChar >> 6) & 0x3F);     
                            bytes[byteIndex++] = (byte)(0x80 | surrogateChar & 0x3F);                                      
                            surrogateChar = -1;
                        } else if (StringInfo.IsHighSurrogate(ch)) {
                            // We have two high surrogate.
                            if (isThrowException) {
                                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHighSurrogate", (charIndex - 1)), 
                                                            "chars"); 
                            }
                            // Encode the previous high-surrogate char.
                            EncodeThreeBytes(surrogateChar, bytes, ref byteIndex);
                            surrogateChar = ch;
                        } else {
                            if (isThrowException) {
                                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHighSurrogate", (charIndex - 1)), 
                                                            "chars"); 
                            }

                            // Encode the previous high-surrogate char.
                            EncodeThreeBytes(surrogateChar, bytes, ref byteIndex);
                            // Not a surrogate. Put the char back so that we can restart the encoding.
                            surrogateChar = -1;
                            charIndex--;
                        }                        
                    } else if (ch < 0x0080) {
                        bytes[byteIndex++] = (byte)ch;
                    } else if (ch < 0x0800) {
                        bytes[byteIndex++] = (byte)(0xC0 | ch >> 6 & 0x1F);
                        bytes[byteIndex++] = (byte)(0x80 | ch & 0x3F);
                    } else if (StringInfo.IsHighSurrogate(ch)) {
                        //
                        // Found the start of a surrogate.
                        //
                        surrogateChar = ch;
                    } else if (StringInfo.IsLowSurrogate(ch) && isThrowException) {
                        throw new ArgumentException( 
                            String.Format(Environment.GetResourceString("Argument_InvalidLowSurrogate"), (charIndex - 1)), "chars"); 
                    } else { //we now know that the char is >=0x0800 and isn't a high surrogate
                        bytes[byteIndex++] = (byte)(0xE0 | ch >> 12 & 0x0F);
                        bytes[byteIndex++] = (byte)(0x80 | ch >> 6 & 0x3F);
                        bytes[byteIndex++] = (byte)(0x80 | ch & 0x3F);
                    }
                }
                if (surrogateChar > 0) {
                    if (encoder != null && !encoder.mustFlush) {
                        encoder.surrogateChar = surrogateChar;
                        encoder.storedSurrogate = true;
                    }
                    else {
                        if (isThrowException) {
                            throw new ArgumentException(
                                                    String.Format(Environment.GetResourceString("Argument_InvalidHighSurrogate"), (charIndex - 1)), "chars");
                        }
                        EncodeThreeBytes(surrogateChar, bytes, ref byteIndex);
                    }
                }                
            } catch (IndexOutOfRangeException) {
                throw new ArgumentException(Environment.GetResourceString("Argument_ConversionOverflow"));
            }

            return byteIndex - byteStart;
        }
Example #4
0
        private unsafe int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex, UTF8Encoder encoder) {
            if (chars == null || bytes == null) {
                throw new ArgumentNullException((chars == null ? "chars" : "bytes"), 
                      Environment.GetResourceString("ArgumentNull_Array"));
            }        
            if (charIndex < 0 || charCount < 0) {
                throw new ArgumentOutOfRangeException((charIndex<0 ? "charIndex" : "charCount"), 
                      Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (chars.Length - charIndex < charCount) {
                throw new ArgumentOutOfRangeException("chars",
                      Environment.GetResourceString("ArgumentOutOfRange_IndexCountBuffer"));
            }
            if (byteIndex < 0 || byteIndex > bytes.Length) {
                throw new ArgumentOutOfRangeException("byteIndex",
                     Environment.GetResourceString("ArgumentOutOfRange_Index"));
            }

            int retVal = -1;
            if (chars.Length==0) {
                return 0;
            }
            fixed (char *p = chars) {
                retVal = GetBytes(p, charIndex, charCount, bytes, byteIndex, encoder);
            }
            BCLDebug.Assert(retVal!=-1, "[UTF8Encoding.GetByteCount]retVal!=-1");
            return retVal;
        }
Example #5
0
        internal unsafe int GetByteCount(char *chars, int index, int count, UTF8Encoder encoder) {

            BCLDebug.Assert(chars!=null, "[UTF8Encoding.GetByteCount]chars!=null");

            int end = index + count;
            int byteCount = 0;
    
            bool inSurrogate;

            if (encoder == null || !encoder.storedSurrogate) {
                inSurrogate = false;
            }
            else {
                inSurrogate = true;
            }
    
            while (index < end && byteCount >= 0) {
                char ch = chars[index++];

                if (inSurrogate) {
                    //
                    // In previous char, we encounter a high surrogate, so we are expecting a low surrogate here.
                    //
                    if (StringInfo.IsLowSurrogate(ch)) {
                        inSurrogate = false;
                        //
                        // One surrogate pair will be translated into 4 bytes UTF8.
                        //
                        byteCount += 4;
                    } 
                    else if (StringInfo.IsHighSurrogate(ch)) {
                        // We have two high surrogates.
                        if (isThrowException) {
                            throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHighSurrogate", (index - 1)), 
                                                        "chars");                                                        
                        }
                        // Encode the previous high-surrogate char.
                        byteCount += 3;
                        // The isSurrogate is still true, because this could be the start of another valid surrogate pair.
                    } else {
                        if (isThrowException) {
                            throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHighSurrogate", (index - 1)), 
                                                        "chars");                                                        
                        }
                        // Encode the previous high-surrogate char.
                        byteCount += 3;
                        // Not a surrogate. Put the char back so that we can restart the encoding.
                        inSurrogate = false;
                        index--;
                    }
                } else if (ch < 0x0080)
                    byteCount++;
                else if (ch < 0x0800) {
                    byteCount += 2;
                } else {
                    if (StringInfo.IsHighSurrogate(ch)) {
                        //
                        // Found the start of a surrogate.
                        //
                        inSurrogate = true;
                    }
                    else if (StringInfo.IsLowSurrogate(ch) && isThrowException) {
                        //
                        // Found a low surrogate without encountering a high surrogate first.
                        //
                        throw new ArgumentException( 
                                                    String.Format(Environment.GetResourceString("Argument_InvalidLowSurrogate"), (index - 1)), "chars");
                    }
                    else {
                        byteCount += 3;
                    }
                }
            }

            // Check for overflows.
            if (byteCount < 0)
                throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_GetByteCountOverflow"));

            if (inSurrogate) {
                if (encoder == null || encoder.mustFlush) {
                    if (isThrowException) {
                        throw new ArgumentException( 
                            String.Format(Environment.GetResourceString("Argument_InvalidHighSurrogate"), (index - 1)), "chars");
                    }
                    byteCount += 3;
                }
            }
            return byteCount;
        }
Example #6
0
    IEnumerator _onFinishGame(ResponseFinishGame responseData)
    {
        UnMarkPot();
        PokerObserver.Game.IsClientListening       = false;
        PokerObserver.Instance.isWaitingFinishGame = true;

        float totalTimeFinishGame    = responseData.time / 1000f;
        float waitTimeViewResultCard = totalTimeFinishGame > 2f ? 1f : 0f;
        float timeEffectPot          = totalTimeFinishGame - waitTimeViewResultCard;

        if (responseData.pots.Length > 0)
        {
            timeEffectPot /= responseData.pots.Length;
        }

        bool isFaceUp = PokerObserver.Game.GetTotalPlayerNotFold > 1;

        if (isFaceUp)
        {
            if (responseData.dealComminityCards.Length == 5)
            {
                int[] threeCard = new int[3];
                Array.Copy(responseData.dealComminityCards, 0, threeCard, 0, 3);
                CreateCardDeal(threeCard);
                yield return(new WaitForSeconds(1.0f));

                int[] cardFouth = new int[1];
                Array.Copy(responseData.dealComminityCards, 3, cardFouth, 0, 1);
                CreateCardDeal(cardFouth);
                yield return(new WaitForSeconds(1.0f));

                int[] cardFive = new int[1];
                Array.Copy(responseData.dealComminityCards, 4, cardFive, 0, 1);
                CreateCardDeal(cardFive);
            }
            else
            {
                CreateCardDeal(responseData.dealComminityCards);
            }
        }

        #region SET RESULT TITLE
        PokerPlayerUI[] playerUI = GameObject.FindObjectsOfType <PokerPlayerUI>();
        for (int i = 0; i < playerUI.Length; i++)
        {
            for (int j = 0; j < responseData.players.Length; j++)
            {
                if (playerUI[i].UserName == responseData.players[j].userName)
                {
                    playerUI[i].SetTitle(isFaceUp ? UTF8Encoder.DecodeEncodedNonAsciiCharacters(responseData.players[j].ranking) : null);
                }
            }
        }

        #endregion

        yield return(new WaitForSeconds(waitTimeViewResultCard * 3 / 4f));

        #region UPDATE CARD PER POTS SUMMARY
        foreach (ResponseResultSummary summary in responseData.pots)
        {
            ResponseMoneyExchange playerWin = Array.Find <ResponseMoneyExchange>(summary.players, p => p.winner);
            List <string>         lstWinner = new List <string>();
            foreach (ResponseMoneyExchange item in summary.players)
            {
                if (item.winner)
                {
                    lstWinner.Add(item.userName);

                    if (PokerObserver.Game.IsMainPlayer(item.userName))
                    {
                        PuSound.Instance.Play(SoundType.PlayerWin);
                        string rankWin = Array.Find <ResponseFinishCardPlayer>(responseData.players, rdp => rdp.userName == item.userName).ranking;

                        if (!string.IsNullOrEmpty(PokerObserver.Game.mUserInfo.info.facebookId))
                        {
                            StartCoroutine(gpView.ShowBtnShareFacebook(UTF8Encoder.DecodeEncodedNonAsciiCharacters(rankWin), 3f));
                        }
                    }
                }
            }

            if (potContainer != null && playerWin != null)
            {
                string           rankWin       = Array.Find <ResponseFinishCardPlayer>(responseData.players, rdp => rdp.userName == playerWin.userName).ranking;
                RankEndGameModel playerWinRank = new RankEndGameModel(UTF8Encoder.DecodeEncodedNonAsciiCharacters(rankWin));

                if (lstWinner.Count > 0)
                {
                    for (int i = 0; i < lstWinner.Count(); i++)
                    {
                        if (GetPlayerUI(lstWinner[i]) != null)
                        {
                            GetPlayerUI(lstWinner[i]).SetResult(true);
                        }
                    }
                }

                potContainer.SummaryPot(summary, timeEffectPot);

                if (isFaceUp)
                {
                    List <GameObject> listHightlight = new List <GameObject>();
                    List <GameObject> listMask       = new List <GameObject>();
                    List <int>        list           = new List <int>();

                    if (playerWinRank != null)
                    {
                        DialogService.Instance.ShowDialog(playerWinRank);
                    }
                    else
                    {
                        Logger.LogError("Can't found player Win");
                    }

                    foreach (ResponseMoneyExchange item in summary.players)
                    {
                        if (item.winner)
                        {
                            list.AddRange(item.cards);
                            listHightlight.AddRange(cardsDeal.FindAll(o => list.Contains(o.GetComponent <PokerCardObject>().card.cardId)));
                        }
                    }

                    listMask = cardsDeal.FindAll(o => listHightlight.Contains(o) == false);
                    foreach (GameObject card in listMask)
                    {
                        card.GetComponent <PokerCardObject>().SetMask(true);
                    }

                    for (int i = 0; i < 20; i++)
                    {
                        listHightlight.ForEach(o => o.GetComponent <PokerCardObject>().SetHighlight(i % 2 == 0));
                        yield return(new WaitForSeconds(timeEffectPot / 20f));
                    }
                    listHightlight.ForEach(o => o.GetComponent <PokerCardObject>().SetHighlight(false));
                    listMask.ForEach(o => o.GetComponent <PokerCardObject>().SetMask(false));
                    playerWinRank.DestroyUI();
                    yield return(new WaitForEndOfFrame());
                }
                else
                {
                    yield return(new WaitForSeconds(timeEffectPot));
                }

                if (lstWinner.Count > 0)
                {
                    for (int i = 0; i < lstWinner.Count(); i++)
                    {
                        if (GetPlayerUI(lstWinner[i]) != null)
                        {
                            GetPlayerUI(lstWinner[i]).SetResult(false);
                        }
                    }
                }
            }
        }
        #endregion
        yield return(new WaitForSeconds(waitTimeViewResultCard / 4f));

        // Reset Result title
        if (isFaceUp)
        {
            Array.ForEach <PokerPlayerUI>(playerUI, p => { if (p != null)
                                                           {
                                                               p.SetTitle(null);
                                                           }
                                          });
        }

        Array.ForEach <PokerPlayerUI>(playerUI, p => p.ResetDataOnFinishGame());

        #region Handle Disconnect and Reconnect
        foreach (PokerPlayerUI p in listPlayerQuit)
        {
            dictPlayerObject.Remove(p.UserName);
            GameObject.Destroy(p.gameObject);
        }
        listPlayerQuit.Clear();
        foreach (string key in dictReJoinGame.Keys)
        {
            dictPlayerObject.Add(key, dictReJoinGame[key]);
        }
        dictReJoinGame.Clear();
        #endregion

        ResetNewRound();
        PokerObserver.Instance.isWaitingFinishGame = false;
        PokerObserver.Game.EndFinishGame();
        PokerObserver.Game.IsClientListening = true;
    }