public virtual async Task <bool> SendToConnectionAsync <S>(S packet, IConnectionTcpServer connection) where S : IPacket { try { if (_handler != null && _handler.IsServerRunning && _connectionManager.IsConnectionOpen(connection)) { if (!await _handler.SendAsync(packet, connection)) { return(false); } await FireEventAsync(this, new TcpMessageServerEventArgs { MessageEventType = MessageEventType.Sent, Packet = packet, Connection = connection, }); return(true); } } catch (Exception ex) { await FireEventAsync(this, new TcpErrorServerEventArgs { Connection = connection, Exception = ex, Message = ex.Message }); } return(false); }
public virtual async Task <bool> SendToConnectionAsync <S>(S packet, IConnectionTcpServer connection) where S : IPacket { if (_handler.IsServerRunning) { if (_connectionManager.IsConnectionOpen(connection)) { try { if (!await _handler.SendAsync(packet, connection)) { return(false); } await FireEventAsync(this, new TcpMessageServerAuthEventArgs <T> { MessageEventType = MessageEventType.Sent, Connection = connection, Packet = packet, UserId = default }); return(true); }