水电费

This commit is contained in:
bob
2025-07-16 17:47:53 +08:00
parent 7cccd2a81c
commit 3bd1ffbb75
75 changed files with 2148 additions and 1265 deletions

View File

@@ -0,0 +1,38 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Authentication.Jwt;
using Fantasy.Network;
using Fantasy.Network.Interface;
using Fantasy.Platform.Net;
namespace Fantasy.Authentication.Handler;
public class C2A_LoginRequestHandler : MessageRPC<C2A_LoginRequest, A2C_LoginResponse>
{
protected override async FTask Run(Session session, C2A_LoginRequest request, A2C_LoginResponse response,
Action reply)
{
var scene = session.Scene;
var result = await AuthenticationHelper.Login(scene, request.Username, request.Password);
if (result.ErrorCode == 0)
{
// 通过配置表或其他方式拿到Gate服务器组的信息
var gates = SceneConfigData.Instance.GetSceneBySceneType(SceneType.Gate);
// 通过当前账号的ID拿到要分配Gate服务器
var gatePosition = result.AccountId % gates.Count;
// 通过计算出来的位置下标拿到Gate服务器的配置
var gateSceneConfig = gates[(int)gatePosition];
// 通过Gate的SceneConfig文件拿到外网的ID地址和端口
var outerPort = gateSceneConfig.OuterPort;
var processConfig = ProcessConfigData.Instance.Get(gateSceneConfig.ProcessConfigId);
var machineConfig = MachineConfigData.Instance.Get(processConfig.MachineId);
// 颁发一个ToKen令牌给客户端
response.ToKen = AuthenticationJwtHelper.GetToken(scene, result.AccountId,
$"{machineConfig.OuterIP}:{outerPort}", gateSceneConfig.Id);
}
response.ErrorCode = result.ErrorCode;
Log.Debug($"Login 当前的服务器是:{scene.SceneConfigId}");
}
}

View File

@@ -0,0 +1,25 @@
using Fantasy;
using Fantasy.Async;
using Fantasy.Network;
using Fantasy.Network.Interface;
namespace Fantasy.Authentication.Handler;
public sealed class C2A_RegisterRequestHandler : MessageRPC<C2A_RegisterRequest, A2C_RegisterResponse>
{
protected override async FTask Run(Session session, C2A_RegisterRequest request, A2C_RegisterResponse response,
Action reply)
{
if (!session.CheckInterval(2000))
{
// 返回这个3代表操作过于频繁。
response.ErrorCode = 3;
return;
}
session.SetTimeout(3000);
response.ErrorCode =
await AuthenticationHelper.Register(session.Scene, request.Username, request.Password, "用户注册");
Log.Debug($"Register 当前的服务器是:{session.Scene.SceneConfigId}");
}
}