Skip to content

Commit

Permalink
[Kritor] Intrudoce Kritor (LagrangeDev#270)
Browse files Browse the repository at this point in the history
* [Kritor] Introduce Lagrange.Kritor

* [Kritor] Setup structure
  • Loading branch information
Linwenxuan authored Apr 1, 2024
1 parent 44477b9 commit 4257484
Show file tree
Hide file tree
Showing 38 changed files with 1,817 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Lagrange.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "SolutionI
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lagrange.Audio", "Lagrange.Audio\Lagrange.Audio.csproj", "{2D462D26-0FD5-40A9-A0C8-F7449117EE0E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lagrange.Kritor", "Lagrange.Kritor\Lagrange.Kritor.csproj", "{FD0A15C0-600E-44A9-BAA8-6FAE0A1CA7EE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -42,6 +44,10 @@ Global
{2D462D26-0FD5-40A9-A0C8-F7449117EE0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D462D26-0FD5-40A9-A0C8-F7449117EE0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D462D26-0FD5-40A9-A0C8-F7449117EE0E}.Release|Any CPU.Build.0 = Release|Any CPU
{FD0A15C0-600E-44A9-BAA8-6FAE0A1CA7EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD0A15C0-600E-44A9-BAA8-6FAE0A1CA7EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD0A15C0-600E-44A9-BAA8-6FAE0A1CA7EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD0A15C0-600E-44A9-BAA8-6FAE0A1CA7EE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
35 changes: 35 additions & 0 deletions Lagrange.Kritor/Lagrange.Kritor.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<Protobuf Include="Protos\auth\*" GrpcServices="Server"/>
<Protobuf Include="Protos\common\*" GrpcServices="Server"/>
<Protobuf Include="Protos\core\*" GrpcServices="Server"/>
<Protobuf Include="Protos\customization\*" GrpcServices="Server"/>
<Protobuf Include="Protos\developer\*" GrpcServices="Server"/>
<Protobuf Include="Protos\event\*" GrpcServices="Server"/>
<Protobuf Include="Protos\file\*" GrpcServices="Server"/>
<Protobuf Include="Protos\friend\*" GrpcServices="Server"/>
<Protobuf Include="Protos\group\*" GrpcServices="Server"/>
<Protobuf Include="Protos\guild\*" GrpcServices="Server"/>
<Protobuf Include="Protos\message\*" GrpcServices="Server"/>
<Protobuf Include="Protos\reverse\*" GrpcServices="Server"/>
<Protobuf Include="Protos\web\*" GrpcServices="Server"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.57.0"/>
<PackageReference Include="LiteDB" Version="5.0.17" />
<PackageReference Include="Net.Codecrete.QrCodeGenerator" Version="1.6.1" />
</ItemGroup>

<ItemGroup>
<Folder Include="Core\" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions Lagrange.Kritor/LagrangeApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Lagrange.Kritor;

public class LagrangeApp : IHost
{
private readonly IHost _hostApp;

public IServiceProvider Services => _hostApp.Services;

public ILogger<LagrangeApp> Logger { get; }

internal LagrangeApp(IHost host)
{
_hostApp = host;
Logger = Services.GetRequiredService<ILogger<LagrangeApp>>();
}

public void Dispose()
{
throw new NotImplementedException();
}

public async Task StartAsync(CancellationToken cancellationToken = new CancellationToken())
{
throw new NotImplementedException();
}

public async Task StopAsync(CancellationToken cancellationToken = new CancellationToken())
{
throw new NotImplementedException();
}
}
6 changes: 6 additions & 0 deletions Lagrange.Kritor/LagrangeAppBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Lagrange.Kritor;

public sealed class LagrangeAppBuilder
{

}
17 changes: 17 additions & 0 deletions Lagrange.Kritor/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Lagrange.Kritor;

internal static class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddGrpc();

var app = builder.Build();

app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");

app.Run();
}
}
23 changes: 23 additions & 0 deletions Lagrange.Kritor/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5211",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7233;http://localhost:5211",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
86 changes: 86 additions & 0 deletions Lagrange.Kritor/Protos/auth/authentication.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
syntax = "proto3";

package kritor.authentication;

option csharp_namespace = "Kritor.Authentication";
option java_multiple_files = true;
option java_package = "io.kritor.authentication";
option go_package = "grpc/kritor/authentication";

service AuthenticationService {
rpc Authenticate(AuthenticateRequest) returns (AuthenticateResponse);
rpc GetAuthenticationState(GetAuthenticationStateRequest) returns (GetAuthenticationStateResponse);

rpc GetTicket(GetTicketRequest) returns (GetTicketResponse);
rpc AddTicket(AddTicketRequest) returns (AddTicketResponse);
rpc DeleteTicket(DeleteTicketRequest) returns (DeleteTicketResponse);
}

/*
在某个账号授权成功之后,接下来所有的请求都必须围绕该账号,且禁止再次发送授权包。
*/
message AuthenticateRequest {
string account = 1; // 客户端连接认证账号
string ticket = 2; // 客户端连接认证ticket
}

message AuthenticateResponse {
enum AuthenticateResponseCode {
OK = 0;
NO_ACCOUNT = 1;
NO_TICKET = 2;
LOGIC_ERROR = 3;
}

AuthenticateResponseCode code = 1; // 认证结果
string msg = 2; // 错误信息
}

message GetAuthenticationStateRequest {
string account = 1; // 客户端连接认证账号
}

message GetAuthenticationStateResponse {
bool is_required = 1; // 是否需要认证
}


/* 所有对认证ticket增删查都需要使用super ticket */

enum TicketOperationResponseCode {
OK = 0;
ERROR = 1;
}

message GetTicketRequest {
string account = 1; // 客户端连接认证账号
string super_ticket = 2; // 客户端连接认证super ticket
}

message GetTicketResponse {
TicketOperationResponseCode code = 1;
string msg = 2;
repeated string tickets = 3; // 返回的客户端ticket,非super ticket
}

message AddTicketRequest {
string account = 1; // 客户端连接认证账号
string super_ticket = 2; // 客户端连接认证super ticket
string ticket = 3;
}

message AddTicketResponse {
TicketOperationResponseCode code = 1;
string msg = 2;
}

message DeleteTicketRequest {
string account = 1; // 客户端连接认证账号
string super_ticket = 2; // 客户端连接认证super ticket
string ticket = 3;
}

message DeleteTicketResponse {
TicketOperationResponseCode code = 1;
string msg = 2;
}
31 changes: 31 additions & 0 deletions Lagrange.Kritor/Protos/common/contact.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
syntax = "proto3";

package kritor.common;

option csharp_namespace = "Kritor.Common";
option java_multiple_files = true;
option java_package = "io.kritor.common";
option go_package = "grpc/kritor/common";

enum Scene {
GROUP = 0; // 群聊
FRIEND = 1; // 私聊
GUILD = 2; // 频道
STRANGER_FROM_GROUP = 10; // 群临时会话

// 以下类型为可选实现
NEARBY = 5; // 附近的人
STRANGER = 9; // 陌生人
}

message Contact {
Scene scene = 1;
string peer = 2; // 群聊则为群号 私聊则为uid 频道消息则为频道号
optional string sub_peer = 3; // 群临时聊天则为群号 频道消息则为子频道号 其它情况可不提供
}

message Sender {
string uid = 1;
optional uint64 uin = 2;
optional string nick = 3;
}
42 changes: 42 additions & 0 deletions Lagrange.Kritor/Protos/common/message_data.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
syntax = "proto3";

package kritor.common;

option csharp_namespace = "Kritor.Common";
option java_multiple_files = true;
option java_package = "io.kritor.common";
option go_package = "grpc/kritor/common";

import "Protos/common/contact.proto";
import "Protos/common/message_element.proto";

message PushMessageBody {
uint32 time = 1;
string message_id = 2;
uint64 message_seq = 3;
Contact contact = 4; // 从什么地方收到的信息
Sender sender = 5; // 发送者详细信息
repeated Element elements = 6; // 发的什么东西
}

message ForwardMessageBody {
oneof forward_message {
string message_id = 1;
PushMessageBody message = 2;
}
}

message EssenceMessageBody {
uint32 group_id = 1;
string sender_uid = 2;
uint64 sender_uin = 3;
string sender_nick = 4;
uint64 operator_uid = 5;
uint64 operator_uin = 6;
string operator_nick = 7;
uint32 operation_time = 8;
uint32 message_time = 9;
string message_id = 10;
uint64 message_seq = 11;
string json_elements = 12;
}
Loading

0 comments on commit 4257484

Please sign in to comment.