public void CheckWriting1Packet()
        {
            m_PacketReader.RegisterType(typeof(WrapperPacket));
            WrapperPacket writtenPacket = new WrapperPacket("Test1", 100);

            m_PacketWriter.Write(writtenPacket);
            Assert.AreEqual(108, m_MemoryStream.Position);
            m_MemoryStream.Position = 0;
            IPacket readPacket = m_PacketReader.Read();

            Assert.AreEqual(writtenPacket, readPacket);
        }
 public void WriteLoginStream(IPacketWriter writer)
 {
     writer.Write(CompletedQuests, q => writer.WriteInt32(q.quest.GetResourceId()));
     writer.Write(Quests, (index, item) => //TODO should this be QuestTimerProgress[]?
     {
         for (int i = 0; i < item.Targets.Count; i++)
         {
             writer.WriteInt32(0);
             writer.WriteInt32(0);
             writer.WriteInt32(item.Targets[i].ResourceID);
             writer.WriteInt32(targetProgress[index]);
         }
     });
 }
Exemple #3
0
        internal static void WriteUserList(IPacketWriter Writer, IEnumerable <IUser> users)
        {
            if (users.Count() > byte.MaxValue)
            {
                throw new ArgumentException("Too many users, max is " + byte.MaxValue);
            }

            List <byte[]> usersDatas = new List <byte[]>();

            foreach (var user in users)
            {
                usersDatas.Add(UserData(user));
            }

            using (var buffer = FeenPacketBuffer.Acquire())
            {
                buffer.Write(PacketID.UserList);
                buffer.WriteLength(usersDatas.Sum(m => m.Length) + 1);
                buffer.Write((byte)usersDatas.Count());
                buffer.Write(usersDatas.SelectMany(m => m).ToArray());

                if (Writer != null)
                {
                    Writer.Write(buffer);
                }
            }
        }
        public static void WriteAddonInfo(this IAuthHandler authHandler, IPacketReader inPacket, IPacketWriter outPacket, int size)
        {
            int count = 0x100; // arbitrary number

            if (Authenticator.ClientBuild >= 9464)
            {
                count = inPacket.ReadInt32(); // addon count
            }
            int i = 0;

            while (inPacket.Position < size && i < count)
            {
                string addonName   = inPacket.ReadString();
                bool   enabled     = inPacket.ReadBool();
                uint   filecrc     = inPacket.ReadUInt32();
                uint   urlcrc      = inPacket.ReadUInt32();
                bool   requireskey = filecrc != 0x1C776D01u && filecrc != 0x4C1C776Du; // offical crcs

                outPacket.WriteUInt8(2);                                               // blizzard
                outPacket.WriteBool(true);                                             // enabled
                outPacket.WriteBool(requireskey);
                if (requireskey)
                {
                    outPacket.Write(AddonPublicKey);
                }
                outPacket.WriteUInt32(0); // use addon url file
                outPacket.WriteUInt8(0);  // addon url filename, cstring

                i++;
            }

            outPacket.WriteUInt32(0); // banned addon count
        }
Exemple #5
0
        public void WriteToPacket(IPacketWriter writer)
        {
            writer.WritePoint2D(_position);
            writer.WritePoint2D(_vPosition);

            writer.WriteByte((byte)_fragments.Count);
            _fragments.ForEach(f => writer.Write(f));
        }
Exemple #6
0
        internal static void WriteMobStatsFlag(this IPacketWriter writer, IDictionary <MobStatType, IMobStat> stats)
        {
            var flag = new Flags(MobStatsFlagSize);

            stats.Keys.ForEach(t => flag.SetFlag((int)t));

            writer.Write(flag);
        }
Exemple #7
0
 public void WriteLoginStream(IPacketWriter writer) //TODO unpack db data and use that
 {
     Debug.LogWarning("TODO unpack db data and use that");
     writer.Write(SkilldeckSkills, (index, skill) =>
     {
         writer.WriteInt32(0);          //skilldeck id?
         writer.WriteInt32(skill != null ? skill.GetResourceId() : 0);
         writer.WriteByte((byte)index); //deckslot
     });
 }
Exemple #8
0
        public void WriteToPacket(IPacketWriter writer)
        {
            var history = History
                          .OfType <AbstractModifyInventoryOperation>()
                          .OrderBy(o => o.Timestamp)
                          .ToList();

            writer.WriteByte((byte)history.Count);
            history.ForEach(o => writer.Write(o));
        }
Exemple #9
0
 internal static void WritePingResp(IPacketWriter Writer, ushort timestamp)
 {
     using (var buffer = new FeenPacketBuffer(PacketID.PingResp, new byte[] { (byte)(timestamp >> 8), (byte)(timestamp) }))
     {
         if (Writer != null)
         {
             Writer.Write(buffer);
         }
     }
 }
Exemple #10
0
 internal static void WriteUserLogout(IPacketWriter Writer, IUser user)
 {
     using (var buffer = new FeenPacketBuffer(PacketID.UserLogout, UserData(user)))
     {
         if (Writer != null)
         {
             Writer.Write(buffer);
         }
     }
 }
