예제 #1
0
 /// <summary>
 /// Writes the <see cref="NpcElixirSlot"/> to the specified <see cref="MessageWriter"/>.
 /// </summary>
 /// <param name="writer">
 /// <see cref="MessageWriter"/> that will be used to write the <see cref="NpcElixirSlot"/>.
 /// </param>
 public override void WriteSlot(MessageWriter writer)
 {
     writer.Write(ID);
     writer.Write(Elixir);
 }
예제 #2
0
 /// <summary>
 /// Writes the <see cref="UnitUpgradeSlot"/> to the specified <see cref="MessageWriter"/>.
 /// </summary>
 /// <param name="writer">
 /// <see cref="MessageWriter"/> that will be used to write the <see cref="UnitUpgradeSlot"/>.
 /// </param>
 public override void WriteSlot(MessageWriter writer)
 {
     writer.Write(ID);
     writer.Write(Level);
 }
예제 #3
0
 /// <summary>
 /// Writes the <see cref="AchievementProgessSlot"/> to the specified <see cref="MessageWriter"/>.
 /// </summary>
 /// <param name="writer">
 /// <see cref="MessageWriter"/> that will be used to write the <see cref="AchievementProgessSlot"/>.
 /// </param>
 public override void WriteSlot(MessageWriter writer)
 {
     writer.Write(ID);
     writer.Write(Progress);
 }
예제 #4
0
 /// <summary>
 /// Writes the <see cref="HeroUpgradeSlot"/> to the specified <see cref="MessageWriter"/>.
 /// </summary>
 /// <param name="writer">
 /// <see cref="MessageWriter"/> that will be used to write the <see cref="HeroUpgradeSlot"/>.
 /// </param>
 public override void WriteSlot(MessageWriter writer)
 {
     writer.Write(ID);
     writer.Write(Health);
 }
예제 #5
0
 /// <summary>
 /// Writes the <see cref="HeroStateSlot"/> to the specified <see cref="MessageWriter"/>.
 /// </summary>
 /// <param name="writer">
 /// <see cref="MessageWriter"/> that will be used to write the <see cref="HeroStateSlot"/>.
 /// </param>
 public override void WriteSlot(MessageWriter writer)
 {
     writer.Write(ID);
     writer.Write(State);
 }
예제 #6
0
        /// <summary>
        /// Writes the <see cref="AvatarData"/> to the specified <see cref="MessageWriter"/>.
        /// </summary>
        /// <param name="writer">
        /// <see cref="MessageWriter"/> that will be used to write the <see cref="AvatarData"/>.
        /// </param>
        public void Write(MessageWriter writer)
        {
            if (OwnVillageData == null)
                throw new NullReferenceException("OwnAvatarData was null.");

            OwnVillageData.Write(writer);

            writer.Write(UserID);
            writer.Write(UserID2);
            writer.Write(OwnClanData != null);
            if (OwnClanData != null)
            {
                writer.Write(OwnClanData.ID);
                writer.Write(OwnClanData.Name);
                writer.Write(OwnClanData.Badge);
                writer.Write(OwnClanData.Role);
                writer.Write(OwnClanData.Level);
                writer.Write(OwnClanData.Unknown1);
            }
            writer.Write(Unknown1);

            writer.Write(Unknown2);
            writer.Write(Unknown3);
            writer.Write(Unknown4);
            writer.Write(Unknown5);
            writer.Write(Unknown6);
            writer.Write(Unknown7);
            writer.Write(Unknown8);
            writer.Write(Unknown9);
            writer.Write(Unknown10);
            writer.Write(Unknown11);

            writer.Write(League);
            writer.Write(AllianceCastleLevel);
            writer.Write(AllianceCastleTotalCapacity);
            writer.Write(AllianceCastleUsedCapacity);
            writer.Write(TownHallLevel);
            writer.Write(Name);

            writer.Write(Unknown12);

            writer.Write(Level);
            writer.Write(Experience);
            writer.Write(Gems);
            writer.Write(FreeGems);

            writer.Write(Unknown13);
            writer.Write(Unknown14);

            writer.Write(Trophies);

            writer.Write(AttacksWon);
            writer.Write(AttacksLost);
            writer.Write(DefensesWon);
            writer.Write(DefensesLost);

            writer.Write(Unknown19);
            writer.Write(Unknown20);
            writer.Write(Unknown21);

            writer.Write(Unknown22); // if Unknown22 then read Unknown23?
            writer.Write(Unknown23);

            writer.Write(IsNamed);

            writer.Write(Unknown24);
            writer.Write(Unknown25);
            writer.Write(Unknown26);
            writer.Write(Unknown27);

            Slot.WriteSlotArray(writer, ResourcesCapacity);
            Slot.WriteSlotArray(writer, ResourcesAmount);
            Slot.WriteSlotArray(writer, Units);
            Slot.WriteSlotArray(writer, Spells);
            Slot.WriteSlotArray(writer, UnitUpgrades);
            Slot.WriteSlotArray(writer, SpellUpgrades);
            Slot.WriteSlotArray(writer, HeroUpgrades);
            Slot.WriteSlotArray(writer, HeroHealths);
            Slot.WriteSlotArray(writer, HeroStates);
            Slot.WriteSlotArray(writer, TutorialProgess);
            Slot.WriteSlotArray(writer, Acheivements);
            Slot.WriteSlotArray(writer, AcheivementProgress);
            Slot.WriteSlotArray(writer, NpcStars);
            Slot.WriteSlotArray(writer, NpcGold);
            Slot.WriteSlotArray(writer, NpcElixir);

            writer.Write(Unknown28);
        }
