static async Task Main(string[] args) { AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit); Console.CancelKeyPress += new ConsoleCancelEventHandler(OnProcessExit); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); chatViewer = new ChatViewer(); Task formTask = new Task(() => Application.Run(chatViewer)); Task consoleTask = new Task(() => { //chatViewer.Invoke(new Action(() => { chatViewer.Width = 500; })); Console.OutputEncoding = System.Text.Encoding.UTF8; connection = new SqlConnection("Server=GMRMLTV;Database=RyanAChatroomDB;User Id=sa;Password=GreatMinds110;"); connection.Open(); login = new Login(); rooms = new Rooms(); 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(), new ListRoomsCommand(), new FriendCommand(), new MailCommand()); while (running) { commandHandler.InputCommand(); } connection.Close(); }); formTask.Start(); consoleTask.Start(); Task.WaitAny(formTask, consoleTask); }
public void AttemptLogin(string username, string password) { DataTable table = Program.ExecuteUSP("usp_Login", ("@Username", username), ("@Password", password)); 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; Program.ExecuteUSP("usp_SetOnline", ("@UserID", userID), ("@Online", true)); LoadMail(); if (mail.Count == 0) { Console.WriteLine("You have no new mail"); } else { ConsoleAdditions.WriteLine($"You have §d{mail.Count} §7new mail!\nEnter '.mail read' to view these messages."); } }
public void Execute(string input) { if (input.Length == 0) { return; } 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);//26 } }
public void SendMessage(string input) { if (roomID == -1) { ConsoleAdditions.WriteLine(input); } else { Program.ExecuteUSP("usp_SendMessage", ("@Message", input), ("@Date", DateTime.Now), ("@UserID", Program.login.userID), ("@UserName", Program.login.username), ("@RoomID", roomID)); Console.Clear(); DataRow[] messages = Program.rooms.ReadMessages(); StringBuilder stringBuilder = new StringBuilder(); foreach (DataRow row in messages) { stringBuilder.Append(row[1]); stringBuilder.Append(": "); stringBuilder.AppendLine(row[0].ToString()); } Program.chatViewer.Invoke(new Action(() => { Program.chatViewer.label.Text = stringBuilder.ToString(); })); } }
public void Respond(string info) { ConsoleAdditions.WriteLine(info); }
public void Fail(string error) { ConsoleAdditions.WriteLine($"§4{error}"); Program.commandHandler.Execute($".help {label}"); }
public void Fail() { ConsoleAdditions.WriteLine($"§4Command execution failed. Please view the following information on {label}§4."); Program.commandHandler.Execute($".help {label}"); }
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); }