Esempio n. 1
0
        private void AttemptLogin(string[] user_pass)
        {
            string user = user_pass[0];
            string pass = user_pass[1];

            foreach (Client c in server.GetClients())
            {
                if (c.User == user)
                {
                    // use hashing techniques in Matches() function to validate user
                    if (c.Matches(user, pass))
                    {
                        clientSocket.Send(ASCIIEncoding.ASCII.GetBytes("[@" + user + "] You have successfully logged in."));
                        // we have logged in, set the proper client object
                        //  and notify UI update
                        this.client     = c;
                        client.LoggedIn = true;
                        if (updateUI != null)
                        {
                            updateUI();
                        }
                    }
                    else
                    {
                        // incorrect password
                        clientSocket.Send(ASCIIEncoding.ASCII.GetBytes("[@" + user + "] Incorrect login."));
                    }
                }
                else
                {
                    // incorrect username
                    clientSocket.Send(ASCIIEncoding.ASCII.GetBytes("[@" + user + "] Incorrect login."));
                }
            }
        }
        static void Main()
        {
            Server server = new Server("192.168.1.36", 3000);

            server.Start();

            // Example :

            Console.WriteLine("");
            Console.WriteLine("## HELP");
            Console.WriteLine(" - ls: list clients connected");

            while (server.IsRunning())
            {
                string msg = Console.ReadLine();
                if (!string.IsNullOrEmpty(msg))
                {
                    switch (msg)
                    {
                    case "ls":
                        Console.WriteLine("Clients connected:");
                        server.GetClients().ForEach((s) => { Console.WriteLine(" - " + s.RemoteEndPoint); });
                        break;
                    }
                }
            }
        }
Esempio n. 3
0
 private void UpdateFormUI()
 {
     if (server.GetClients().Count > 0)
     {
         Clients.Items.Clear();
         foreach (Client c in server.GetClients())
         {
             if (c.LoggedIn)
             {
                 Clients.Items.Add(c.User);
             }
             else
             {
                 Clients.Items.Add("[inactive] " + c.User);
             }
         }
     }
 }