Esempio n. 1
0
        /// <summary>
        /// Called when a client message is received from the network.
        /// </summary>
        /// <param name="packetMsg">The packet message.</param>
        protected virtual bool OnClientMsgReceived(IPacketMsg packetMsg)
        {
            if (packetMsg == null)
            {
                DebugLog.WriteLine("CMClient", "Packet message failed to parse, shutting down connection");
                Disconnect();
                return(false);
            }

            DebugLog.WriteLine("CMClient", "<- Recv'd EMsg: {0} ({1}) (Proto: {2})", packetMsg.MsgType, ( int )packetMsg.MsgType, packetMsg.IsProto);

            // Multi message gets logged down the line after it's decompressed
            if (packetMsg.MsgType != EMsg.Multi)
            {
                try
                {
                    DebugNetworkListener?.OnIncomingNetworkMessage(packetMsg.MsgType, packetMsg.GetData());
                }
                catch (Exception e)
                {
                    DebugLog.WriteLine("CMClient", "DebugNetworkListener threw an exception: {0}", e);
                }
            }

            switch (packetMsg.MsgType)
            {
            case EMsg.Multi:
                HandleMulti(packetMsg);
                break;

            case EMsg.ClientLogOnResponse:     // we handle this to get the SteamID/SessionID and to setup heartbeating
                HandleLogOnResponse(packetMsg);
                break;

            case EMsg.ClientLoggedOff:     // to stop heartbeating when we get logged off
                HandleLoggedOff(packetMsg);
                break;

            case EMsg.ClientServerList:     // Steam server list
                HandleServerList(packetMsg);
                break;

            case EMsg.ClientCMList:
                HandleCMList(packetMsg);
                break;

            case EMsg.ClientSessionToken:     // am session token
                HandleSessionToken(packetMsg);
                break;
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Called when a client message is received from the network.
        /// </summary>
        /// <param name="packetMsg">The packet message.</param>
        protected virtual bool OnClientMsgReceived([NotNullWhen(true)] IPacketMsg?packetMsg)
        {
            if (packetMsg == null)
            {
                LogDebug("CMClient", "Packet message failed to parse, shutting down connection");
                Disconnect(userInitiated: false);
                return(false);
            }

            // Multi message gets logged down the line after it's decompressed
            if (packetMsg.MsgType != EMsg.Multi)
            {
                try
                {
                    DebugNetworkListener?.OnIncomingNetworkMessage(packetMsg.MsgType, packetMsg.GetData());
                }
                catch (Exception e)
                {
                    LogDebug("CMClient", "DebugNetworkListener threw an exception: {0}", e);
                }
            }

            switch (packetMsg.MsgType)
            {
            case EMsg.Multi:
                HandleMulti(packetMsg);
                break;

            case EMsg.ClientLogOnResponse:     // we handle this to get the SteamID/SessionID and to setup heartbeating
                HandleLogOnResponse(packetMsg);
                break;

            case EMsg.ClientLoggedOff:     // to stop heartbeating when we get logged off
                HandleLoggedOff(packetMsg);
                break;

            case EMsg.ClientServerUnavailable:
                HandleServerUnavailable(packetMsg);
                break;

            case EMsg.ClientCMList:
                HandleCMList(packetMsg);
                break;

            case EMsg.ClientSessionToken:     // am session token
                HandleSessionToken(packetMsg);
                break;
            }

            return(true);
        }
Esempio n. 3
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)
            {
            }
        }
Esempio n. 4
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)
            {
            }
        }