Esempio n. 1
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);
     }
 }
Esempio n. 2
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);
               
            }
        }
Esempio 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);
                }
            }
        }
Esempio n. 4
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);

            }
        }