예제 #7
0
 /// <summary>
 /// Writes the <see cref="ResourceCapacitySlot"/> to the specified <see cref="MessageWriter"/>.
 /// </summary>
 /// <param name="writer">
 /// <see cref="MessageWriter"/> that will be used to write the <see cref="ResourceCapacitySlot"/>.
 /// </param>
 public override void WriteSlot(MessageWriter writer)
 {
     writer.Write(ID);
     writer.Write(Capacity);
 }
예제 #8
0
 /// <summary>
 /// Writes the <see cref="UnitSlot"/> to the specified <see cref="MessageWriter"/>.
 /// </summary>
 /// <param name="writer">
 /// <see cref="MessageWriter"/> that will be used to write the <see cref="UnitSlot"/>.
 /// </param>
 public override void WriteSlot(MessageWriter writer)
 {
     writer.Write(ID);
     writer.Write(Amount);
 }
예제 #9
0
        /// <summary>
        /// Writes the <see cref="VillageData"/> to the specified <see cref="MessageWriter"/>.
        /// </summary>
        /// <param name="writer">
        /// <see cref="MessageWriter"/> that will be used to write the <see cref="VillageData"/>.
        /// </param>
        /// <exception cref="NotImplementedException">Compressed set to false.</exception>
        public void Write(MessageWriter writer)
        {
            if (!Compressed) // quit early just not to mess up the stream
                throw new NotImplementedException("Uncompressed Village definition is not implemented.");

            writer.Write(Unknown1); // 0
            writer.Write(UserID);
            writer.Write((int)ShieldDuration.TotalSeconds);
            writer.Write(Unknown2); // 1200
            writer.Write(Unknown3); // 60
            writer.Write(Compressed);

            using (var bw = new BinaryWriter(new MemoryStream()))
            {
                var homeJson = Home.ToJson();
                var comHomeJson = ZlibStream.CompressString(homeJson);

                bw.Write(homeJson.Length);
                bw.Write(comHomeJson);
                writer.Write(((MemoryStream)bw.BaseStream).ToArray(), true);
            }

            writer.Write(Unknown4);
        }
예제 #10
0
        public Crypto8 Crypto { get; set; } //TODO: Get only.

        /// <summary>
        /// Sends the specified message using the <see cref="Connection"/> socket.
        /// </summary>
        /// <param name="message"><see cref="Message"/> to send.</param>
        /// <exception cref="ArgumentNullException"><paramref name="message"/> is null.</exception>
        /// <exception cref="InvalidMessageException"><paramref name="message"/> length greater than <see cref="Message.MaxSize"/>.</exception>
        public void SendMessage(Message message)
        {
            //TODO: Custom write for LoginRequestMessage.
            if (message == null)
                throw new ArgumentNullException("message");

            using (var deMessageWriter = new MessageWriter(new MemoryStream()))
            {
                message.WriteMessage(deMessageWriter);
                var body = ((MemoryStream)deMessageWriter.BaseStream).ToArray();
                Crypto.Encrypt(ref body);

                if (body.Length > Message.MaxSize)
                    throw new InvalidMessageException("Length of message is greater than Message.MaxSize.");

                using (var enMessageWriter = new MessageWriter(new MemoryStream()))
                {
                    var len = BitConverter.GetBytes(body.Length);
                    if (BitConverter.IsLittleEndian)
                        Array.Reverse(len);

                    enMessageWriter.Write(message.ID);
                    enMessageWriter.Write(len, 1, 3); // message len
                    enMessageWriter.Write(message.Version);
                    enMessageWriter.Write(body); // encrypted body

                    var messageData = ((MemoryStream)enMessageWriter.BaseStream).ToArray();
                    var args = _sendPool.Pop();
                    var token = args.UserToken as MessageSendToken;
                    token.ID = message.ID;
                    token.Length = body.Length;
                    token.Version = message.Version;
                    token.Body = messageData;

                    StartSend(args);
                }
            }
        }