mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-23 21:25:52 +12:00
Remove \0 from packet unless XmlSocket
This commit is contained in:
parent
3ed0120b9b
commit
eefc2b926d
6 changed files with 300 additions and 328 deletions
|
@ -1,24 +1,26 @@
|
|||
using HISP.Security;
|
||||
using HISP.Util;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace HISP.Server.Network
|
||||
{
|
||||
public class XmlSocket : Transport
|
||||
{
|
||||
private const byte XMLSOCKET_PACKET_TERMINATOR = 0x00;
|
||||
public override void ProcessReceivedPackets(int available, byte[] buffer)
|
||||
{
|
||||
// In XmlSocket Packets are terminates by 0x00 so we have to read until we receive that terminator
|
||||
for (int i = 0; i < available; i++)
|
||||
{
|
||||
currentPacket.Add(buffer[i]);
|
||||
if (buffer[i] == PacketBuilder.PACKET_TERMINATOR) // Read until \0...
|
||||
if (buffer[i] == XMLSOCKET_PACKET_TERMINATOR) // Read until \0...
|
||||
{
|
||||
onReceiveCallback(currentPacket.ToArray());
|
||||
currentPacket.Clear();
|
||||
}
|
||||
currentPacket.Add(buffer[i]);
|
||||
}
|
||||
|
||||
|
||||
// Handle XMLSocket Policy File
|
||||
if (Helper.ByteArrayStartsWith(buffer, Encoding.UTF8.GetBytes("<policy-file-request/>")))
|
||||
{
|
||||
|
@ -34,5 +36,16 @@ namespace HISP.Server.Network
|
|||
}
|
||||
}
|
||||
|
||||
public override void Send(byte[] data)
|
||||
{
|
||||
// add \0 to the end of the buffer
|
||||
byte[] buffer = new byte[data.Length + 1];
|
||||
Array.Copy(data, buffer, data.Length); // copy packet to buffer
|
||||
buffer[buffer.Length - 1] = XMLSOCKET_PACKET_TERMINATOR;
|
||||
|
||||
// send to the server
|
||||
base.Send(data);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue