Meum/Meum.Client.CLI/Program.cs
2025-05-08 21:48:57 +05:00

104 lines
3.7 KiB
C#
Raw 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.Net.Quic;
using System.Reflection;
using DTLib.Console;
using DTLib.Demystifier;
using DTLib.Extensions;
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.ResetColor();
try
{
var v = Assembly.GetExecutingAssembly().GetName().Version;
string title = $"Meum CLI v{v?.ToString(3) ?? "Null"}";
Console.Title = title;
if (!QuicConnection.IsSupported)
throw new Exception("Quic is not supported, check for presence of libmsquic and openssl");
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)
{
var addrstr =
ColoredConsole.ReadLine("enter user address (name@server.xyz)", ConsoleColor.Blue);
if (string.IsNullOrEmpty(addrstr))
continue;
userAddress = new(addrstr);
}
Client client = new();
if (serverEndPoint == null)
{
serverAddress = ColoredConsole.ReadLine("enter server address (server.xyz)", ConsoleColor.Blue);
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 conn.PingAsync();
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();
}
}
}