Пример #1
0
        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);
        }
Пример #2
0
        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.");
            }
        }
Пример #3
0
        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
            }
        }
Пример #4
0
        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(); }));
            }
        }
Пример #5
0
 public void Respond(string info)
 {
     ConsoleAdditions.WriteLine(info);
 }
Пример #6
0
 public void Fail(string error)
 {
     ConsoleAdditions.WriteLine($"§4{error}");
     Program.commandHandler.Execute($".help {label}");
 }
Пример #7
0
 public void Fail()
 {
     ConsoleAdditions.WriteLine($"§4Command execution failed. Please view the following information on {label}§4.");
     Program.commandHandler.Execute($".help {label}");
 }