1
0
Fork 0
This repository has been archived on 2019-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Galactic_Colors_Control/Galactic Colors Control Con.../Program.cs

99 lines
3.2 KiB
C#
Raw Normal View History

using Galactic_Colors_Control;
2016-11-13 00:26:03 +00:00
using Galactic_Colors_Control_Common;
using Galactic_Colors_Control_Common.Protocol;
using System;
2016-10-17 11:09:45 +00:00
using System.Reflection;
namespace Galactic_Colors_Control_Console
{
2016-11-13 00:26:03 +00:00
/// <summary>
/// Console Client
/// </summary>
2016-10-17 11:09:45 +00:00
internal class Program
{
private static Client client;
private static bool run = true;
2016-11-13 00:26:03 +00:00
private static char commandChar = '/';
2016-10-17 11:09:45 +00:00
private static void Main()
{
client = new Client();
2016-11-13 00:26:03 +00:00
client.OnEvent += new EventHandler(OnEvent); //Set OnEvent function
Console.Title = "Galactic Colors Control Client"; //Start display
2016-10-17 11:09:45 +00:00
Console.Write(">");
2016-11-13 00:26:03 +00:00
Common.ConsoleWrite("Galactic Colors Control Client", ConsoleColor.Red);
2016-11-14 14:09:44 +00:00
Common.ConsoleWrite("Console " + Assembly.GetEntryAssembly().GetName().Version.ToString(), ConsoleColor.Yellow);
2016-10-17 11:09:45 +00:00
bool hostSet = false;
2016-11-13 00:26:03 +00:00
while (!hostSet) //Request hostname
2016-10-17 11:09:45 +00:00
{
2016-11-13 00:26:03 +00:00
Common.ConsoleWrite("Enter server host:");
2016-10-17 11:09:45 +00:00
string host = client.ValidateHost(Console.ReadLine());
2016-11-13 00:26:03 +00:00
if (host[0] == '*')
2016-10-17 11:09:45 +00:00
{
2016-11-13 00:26:03 +00:00
host = host.Substring(1);
Common.ConsoleWrite(host, ConsoleColor.Red);
2016-10-17 11:09:45 +00:00
client.ResetHost();
}
else
{
2016-11-13 00:26:03 +00:00
Common.ConsoleWrite("Use " + host + "? y/n");
2016-10-17 11:09:45 +00:00
ConsoleKeyInfo c = new ConsoleKeyInfo();
while (c.Key != ConsoleKey.Y && c.Key != ConsoleKey.N)
2016-10-17 11:09:45 +00:00
{
c = Console.ReadKey();
}
if (c.Key == ConsoleKey.Y)
2016-10-17 11:09:45 +00:00
{
hostSet = true;
}
else
{
client.ResetHost();
}
}
}
2016-11-13 00:26:03 +00:00
if (client.ConnectHost()) //Try connection
2016-10-17 11:09:45 +00:00
{
run = true;
while (run)
{
2016-11-13 00:26:03 +00:00
Execute(Console.ReadLine()); //Process console input
2016-10-17 11:09:45 +00:00
if (!client.isRunning) { run = false; }
}
Console.Read();
}
else
{
2016-11-13 00:26:03 +00:00
Common.ConsoleWrite("Can't connect sorry. Bye", ConsoleColor.Red);
2016-10-17 11:09:45 +00:00
Console.Read();
}
}
2016-11-13 00:26:03 +00:00
private static void Execute(string input)
2016-10-17 11:09:45 +00:00
{
2016-11-13 00:26:03 +00:00
if (input == null)
return;
2016-10-20 21:09:48 +00:00
2016-11-13 00:26:03 +00:00
if (input.Length == 0)
return;
string[] req;
2016-11-14 14:09:44 +00:00
if (input[0] == commandChar)
2016-11-13 00:26:03 +00:00
{
input = input.Substring(1);
req = Common.SplitArgs(input);
2016-10-17 11:09:45 +00:00
}
2016-11-13 00:26:03 +00:00
else
{
req = Common.Strings("say", input);
}
Common.ConsoleWrite(client.Request(req).ToSmallString()); //Add processing (common)
2016-10-17 11:09:45 +00:00
}
2016-11-13 00:26:03 +00:00
private static void OnEvent(object sender, EventArgs e)
2016-10-17 11:09:45 +00:00
{
2016-11-13 00:26:03 +00:00
EventData eve = ((EventDataArgs)e).Data;
Common.ConsoleWrite(eve.ToSmallString()); //TODO add processing (common)
2016-10-17 11:09:45 +00:00
}
}
}