/// <summary> /// Appends the string packer to another packet. /// </summary> /// <param name="Packet">The packet.</param> /// <param name="offset">Append offset.</param> public void AppendAndFinish(DataPacket Packet, int offset) { if (stringPacket == null) return; Packet.WriteBytes(stringPacket.Copy(), offset); stringPacket.Dispose(); }
/// <summary> /// Sends a packet to the client. /// </summary> /// <param name="Packet">The packet to send.</param> public void Send(DataPacket Packet) { if (IsAIBot) return; // TODO: rewrite the sockets to actually handle this proper ... if (Packet.ReadString(Packet.BufferLength - 8, 8) == "TQClient") // this is actually never used, not removing it though just to be sure { using (var sendPacket = new DataPacket(Packet)) { sendPacket.WriteBytes(Packet.Copy(), 0); sendPacket.WriteString("TQServer", sendPacket.BufferLength - 8); NetworkClient.Send(sendPacket); } } else { using (var sendPacket = new DataPacket(new byte[Packet.BufferLength + 8])) { sendPacket.WriteBytes(Packet.Copy(), 0); sendPacket.WriteString("TQServer", sendPacket.BufferLength - 8); NetworkClient.Send(sendPacket); } } }
/// <summary> /// Adds a string to the packet. /// </summary> /// <param name="str">The string to add.</param> public void AddString(string str) { DataPacket expanded = new DataPacket(new byte[Size + str.Length + 1]); // creates a new packet expanded.WriteByte((byte)(stringPacket.ReadByte(0) + 1), 0); // sets a new string packet size expanded.WriteBytes(stringPacket.Copy(), 0); // copies all the current strings if (string.IsNullOrEmpty(str) || string.IsNullOrWhiteSpace(str)) expanded.WriteByte(0, Size); else expanded.WriteStringWithLength(str, Size); // writes the new string at the end stringPacket.Dispose(); // disposes the old packet stringPacket = expanded; // sets the old packet to be the new }