Ejemplo n.º 1
0
        private void UIActionGameFinishedEvent(Builders.GameFinished value)
        {
            if (UIDatas.HasIndex)
            {
                List <int> cardsToSave = new List <int>();
                foreach (var item in UIDatas.Deck)
                {
                    for (int i = 0; i < item.CardCount; i++)
                    {
                        cardsToSave.Add(item.Card.Id);
                    }
                }

                if (!Connector.SaveMatchResult(UIDatas.OpponentClasse, cardsToSave, UIDatas.OpponentPseudo, UIDatas.OwnClasse, value.WinnerPlayer == UIDatas.MyIndex ? 1 : 0, UIDatas.CurrentTurn, (int)UIDatas.GameType, DateTime.Now))
                {
                    MessageBox.Show("Erreur lors de la sauvegarde des données.");
                }
            }

            UIDatas.MyIndex  = 0;
            UIDatas.HasIndex = false;

            toggleDeckButton.Dispatcher.Invoke(new HideGrid1(this.UpdateGrid1), new object[] { false });

            UIDatas.OpponentPlayedCards.Clear();
            UIDatas.ClearDeck();
            UIDatas.NotifyPropertyChanged("Deck");

            UIDatas.OpponentPseudo    = UIDatas.OwnPseudo;
            UIDatas.OpponentVictories = UIDatas.OwnVictories;
            UIDatas.OpponentDefeats   = UIDatas.OwnDefeats;
            UIDatas.OpponentLevel     = UIDatas.OwnLevel;

            UIDatas.CurrentTurn    = 0;
            UIDatas.OpponentFleaux = 0;
        }
Ejemplo n.º 2
0
        private void Krosmaga(int ID, byte[] data)
        {
            //bool passTest = false;
            Stream f = new MemoryStream(data);

            b = new BinaryReader(f);

            /*b.ReadBytes(2);
             *
             * var d = b.ReadBytes(2);
             * string txt = "";
             * foreach (var item in d)
             * {
             *  txt += item.ToString("X");
             * }
             * int sizeofmessage = int.Parse(txt, System.Globalization.NumberStyles.HexNumber);
             *
             * if (messageToBeCompleted && sizeofmessage > 41)
             * {
             *  if(expectedSizeToComplete > (actualSizeToComplete + sizeofmessage - 40))
             *  {
             *      messageToBeCompleted = true;
             *      Buffer.BlockCopy(data, 40, bytesToComplete, actualSizeToComplete, sizeofmessage-40);
             *      actualSizeToComplete += (sizeofmessage - 40);
             *      return;
             *  }
             *  else
             *  {
             *      Buffer.BlockCopy(data, 40, bytesToComplete, actualSizeToComplete, sizeofmessage - 40);
             *
             *      messageToBeCompleted = false;
             *      expectedSizeToComplete = 0;
             *      actualSizeToComplete = 0;
             *
             *      f = new MemoryStream(bytesToComplete);
             *      b = new BinaryReader(f);
             *      passTest = true;
             *  }
             * }*/

            if (b.BaseStream.Length >= 41)
            {
                b.BaseStream.Position = 40;
            }

            b.ReadBytes(3);
            while (b.BaseStream.Position < b.BaseStream.Length && b.ReadByte() != 0)
            {
                b.ReadBytes(3);
                string messageId = ConcatHeader();
                b.ReadByte();
                uint   size = ReadRawVarint32();
                byte[] send;

                /*if(!passTest && size > sizeofmessage)
                 * {
                 *  messageToBeCompleted = true;
                 *  bytesToComplete = new byte[4096];
                 *  expectedSizeToComplete = (int)size + (int)b.BaseStream.Position;
                 *  Buffer.BlockCopy(data, 0, bytesToComplete, actualSizeToComplete, sizeofmessage);
                 *  actualSizeToComplete += sizeofmessage;
                 *  return;
                 * }*/

                switch (messageId)
                {
                //case "104BE831BFC1F6EB11C8B453B7F257C499": // LeaderboardPersonnalEntryEvent
                case "A743D4E99C61572311D93D8A99B0D00AB9":     // StartOfTurnEvent
                    Builders.StartOfTurn startofturn = new Builders.StartOfTurn();
                    send = b.ReadBytes((int)size);
                    startofturn.Decode(send);
                    UIActionStartOfTurn(startofturn);
                    break;

                case "89438706FC2AE2CD11B3891BE848AD7887":     // GameStartedEvent
                    Builders.GameStarted gamestarted = new Builders.GameStarted();
                    send = b.ReadBytes((int)size);
                    gamestarted.Decode(send);
                    UIActionGameEventStarted(gamestarted);
                    break;

                case "1B4FF61A6FBC09E611F2CBA7E5FB5391BA":     // GameFinishedEvent
                    Builders.GameFinished gamefinished = new Builders.GameFinished();
                    send = b.ReadBytes((int)size);
                    gamefinished.Decode(send);
                    UIActionGameFinishedEvent(gamefinished);
                    break;

                case "98400741B1CB5A4A110FC4D2D51E2D4CA9":     // GameEventsEvent
                    Builders.GameEvents gameevents = new Builders.GameEvents();
                    send = b.ReadBytes((int)size);
                    gameevents.Decode(send);
                    UIActionGameEventsEvent(gameevents);
                    break;

                case "24454BD9B42E0A231174846DD1A86A7ABB":     // PlayerAccountLoadedEvent
                    Builders.PlayerAccountLoaded playerAccountLoaded = new Builders.PlayerAccountLoaded();
                    send = b.ReadBytes((int)size);
                    playerAccountLoaded.Decode(send);
                    break;

                /*case "F64A6D942BA9B2A01139131B120F0A6494":
                 *  test = true;
                 *  break;*/
                default:
                    if (b.BaseStream.Position + size > b.BaseStream.Length)
                    {
                        size = (uint)b.BaseStream.Length - (uint)b.BaseStream.Position - 5;
                    }
                    if (size != 0)
                    {
                        b.ReadBytes((int)size);
                    }
                    break;
                }
                b.ReadBytes(3);
            }
        }