changed colours and added validation to more inputs

This commit is contained in:
Jake Howard 2015-01-10 23:17:04 +00:00
parent 45a094a25f
commit bd0a281a0b

View file

@ -20,7 +20,7 @@ namespace Pithos
} }
public void display(string text, Color colour) { public void display(string text, Color colour) {
/* Message Color Codes: /* Message Color Codes:
* Green: User Messages (Mainly Echo) * Light Green: User Messages (Mainly Echo)
* Orange: Admin Commands * Orange: Admin Commands
* Black: General text / Date * Black: General text / Date
* Red: Error Messages * Red: Error Messages
@ -35,26 +35,28 @@ namespace Pithos
output.SelectionLength = text.Length; output.SelectionLength = text.Length;
output.SelectionColor = colour; output.SelectionColor = colour;
output.SelectionStart = length + text.Length; output.SelectionStart = length + text.Length;
output.SelectionColor = Color.Black; output.SelectionColor = Color.White;
} }
private void mainWindow_Load(object sender, EventArgs e) 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) private void executeButton_Click(object sender, EventArgs e) {
{ bool valid = false;
bool valid = true;
string input = inputBox.Text; string input = inputBox.Text;
if (input == "") { display("Error: No command given.", Color.Red); return; } //if its empty, dont bother decoding 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 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 string[] args = input.Substring(1).Split(' '); //splits the input by spaces, and removes init character
inputBox.Text = ""; //clear the contents after execution
try
{
switch (initChar) switch (initChar)
{ {
case "/": case "/":
if (args[0] == "exec") //runs a pithos program if (args[0] == "exec") //runs a pithos program
{ {
pithosPrograms.decodeInput(input); valid = pithosPrograms.decodeInput(input);
return; return;
} }
else if (args[0] == "start") //runs a program (using cmd) else if (args[0] == "start") //runs a program (using cmd)
@ -63,16 +65,33 @@ namespace Pithos
} }
else { valid = decoder.command(input); } //decode other commands else { valid = decoder.command(input); } //decode other commands
break; break;
case "¦": //admin commands case "¦": //admin commands
privateFunctions.adminCommands(input); if (!adminMode) {
display("Access Denied: Admin commands are currently disabled.", Color.Orange);
return;
}
valid = privateFunctions.adminCommands(input);
break;
default:
break; break;
} }
} catch {
displayError(input);
return;
}
if (!valid) { displayError(input); }
}
if (input.Substring(0, 4).ToLower() == "echo") private void displayError(string input)
{ {
display(input.Substring(5), Color.Green); display("Error: Command '" + input + "' is not recognised.", Color.Red);
} }
inputBox.Text = ""; //clear the contents after execution
private void mainWindow_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
} }
} }
} }