コード例 #1
0
ファイル: TcpConnection.cs プロジェクト: sherpic/SteamKit
        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);
                }
            }
        }
コード例 #2
0
        /// <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);
            }
        }
コード例 #3
0
        /// <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)
            {
            }
        }
コード例 #4
0
ファイル: TcpConnection.cs プロジェクト: Badca52/SteamKit
        /// <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();
            }
        }
コード例 #5
0
ファイル: CMClient.cs プロジェクト: ywscr/SteamKit
        /// <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)
            {
            }
        }
コード例 #6
0
        /// <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));
        }
コード例 #7
0
        /// <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));
        }
コード例 #8
0
ファイル: CMClient.cs プロジェクト: sherpic/SteamKit
        /// <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)
            {
            }
        }
コード例 #9
0
        /// <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();
                }
            }
        }
コード例 #10
0
ファイル: CMClient.cs プロジェクト: DoctorMcKay/SteamKit
        /// <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 )
            {
            }
        }
コード例 #11
0
        /// <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 );
            }

        }
コード例 #12
0
ファイル: TcpConnection.cs プロジェクト: ChronosWS/SteamKit
        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);
                }
            }
        }
コード例 #13
0
ファイル: UdpConnection.cs プロジェクト: DoctorMcKay/SteamKit
        /// <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 ) );
        }
コード例 #14
0
 public void HandleClientMsg(IClientMsg clientMsg)
 => OnClientMsgReceived(GetPacketMsg(clientMsg.Serialize()));
コード例 #15
0
ファイル: CMClientFacts.cs プロジェクト: DoctorMcKay/SteamKit
 public void HandleClientMsg( IClientMsg clientMsg )
     => OnClientMsgReceived( GetPacketMsg( clientMsg.Serialize() ) );
コード例 #16
0
ファイル: TcpConnection.cs プロジェクト: Badca52/SteamKit
        /// <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();
            }
        }