예제 #1
0
파일: Program.cs 프로젝트: CloseUpDK/iRTVO
        static void iRTVOConnection_ProcessMessage(iRTVORemoteEvent e)
        {
            Console.WriteLine("Received Command: " + e.Message.Command);
            switch (e.Message.Command.ToUpperInvariant())
            {               
                case "ADDCAM":
                    {
                        iRacingCameras[e.Message.Arguments[1].ToLowerInvariant()] = Convert.ToInt32(e.Message.Arguments[0]);
                        break;
                    }
                case "ADDDRIVER":
                    {
                        iRacingDrivers[e.Message.Arguments[1].ToLowerInvariant()] = Convert.ToInt32(e.Message.Arguments[0]);
                        break;
                    }
                case "ADDBUTTON":
                    {                        
                        iRacingButtons[e.Message.Arguments[1].ToLowerInvariant()] = e.Message.Arguments[0];
                        break;
                    }

                default:
                    break;

            }
        }
예제 #2
0
 public static void ProcessInternalMessage(iRTVOMessage incomingMessage)
 {
     if (isServer || (!isConnected))
     {
         iRTVORemoteEvent e = new iRTVORemoteEvent(incomingMessage);
         if (_ProcessMessage != null)
         {
             using (TimeCall tc = new TimeCall("ProcessInternalMessage"))
             {
                 _ProcessMessage(e);
                 if (isServer && e.Forward)
                 {
                     ForwardMessage(incomingMessage);
                 }
             }
         }
     }
     else
     {
         BroadcastMessage(incomingMessage);
     }
 }
예제 #3
0
        private static void HandleIncomingMessage(PacketHeader header, Connection connection, iRTVOMessage incomingMessage)
        {
            logger.Log(NLog.LogLevel.Debug,"HandleIncomingMessage: {0}", incomingMessage.ToString());
            
            if (isServer && (incomingMessage.Command == "AUTHENTICATE"))
            {
                if ((incomingMessage.Arguments == null) || (incomingMessage.Arguments.Count() != 1))
                {
                    logger.Error("HandleIncomingMessage: Wrong arguments to Authenticate from {0}", connection.ConnectionInfo.NetworkIdentifier);
                    connection.CloseConnection(false,-100);
                    return;
                }
                if (String.Compare(_Password, Convert.ToString(incomingMessage.Arguments[0])) != 0)
                {
                    logger.Error("HandleIncomingMessage: Worng Password from {0}", connection.ConnectionInfo.NetworkIdentifier);
                    connection.CloseConnection(false,-200);
                }
                logger.Info("Client {0} authenticated.", connection.ConnectionInfo.NetworkIdentifier);
                isAuthenticated[connection.ConnectionInfo.NetworkIdentifier] = true;
                connection.SendObject("iRTVOMessage", new iRTVOMessage(NetworkComms.NetworkIdentifier, "AUTHENTICATED"));
                if (_NewClient != null)
                    _NewClient(connection.ConnectionInfo.NetworkIdentifier);
                return;
            }

            if (!isServer && (incomingMessage.Command == "AUTHENTICATED"))
            {
                if (_ClientConnectionEstablished != null)
                    _ClientConnectionEstablished();
                return;
            }

            if (isServer && (!isAuthenticated.ContainsKey(connection.ConnectionInfo.NetworkIdentifier) ||  !isAuthenticated[connection.ConnectionInfo.NetworkIdentifier]))
            {
                logger.Warn("HandleIncomingMessage: Command from unauthorized client {0}",connection.ConnectionInfo.NetworkIdentifier);
                connection.CloseConnection(false,-300);
                return;
            }

            iRTVORemoteEvent e = new iRTVORemoteEvent(incomingMessage);
            if (_ProcessMessage != null)
            {
                using ( TimeCall tc = new TimeCall("ProcessMessage") )
                    _ProcessMessage(e);
            }
            // Handler signals to abort this connection!
            if (e.Cancel)
            {
                logger.Error("HandleIncomingMessage: ProcessMessage signaled to close client {0}", connection.ConnectionInfo.NetworkIdentifier);
                connection.CloseConnection(true, -400);
            }
            else
            {
               
                if (isServer && e.Forward)
                    ForwardMessage(incomingMessage);
               
            }
        }
예제 #4
0
        private static void HandleIncomingMessage(PacketHeader header, Connection connection, iRTVOMessage incomingMessage)
        {
            logger.Log(NLog.LogLevel.Debug, "HandleIncomingMessage: {0}", incomingMessage.ToString());

            if (isServer && (incomingMessage.Command == "AUTHENTICATE"))
            {
                if ((incomingMessage.Arguments == null) || (incomingMessage.Arguments.Count() != 1))
                {
                    logger.Error("HandleIncomingMessage: Wrong arguments to Authenticate from {0}", connection.ConnectionInfo.NetworkIdentifier);
                    connection.CloseConnection(false, -100);
                    return;
                }
                if (String.Compare(_Password, Convert.ToString(incomingMessage.Arguments[0])) != 0)
                {
                    logger.Error("HandleIncomingMessage: Worng Password from {0}", connection.ConnectionInfo.NetworkIdentifier);
                    connection.CloseConnection(false, -200);
                }
                logger.Info("Client {0} authenticated.", connection.ConnectionInfo.NetworkIdentifier);
                isAuthenticated[connection.ConnectionInfo.NetworkIdentifier] = true;
                connection.SendObject("iRTVOMessage", new iRTVOMessage(NetworkComms.NetworkIdentifier, "AUTHENTICATED"));
                if (_NewClient != null)
                {
                    _NewClient(connection.ConnectionInfo.NetworkIdentifier);
                }
                return;
            }

            if (!isServer && (incomingMessage.Command == "AUTHENTICATED"))
            {
                if (_ClientConnectionEstablished != null)
                {
                    _ClientConnectionEstablished();
                }
                return;
            }

            if (isServer && (!isAuthenticated.ContainsKey(connection.ConnectionInfo.NetworkIdentifier) || !isAuthenticated[connection.ConnectionInfo.NetworkIdentifier]))
            {
                logger.Warn("HandleIncomingMessage: Command from unauthorized client {0}", connection.ConnectionInfo.NetworkIdentifier);
                connection.CloseConnection(false, -300);
                return;
            }

            iRTVORemoteEvent e = new iRTVORemoteEvent(incomingMessage);

            if (_ProcessMessage != null)
            {
                using (TimeCall tc = new TimeCall("ProcessMessage"))
                    _ProcessMessage(e);
            }
            // Handler signals to abort this connection!
            if (e.Cancel)
            {
                logger.Error("HandleIncomingMessage: ProcessMessage signaled to close client {0}", connection.ConnectionInfo.NetworkIdentifier);
                connection.CloseConnection(true, -400);
            }
            else
            {
                if (isServer && e.Forward)
                {
                    ForwardMessage(incomingMessage);
                }
            }
        }
예제 #5
0
        public static void ProcessInternalMessage( iRTVOMessage incomingMessage )
        {
            if (isServer || (!isConnected))
            {
                iRTVORemoteEvent e = new iRTVORemoteEvent(incomingMessage);
                if (_ProcessMessage != null)
                {
                    using (TimeCall tc = new TimeCall("ProcessInternalMessage"))
                    {
                        _ProcessMessage(e);
                        if (isServer && e.Forward)
                            ForwardMessage(incomingMessage);
                    }
                }
            }
            else
            {
                BroadcastMessage(incomingMessage);

            }
        }