Пример #1
0
        private static void ForwardMessage(iRTVOMessage incomingMessage)
        {
            var allRelayConnections = NetworkComms.GetExistingConnection();// (from current in NetworkComms.GetExistingConnection() where current != connection select current).ToArray();

            incomingMessage.Source = NetworkComms.NetworkIdentifier;

            logger.Info("Forwarding Command {0} to {1} Clients", incomingMessage.Command, allRelayConnections.Count);
            //We will now send the message to every other connection
            foreach (var relayConnection in allRelayConnections)
            {
                if (relayConnection.ConnectionInfo.NetworkIdentifier == incomingMessage.Source)
                {
                    logger.Debug("Not sending redundant message to {0}", incomingMessage.Source);
                    continue;
                }
                //We ensure we perform the send within a try catch
                //To ensure a single failed send will not prevent the
                //relay to all working connections.
                try { relayConnection.SendObject("iRTVOMessage", incomingMessage); }
                catch (CommsException ex)
                {
                    logger.Warn("Broadcast to {0} failed: {1}", relayConnection, ex.ToString());
                }
            }
        }
Пример #2
0
        public static void BroadcastMessage(string Command, params object[] Arguments)
        {
            string[] args = new string[Arguments.Length];
            for (int i = 0; i < Arguments.Length; i++)
            {
                args[i] = Convert.ToString(Arguments[i]);
            }

            iRTVOMessage m = new iRTVOMessage(NetworkComms.NetworkIdentifier, Command, args);

            BroadcastMessage(m);
        }
Пример #3
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);
     }
 }
Пример #4
0
        public static void SendMessage(string targetClient, string Command, params object[] Arguments)
        {
            if (!isServer)
            {
                throw new UnauthorizedAccessException("Only the server can call this function!");
            }

            string[] args = new string[Arguments.Length];
            for (int i = 0; i < Arguments.Length; i++)
            {
                args[i] = Convert.ToString(Arguments[i]);
            }

            iRTVOMessage m = new iRTVOMessage(NetworkComms.NetworkIdentifier, Command, args);

            var allRelayConnections = NetworkComms.GetExistingConnection();// (from current in NetworkComms.GetExistingConnection() where current != connection select current).ToArray();


            logger.Info("Sending Command {0} to {1} ", Command, targetClient);
            //We will now send the message to every other connection
            foreach (var relayConnection in allRelayConnections)
            {
                if (relayConnection.ConnectionInfo.NetworkIdentifier != targetClient)
                {
                    continue;
                }
                //We ensure we perform the send within a try catch
                //To ensure a single failed send will not prevent the
                //relay to all working connections.
                try { relayConnection.SendObject("iRTVOMessage", m); }
                catch (CommsException ex)
                {
                    logger.Warn("Broadcast to {0} failed: {1}", relayConnection, ex.ToString());
                }
            }
        }
Пример #5
0
        public static void BroadcastMessage(iRTVOMessage m)
        {
            if (isServer)                                                       // Server Broadcasts to all clients
            {
                var allRelayConnections = NetworkComms.GetExistingConnection(); // (from current in NetworkComms.GetExistingConnection() where current != connection select current).ToArray();


                logger.Debug("Broadcasting Command {0} to {1} Clients", m.Command, allRelayConnections.Count);
                //We will now send the message to every other connection
                foreach (var relayConnection in allRelayConnections)
                {
                    //We ensure we perform the send within a try catch
                    //To ensure a single failed send will not prevent the
                    //relay to all working connections.
                    try { relayConnection.SendObject("iRTVOMessage", m); }
                    catch (CommsException ex)
                    {
                        logger.Warn("Broadcast to {0} failed: {1}", relayConnection, ex.ToString());
                    }
                }

                return;
            }
            else // Client only sends to server
            {
                if (serverConnection != null)
                {
                    logger.Debug("Sending Command '{0}' to Server", m.Command);
                    try { serverConnection.SendObject("iRTVOMessage", m); }
                    catch (CommsException ex)
                    {
                        logger.Error("Sending of Command '{0}' failed: {1}", m.Command, ex.ToString());
                    }
                }
            }
        }
Пример #6
0
 public iRTVORemoteEvent(iRTVOMessage m)
 {
     Cancel  = false;
     Message = m;
 }
