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); } }
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(); }
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; }
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(); } }
public void Fail() { ConsoleAdditions.WriteLine($"§4Command execution failed. Please view the following information on {label}§4."); Program.commandHandler.Execute($".help {label}"); }