/// <summary> /// Send a packet /// </summary> /// <param name="packet"></param> /// <param name="connection"></param> /// <param name="channel"></param> /// <returns>false if there was an error during sending, otherwise true</returns> private bool Send(ArraySegment <byte> packet, HlapiConn connection, byte channel) { if (_network.PreprocessPacketToClient(packet, connection)) { return(true); } // We don't consider sending to a disconnected connection a failure. // It could easily be caused by a race (i.e. they only just disconnected) and we don't really care if packets to non-clients get lost! if (!connection.Connection.isConnected || connection.Connection.lastError == NetworkError.Timeout) { return(true); } var length = _network.CopyPacketToNetworkWriter(packet, _sendWriter); // ReSharper disable once ConditionIsAlwaysTrueOrFalse (Justification it shouldn't be null, but sanity check anyway) // ReSharper disable HeuristicUnreachableCode if (connection.Connection == null) { Log.Error("Cannot send to a null destination"); return(false); } // ReSharper restore HeuristicUnreachableCode else if (!connection.Connection.SendBytes(_sendWriter.AsArray(), length, channel)) { return(false); } return(true); }
private void Send(ArraySegment <byte> packet, HlapiConn connection, byte channel) { if (_network.PreprocessPacketToClient(packet, connection)) { return; } var length = _network.CopyPacketToNetworkWriter(packet, _sendWriter); if (connection.Connection == null) { Log.Error("Cannot send to a null destination"); } else if (!connection.Connection.SendBytes(_sendWriter.AsArray(), length, channel)) { Log.Error("Failed to send a message"); } }