You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.1 KiB
109 lines
3.1 KiB
using System; |
|
using System.IO; |
|
using MatrixDotNetLib; |
|
using Newtonsoft.Json; |
|
|
|
namespace MatrixDotNetCmd |
|
{ |
|
class Program |
|
{ |
|
static void Main(string[] args) |
|
{ |
|
// create new globals object |
|
Globals globals = new Globals(); |
|
|
|
// start output |
|
Console.WriteLine("MatrixDotNetLib v0.1 - A .NET Core library for Matrix"); |
|
|
|
// create a new Matrix session |
|
MatrixSessionManager session = new MatrixSessionManager(); |
|
|
|
// input server |
|
Console.Write("Enter Matrix server FQDN:"); |
|
string server = Console.ReadLine(); |
|
|
|
// input username |
|
Console.Write("Enter Matrix username:"); |
|
string user = Console.ReadLine(); |
|
|
|
// input pass |
|
string pass = ""; |
|
Console.Write("Enter Matrix password: "); |
|
|
|
// capture key input and replace with * in console session |
|
ConsoleKeyInfo key; |
|
|
|
do |
|
{ |
|
key = Console.ReadKey(true); |
|
|
|
// Backspace Should Not Work |
|
if (key.Key != ConsoleKey.Backspace) |
|
{ |
|
pass += key.KeyChar; |
|
Console.Write("*"); |
|
} |
|
else |
|
{ |
|
Console.Write("\b"); |
|
} |
|
} |
|
// stop once user hits Enter |
|
while (key.Key != ConsoleKey.Enter); |
|
|
|
pass = pass.Trim(); |
|
|
|
Console.WriteLine(); |
|
Console.WriteLine("Logging in..."); |
|
|
|
// log in to Matrix and get a token |
|
// response.Token |
|
try |
|
{ |
|
// create a new response object; trim password to remove added \r character |
|
MatrixLoginResponse response = session.Login(server, user, pass); |
|
|
|
// notify user is logged in |
|
Console.WriteLine("Logged in!"); |
|
|
|
// assign globals |
|
globals.Token = response.Token; |
|
globals.Server = server; |
|
globals.Session = response; |
|
|
|
MatrixUserRooms rooms = session.GetRooms(); |
|
|
|
// prompt user to choose a room |
|
// i guess we should find an alias for each room, if it exists |
|
|
|
Console.WriteLine(rooms.Joined[0]); |
|
} |
|
catch(Exception ex) |
|
{ |
|
// something bad happened |
|
Console.WriteLine("Error!"); |
|
|
|
// display the error code and message |
|
Console.WriteLine(ex.Message); |
|
} |
|
} |
|
} |
|
|
|
public class Globals |
|
{ |
|
/// <summary> |
|
/// Gets or sets login session token |
|
/// </summary> |
|
public string Token { get; set; } |
|
|
|
/// <summary> |
|
/// Gets or sets server FQDN |
|
/// </summary> |
|
public string Server { get; set; } |
|
|
|
/// <summary> |
|
/// Gets or sets the login session as an object |
|
/// </summary> |
|
public MatrixLoginResponse Session { get; set; } |
|
} |
|
}
|
|
|