83 lines
3.0 KiB
C#
83 lines
3.0 KiB
C#
|
using System;
|
|||
|
using System.Text;
|
|||
|
|
|||
|
namespace ET
|
|||
|
{
|
|||
|
[MessageHandler]
|
|||
|
public class C2G_LoginGateHandler : AMRpcHandler<C2G_LoginGate, G2C_LoginGate>
|
|||
|
{
|
|||
|
protected override async ETTask Run(Session session, C2G_LoginGate request, G2C_LoginGate response, Action reply)
|
|||
|
{
|
|||
|
Scene scene = session.DomainScene();
|
|||
|
if (scene == null)
|
|||
|
{
|
|||
|
response.Message = $"scene ==null ";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
var userId = scene.GetComponent<GateSessionKeyComponent>().Get(request.Key);
|
|||
|
if (userId == 0)
|
|||
|
{
|
|||
|
response.Error = ErrorCode.ERR_ConnectGateKeyError;
|
|||
|
response.Message = "Gate key验证失败!";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
var list = await DBComponent.Instance.Query<Account>(t => t.UserId == userId);
|
|||
|
Account account = list[0];
|
|||
|
if (account == null)
|
|||
|
{
|
|||
|
response.Message = "没有帐号!";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
if (account.identifyList == null)
|
|||
|
{
|
|||
|
account.identifyList = new();
|
|||
|
}
|
|||
|
if (request.Identify==null)
|
|||
|
{
|
|||
|
response.Message = "系统错误!";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
byte[] bytes = Encoding.UTF8.GetBytes(request.Identify);
|
|||
|
Utility.Encryption.GetSelfXorBytes(bytes, CryptionHelper.GetXorKey());
|
|||
|
string key = Encoding.UTF8.GetString(bytes);
|
|||
|
account.identifyList.Add(key);
|
|||
|
await DBComponent.Instance.Save(account);
|
|||
|
//!上线
|
|||
|
User user = await GateUserComponent.Instance.OnLine(session, userId, request.Platform);
|
|||
|
if (user == null)
|
|||
|
{
|
|||
|
response.Error = ErrorCode.ERR_ConnectGateKeyError;
|
|||
|
response.Message = "用户信息查询不到";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
if (AppConfig.inst.isHeartBeat)
|
|||
|
session.AddComponent<SessionIdleCheckerComponent, int, int, int>(3 * 1000, 5 * 1000, int.MaxValue);
|
|||
|
var component = session.AddComponent<SessionPlayerComponent>();
|
|||
|
component.User = user;
|
|||
|
session.AddComponent<MailBoxComponent, MailboxType>(MailboxType.GateSession);
|
|||
|
|
|||
|
|
|||
|
if (!user.hasRole)
|
|||
|
{
|
|||
|
response.HasRole = false;
|
|||
|
response.PlayerId = user.Id;
|
|||
|
response.ServerTime = TimeHelper.ClientNow();
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
response.PlayerId = user.Id;
|
|||
|
response.HasRole = true;
|
|||
|
response.JobId = user.JobId;
|
|||
|
response.SkinId = user.SkinId == 0 ? user.JobId : user.SkinId;
|
|||
|
response.ServerTime = TimeHelper.ClientNow();
|
|||
|
reply();
|
|||
|
await ETTask.CompletedTask;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|