This repository has been archived on 2026-11-17. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
uff_matrix/Program.cs
2021-05-11 16:00:34 +02:00

73 lines
2.5 KiB
C#

using System;
using System.Xml;
using Matrix.Client;
using Matrix.Structures;
namespace uff_matrix
{
static class Program
{
public static MatrixClient Client;
public static readonly XmlDocument XmlDoc = new XmlDocument();
static void Main(string[] args)
{
Commands.InitCommands();
// open config
XmlDoc.Load("/config/app.config");
//load config nodes
XmlNode appSettingsNode = XmlDoc.SelectSingleNode("appSettings");
var accessToken = appSettingsNode.SelectSingleNode("accesstoken");
var userId = appSettingsNode.SelectSingleNode("userid");
// we always want to reuse our old sessions
if (accessToken != null && userId != null)
{
Console.WriteLine("[login] found old session");
string homeserverUrl = appSettingsNode.SelectSingleNode("homeserverUrl").InnerText;
Client = new MatrixClient(homeserverUrl);
Client.UseExistingToken(userId.InnerText, accessToken.InnerText);
}
// generate new session
else
{
Console.WriteLine("[login] can't find old session, generating new one");
string username = appSettingsNode.SelectSingleNode("user").InnerText;
string password = appSettingsNode.SelectSingleNode("password").InnerText;;
string homeserverUrl = appSettingsNode.SelectSingleNode("homeserverUrl").InnerText;
Console.WriteLine("[login] got username from config: " + username);
Client = new MatrixClient(homeserverUrl);
MatrixLoginResponse login = Client.LoginWithPassword(username, password);
Helper.CreateConfigElement("appSettings", "userid", login.user_id);
Helper.CreateConfigElement("appSettings", "accesstoken", login.access_token);
var imageConfig = Program.XmlDoc.GetElementsByTagName("img");
if (imageConfig.Count == 0)
{
Helper.CreateConfigElement("appSettings", "img", null);
}
}
Console.WriteLine("[sync] Starting sync");
Client.StartSync();
InviteHandler.AcceptAllInvite();
foreach (var room in Client.GetAllRooms())
{
RegisterRoom.RegisterNewRoom(room);
}
}
}
}