public override void Flush() { try { IMessage message; lock (m_SyncRoot) { if (IsLeave) { return; } while (m_SendMessages.Count > 0) { message = m_SendMessages.Dequeue(); if (Packet == null || message is FreeMessage) { message.Write(m_Writer); } else { Packet.InMessage(m_Writer, message); } } m_Writer.Flush(); //flush to socket } } catch (System.Exception e) { m_Handler.OnError(this, e); } }
/// <summary>Initializes a new instance of the <see cref="CsvWriter" /> class.</summary> /// <param name="properties">Extended properties.</param> /// <param name="layout">The table layout.</param> /// <param name="stream">The stream.</param> /// <param name="closeBaseStream">if set to <c>true</c> [close base stream on close].</param> public CsvWriter(RowLayout layout, Stream stream, CsvProperties properties = default, bool closeBaseStream = false) { BaseStream = stream ?? throw new ArgumentNullException(nameof(stream)); Layout = layout ?? throw new ArgumentNullException(nameof(layout)); Properties = properties.Valid ? properties : CsvProperties.Default; CloseBaseStream = closeBaseStream; writer = new DataWriter(stream, Properties.Encoding, Properties.NewLineMode); if (Properties.NoHeader) { return; } // write header for (var i = 0; i < Layout.FieldCount; i++) { if (i > 0) { writer.Write(Properties.Separator); } if (Properties.StringMarker.HasValue) { writer.Write(Properties.StringMarker.Value); } writer.Write(Layout[i].NameAtDatabase); if (Properties.StringMarker.HasValue) { writer.Write(Properties.StringMarker.Value); } } writer.WriteLine(); writer.Flush(); }
/// <summary>Writes the specified structure.</summary> /// <typeparam name="T"></typeparam> /// <param name="item">The structure.</param> public void Write <T>(T item) where T : struct { if (exception != null) { var ex = exception; exception = null; throw ex; } if (!stream.IsConnected) { if (connectionResult != null) { return; } AsyncWaitConnection(); } writer.Write(nextPacketNumber); var packetSize = Marshal.SizeOf(item); var remainder = packetSize % 8; if (remainder > 0) { packetSize += 8 - remainder; } writer.Write(packetSize); var buffer = new byte[packetSize]; MarshalStruct.Write(item, buffer, 0); writer.Write(buffer); if (--nextPacketNumber < -0xFFFF) { nextPacketNumber = -1; } writer.Flush(); }
void WriteCommand(string command) { lock (_lock) { _dataWriter.WriteString(command + Environment.NewLine); _dataWriter.Store(); _dataWriter.Flush(); Thread.Sleep(100); } }
private void writeChar() { DataWriter dw = initPofWriter("Char"); WritingPofHandler wfh = new WritingPofHandler(dw); PofStreamWriter psw = new PofStreamWriter(wfh, new SimplePofContext()); psw.WriteChar(0, 'f'); psw.WriteChar(0, '0'); dw.Flush(); dw.Close(); }
private void Setup(CharacterEntity character, PlaneEntity vehicle) { DataStream ds = new DataStream(); DataWriter dw = new DataWriter(ds); dw.WriteLong(character.EID); dw.WriteByte(2); // TODO: Enum? dw.WriteLong(vehicle.EID); dw.Flush(); Data = ds.ToArray(); dw.Close(); }
private void writeInt64() { DataWriter dw = initPofWriter("Int64"); WritingPofHandler wfh = new WritingPofHandler(dw); PofStreamWriter psw = new PofStreamWriter(wfh, new SimplePofContext()); psw.WriteInt64(0, -1L); psw.WriteInt64(0, Int64.MaxValue); dw.Flush(); dw.Close(); }
private void WriteDataToFile(string fileName, string[] data) { FileStream stream = File.OpenWrite(fileName); DataWriter writer = new DataWriter(stream); foreach (var value in data) { writer.WriteLine(value); } writer.Flush(); }
ImapAnswer SendCommand(string cmd) { var id = counter++.ToString("X2"); var command = id + " " + cmd; var writer = new DataWriter(stream); writer.Write(ASCII.GetBytes(command + ImapNewLine)); writer.Flush(); var answer = ReadAnswer(id, true); return(answer); }
private void writeDecimal32() { DataWriter dw = initPofWriter("Dec32"); WritingPofHandler wfh = new WritingPofHandler(dw); PofStreamWriter psw = new PofStreamWriter(wfh, new SimplePofContext()); psw.WriteDecimal(0, new Decimal(99999, 0, 0, false, 0)); psw.WriteDecimal(0, new Decimal(9999999, 0, 0, false, 0)); psw.WriteDecimal(0, new Decimal(9999999, 0, 0, false, 28)); dw.Flush(); dw.Close(); }
public byte[] ToBytes() { DataStream ds = new DataStream(1000); DataWriter dw = new DataWriter(ds); WriteBasicBytes(dw); dw.WriteInt(Components.Count); foreach (ItemStackBase itb in Components) { dw.WriteFullBytes(itb.ToBytes()); } dw.Flush(); return(ds.ToArray()); }
/*---------Utility methods for writing POF data----------------------*/ private void writeByte() { DataWriter dw = initPofWriter("Byte"); WritingPofHandler wfh = new WritingPofHandler(dw); PofStreamWriter psw = new PofStreamWriter(wfh, new SimplePofContext()); psw.WriteByte(0, 1); psw.WriteByte(0, 0); psw.WriteByte(0, 200); psw.WriteByte(0, 255); dw.Flush(); dw.Close(); }
string PrepareLiteralDataCommand(string cmd) { var id = counter++.ToString("X2"); var command = id + " " + cmd; var writer = new DataWriter(stream); writer.Write(ASCII.GetBytes(command + ImapNewLine)); writer.Flush(); var answer = ReadAnswer("+", false); if (!answer.Result.ToUpperInvariant().StartsWith("+ READY")) { answer.Throw(); } return(id); }
private void writeDecimal64() { DataWriter dw = initPofWriter("Dec64"); WritingPofHandler wfh = new WritingPofHandler(dw); PofStreamWriter psw = new PofStreamWriter(wfh, new SimplePofContext()); psw.WriteDecimal(0, new Decimal(9999999999)); Decimal d2 = new Decimal(9999999999999999); psw.WriteDecimal(0, d2); int[] value = Decimal.GetBits(d2); psw.WriteDecimal(0, new Decimal(value[0], value[1], value[3], false, 28)); dw.Flush(); dw.Close(); }
/// <summary>Uploads a message to the specified mailbox.</summary> /// <param name="mailboxName">Name of the mailbox.</param> /// <param name="messageData">The message data.</param> /// <exception cref="System.ArgumentNullException">messageData.</exception> public void UploadMessageData(string mailboxName, byte[] messageData) { var mailbox = UTF7.EncodeExtendedUTF7(mailboxName); if (messageData == null) { throw new ArgumentNullException(nameof(messageData)); } var id = PrepareLiteralDataCommand("APPEND \"" + mailbox + "\" (\\Seen) {" + messageData.Length + "}"); var writer = new DataWriter(stream); writer.Write(messageData); writer.Write((byte)13); writer.Write((byte)10); writer.Flush(); ReadAnswer(id, true); }
private void writeDecimal128() { DataWriter dw = initPofWriter("Dec128"); WritingPofHandler wfh = new WritingPofHandler(dw); PofStreamWriter psw = new PofStreamWriter(wfh, new SimplePofContext()); psw.WriteDecimal(0, Decimal.MaxValue); Decimal d1 = Decimal.Add(new Decimal(Int64.MaxValue), Decimal.One); psw.WriteDecimal(0, d1); // Scale the maximum integer plus one value int[] value = Decimal.GetBits(d1); psw.WriteDecimal(0, new Decimal(value[0], value[1], value[3], false, 28)); dw.Flush(); dw.Close(); }
private void Setup(CharacterEntity character, CarEntity vehicle) { DataStream ds = new DataStream(); DataWriter dw = new DataWriter(ds); dw.WriteLong(character.EID); dw.WriteByte(0); // TODO: Enum? dw.WriteInt(vehicle.DrivingMotors.Count); dw.WriteInt(vehicle.SteeringMotors.Count); for (int i = 0; i < vehicle.DrivingMotors.Count; i++) { dw.WriteLong(vehicle.DrivingMotors[i].JID); } for (int i = 0; i < vehicle.SteeringMotors.Count; i++) { dw.WriteLong(vehicle.SteeringMotors[i].JID); } dw.Flush(); Data = ds.ToArray(); dw.Close(); }
public AddCloudPacketOut(Cloud cloud) { UsageType = NetUsageType.CLOUDS; ID = ServerToClientPacket.ADD_CLOUD; DataStream ds = new DataStream(); DataWriter dw = new DataWriter(ds); dw.WriteBytes(cloud.Position.ToDoubleBytes()); dw.WriteBytes((cloud.Velocity + cloud.TheRegion.Wind).ToDoubleBytes()); dw.WriteLong(cloud.CID); dw.WriteInt(cloud.Points.Count); for (int i = 0; i < cloud.Points.Count; i++) { dw.WriteBytes(cloud.Points[i].ToDoubleBytes()); dw.WriteFloat((float)cloud.Sizes[i]); dw.WriteFloat((float)cloud.EndSizes[i]); } dw.Flush(); Data = ds.ToArray(); dw.Close(); }
public BlockEditPacketOut(Location[] pos, ushort[] mat, byte[] dat, byte[] paints) { UsageType = NetUsageType.CHUNKS; ID = ServerToClientPacket.BLOCK_EDIT; DataStream outp = new DataStream(); DataWriter dw = new DataWriter(outp); dw.WriteInt(pos.Length); for (int i = 0; i < pos.Length; i++) { dw.WriteBytes(pos[i].ToDoubleBytes()); } for (int i = 0; i < mat.Length; i++) { dw.WriteBytes(Utilities.UshortToBytes(mat[i])); } dw.WriteBytes(dat); dw.WriteBytes(paints); dw.Flush(); Data = outp.ToArray(); }
public byte[] ServerBytes() { DataStream data = new DataStream(1000); DataWriter dw = new DataWriter(data); dw.WriteInt(Attributes.Count); foreach (KeyValuePair <string, TemplateObject> entry in Attributes) { dw.WriteFullString(entry.Key); if (entry.Value is IntegerTag) { dw.WriteByte(0); dw.WriteLong(((IntegerTag)entry.Value).Internal); } else if (entry.Value is NumberTag) { dw.WriteByte(1); dw.WriteDouble(((NumberTag)entry.Value).Internal); } else if (entry.Value is BooleanTag) { dw.WriteByte(2); dw.WriteByte((byte)(((BooleanTag)entry.Value).Internal ? 1 : 0)); } // TODO: shared BaseItemTag? else { dw.WriteByte(3); dw.WriteFullString(entry.Value.ToString()); } } WriteBasicBytes(dw); dw.WriteInt(Components.Count); foreach (ItemStack itb in Components) { dw.WriteFullBytes(itb.ServerBytes()); } dw.Flush(); return(data.ToArray()); }
/// <summary> /// LIST. /// </summary> /// <remarks> /// This command causes a list to be sent from the server to the /// passive DTP. If the pathname specifies a directory or other /// group of files, the server should transfer a list of files /// in the specified directory. If the pathname specifies a /// file then the server should send current information on the /// file. A null argument implies the user's current working or /// default directory. The data transfer is over the data /// connection in type ASCII or type EBCDIC. (The user must /// ensure that the TYPE is appropriately ASCII or EBCDIC). /// Since the information on a file may vary widely from system /// to system, this information may be hard to use automatically /// in a program, but may be quite useful to a human user. /// </remarks> void LIST(string args) { if (!CheckLogin()) { return; } //get entries if (!GetDirectoryEntries(out FtpDirectoryEntry[] entries)) { return; } //get connection if (!GetDataConnection(out TcpClient tcpClient)) { return; } //send data try { using (Stream s = tcpClient.GetStream()) { DataWriter dataWriter = new DataWriter(s, newLineMode: NewLineMode.CRLF); foreach (FtpDirectoryEntry entry in entries) { dataWriter.WriteLine(entry.ToString()); Trace.TraceInformation("{0}: {1}", tcpClient.Client.RemoteEndPoint, entry); } dataWriter.Flush(); dataWriter.Close(); SendAnswer("226 Transfer complete"); } } catch { tcpClient.Close(); SendAnswer("426 Connection closed; transfer aborted."); } }
private void writeInt128() { DataWriter dw = initPofWriter("Int128"); WritingPofHandler wfh = new WritingPofHandler(dw); PofStreamWriter psw = new PofStreamWriter(wfh, new SimplePofContext()); // Test data: // First byte array is equivalent to BigInteger.TEN byte[] b1 = { 0x0a }; // Second byte array is equivalent to BigInteger("55 5555 5555 5555 5555") // (spaces are there for human parsing). // Equivalent to hex: 0x 07 b5 ba d5 95 e2 38 e3 byte[] b2 = { 0x07, 0xb5, 0xba, 0xd5, 0x95, 0xe2, 0x38, 0xe3 }; RawInt128 rawInt1 = new RawInt128(b1); RawInt128 rawInt2 = new RawInt128(b2); psw.WriteRawInt128(0, rawInt1); psw.WriteRawInt128(0, rawInt2); dw.Flush(); dw.Close(); }
public byte[] GetCharacterNetData() { DataStream ds = new DataStream(); DataWriter dr = new DataWriter(ds); dr.WriteBytes(GetPosition().ToDoubleBytes()); Quaternion quat = GetOrientation(); dr.WriteFloat((float)quat.X); dr.WriteFloat((float)quat.Y); dr.WriteFloat((float)quat.Z); dr.WriteFloat((float)quat.W); dr.WriteFloat((float)GetMass()); dr.WriteFloat((float)CBAirForce); dr.WriteFloat((float)CBAirSpeed); dr.WriteFloat((float)CBCrouchSpeed); dr.WriteFloat((float)CBDownStepHeight); dr.WriteFloat((float)CBGlueForce); dr.WriteFloat((float)CBHHeight); dr.WriteFloat((float)CBJumpSpeed); dr.WriteFloat((float)CBMargin); dr.WriteFloat((float)CBMaxSupportSlope); dr.WriteFloat((float)CBMaxTractionSlope); dr.WriteFloat((float)CBProneSpeed); dr.WriteFloat((float)CBRadius); dr.WriteFloat((float)CBSlideForce); dr.WriteFloat((float)CBSlideJumpSpeed); dr.WriteFloat((float)CBSlideSpeed); dr.WriteFloat((float)CBStandSpeed); dr.WriteFloat((float)CBStepHeight); dr.WriteFloat((float)CBTractionForce); dr.WriteFloat((float)mod_xrot); dr.WriteFloat((float)mod_yrot); dr.WriteFloat((float)mod_zrot); dr.WriteFloat((float)mod_scale); dr.WriteInt(mod_color.ToArgb()); byte dtx = 0; if (Visible) { dtx |= 1; } if (CGroup == CollisionUtil.Solid) { dtx |= 2; } else if (CGroup == CollisionUtil.NonSolid) { dtx |= 4; } else if (CGroup == CollisionUtil.Item) { dtx |= 2 | 4; } else if (CGroup == CollisionUtil.Player) { dtx |= 8; } else if (CGroup == CollisionUtil.Water) { dtx |= 2 | 8; } else if (CGroup == CollisionUtil.WorldSolid) { dtx |= 2 | 4 | 8; } else if (CGroup == CollisionUtil.Character) { dtx |= 16; } dr.Write(dtx); dr.WriteInt(TheServer.Networking.Strings.IndexForString(model)); dr.Flush(); byte[] Data = ds.ToArray(); dr.Close(); return(Data); }
void IDisposable.Dispose() { DataWriter.Flush(); _writer.Flush(); }
void WriteFieldDefinition(DataWriter writer, RowLayout layout, int version) { if (version < 1) { throw new ArgumentOutOfRangeException(nameof(version)); } if (version > 4) { throw new NotSupportedException("Version not supported!"); } try { writer.Write("DatTable"); writer.Write7BitEncoded32(version); writer.WritePrefixed(layout.Name); writer.Write7BitEncoded32(layout.FieldCount); for (var i = 0; i < layout.FieldCount; i++) { var field = layout[i]; writer.WritePrefixed(field.Name); writer.Write7BitEncoded32((int)field.DataType); writer.Write7BitEncoded32((int)field.Flags); switch (field.DataType) { case DataType.User: case DataType.String: if (version > 2) { writer.Write7BitEncoded32((int)field.StringEncoding); } break; case DataType.DateTime: if (version > 1) { writer.Write7BitEncoded32((int)field.DateTimeKind); writer.Write7BitEncoded32((int)field.DateTimeType); } break; case DataType.TimeSpan: if (version > 3) { writer.Write7BitEncoded32((int)field.DateTimeType); } break; } if ((field.DataType & DataType.MaskRequireValueType) != 0) { var typeName = field.ValueType.AssemblyQualifiedName; var parts = typeName.Split(','); typeName = $"{parts[0]},{parts[1]}"; writer.WritePrefixed(typeName); } } writer.Flush(); } catch (Exception ex) { throw new InvalidOperationException("Could not write field definition!", ex); } }
public void Flush() { writer.Flush(); }