Meum/Meum.Client.CLI/Program.cs
2025-05-09 16:32:35 +05:00

104 lines
3.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

global using System;
global using System.Collections.Generic;
global using System.Threading;
global using System.Threading.Tasks;
global using Meum.Core;
using System.Net;
using System.Reflection;
using DTLib.Console;
using DTLib.Demystifier;
using DTLib.Extensions;
using DTLib.Logging;
namespace Meum.Client.CLI;
class Program
{
private const string greeting_art =
"""
^,,^ |
( ·) Meum! (o.o`7
/ ` | Meum... |`˜ \
\(_,J J L l`,)/
""";
private const string farewell_art =
"""
^,,^ |
( -.-) (>,<`7
/ ` | Goodbye! |`˜ \
\(_,J J L l`,)/
""";
static async Task Main(string[] args)
{
Console.OutputEncoding = StringConverter.UTF8;
Console.InputEncoding = StringConverter.UTF8;
ColoredConsole.Clear();
var loggerRoot = new ConsoleLogger();
try
{
var v = Assembly.GetExecutingAssembly().GetName().Version;
string title = $"Meum CLI v{v?.ToString(3) ?? "Null"}";
Console.Title = title;
Functions.InitMsQuic(loggerRoot);
ColoredConsole.WriteTitle(title, '=', fg: ConsoleColor.Cyan);
ColoredConsole.WriteLine(greeting_art, fg: ConsoleColor.Magenta);
ColoredConsole.WriteHLine('=', fg: ConsoleColor.Cyan);
UserAddress? userAddress = null;
DnsEndPoint? serverEndPoint = null;
string? serverAddress = null;
while (true)
{
try
{
if (userAddress == null)
{
ColoredConsole.Write("enter user address (name@server.xyz): ", ConsoleColor.Blue);
var addrstr = ColoredConsole.ReadLine(ConsoleColor.Cyan);
if (string.IsNullOrEmpty(addrstr))
continue;
userAddress = new(addrstr);
}
Client client = new(loggerRoot);
if (serverEndPoint == null)
{
ColoredConsole.Write("enter server address (server.xyz): ", ConsoleColor.Blue);
serverAddress = ColoredConsole.ReadLine(ConsoleColor.Cyan);
if (string.IsNullOrEmpty(serverAddress))
{
ColoredConsole.WriteLine("null address", ConsoleColor.Red);
continue;
}
serverEndPoint = Functions.ParseDnsEndPoint(serverAddress);
ColoredConsole.WriteTitle(serverAddress, fg: ConsoleColor.Cyan);
}
ColoredConsole.WriteLine("connecting to the server...", ConsoleColor.Blue);
var conn = await client.ConnectToServerAsync(serverEndPoint);
ColoredConsole.WriteLine("Connected to server", ConsoleColor.Green);
await Task.Delay(-1);
}
catch (Exception ex)
{
ColoredConsole.WriteLine(ex.ToStringDemystified(), ConsoleColor.Red);
}
}
}
catch (Exception ex)
{
ColoredConsole.WriteLine(ex.ToStringDemystified(), ConsoleColor.Red);
}
finally
{
Console.ResetColor();
}
}
}