private bool InternalSend(PortalPacket p, bool getResponse) { var buffer = p.Compile(); if (buffer == null) { ToConsole("Send: Buffer Null for {0}", p.ID); return(false); } if (buffer.Length < PortalPacket.MinSize || buffer.Length > PortalPacket.MaxSize) { ToConsole( "Send: Size Out Of Range for {0} at {1}/{2}-{3} bytes", p.ID, buffer.Length, PortalPacket.MinSize, PortalPacket.MaxSize); return(false); } lock (_SendLock) { var size = buffer.Length; while (size > 0 && _Client != null) { size -= _Client.Send(buffer, buffer.Length - size, size, SocketFlags.None); if (!_Client.Connected) { break; } Thread.Sleep(10); } if (size > 0) { ToConsole("Send: Failed for {0} at {1}/{2} bytes", p.ID, buffer.Length - size, buffer.Length); Dispose(); return(false); } ToConsole("Send: Sent Packet {0} at {1} bytes", p.ID, buffer.Length); } if (getResponse) { Receive(); } ProcessReceiveQueue(); return(true); }
private bool InternalSend(PortalPacket p) { if (!IsAlive) { return(false); } var buffer = p.Compile(); if (buffer == null) { if (_DisplaySendOutput) { ToConsole("Send: Buffer Null for {0}", p.ID); } return(false); } var size = buffer.Length; if (size < PortalPacket.MinSize || size > PortalPacket.MaxSize) { if (_DisplaySendOutput) { ToConsole( "Send: Size Out Of Range for {0} at {1}/{2}-{3} bytes", p.ID, size, PortalPacket.MinSize, PortalPacket.MaxSize); } return(false); } var length = size; lock (_SendLock) { while (length > 0 && _Client != null) { length -= _Client.Send(buffer, size - length, length, SocketFlags.None); if (!_Client.Connected || length <= 0) { break; } Thread.Sleep(10); } } if (length > 0) { if (_DisplaySendOutput) { ToConsole("Send: Failed for {0} at {1}/{2} bytes", p.ID, size - length, size); } return(false); } if (_DisplaySendOutput) { ToConsole("Send: Sent Packet {0} at {1} bytes", p.ID, size); } lock (_GetResponseLock) { if (p.GetResponse) { Receive(); ProcessReceiveQueue(); } } return(true); }
private bool InternalSend(PortalPacket p) { if (!IsAlive) { return false; } var buffer = p.Compile(); if (buffer == null) { if (_DisplaySendOutput) { ToConsole("Send: Buffer Null for {0}", p.ID); } return false; } var size = buffer.Length; if (size < PortalPacket.MinSize || size > PortalPacket.MaxSize) { if (_DisplaySendOutput) { ToConsole( "Send: Size Out Of Range for {0} at {1}/{2}-{3} bytes", p.ID, size, PortalPacket.MinSize, PortalPacket.MaxSize); } return false; } var length = size; lock (_SendLock) { while (length > 0 && _Client != null) { length -= _Client.Send(buffer, size - length, length, SocketFlags.None); if (!_Client.Connected || length <= 0) { break; } Thread.Sleep(10); } } if (length > 0) { if (_DisplaySendOutput) { ToConsole("Send: Failed for {0} at {1}/{2} bytes", p.ID, size - length, size); } return false; } if (_DisplaySendOutput) { ToConsole("Send: Sent Packet {0} at {1} bytes", p.ID, size); } lock (_GetResponseLock) { if (p.GetResponse) { Receive(); ProcessReceiveQueue(); } } return true; }
private bool InternalSend(PortalPacket p) { if (p == null) { return(false); } if (IsDisposing && p.ID != 255) { return(false); } if (!IsAlive) { return(false); } /* * while (!_ReceiveSync.WaitOne(10)) * { * if (!IsAlive || (Portal.Ticks % 1000 == 0 && !IsConnected)) * { * return false; * } * * Thread.Sleep(1); * } */ if (IsDisposing && p.ID != 255) { return(false); } if (!IsAlive) { return(false); } try { _NoReceive = true; var buffer = p.Compile(); if (buffer == null) { if (_DisplaySendOutput) { ToConsole("Send: Buffer Null for {0}", p.ID); } Dispose(); return(false); } var size = buffer.Size; if (size < PortalPacket.MinSize || size > PortalPacket.MaxSize) { if (_DisplaySendOutput) { ToConsole( "Send: Size Out Of Range for {0} at {1} / {2} - {3} bytes", p.ID, size, PortalPacket.MinSize, PortalPacket.MaxSize); } Dispose(); return(false); } var length = buffer.Send(_Client, 0, size); if (length < size) { if (_DisplaySendOutput) { ToConsole("Send: Failed for {0} at {1} / {2} bytes", p.ID, length, size); } Dispose(); return(false); } if (_DisplaySendOutput) { ToConsole("Send: Packet {0} at {1} bytes", p.ID, size); } if (p.GetResponse) { if (!Receive(true)) { if (_DisplaySendOutput) { ToConsole("Send: {0} requires a response which could not be handled.", p.ID); } Dispose(); return(false); } ProcessReceiveQueue(); } _NoReceive = false; return(true); } catch (Exception e) { ToConsole("Send: Exception Thrown", e); Dispose(); return(false); } finally { _NoReceive = false; } }
private bool InternalSend(PortalPacket p, bool getResponse) { var buffer = p.Compile(); if (buffer == null) { ToConsole("Send: Buffer Null for {0}", p.ID); return false; } if (buffer.Length < PortalPacket.MinSize || buffer.Length > PortalPacket.MaxSize) { ToConsole( "Send: Size Out Of Range for {0} at {1}/{2}-{3} bytes", p.ID, buffer.Length, PortalPacket.MinSize, PortalPacket.MaxSize); return false; } lock (_SendLock) { var size = buffer.Length; while (size > 0 && _Client != null) { size -= _Client.Send(buffer, buffer.Length - size, size, SocketFlags.None); if (!_Client.Connected) { break; } Thread.Sleep(10); } if (size > 0) { ToConsole("Send: Failed for {0} at {1}/{2} bytes", p.ID, buffer.Length - size, buffer.Length); Dispose(); return false; } ToConsole("Send: Sent Packet {0} at {1} bytes", p.ID, buffer.Length); } if (getResponse) { Receive(); } ProcessReceiveQueue(); return true; }