Пример #1
0
        // Receive incoming initial Connection messages from Clients...
        public static void AddToConnectionList(PacketHeader header, Connection connection, string Connection)
        {
            // Add incoming IP Address to HashSet list...
            ConnectionsList.Add(connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + "|" + Connection);

            // Respond to sender that they are succesfully connected.
            connection.SendObject("Connected", "CONNECTED!");
            Console.WriteLine("\n" + connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + " has CONNECTED!");

            // Send all active connections to all active connections for Client List.
            foreach (var item in NetworkComms.GetExistingConnection())
            {
                foreach (var items in ConnectionsList.Distinct())
                {
                    item.SendObject("Connection", items);
                }
            }

            /* Old method to create files on hard disk for testing the code...
               if (!File.Exists(ConnectionFilePath))
            {
                // Create a file to write to.
                using (StreamWriter sw = File.CreateText(ConnectionFilePath))
                {
                }
            }
            using (StreamWriter sw = File.AppendText(ConnectionFilePath))
            {
                sw.WriteLine(connection.ConnectionInfo.RemoteEndPoint.Address.ToString());
            } */
        }
        private static void AddToConnectionList_Server(PacketHeader header, Connection connection, string Connection)
        {
            // Add incoming IP Address to HashSet list...
            ConnectionsList_Server.Add(connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + "|" + Connection);

            // Respond to sender that they are succesfully connected.
            connection.SendObject("Connected", "CONNECTED!");
            //richTextBox1.AppendText("\n" + connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + " has CONNECTED!" + Environment.NewLine);

            // Send all active connections to all active connections for Client List.
            foreach (var item in NetworkComms.GetExistingConnection())
            {
                foreach (var items in ConnectionsList_Server.Distinct())
                {
                    item.SendObject("Connection", items);
                }
            }
        }
Пример #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 HandleNewConnection(Connection connection)
 {
     if (isServer) // if we are the server, start the handshake
     {
         logger.Info("Connection from {0} ({1}).", connection.ConnectionInfo.NetworkIdentifier,connection.ConnectionInfo);
         connection.SendObject("iRTVOAuthenticate"); // Signal client that it must authenticate to us;                
     }
     else
     {
         logger.Info("Connection to Server established");
         serverConnection = connection;
     }
 }
Пример #5
0
 private static void HandleAuthenticateRequest(PacketHeader header, Connection connection, object incomingMessage)
 {
     logger.Info("Authentication Request Received from {0} ({1})", connection.ConnectionInfo.NetworkIdentifier, connection);
     
     connection.SendObject("iRTVOMessage", new iRTVOMessage(NetworkComms.NetworkIdentifier,"AUTHENTICATE",_Password));
 }
Пример #6
0
 // Check Client version and send update signal if needed.
 public static void VersionCheck(PacketHeader header, Connection connection, string version)
 {
     if (version == LatestClientVersion)
     {
         Console.WriteLine(connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + " is up to date.");
         // Display all connected Clients...
         Console.WriteLine("\nCurrent Clients:");
         foreach (var item in ConnectionsList) { Console.WriteLine(item); }
     }
     else
     {
         connection.SendObject("version", LatestClientVersion);
         Console.WriteLine(connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + " is version " + version + ", and has been notified of available update.");
         // Display all connected Clients...
         Console.WriteLine("\nCurrent Clients:");
         foreach (var item in ConnectionsList) { Console.WriteLine(item); }
     }
 }
 // Check Client version and send update signal if needed.
 private static void VersionCheck_Server(PacketHeader header, Connection connection, string version)
 {
     if (version == LatestClientVersion)
     {
         richTextBox1.AppendText(connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + " is up to date." + Environment.NewLine);
         // Display all connected Clients...
         richTextBox1.AppendText("\nCurrent Clients:" + Environment.NewLine);
         foreach (var item in ConnectionsList_Server) { richTextBox1.AppendText(item + Environment.NewLine); }
     }
     else
     {
         connection.SendObject("version", LatestClientVersion);
         richTextBox1.AppendText(connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + " is version " + version + ", and has been notified of available update." + Environment.NewLine);
         // Display all connected Clients...
         richTextBox1.AppendText("\nCurrent Clients:"  + Environment.NewLine);
         foreach (var item in ConnectionsList_Server) { richTextBox1.AppendText(item + Environment.NewLine); }
     }
 }