Exemple #11
0
        internal static void WritePingReq(IPacketWriter Writer)
        {
            var timestamp = (int)Timekeeper.Elapsed.TotalMilliseconds;

            using (var buffer = new FeenPacketBuffer(PacketID.PingReq, new byte[] { (byte)(timestamp >> 8), (byte)(timestamp) }))
            {
                if (Writer != null)
                {
                    Writer.Write(buffer);
                }
            }
        }
Exemple #12
0
 public void WriteLoginStream(IPacketWriter writer)
 {
     writer.WriteFloat(mFamePoints);
     writer.WriteFloat(mPePPoints);
     writer.WriteInt32(0); //mMayChooseClass ? (bitfield):0
     writer.WriteByte(mAvailableAttributePoints);
     writer.WriteFloat(mHealth);
     writer.WriteByte(0); //Camera mode (?)
     writer.WriteInt32(mMovementSpeed);
     writer.Write(mRecord);
     writer.WriteInt32(mStateRankShift);
     writer.WriteInt32(mExtraBodyPoints);  //not sure
     writer.WriteInt32(mExtraMindPoints);  //not sure
     writer.WriteInt32(mExtraFocusPoints); //not sure
 }
Exemple #13
0
        internal static void WriteLoginRequest(IPacketWriter Writer, string username, string password)
        {
            if (username.Contains('\t') || password.Contains('\t'))
            {
                throw new ArgumentException("Username or password contains invalid character");
            }

            string textdata = string.Format("{0}\t{1}", username, password);

            byte[] data = Encoding.ASCII.GetBytes(textdata);

            using (var buffer = new FeenPacketBuffer(PacketID.LoginRequest, data))
            {
                if (Writer != null)
                {
                    Writer.Write(buffer);
                }
            }
        }
Exemple #14
0
        internal static void WriteAudioData(IPacketWriter Writer, Guid userID, Audio.Codecs.CodecID Codec, byte[] AudioData, int AudioDataLen)
        {
            using (var buffer = FeenPacketBuffer.Acquire())
            {
                buffer.Write(PacketID.Audio);
                buffer.WriteLength(AudioDataLen + (userID == Guid.Empty ? 1 : 17) + 1);
                if (userID == Guid.Empty)
                    buffer.Write(false);
                else
                {
                    buffer.Write(true);
                    buffer.Write(userID.ToByteArray());
                }
                buffer.Write(Codec);
                buffer.Write(AudioData, AudioDataLen);

                if (Writer != null)
                    Writer.Write(buffer);
            }
        }
Exemple #15
0
 public override void WriteAddStream(IPacketWriter writer)
 {
     writer.WriteInt32(CharacterStats.mRecord.MaxHealth);
     writer.WriteFloat(CharacterStats.mRecord.Physique);
     writer.WriteFloat(CharacterStats.mRecord.Morale);
     writer.WriteFloat(CharacterStats.mRecord.Concentration);
     writer.WriteInt32(NPCFameLevel);
     writer.WriteInt32(NPCPePRank);
     writer.WriteInt32(NPCType.GetResourceId());
     writer.Write(RelatedQuestsIds, writer.WriteInt32);
     writer.WriteVector3(transform.position);
     writer.WriteByte((byte)mMovementFlags);
     writer.WriteInt32(mNetFocus != null ? mNetFocus.GetRelevanceID() : -1);
     writer.WriteVector(mNetFocusLocation);
     writer.WriteRotator(mDefaultRotation);
     writer.WriteByte((byte)mCurrentState); //probably mNetState
     writer.WriteInt32(bInvulnerable ? 0 : 1);
     writer.WriteFloat(GroundSpeedModifier);
     writer.WriteInt32(mDebugFilters);
     writer.WriteInt32(Visibility);
 }
Exemple #16
0
        internal static void WriteChat(IPacketWriter Writer, IUser user, string text)
        {
            byte[] dataText = Encoding.ASCII.GetBytes(text);

            using (var buffer = FeenPacketBuffer.Acquire())
            {
                byte[] dataUser = UserData(user);
                var len = dataUser.Length + dataText.Length;

                buffer.Write(PacketID.Chat);

                buffer.WriteLength(len);

                buffer.Write(dataUser);

                buffer.Write(dataText);

                if (Writer != null)
                    Writer.Write(buffer);
            }
        }
Exemple #17
0
        internal static void WriteChat(IPacketWriter Writer, IUser user, string text)
        {
            byte[] dataText = Encoding.ASCII.GetBytes(text);

            using (var buffer = FeenPacketBuffer.Acquire())
            {
                byte[] dataUser = UserData(user);
                var    len      = dataUser.Length + dataText.Length;

                buffer.Write(PacketID.Chat);

                buffer.WriteLength(len);

                buffer.Write(dataUser);

                buffer.Write(dataText);

                if (Writer != null)
                {
                    Writer.Write(buffer);
                }
            }
        }
