Пример #1
0
        public void BinarySendTask( )
        {
            byte sequence = 0;

            while (IsRunning)
            {
                if (SendQueue.TryDequeue(out SendDatagram datagram))
                {
                    byte [] data = datagram.ToBinary( );

                    UnderlyingStream.WriteByte(DatagramHeader);
                    UnderlyingStream.WriteByte(sequence);
                    UnderlyingStream.WriteByte(( byte )datagram.Type.BinaryType);
                    UnderlyingStream.WriteByte(data.CaluCrc8( ));
                    UnderlyingStream.WriteByte(Convert.ToByte(data.Length));
                    UnderlyingStream.Write(data, 0, data.Length);

                    sequence++;
                }
                else
                {
                    Thread.Sleep(20);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Writes a 2-byte unsigned integer value to the underlying stream.
        /// </summary>
        public void Write(ushort value)
        {
            m_Buffer[0] = (byte)(value >> 8);
            m_Buffer[1] = (byte)value;

            UnderlyingStream.Write(m_Buffer, 0, 2);
        }
Пример #3
0
        public BulletinBoardSendPostSummaryPacket(BulletinBoard Board, BulletinBoardPost Post)
            : base(0x71)
        {
            // Set the maximum size
            EnsureCapacity(1024);

            // Fill the packet data
            UnderlyingStream.Write((byte)BulletinPacket.PacketSubType.SendPostSummary);
            int BoardSerial = Board.Serial;

            if ((Post.RootParent != null) && (Post.RootParent is BulletinBoard))
            {
                BoardSerial = (((Item)(Post.RootParent)).Serial);
            }
            UnderlyingStream.Write((int)BoardSerial); // Bulletin Board Serial
            UnderlyingStream.Write((int)Post.Serial); // Post Serial
            int ParentSerial = Board.Serial;

            if ((Post.Parent != null) && ((Post.Parent is BulletinBoard) || (Post.Parent is BulletinBoardPost)))
            {
                ParentSerial = (((Item)(Post.Parent)).Serial);
            }
            UnderlyingStream.Write((int)(ParentSerial == BoardSerial ? 0 : ParentSerial)); // Parent Serial (if it is a reply)
            UnderlyingStream.Write((byte)(Post.Author.Length + 1));
            UnderlyingStream.WriteAsciiNull(Post.Author);
            UnderlyingStream.Write((byte)(Post.Subject.Length + 1));
            UnderlyingStream.WriteAsciiNull(Post.Subject);
            UnderlyingStream.Write((byte)(Post.Date.Length + 1));
            UnderlyingStream.WriteAsciiNull(Post.Date);

            // Log the raw packet info
            BulletinPacket.LogPacket("BulletinBoardSendPostSummaryPacket", UnderlyingStream.ToArray());
        }
Пример #4
0
        /// <summary>
        /// Writes a 4-byte unsigned integer value to the underlying stream.
        /// </summary>
        public void Write(uint value)
        {
            m_Buffer[0] = (byte)(value >> 24);
            m_Buffer[1] = (byte)(value >> 16);
            m_Buffer[2] = (byte)(value >> 8);
            m_Buffer[3] = (byte)value;

            UnderlyingStream.Write(m_Buffer, 0, 4);
        }
Пример #5
0
        ///<inheritdoc />
        public override void Write(byte[] buffer, int offset, int count)
        {
            ThrowIfDisposed();
            if (_memoryStatus == MemoryFlag.AutoOverFlowToDisk && _isInMemory && count + UnderlyingStream.Position > _threshholdSize)
            {
                OverflowToPersistentStream();
            }

            UnderlyingStream.Write(buffer, offset, count);
        }
Пример #6
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (Position >= Length || Length - Position < count)
            {
                throw new IOException("Attempt to write beyond the slice");
            }

            UnderlyingStream.Position = Position + Start;
            UnderlyingStream.Write(buffer, offset, count);
        }
Пример #7
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            long remaining     = Length - (UnderlyingStream.Position - PartialStart);
            int  actuallyWrite = (int)Math.Min(remaining, count);

            if (actuallyWrite < 0)
            {
                return;
            }

            UnderlyingStream.Write(buffer, offset, actuallyWrite);
        }
Пример #8
0
 /// <summary>
 /// Writes a number of 0x00 byte values to the underlying stream.
 /// </summary>
 public void Fill(int length)
 {
     if (UnderlyingStream.Position == UnderlyingStream.Length)
     {
         UnderlyingStream.SetLength(UnderlyingStream.Length + length);
         UnderlyingStream.Seek(0, SeekOrigin.End);
     }
     else
     {
         UnderlyingStream.Write(new byte[length], 0, length);
     }
 }
Пример #9
0
        public BulletinBoardOpenPacket(BulletinBoard Board)
            : base(0x71)
        {
            // Don't need much room here (just enough to take into account a
            // non-default bulletin board name)
            EnsureCapacity(256);

            // Get the name of the bulletin board
            string BoardName = Board.Name == null ? "Bulletin Board" : Board.Name;

            // Fill the packet data
            UnderlyingStream.Write((byte)BulletinPacket.PacketSubType.DisplayBoard);
            UnderlyingStream.Write((int)Board.Serial);
            UnderlyingStream.WriteAsciiNull(BoardName);

            // Log the raw packet info
            BulletinPacket.LogPacket("BulletinBoardOpenPacket", UnderlyingStream.ToArray());
        }
Пример #10
0
 public override void Write(byte[] buffer, int offset, int count)
 {
     if (Direction == Direction.Read)
     {
         throw new InvalidOperationException("Incorrect direction");
     }
     byte[] underlying = new byte[count];
     for (int i = 0; i < count; i++)
     {
         if (Mode == EncryptionMode.Encrypt)
         {
             underlying[i] = encryptByte(buffer[i + offset]);
         }
         else
         {
             underlying[i] = decryptByte(buffer[i + offset]);
         }
     }
     UnderlyingStream.Write(underlying, 0, count);
 }
Пример #11
0
        public override void Write(byte[] buffer,
                                   int offset,
                                   int count)
        {
            var context  = Static <HttpContextBase> .Instance ?? new HttpContextWrapper(HttpContext.Current);
            var response = context.Response;
            var prefixes = new[]
            {
                "text/html", "application/xhtml+xml", "application/atom+xml", "application/rdf+xml"
            };

#if NET20
            if (StringExtensionMethods.StartsWithAny(response.ContentType, StringComparison.OrdinalIgnoreCase, prefixes))
#else
            if (response.ContentType.StartsWithAny(StringComparison.OrdinalIgnoreCase, prefixes))
#endif
            {
                buffer = response
                         .ContentEncoding
                         .GetBytes(_htmlWhitespace.Replace(response.ContentEncoding.GetString(buffer), string.Empty));
            }

            UnderlyingStream.Write(buffer, offset, buffer.Length);

            if (0 == offset)
            {
                Bytes.AddRange(buffer);
                return;
            }

            if (Bytes.Count == offset)
            {
                Bytes.AddRange(buffer);
                return;
            }

            for (var i = 0; i < buffer.Length; i++)
            {
                Bytes[offset + i] = buffer[i];
            }
        }
Пример #12
0
        public AddPostReplyItemPacket(BulletinBoardPost Post)
            : base(0x25, 21)
        {
            // Add the post to the bulletin board
            UnderlyingStream.Write((int)Post.Serial);
            UnderlyingStream.Write((byte)0x0e);                              // Model High
            UnderlyingStream.Write((byte)0xb0);                              // Model Low
            UnderlyingStream.Write((byte)0x00);                              // Unknown
            UnderlyingStream.Write((byte)0x00);                              // Item Count High
            UnderlyingStream.Write((byte)0x00);                              // Item Count Low
            UnderlyingStream.Write((byte)0x00);                              // X Location High
            UnderlyingStream.Write((byte)0x00);                              // X Location Low
            UnderlyingStream.Write((byte)0x00);                              // Y Location High
            UnderlyingStream.Write((byte)0x00);                              // Y Location Low
            UnderlyingStream.Write((byte)0x00);
            UnderlyingStream.Write((int)(((Item)(Post.RootParent)).Serial)); // Parent item serial number
            UnderlyingStream.Write((byte)0x00);                              // Colour High
            UnderlyingStream.Write((byte)0x00);                              // Colour Low

            BulletinPacket.LogPacket("AddPostReplyItemPacket", UnderlyingStream.ToArray());
        }
Пример #13
0
 /// <summary>
 /// Writes a sequence of bytes to the underlying stream
 /// </summary>
 public void Write(byte[] buffer, int offset, int size)
 {
     UnderlyingStream.Write(buffer, offset, size);
 }
Пример #14
0
        public BulletinBoardPostPacket(BulletinBoardPost Post)
            : base(0x71)
        {
            // Set the maximum size
            EnsureCapacity(65535);

            // Fill the packet data
            UnderlyingStream.Write((byte)BulletinPacket.PacketSubType.SendPostMessage);
            int BoardSerial = 0;

            if ((Post.RootParent != null) && (Post.RootParent is BulletinBoard))
            {
                BoardSerial = (((Item)(Post.RootParent)).Serial);
            }
            UnderlyingStream.Write((int)BoardSerial); // Bulletin Board Serial
            UnderlyingStream.Write((int)Post.Serial); // Post Serial
            UnderlyingStream.Write((byte)(Post.Author.Length + 1));
            UnderlyingStream.WriteAsciiNull(Post.Author);
            UnderlyingStream.Write((byte)(Post.Subject.Length + 1));
            UnderlyingStream.WriteAsciiNull(Post.Subject);
            UnderlyingStream.Write((byte)(Post.Date.Length + 1));
            UnderlyingStream.WriteAsciiNull(Post.Date);

            #region Unknown Constant
            // Some constant that is needed (DON'T Change Anything in here unless
            // you've figured out what the contents of the packet do)
            //"\x01\x90\x83\xea\x06\x15\x2e\x07\x1d\x17\x0f\x07\x37\x1f\x7b
            // \x05\xeb\x20\x3d\x04\x66\x20\x4d\x04\x66\x0e\x75\x00\x00"
            UnderlyingStream.Write((byte)0x01);
            UnderlyingStream.Write((byte)0x90);
            UnderlyingStream.Write((byte)0x83);
            UnderlyingStream.Write((byte)0xEA);
            UnderlyingStream.Write((byte)0x06);
            UnderlyingStream.Write((byte)0x15);
            UnderlyingStream.Write((byte)0x2E);
            UnderlyingStream.Write((byte)0x07);
            UnderlyingStream.Write((byte)0x1D);
            UnderlyingStream.Write((byte)0x17);
            UnderlyingStream.Write((byte)0x0F);
            UnderlyingStream.Write((byte)0x07);
            UnderlyingStream.Write((byte)0x37);
            UnderlyingStream.Write((byte)0x1F);
            UnderlyingStream.Write((byte)0x7B);
            UnderlyingStream.Write((byte)0x05);
            UnderlyingStream.Write((byte)0xEB);
            UnderlyingStream.Write((byte)0x20);
            UnderlyingStream.Write((byte)0x3D);
            UnderlyingStream.Write((byte)0x04);
            UnderlyingStream.Write((byte)0x66);
            UnderlyingStream.Write((byte)0x20);
            UnderlyingStream.Write((byte)0x4D);
            UnderlyingStream.Write((byte)0x04);
            UnderlyingStream.Write((byte)0x66);
            UnderlyingStream.Write((byte)0x0E);
            UnderlyingStream.Write((byte)0x75);
            UnderlyingStream.Write((byte)0x00);
            UnderlyingStream.Write((byte)0x00);
            #endregion

            // Lets assume that all of the previous data that is of varying size
            // was completely full (255 characters for Author, Subject, and Date)
            // The total size of the packet so far would then be (in bytes):
            // 1+2+1+4+4+1+255+1+255+1+255+29 = 809 Bytes
            // That leaves 65535-809 = 64726 Bytes for the remaining lines of the
            // message.  Each line can contain a maximum of 255 characters (including the terminating null)
            // And there can only be a total of 255 lines so, to be safe we are only
            // going to allow 250 lines max!  That will result in a total of
            // 250x256 = 64000 Bytes total for a complete message (way under the 64766 limit)

            // Set the maximum number of lines
            int MaxLines = (Post.Message.Length < 250 ? Post.Message.Length : 250);
            UnderlyingStream.Write((byte)MaxLines);

            // Add each line (up to the maximum number of lines)
            for (int x = 0; ((x < Post.Message.Length) && (x < 250)); x++)
            {
                UnderlyingStream.Write((byte)(Post.Message[x].Length + 1));
                UnderlyingStream.WriteAsciiNull(Post.Message[x]);
            }

            // Log the raw packet info
            BulletinPacket.LogPacket("BulletinBoardPostPacket", UnderlyingStream.ToArray());
        }
Пример #15
0
        public BulletinBoardFillItemsPacket(BulletinBoard Board)
            : base(0x3c)
        {
            // Since the maximum size of a packet is 65535 and the overhead of the
            // segment is 19 characters, lets ensure the maximum capacity is available
            EnsureCapacity(65535);

            // There will be a check to allow only a maximum of 3072 posts to be shown
            // on a single bulletin board
            // 3072x19 bytes for an item segment = 58368 bytes (should be very safe)

            // Get all of the items associated with this bulletin board
            //ArrayList OriginalPosts = Board.Items;
            //List<Item> OriginalPosts = Board.Items;
            List <Item> OriginalPosts = new List <Item>();

            foreach (Item item in World.Items.Values)
            {
                // Add each global post to the global post list
                if (item is BulletinBoardPost)
                {
                    //all posts go on every messagebaord
                    //if (item.Parent == Board)
                    OriginalPosts.Add(item);
                }
            }

            // Do a deep copy of each post on the board (need to do this so that
            // the replies can be added to the outgoing message without modifiying
            // the original array list)
            List <Item> AllPosts = new List <Item>();

            //ArrayList AllPosts = new ArrayList(OriginalPosts.Count);
            foreach (BulletinBoardPost OriginalPost in OriginalPosts)
            {
                AllPosts.Add(OriginalPost);
            }

            // Add any global posts to the top of the new list.
            // Global posts can not be replied to since they don't belong to
            // a specific bulletin board.
            if (BulletinBoardGlobalPostList.m_GlobalPostList.Count > 0)
            {
                AllPosts.InsertRange(0, BulletinBoardGlobalPostList.m_GlobalPostList);
            }

            // Collect any replies to posts and insert them into the array list
            // as long as the array list contains less than 3072 items
            for (int x = 0; x < AllPosts.Count; x++)
            {
                // Get the current post object in the list
                BulletinBoardPost Post = AllPosts[x] as BulletinBoardPost;

                // Check if the object retrieved from the list was a post
                if (Post != null)
                {
                    // Check to see if this post item has any child posts
                    if (Post.Items.Count > 0)
                    {
                        // Collect all child posts (replies) and insert them
                        // into the original array list after the current posts
                        // position.
                        foreach (BulletinBoardPost Reply in Post.Items)
                        {
                            AllPosts.Add(Reply); // Add the reply posts to the end
                        }
                    }
                }
            }

            // Fill in the mandatory pieces of the packet
            UnderlyingStream.Write((short)AllPosts.Count);

            // Check each root item for any children
            foreach (BulletinBoardPost Post in AllPosts)
            {
                UnderlyingStream.Write((int)Post.Serial);
                UnderlyingStream.Write((byte)0x0E); // Model High
                UnderlyingStream.Write((byte)0xB0); // Model Low
                UnderlyingStream.Write((byte)0x00); // Unknown
                UnderlyingStream.Write((byte)0x00); // Items In Stack High
                UnderlyingStream.Write((byte)0x00); // Items In Stack Low
                UnderlyingStream.Write((byte)0x00); // X Position High
                UnderlyingStream.Write((byte)0x3A); // X Position Low
                UnderlyingStream.Write((byte)0x00); // Y Position High
                UnderlyingStream.Write((byte)0x3A); // Y Position Low
                UnderlyingStream.Write((byte)0x00);
                UnderlyingStream.Write((int)Board.Serial);
                UnderlyingStream.Write((byte)0x00); // Colour High
                UnderlyingStream.Write((byte)0x00); // Colour Low
            }

            // Log the raw packet info
            BulletinPacket.LogPacket("BulletinBoardFillItemsPacket", UnderlyingStream.ToArray());
        }