public override void Send(IClientMsg clientMsg) { lock (netLock) { if (socket == null || netStream == null) { DebugLog.WriteLine("TcpConnection", "Attempting to send client message when not connected: {0}", clientMsg.MsgType); return; } var data = clientMsg.Serialize(); if (netFilter != null) { data = netFilter.ProcessOutgoing(data); } try { netWriter.Write((uint)data.Length); netWriter.Write(TcpConnection.MAGIC); netWriter.Write(data); } catch (IOException ex) { DebugLog.WriteLine("TcpConnection", "Socket exception while writing data: {0}", ex); } } }
/// <summary> /// Sends the specified client net message. /// </summary> /// <param name="clientMsg">The client net message.</param> public override void Send(IClientMsg clientMsg) { if (!isConnected) { DebugLog.WriteLine("TcpConnection", "Attempting to send client message when not connected: {0}", clientMsg.MsgType); return; } byte[] data = clientMsg.Serialize(); // encrypt outgoing traffic if we need to if (NetFilter != null) { data = NetFilter.ProcessOutgoing(data); } lock ( sock ) { // write header netWriter.Write(( uint )data.Length); netWriter.Write(TcpConnection.MAGIC); netWriter.Write(data); } }
/// <summary> /// Sends the specified client message to the UFS server. /// This method will automatically assign the correct <see cref="IClientMsg.SteamID"/> of the message, as given by the parent <see cref="SteamClient"/>. /// </summary> /// <param name="msg">The client message to send.</param> public void Send(IClientMsg msg) { if (msg == null) { throw new ArgumentNullException(nameof(msg)); } msg.SteamID = steamClient.SteamID; DebugLog.WriteLine(nameof(UFSClient), "Sent -> EMsg: {0} {1}", msg.MsgType, msg.IsProto ? "(Proto)" : ""); // we'll swallow any network failures here because they will be thrown later // on the network thread, and that will lead to a disconnect callback // down the line try { connection.Send(msg.Serialize()); } catch (IOException) { } catch (SocketException) { } }
/// <summary> /// Sends the specified client net message. /// </summary> /// <param name="clientMsg">The client net message.</param> public override void Send(IClientMsg clientMsg) { byte[] data = clientMsg.Serialize(); // encrypt outgoing traffic if we need to if (NetFilter != null) { data = NetFilter.ProcessOutgoing(data); } netLock.EnterReadLock(); try { if (netStream == null) { DebugLog.WriteLine("TcpConnection", "Attempting to send client message when not connected: {0}", clientMsg.MsgType); return; } // need to ensure ordering between concurrent Sends lock ( netWriter ) { // write header netWriter.Write((uint)data.Length); netWriter.Write(TcpConnection.MAGIC); netWriter.Write(data); } } finally { netLock.ExitReadLock(); } }
/// <summary> /// Sends the specified client message to the server. /// This method automatically assigns the correct SessionID and SteamID of the message. /// </summary> /// <param name="msg">The client message to send.</param> public void Send(IClientMsg msg) { if (msg == null) { throw new ArgumentNullException(nameof(msg), "A value for 'msg' must be supplied"); } var sessionID = this.SessionID; if (sessionID.HasValue) { msg.SessionID = sessionID.Value; } var steamID = this.SteamID; if (steamID != null) { msg.SteamID = steamID; } try { DebugNetworkListener?.OnOutgoingNetworkMessage(msg.MsgType, msg.Serialize()); } catch (Exception e) { LogDebug("CMClient", "DebugNetworkListener threw an exception: {0}", e); } // we'll swallow any network failures here because they will be thrown later // on the network thread, and that will lead to a disconnect callback // down the line try { connection?.Send(msg.Serialize()); } catch (IOException) { } catch (SocketException) { } }
/// <summary> /// Serializes and sends the provided message to the server in as many packets as is necessary. /// </summary> /// <param name="clientMsg">The ClientMsg</param> public override void Send(IClientMsg clientMsg) { if (state != State.Connected) return; byte[] data = clientMsg.Serialize(); if (NetFilter != null) data = NetFilter.ProcessOutgoing(data); SendData(new MemoryStream(data)); }
/// <summary> /// Serializes and sends the provided message to the server in as many packets as is necessary. /// </summary> /// <param name="clientMsg">The ClientMsg</param> public override void Send(IClientMsg clientMsg) { if (state != (int)State.Connected) { return; } byte[] data = clientMsg.Serialize(); if (filter != null) { data = filter.ProcessOutgoing(data); } SendData(new MemoryStream(data)); }
/// <summary> /// Sends the specified client message to the server. /// This method automatically assigns the correct SessionID and SteamID of the message. /// </summary> /// <param name="msg">The client message to send.</param> public void Send(IClientMsg msg) { if (msg == null) { throw new ArgumentException("A value for 'msg' must be supplied"); } if (this.SessionID.HasValue) { msg.SessionID = this.SessionID.Value; } if (this.SteamID != null) { msg.SteamID = this.SteamID; } DebugLog.WriteLine("CMClient", "Sent -> EMsg: {0} (Proto: {1})", msg.MsgType, msg.IsProto); try { DebugNetworkListener?.OnOutgoingNetworkMessage(msg.MsgType, msg.Serialize()); } catch (Exception e) { DebugLog.WriteLine("CMClient", "DebugNetworkListener threw an exception: {0}", e); } // we'll swallow any network failures here because they will be thrown later // on the network thread, and that will lead to a disconnect callback // down the line try { connection.Send(msg); } catch (IOException) { } catch (SocketException) { } }
/// <summary> /// Sends the specified client net message. /// </summary> /// <param name="clientMsg">The client net message.</param> public override void Send(IClientMsg clientMsg) { byte[] data = clientMsg.Serialize(); // a Send from the netThread has the potential to acquire the read lock and block while Disconnect is trying to join us while (!wantsNetShutdown && !netLock.TryEnterReadLock(500)) { } try { if (wantsNetShutdown || netStream == null) { DebugLog.WriteLine("TcpConnection", "Attempting to send client message when not connected: {0}", clientMsg.MsgType); return; } // encrypt outgoing traffic if we need to if (filter != null) { data = filter.ProcessOutgoing(data); } // need to ensure ordering between concurrent Sends lock ( netWriter ) { // write header netWriter.Write((uint)data.Length); netWriter.Write(TcpConnection.MAGIC); netWriter.Write(data); } } finally { if (netLock.IsReadLockHeld) { netLock.ExitReadLock(); } } }
/// <summary> /// Sends the specified client message to the server. /// This method automatically assigns the correct SessionID and SteamID of the message. /// </summary> /// <param name="msg">The client message to send.</param> public void Send( IClientMsg msg ) { if ( msg == null ) throw new ArgumentException( "A value for 'msg' must be supplied" ); if ( this.SessionID.HasValue ) msg.SessionID = this.SessionID.Value; if ( this.SteamID != null ) msg.SteamID = this.SteamID; DebugLog.WriteLine( "CMClient", "Sent -> EMsg: {0} (Proto: {1})", msg.MsgType, msg.IsProto ); try { DebugNetworkListener?.OnOutgoingNetworkMessage(msg.MsgType, msg.Serialize()); } catch ( Exception e ) { DebugLog.WriteLine( "CMClient", "DebugNetworkListener threw an exception: {0}", e ); } // we'll swallow any network failures here because they will be thrown later // on the network thread, and that will lead to a disconnect callback // down the line try { connection.Send( msg ); } catch ( IOException ) { } catch ( SocketException ) { } }
/// <summary> /// Sends the specified client net message. /// </summary> /// <param name="clientMsg">The client net message.</param> public override void Send( IClientMsg clientMsg ) { if ( !isConnected ) { DebugLog.WriteLine( "TcpConnection", "Attempting to send client message when not connected: {0}", clientMsg.MsgType ); return; } byte[] data = clientMsg.Serialize(); // encrypt outgoing traffic if we need to if ( NetFilter != null ) { data = NetFilter.ProcessOutgoing( data ); } lock ( sock ) { // write header netWriter.Write( ( uint )data.Length ); netWriter.Write( TcpConnection.MAGIC ); netWriter.Write( data ); } }
public override void Send(IClientMsg clientMsg) { lock (netLock) { if (socket == null || netStream == null) { DebugLog.WriteLine("TcpConnection", "Attempting to send client message when not connected: {0}", clientMsg.MsgType); return; } byte[] data = clientMsg.Serialize(); if (netFilter != null) { data = netFilter.ProcessOutgoing(data); } try { netWriter.Write((uint)data.Length); netWriter.Write(TcpConnection.MAGIC); netWriter.Write(data); } catch (IOException ex) { DebugLog.WriteLine("TcpConnection", "Socket exception while writing data: {0}", ex); } } }
/// <summary> /// Serializes and sends the provided message to the server in as many packets as is necessary. /// </summary> /// <param name="clientMsg">The ClientMsg</param> public override void Send( IClientMsg clientMsg ) { if ( state != (int)State.Connected ) return; byte[] data = clientMsg.Serialize(); if ( filter != null ) data = filter.ProcessOutgoing( data ); SendData( new MemoryStream( data ) ); }
public void HandleClientMsg(IClientMsg clientMsg) => OnClientMsgReceived(GetPacketMsg(clientMsg.Serialize()));
public void HandleClientMsg( IClientMsg clientMsg ) => OnClientMsgReceived( GetPacketMsg( clientMsg.Serialize() ) );
/// <summary> /// Sends the specified client net message. /// </summary> /// <param name="clientMsg">The client net message.</param> public override void Send( IClientMsg clientMsg ) { byte[] data = clientMsg.Serialize(); // encrypt outgoing traffic if we need to if ( NetFilter != null ) { data = NetFilter.ProcessOutgoing( data ); } netLock.EnterReadLock(); try { if ( netStream == null ) { DebugLog.WriteLine( "TcpConnection", "Attempting to send client message when not connected: {0}", clientMsg.MsgType ); return; } // need to ensure ordering between concurrent Sends lock ( netWriter ) { // write header netWriter.Write( (uint)data.Length ); netWriter.Write( TcpConnection.MAGIC ); netWriter.Write( data ); } } finally { netLock.ExitReadLock(); } }