From e918cfe74543273b97ee86299c1bbcf37666deaf Mon Sep 17 00:00:00 2001 From: Yuuki Wesp Date: Tue, 22 Oct 2024 08:23:26 +0300 Subject: [PATCH 1/2] add fusion --- Argon.Server.sln | 7 +++++ src/Argon.Api/Argon.Api.csproj | 30 ++++++++++++--------- src/Argon.Api/Program.cs | 9 +++++++ src/Argon.Api/Services/UserAuthorization.cs | 14 ++++++++++ src/Argon.Contracts/Argon.Contracts.csproj | 22 +++++++++++++++ src/Argon.Contracts/IUserAuthorization.cs | 29 ++++++++++++++++++++ 6 files changed, 98 insertions(+), 13 deletions(-) create mode 100644 src/Argon.Api/Services/UserAuthorization.cs create mode 100644 src/Argon.Contracts/Argon.Contracts.csproj create mode 100644 src/Argon.Contracts/IUserAuthorization.cs diff --git a/Argon.Server.sln b/Argon.Server.sln index 1d05c002..596eb517 100644 --- a/Argon.Server.sln +++ b/Argon.Server.sln @@ -19,6 +19,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .gitmodules = .gitmodules EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Argon.Contracts", "src\Argon.Contracts\Argon.Contracts.csproj", "{151002BD-57E5-440B-9CA7-C681A69CA02C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -37,6 +39,10 @@ Global {D781D76E-6DD7-4C82-96D2-CA5D316BBF1E}.Debug|Any CPU.Build.0 = Debug|Any CPU {D781D76E-6DD7-4C82-96D2-CA5D316BBF1E}.Release|Any CPU.ActiveCfg = Release|Any CPU {D781D76E-6DD7-4C82-96D2-CA5D316BBF1E}.Release|Any CPU.Build.0 = Release|Any CPU + {151002BD-57E5-440B-9CA7-C681A69CA02C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {151002BD-57E5-440B-9CA7-C681A69CA02C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {151002BD-57E5-440B-9CA7-C681A69CA02C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {151002BD-57E5-440B-9CA7-C681A69CA02C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -45,6 +51,7 @@ Global {872FE764-2544-4E27-9193-BA625245F8D5} = {43C63C3C-90EB-4AED-BB15-B30F76F93A9E} {3AEA5748-B88E-45FF-B3DC-319A7A8D13B4} = {43C63C3C-90EB-4AED-BB15-B30F76F93A9E} {D781D76E-6DD7-4C82-96D2-CA5D316BBF1E} = {43C63C3C-90EB-4AED-BB15-B30F76F93A9E} + {151002BD-57E5-440B-9CA7-C681A69CA02C} = {43C63C3C-90EB-4AED-BB15-B30F76F93A9E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {576333C3-629F-47F8-BE21-3E82EDC2655D} diff --git a/src/Argon.Api/Argon.Api.csproj b/src/Argon.Api/Argon.Api.csproj index 24c3a4c3..7b3b2a21 100644 --- a/src/Argon.Api/Argon.Api.csproj +++ b/src/Argon.Api/Argon.Api.csproj @@ -8,27 +8,31 @@ - - - - - + + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + + + + - + + diff --git a/src/Argon.Api/Program.cs b/src/Argon.Api/Program.cs index 5403daf6..edadd741 100644 --- a/src/Argon.Api/Program.cs +++ b/src/Argon.Api/Program.cs @@ -1,7 +1,12 @@ +using ActualLab.Fusion; +using ActualLab.Fusion.Authentication; +using ActualLab.Rpc; +using ActualLab.Rpc.Server; using Argon.Api.Entities; using Argon.Api.Extensions; using Argon.Api.Migrations; using Argon.Api.Services; +using Argon.Contracts; using Argon.Sfu; var builder = WebApplication.CreateBuilder(args); @@ -10,6 +15,9 @@ builder.AddRedisOutputCache("cache"); builder.AddRabbitMQClient("rmq"); builder.AddNpgsqlDbContext("DefaultConnection"); +builder.Services.AddFusion(RpcServiceMode.Server, true) + .Rpc.AddServer() + .AddWebSocketServer(true); builder.Services.AddControllers(); builder.AddSwaggerWithAuthHeader(); builder.AddJwt(); @@ -25,6 +33,7 @@ app.UseAuthorization(); app.MapControllers(); app.MapDefaultEndpoints(); +app.MapRpcWebSocketServer(); var buildTime = File.GetLastWriteTimeUtc(typeof(Program).Assembly.Location); app.MapGet("/", () => new { buildTime }); await app.WarpUp().RunAsync(); \ No newline at end of file diff --git a/src/Argon.Api/Services/UserAuthorization.cs b/src/Argon.Api/Services/UserAuthorization.cs new file mode 100644 index 00000000..03aac0ba --- /dev/null +++ b/src/Argon.Api/Services/UserAuthorization.cs @@ -0,0 +1,14 @@ +namespace Argon.Api.Services; + +using Grains.Interfaces; +using Contracts; + +public class UserAuthorization(IGrainFactory grainFactory) : IUserAuthorization +{ + public async Task AuthorizeAsync(AuthorizeRequest request) + { + // TODO machineKey + var token = await grainFactory.GetGrain(request.username).Authenticate(request.password); + return new AuthorizeResponse(token, [new ServerResponse(Guid.NewGuid(), "xuita", null)]); + } +} \ No newline at end of file diff --git a/src/Argon.Contracts/Argon.Contracts.csproj b/src/Argon.Contracts/Argon.Contracts.csproj new file mode 100644 index 00000000..cd6dcee5 --- /dev/null +++ b/src/Argon.Contracts/Argon.Contracts.csproj @@ -0,0 +1,22 @@ + + + + net8.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/src/Argon.Contracts/IUserAuthorization.cs b/src/Argon.Contracts/IUserAuthorization.cs new file mode 100644 index 00000000..abcda690 --- /dev/null +++ b/src/Argon.Contracts/IUserAuthorization.cs @@ -0,0 +1,29 @@ +namespace Argon.Contracts; + +using System.Runtime.Serialization; +using ActualLab.Fusion; +using ActualLab.Rpc; +using MemoryPack; +using MessagePack; + +public interface IUserAuthorization : IRpcService +{ + Task AuthorizeAsync(AuthorizeRequest request); +} + +[DataContract, MemoryPackable(GenerateType.VersionTolerant), MessagePackObject] +public sealed partial record AuthorizeRequest( + [property: DataMember(Order = 0), MemoryPackOrder(0), Key(0)] string username, + [property: DataMember(Order = 1), MemoryPackOrder(1), Key(1)] string password, + [property: DataMember(Order = 2), MemoryPackOrder(2), Key(2)] string machineKey); + + +public sealed partial record ServerResponse( + [property: DataMember(Order = 0), MemoryPackOrder(0), Key(0)] Guid serverId, + [property: DataMember(Order = 1), MemoryPackOrder(1), Key(1)] string serverName, + [property: DataMember(Order = 2), MemoryPackOrder(2), Key(2)] string? avatarFileId +); + +public sealed partial record AuthorizeResponse( + [property: DataMember(Order = 0), MemoryPackOrder(0), Key(0)] string token, + [property: DataMember(Order = 1), MemoryPackOrder(1), Key(1)] List servers); \ No newline at end of file From 6b9ec82b0423a1259d6a325c855340260b052475 Mon Sep 17 00:00:00 2001 From: Yuuki Wesp Date: Tue, 22 Oct 2024 20:06:53 +0300 Subject: [PATCH 2/2] add ReSharper dotsetting --- Argon.Server.sln.DotSettings | 86 ++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/Argon.Server.sln.DotSettings b/Argon.Server.sln.DotSettings index d0863044..ee0defef 100644 --- a/Argon.Server.sln.DotSettings +++ b/Argon.Server.sln.DotSettings @@ -1,5 +1,91 @@  + True + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + DO_NOT_SHOW + True + True + True + Replace + Replace + True + True + True + Replace + False + False + True + True + False + False + True + False + True + False + False + True + <Policy><Descriptor Staticness="Any" AccessRightKinds="Private, Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="types_should_be_pascal_case"><ElementKinds><Kind Name="CLASS" /><Kind Name="STRUCT" /><Kind Name="INTERFACE" /><Kind Name="ENUM" /></ElementKinds></Descriptor><Policy Inspect="False" Prefix="" Suffix="" Style="AaBb" /></Policy> + False + True + True + False + 22107 + 12 + 12 + 12 + 9 + True + True + True + 10/22/2024 06:15:42 + 09/05/2024 19:44:56 + 10/22/2024 03:14:36 + VS + True + 09/16/2024 12:35:05 + 10/21/2024 17:06:09 + True + True + True + True + True + True + True + True + True + True + True + True + True + EnvironmentGeneral + False + 0.51914241960183771 + True + True + True + 2024.2.4.0 + 2024.2.4.0 + True True + True + True True + True True True \ No newline at end of file