Exemple #1
0
        public void Execute(string input)
        {
            if (input[0] == '.')
            {
                string[] split = input.Split(' ');

                if (split.Count() == 0)
                {
                    return;
                }

                string[] args = new string[split.Count() - 1];
                for (int i = 0; i < args.Count(); i++)
                {
                    args[i] = split[i + 1];
                }
                string label = split[0];

                foreach (Command command in activeCommands)
                {
                    if (command.label.ToLower() == label || command.aliases.Contains(label))
                    {
                        command.Execute(args);
                        return;
                    }
                }
                ConsoleAdditions.WriteLine($"§7Command {label}§7 does not exist. Enter '.help' to see available commands.");
            }
            else
            {
                Program.rooms.SendMessage(input);
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            SqlConnection connection = new SqlConnection("Server=GMRMLTV;Database=RyanAChatroomDB;User Id=sa;Password=GreatMinds110;");

            connection.Open();

            login          = new Login(connection);
            rooms          = new Rooms(connection);
            commandHandler = new CommandHandler();

            ConsoleAdditions.WriteLine("Welcome to the §aCh@room§7.\nPlease login or register");
            while (!login.Success)
            {
                commandHandler.InputCommand();
            }

            commandHandler.Deregister("login", "register");
            commandHandler.Register(new ExitCommand(), new CreateRoomCommand(), new JoinCommand());

            while (running)
            {
                commandHandler.InputCommand();
            }

            connection.Close();
        }
Exemple #3
0
        public void AttemptLogin(string username, string password)
        {
            SqlCommand command = new SqlCommand();

            command.Connection  = connection;
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "usp_Login";

            command.Parameters.AddWithValue("@Username", username);
            command.Parameters.AddWithValue("@Password", password);

            DataTable      table   = new DataTable();
            SqlDataAdapter adapter = new SqlDataAdapter(command);

            adapter.Fill(table);

            Console.Clear();

            if (table.Rows.Count == 0)
            {
                if (!usernameExists(username))
                {
                    Console.WriteLine("Username does not exist. Please try again");
                    return;
                }
                else
                {
                    Console.WriteLine("Incorrect password. Please try again");
                    return;
                }
            }
            else
            {
                ConsoleAdditions.WriteLine($"Welcome §a{username}§7.");
                Success = true;
            }

            userID        = table.Rows[0]["UserID"].ToString();
            this.username = username;
        }
Exemple #4
0
        public void SendMessage(string input)
        {
            if (roomID == -1)
            {
                ConsoleAdditions.WriteLine(input);
            }
            else
            {
                SqlCommand command = new SqlCommand();
                command.Connection  = connection;
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "usp_SendMessage";

                command.Parameters.AddWithValue("@Message", input);
                command.Parameters.AddWithValue("@Date", DateTime.Now);
                command.Parameters.AddWithValue("@UserID", Program.login.userID);
                command.Parameters.AddWithValue("@UserName", Program.login.username);
                command.Parameters.AddWithValue("@RoomID", roomID);

                command.ExecuteNonQuery();
            }
        }
Exemple #5
0
        public void InputCommand()
        {
            ConsoleAdditions.Write("§7> ");
            string input               = "";
            int    inputLengthAtTab    = 0;
            int    commandEndingsIndex = 0;

            List <string> intendedCommandEndings = new List <string>();

            while (true)
            {
                var key = Console.ReadKey(true);
                if (key.Key == ConsoleKey.Enter)
                {
                    intendedCommandEndings.Clear();
                    Console.WriteLine();
                    break;
                }
                else if (key.Key == ConsoleKey.Tab)
                {
                    if (intendedCommandEndings.Count > 0)
                    {
                        commandEndingsIndex++;
                        if (commandEndingsIndex >= intendedCommandEndings.Count)
                        {
                            commandEndingsIndex = 0;
                        }

                        int inputLength = input.Length;

                        for (int i = inputLength; i > inputLengthAtTab; i--)
                        {
                            Console.Write('\x08');
                        }
                        for (int i = inputLength; i > inputLengthAtTab; i--)
                        {
                            Console.Write(' ');
                        }
                        for (int i = inputLength; i > inputLengthAtTab; i--)
                        {
                            Console.Write('\x08');
                        }
                        input = input.Substring(0, input.Length - (inputLength - inputLengthAtTab));

                        Console.Write(intendedCommandEndings[commandEndingsIndex]);
                        input += intendedCommandEndings[commandEndingsIndex];
                        continue;
                    }

                    string[] split = input.Split(' ');

                    inputLengthAtTab = input.Length;

                    if (split.Count() == 1)
                    {
                        foreach (Command command in activeCommands)
                        {
                            foreach (string alias in command.aliases)
                            {
                                if (alias.Length < split[0].Length)
                                {
                                    continue;
                                }
                                else if (alias.Substring(0, split[0].Length) == split[0].ToLower())
                                {
                                    intendedCommandEndings.Add(alias.Substring(split[0].Length));
                                }
                            }

                            if (command.label.Length < split[0].Length)
                            {
                                continue;
                            }
                            else if (command.label.Substring(0, split[0].Length) == split[0].ToLower())
                            {
                                intendedCommandEndings.Add(command.label.Substring(split[0].Length));
                            }
                        }
                    }

                    if (intendedCommandEndings.Count != 0)
                    {
                        Console.Write(intendedCommandEndings[0]);
                        input += intendedCommandEndings[0];
                    }
                }
                else if (key.Key == ConsoleKey.Backspace)
                {
                    intendedCommandEndings.Clear();
                    if (input.Length == 0)
                    {
                        continue;
                    }
                    Console.Write('\x08');
                    Console.Write(' ');
                    Console.Write('\x08');
                    input = input.Substring(0, input.Length - 1);
                }
                else
                {
                    intendedCommandEndings.Clear();
                    Console.Write(key.KeyChar);
                    input += key.KeyChar;
                }
            }

            Execute(input);
        }
Exemple #6
0
 public void Fail()
 {
     ConsoleAdditions.WriteLine($"§4Command execution failed. Please view the following information on {label}§4.");
     Program.commandHandler.Execute($".help {label}");
 }