Exemple #18
0
        internal static void WriteLoginStatus(IPacketWriter Writer, bool isLoggedIn, string message = null)
        {
            byte[] dataText    = message == null || message.Length == 0 ? null : Encoding.ASCII.GetBytes(message);
            int    dataTextLen = dataText == null ? 0 : dataText.Length;

            using (var buffer = FeenPacketBuffer.Acquire())
            {
                buffer.Write(PacketID.LoginStatus);
                buffer.WriteLength(3 + dataTextLen);
                buffer.Write(isLoggedIn);
                buffer.Write((ushort)FeenPhone.Accounting.AccountHandler.Instance.Version);

                if (dataText != null)
                {
                    buffer.Write(dataText);
                }

                if (Writer != null)
                {
                    Writer.Write(buffer);
                }
            }
        }
Exemple #19
0
        internal static void WriteAudioData(IPacketWriter Writer, Guid userID, Audio.Codecs.CodecID Codec, byte[] AudioData, int AudioDataLen)
        {
            using (var buffer = FeenPacketBuffer.Acquire())
            {
                buffer.Write(PacketID.Audio);
                buffer.WriteLength(AudioDataLen + (userID == Guid.Empty ? 1 : 17) + 1);
                if (userID == Guid.Empty)
                {
                    buffer.Write(false);
                }
                else
                {
                    buffer.Write(true);
                    buffer.Write(userID.ToByteArray());
                }
                buffer.Write(Codec);
                buffer.Write(AudioData, AudioDataLen);

                if (Writer != null)
                {
                    Writer.Write(buffer);
                }
            }
        }
Exemple #20
0
        internal static void WriteUserList(IPacketWriter Writer, IEnumerable<IUser> users)
        {
            if (users.Count() > byte.MaxValue)
                throw new ArgumentException("Too many users, max is " + byte.MaxValue);

            List<byte[]> usersDatas = new List<byte[]>();

            foreach (var user in users)
                usersDatas.Add(UserData(user));

            using (var buffer = FeenPacketBuffer.Acquire())
            {
                buffer.Write(PacketID.UserList);
                buffer.WriteLength(usersDatas.Sum(m => m.Length) + 1);
                buffer.Write((byte)usersDatas.Count());
                buffer.Write(usersDatas.SelectMany(m => m).ToArray());

                if (Writer != null)
                    Writer.Write(buffer);
            }
        }
Exemple #21
0
        internal static void WriteLoginRequest(IPacketWriter Writer, string username, string password)
        {
            if (username.Contains('\t') || password.Contains('\t'))
                throw new ArgumentException("Username or password contains invalid character");

            string textdata = string.Format("{0}\t{1}", username, password);
            byte[] data = Encoding.ASCII.GetBytes(textdata);

            using (var buffer = new FeenPacketBuffer(PacketID.LoginRequest, data))
            {
                if (Writer != null)
                    Writer.Write(buffer);
            }
        }
Exemple #22
0
        internal static void WriteLoginStatus(IPacketWriter Writer, bool isLoggedIn, string message = null)
        {
            byte[] dataText = message == null || message.Length == 0 ? null : Encoding.ASCII.GetBytes(message);
            int dataTextLen = dataText == null ? 0 : dataText.Length;

            using (var buffer = FeenPacketBuffer.Acquire())
            {
                buffer.Write(PacketID.LoginStatus);
                buffer.WriteLength(3 + dataTextLen);
                buffer.Write(isLoggedIn);
                buffer.Write((ushort)FeenPhone.Accounting.AccountHandler.Instance.Version);

                if (dataText != null)
                    buffer.Write(dataText);

                if (Writer != null)
                    Writer.Write(buffer);
            }
        }
Exemple #23
0
 public void WriteAddStream(IPacketWriter writer)
 {
     writer.Write(mReplicatedEffects, writer.WriteInt32);
 }
Exemple #24
0
 internal static void WritePingReq(IPacketWriter Writer)
 {
     var timestamp = (int)Timekeeper.Elapsed.TotalMilliseconds;
     using (var buffer = new FeenPacketBuffer(PacketID.PingReq, new byte[] { (byte)(timestamp >> 8), (byte)(timestamp) }))
     {
         if (Writer != null)
             Writer.Write(buffer);
     }
 }
Exemple #25
0
 internal static void WritePingResp(IPacketWriter Writer, ushort timestamp)
 {
     using (var buffer = new FeenPacketBuffer(PacketID.PingResp, new byte[] { (byte)(timestamp >> 8), (byte)(timestamp) }))
     {
         if (Writer != null)
             Writer.Write(buffer);
     }
 }
Exemple #26
0
 public void WriteToPacket(IPacketWriter writer)
 {
     writer.WriteByte((byte)_history.Count);
     _history.ForEach(o => writer.Write(o));
 }
Exemple #27
0
 internal static void WriteUserLogout(IPacketWriter Writer, IUser user)
 {
     using (var buffer = new FeenPacketBuffer(PacketID.UserLogout, UserData(user)))
     {
         if (Writer != null)
             Writer.Write(buffer);
     }
 }