From bd0a281a0b4fce5bb0b160b87d61ebc723ee6fd9 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 10 Jan 2015 23:17:04 +0000 Subject: [PATCH] changed colours and added validation to more inputs --- mainWindow.cs | 77 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 29 deletions(-) diff --git a/mainWindow.cs b/mainWindow.cs index 052cd1a..045b4f2 100644 --- a/mainWindow.cs +++ b/mainWindow.cs @@ -20,7 +20,7 @@ namespace Pithos } public void display(string text, Color colour) { /* Message Color Codes: - * Green: User Messages (Mainly Echo) + * Light Green: User Messages (Mainly Echo) * Orange: Admin Commands * Black: General text / Date * Red: Error Messages @@ -35,44 +35,63 @@ namespace Pithos output.SelectionLength = text.Length; output.SelectionColor = colour; output.SelectionStart = length + text.Length; - output.SelectionColor = Color.Black; + output.SelectionColor = Color.White; } private void mainWindow_Load(object sender, EventArgs e) { - display("Currently Logged in as: " + Environment.UserDomainName + "\\" + Environment.UserName, Color.Blue); + display("Currently Logged in as: " + Environment.UserDomainName + "\\" + Environment.UserName, Color.White); } - private void executeButton_Click(object sender, EventArgs e) - { - bool valid = true; + private void executeButton_Click(object sender, EventArgs e) { + bool valid = false; string input = inputBox.Text; if (input == "") { display("Error: No command given.", Color.Red); return; } //if its empty, dont bother decoding string initChar = input.Substring(0, 1); //gets the first character in the input string[] args = input.Substring(1).Split(' '); //splits the input by spaces, and removes init character - switch (initChar) - { - case "/": - if (args[0] == "exec") //runs a pithos program - { - pithosPrograms.decodeInput(input); - return; - } - else if (args[0] == "start") //runs a program (using cmd) - { - - } - else { valid = decoder.command(input); } //decode other commands - break; - case "¦": //admin commands - privateFunctions.adminCommands(input); - break; - } - - if (input.Substring(0, 4).ToLower() == "echo") - { - display(input.Substring(5), Color.Green); - } inputBox.Text = ""; //clear the contents after execution + try + { + switch (initChar) + { + case "/": + if (args[0] == "exec") //runs a pithos program + { + valid = pithosPrograms.decodeInput(input); + return; + } + else if (args[0] == "start") //runs a program (using cmd) + { + + } + else { valid = decoder.command(input); } //decode other commands + break; + + case "¦": //admin commands + if (!adminMode) { + display("Access Denied: Admin commands are currently disabled.", Color.Orange); + return; + } + valid = privateFunctions.adminCommands(input); + break; + + default: + break; + } + } catch { + displayError(input); + return; + } + if (!valid) { displayError(input); } + } + + private void displayError(string input) + { + display("Error: Command '" + input + "' is not recognised.", Color.Red); + } + + private void mainWindow_FormClosing(object sender, FormClosingEventArgs e) + { + Application.Exit(); } } }