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); }
public virtual void Send(Stream s) { s.Write(BitConverter.GetBytes((ushort)type), 0, sizeof(ushort)); if (payload != null) { MemoryStream writeBuffer = new MemoryStream(1); payload.WriteToStream(writeBuffer); if (writeBuffer.Length < 150) { s.WriteByte(0); s.Write(BitConverter.GetBytes((uint)writeBuffer.Length), 0, sizeof(uint)); s.Write(writeBuffer.GetBuffer(), 0, (int)writeBuffer.Length); #if DEBUG Console.WriteLine("S" + writeBuffer.Length + ": " + type); #endif } else { int uncompressed = (int)writeBuffer.Length; writeBuffer = new MemoryStream(1); GZipOutputStream comp = new GZipOutputStream(writeBuffer, 5); comp.IsStreamOwner = false; payload.WriteToStream(comp); comp.Close(); s.WriteByte(1); s.Write(BitConverter.GetBytes((uint)writeBuffer.Length), 0, sizeof(uint)); s.Write(writeBuffer.GetBuffer(), 0, (int)writeBuffer.Length); #if DEBUG Console.WriteLine("S" + writeBuffer.Length + "(uncompressed" + uncompressed + ": " + type); #endif } } else { s.WriteByte(0); s.Write(BitConverter.GetBytes((uint)0), 0, sizeof(uint)); #if DEBUG if (type != RequestType.Bancho_Ping && type != RequestType.Osu_Pong) { Console.WriteLine("S0: " + type); } #endif } s.Flush(); }