Example #1
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 );
            }

        }
Example #2
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)
            {
            }
        }
Example #3
0
        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);
                }
            }
        }
Example #4
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();

            // 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();
            }
        }
Example #5
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);
            }
        }
Example #6
0
        /// <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 (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);


            // 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)
            {
            }
        }
Example #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 != State.Connected)
                return;

            byte[] data = clientMsg.Serialize();

            if (NetFilter != null)
                data = NetFilter.ProcessOutgoing(data);

            SendData(new MemoryStream(data));
        }
Example #8
0
        /// <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");
            }

            DebugLog.Assert(IsConnected, nameof(CMClient), "Send() was called while not connected to Steam.");

            var sessionID = this.SessionID;

            if (sessionID.HasValue)
            {
                msg.SessionID = sessionID.Value;
            }

            var steamID = this.SteamID;

            if (steamID != null)
            {
                msg.SteamID = steamID;
            }

            var serialized = msg.Serialize();

            try
            {
                DebugNetworkListener?.OnOutgoingNetworkMessage(msg.MsgType, serialized);
            }
            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(serialized);
            }
            catch (IOException)
            {
            }
            catch (SocketException)
            {
            }
        }
Example #9
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));
        }
Example #10
0
        /// <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)
            {
            }
        }
Example #11
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();
                }
            }
        }
Example #12
0
        /// <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 ( 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 );


            // 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 )
            {
            }
        }
Example #13
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 )
        {
            msg.SteamID = steamClient.SteamID;

            DebugLog.WriteLine( "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 );
            }
            catch ( IOException )
            {
            }
            catch ( SocketException )
            {
            }
        }
Example #14
0
        /// <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 )
            {
            }
        }
Example #15
0
 /// <summary>
 /// Sends the specified client net message.
 /// </summary>
 /// <param name="clientMsg">The client net message.</param>
 public abstract void Send( IClientMsg clientMsg );
Example #16
0
        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);
                }
            }
        }
Example #17
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();

            // 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();
            }
        }
Example #18
0
 /// <summary>
 /// Sends the specified client net message.
 /// </summary>
 /// <param name="clientMsg">The client net message.</param>
 public abstract void Send(IClientMsg clientMsg);
        public void Process()
        {
            Socket clientSocket = null;

            try
            {
                clientSocket = client.Client;
                var bytes       = new byte[4096];
                var byteRecieve = 0;

                while (true)
                {
                    var msgRecieved = Encoding.Unicode.GetString(bytes, 0, byteRecieve);

                    while (clientSocket.Available > 0)
                    {
                        byteRecieve  = clientSocket.Receive(bytes);
                        msgRecieved += Encoding.Unicode.GetString(bytes, 0, byteRecieve);
                    }

                    var    msg = msgRecieved.Split(' ');
                    string message;

                    if (msg.Length < 2)
                    {
                        continue;
                    }

                    switch (msg[0])
                    {
                    case ("GetAllProc"):
                        _clientMsg = new GetAllInfoMsg();
                        break;

                    case ("Restart"):
                        _clientMsg = new RestartProcMsg();
                        break;

                    case ("Stop"):
                        _clientMsg = new StopProcMsg();
                        break;
                    }

                    message = _clientMsg.CallBackMsg(msg[1]);

                    UnicodeEncoding encoder = new UnicodeEncoding();
                    byte[]          buffer  = encoder.GetBytes(message);

                    clientSocket.Send(buffer);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(string.Format("Server {0}", ex.Message));
            }
            finally
            {
                if (clientSocket != null)
                {
                    clientSocket.Close();
                }

                if (client != null)
                {
                    client.Close();
                }
            }
        }
Example #20
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 ) );
        }
Example #21
0
 public void HandleClientMsg( IClientMsg clientMsg )
     => OnClientMsgReceived( GetPacketMsg( clientMsg.Serialize() ) );
Example #22
0
 public void HandleClientMsg(IClientMsg clientMsg)
 => OnClientMsgReceived(GetPacketMsg(clientMsg.Serialize()));