Exemplo n.º 1
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);
                }
            }
        }
Exemplo n.º 2
0
 internal static void WriteUserLogout(IPacketWriter Writer, IUser user)
 {
     using (var buffer = new FeenPacketBuffer(PacketID.UserLogout, UserData(user)))
     {
         if (Writer != null)
         {
             Writer.Write(buffer);
         }
     }
 }
Exemplo n.º 3
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);
         }
     }
 }
Exemplo n.º 4
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);
                }
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
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);
                }
            }
        }
Exemplo n.º 7
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);
                }
            }
        }
Exemplo n.º 8
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);
                }
            }
        }
Exemplo n.º 9
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);
                }
            }
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 11
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);
     }
 }
Exemplo n.º 12
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);
     }
 }