Ejemplo n.º 1
0
        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;

            }
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
               
            }
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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);

            }
        }