summary refs log tree commit diff
path: root/ModAS.Server/Controllers
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-12-23 08:54:55 +0100
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-12-23 08:54:55 +0100
commite051007ecdb3097bc9942fd9db369101a9568a0d (patch)
tree8227a254a69ad7227cc230127ef4052dff9a08d1 /ModAS.Server/Controllers
downloadModAS-e051007ecdb3097bc9942fd9db369101a9568a0d.tar.xz
Basic test
Diffstat (limited to 'ModAS.Server/Controllers')
-rw-r--r--ModAS.Server/Controllers/DebugController.cs68
-rw-r--r--ModAS.Server/Controllers/HomeController.cs21
2 files changed, 89 insertions, 0 deletions
diff --git a/ModAS.Server/Controllers/DebugController.cs b/ModAS.Server/Controllers/DebugController.cs
new file mode 100644

index 0000000..39bff65 --- /dev/null +++ b/ModAS.Server/Controllers/DebugController.cs
@@ -0,0 +1,68 @@ +using ArcaneLibs.Extensions; +using LibMatrix; +using LibMatrix.Homeservers; +using Microsoft.AspNetCore.Mvc; +using ModAS.Server.Services; +using MxApiExtensions.Services; + +namespace WebApplication1.Controllers; + +[ApiController] +public class DebugController(ModASConfiguration config, AuthenticatedHomeserverProviderService authHsProvider) : ControllerBase { + [HttpGet("/_matrix/_modas/debug")] + public IActionResult Index() { + return Ok(new { + Request = Request.Headers, + Response = Response.Headers + }); + } + + [HttpGet("/_matrix/_modas/debug/config")] + public IActionResult Config() { + return Ok(config); + } + + [HttpGet("/_matrix/_modas/debug/known_users")] + public IActionResult KnownUsers() { + return Ok(authHsProvider.KnownUsers.Keys); + } + + [HttpGet("/_matrix/_modas/debug/test_locate_users")] + public async IAsyncEnumerable<string> TestLocateUsers([FromQuery] string startUser) { + List<string> foundUsers = [startUser], processedRooms = new List<string>(); + var foundNew = true; + while (foundNew) { + foundNew = false; + foreach (var user in foundUsers.ToList()) { + AuthenticatedHomeserverGeneric? ahs = null; + try { + ahs = await authHsProvider.GetImpersonatedHomeserver(user); + await ahs.GetJoinedRooms(); + } + catch (MatrixException e) { + if(e is {ErrorCode: "M_FORBIDDEN"}) continue; + throw; + } + + if(ahs is null) continue; + var rooms = await ahs.GetJoinedRooms(); + Console.WriteLine($"Got {rooms.Count} rooms"); + rooms.RemoveAll(r => processedRooms.Contains(r.RoomId)); + processedRooms.AddRange(rooms.Select(r => r.RoomId)); + foundNew = rooms.Count > 0; + Console.WriteLine($"Found {rooms.Count} new rooms"); + + var roomMemberTasks = rooms.Select(r => r.GetMembersListAsync(false)).ToAsyncEnumerable(); + await foreach (var roomMembers in roomMemberTasks) { + Console.WriteLine($"Got {roomMembers.Count} members"); + foreach (var member in roomMembers) { + if (!member.StateKey.EndsWith(':' + config.ServerName)) continue; + if (foundUsers.Contains(member.StateKey)) continue; + foundUsers.Add(member.StateKey); + yield return member.StateKey; + } + } + } + } + } +} \ No newline at end of file diff --git a/ModAS.Server/Controllers/HomeController.cs b/ModAS.Server/Controllers/HomeController.cs new file mode 100644
index 0000000..290441e --- /dev/null +++ b/ModAS.Server/Controllers/HomeController.cs
@@ -0,0 +1,21 @@ +using System.Diagnostics; +using Microsoft.AspNetCore.Mvc; + +namespace WebApplication1.Controllers; + +[ApiController] +public class HomeController : Controller +{ + private readonly ILogger<HomeController> _logger; + + public HomeController(ILogger<HomeController> logger) + { + _logger = logger; + } + + [HttpGet("/_matrix/_modas")] + public IActionResult Index() { + //return wwwroot/index.html + return LocalRedirect("/index.html"); + } +} \ No newline at end of file