Example #1
0
        private int sendOsu(SerializationWriter sw)
        {
            bSerializable bPayload = payload as bSerializable;

            if (type == RequestType.Irc_Only)
            {
                return(0);
            }

            long sentBytes = 0;

            //set the position to after the header..
            MemoryStream payloadBuffer = (MemoryStream)sw.BaseStream;

            sw.Seek(HEADER_LEN, SeekOrigin.Begin);


            int payloadSize = 0;

            if (bPayload != null)
            {
                bPayload.WriteToStream(sw);
                payloadSize = (int)payloadBuffer.Position - HEADER_LEN;
            }

            sw.Seek(0, SeekOrigin.Begin);

            sw.Write((ushort)type);
            sw.Write((byte)0);
            sw.Write((uint)payloadSize);

            return(HEADER_LEN + payloadSize);
        }
Example #2
0
        public int Send(RequestTarget target, SerializationWriter sw)
        {
            if (Cache)
            {
                byte[] cache = byteCache[(int)target];

                if (cache != null)
                {
                    //use the byte-cache, since it is present.
                    if (cache.Length > 0)
                    {
                        sw.Seek(0, SeekOrigin.Begin);
                        sw.BaseStream.Write(cache, 0, cache.Length);
                    }

                    return(cache.Length);
                }

                //cache miss; we will fill it later on...
            }

            int sendLength;

            switch (target)
            {
            case RequestTarget.Irc:
                sendLength = sendIrc(sw);
                break;

            default:
            case RequestTarget.Osu:
                sendLength = sendOsu(sw);
                break;
            }

            if (Cache)
            {
                //fill the byte-cache.
                byte[] cache = new byte[sendLength];
                if (sendLength > 0)
                {
                    sw.Seek(0, SeekOrigin.Begin);
                    sw.BaseStream.Read(cache, 0, sendLength);
                }

                byteCache[(int)target] = cache;
            }

            return(sendLength);
        }
Example #3
0
        private int sendIrc(SerializationWriter sw)
        {
            iSerializable iPayload = payload as iSerializable;

            if (iPayload == null)
            {
                return(0);
            }

            MemoryStream payloadBuffer = (MemoryStream)sw.BaseStream;

            sw.Seek(0, SeekOrigin.Begin);
            iPayload.WriteToStreamIrc(sw);

            return((int)payloadBuffer.Position);
        }
Example #4
0
        public void SerializeCommands(Stream outStream)
        {
            if (CommandQueue.IsEmpty)
            {
                return;
            }
            var writer = new SerializationWriter(outStream);

            Command command;

            while (outStream.Length < 6144L && this.CommandQueue.TryDequeue(out command))
            {
                var begin = writer.BaseStream.Position;

                writer.Write(command.Id);
                writer.Write((byte)0);
                writer.Write(0);

                if (command.noHasData)
                {
                    continue;
                }
                if (command.Serializable != null)
                {
                    command.Serializable.WriteToStream(writer);
                }
                else
                {
                    writer.method_0(command.RegularType); //TODO: Improve this
                }

                writer.BaseStream.Position = begin + 3; //this is weird >_>
                writer.Write((int)(writer.BaseStream.Length - begin) - 7);
                writer.Seek(0, SeekOrigin.End);
            }

            //Debug.WriteLine($"Sent: {Utils.ByteArrayRepr((writer.BaseStream as MemoryStream).ToArray())}");
            outStream.Position = 0;
        }