Пример #7
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);
                }
            }
        }
Пример #8
0
        public static void SendMessage(string targetClient, string Command , params object[] Arguments )
        {
            if (!isServer)
                throw new UnauthorizedAccessException("Only the server can call this function!");

            string[] args = new string[ Arguments.Length ];
            for(int i=0;i < Arguments.Length; i++)
                args[i] = Convert.ToString(Arguments[i]);

            iRTVOMessage m = new iRTVOMessage(NetworkComms.NetworkIdentifier, Command, args);
        
            var allRelayConnections = NetworkComms.GetExistingConnection();// (from current in NetworkComms.GetExistingConnection() where current != connection select current).ToArray();


            logger.Info("Sending Command {0} to {1} ", Command, targetClient);
            //We will now send the message to every other connection
            foreach (var relayConnection in allRelayConnections)
            {
                if (relayConnection.ConnectionInfo.NetworkIdentifier != targetClient)
                {                    
                    continue;
                }
                //We ensure we perform the send within a try catch
                //To ensure a single failed send will not prevent the
                //relay to all working connections.
                try { relayConnection.SendObject("iRTVOMessage", m); }
                catch (CommsException ex)
                {
                    logger.Warn("Broadcast to {0} failed: {1}", relayConnection, ex.ToString());
                }
            }
        }
Пример #9
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);
               
            }
        }
Пример #10
0
        private static void ForwardMessage(iRTVOMessage incomingMessage)
        {
            var allRelayConnections = NetworkComms.GetExistingConnection();// (from current in NetworkComms.GetExistingConnection() where current != connection select current).ToArray();
            incomingMessage.Source = NetworkComms.NetworkIdentifier;

            logger.Info("Forwarding Command {0} to {1} Clients", incomingMessage.Command, allRelayConnections.Count);
            //We will now send the message to every other connection
            foreach (var relayConnection in allRelayConnections)
            {
                if (relayConnection.ConnectionInfo.NetworkIdentifier == incomingMessage.Source)
                {
                    logger.Debug("Not sending redundant message to {0}", incomingMessage.Source);
                    continue;
                }
                //We ensure we perform the send within a try catch
                //To ensure a single failed send will not prevent the
                //relay to all working connections.
                try { relayConnection.SendObject("iRTVOMessage", incomingMessage); }
                catch (CommsException ex)
                {
                    logger.Warn("Broadcast to {0} failed: {1}", relayConnection, ex.ToString());
                }
            }
        }
Пример #11
0
        public static void BroadcastMessage( string Command , params object[] Arguments )
        {
            string[] args = new string[ Arguments.Length ];
            for(int i=0;i < Arguments.Length; i++)
                args[i] = Convert.ToString(Arguments[i]);

            iRTVOMessage m = new iRTVOMessage(NetworkComms.NetworkIdentifier, Command, args);

            BroadcastMessage(m);

        }
Пример #12
0
        public static void BroadcastMessage(iRTVOMessage m)
        {
            if (isServer) // Server Broadcasts to all clients
            {

                var allRelayConnections = NetworkComms.GetExistingConnection();// (from current in NetworkComms.GetExistingConnection() where current != connection select current).ToArray();


                logger.Debug("Broadcasting Command {0} to {1} Clients", m.Command, allRelayConnections.Count);
                //We will now send the message to every other connection
                foreach (var relayConnection in allRelayConnections)
                {
                    //We ensure we perform the send within a try catch
                    //To ensure a single failed send will not prevent the
                    //relay to all working connections.
                    try { relayConnection.SendObject("iRTVOMessage", m); }
                    catch (CommsException ex)
                    {
                        logger.Warn("Broadcast to {0} failed: {1}", relayConnection, ex.ToString());
                    }
                }

                return;
            }
            else // Client only sends to server
            {
                if (serverConnection != null)
                {
                    logger.Debug("Sending Command '{0}' to Server", m.Command);
                    try { serverConnection.SendObject("iRTVOMessage", m); }
                    catch (CommsException ex)
                    {
                        logger.Error("Sending of Command '{0}' failed: {1}", m.Command, ex.ToString());
                    }
                }
            }
        }
Пример #13
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);

            }
        }
Пример #14
0
 public iRTVORemoteEvent(iRTVOMessage m)
 {
     Cancel = false;
     Message = m;
 }