示例#1
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)
            {
            }
        }
示例#2
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)
            {
            }
        }