changed colours and added validation to more inputs
This commit is contained in:
parent
45a094a25f
commit
bd0a281a0b
1 changed files with 48 additions and 29 deletions
|
@ -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 {
|
||||||
if (input.Substring(0, 4).ToLower() == "echo")
|
displayError(input);
|
||||||
{
|
return;
|
||||||
display(input.Substring(5), Color.Green);
|
|
||||||
}
|
}
|
||||||
inputBox.Text = ""; //clear the contents after execution
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue