2021-04-08 20:09:59 +08:00
|
|
|
|
using System;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
using System.Collections.Generic;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-11 19:50:39 +08:00
|
|
|
|
long userId = scene.GetComponent<GateSessionKeyComponent>().Get(request.Key);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (userId == 0)
|
|
|
|
|
{
|
|
|
|
|
response.Error = ErrorCode.ERR_ConnectGateKeyError;
|
|
|
|
|
response.Message = "Gate key验证失败!";
|
|
|
|
|
reply();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
List<Account> list = await DBComponent.Instance.Query<Account>(t => t.UserId == userId);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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);
|
2021-04-11 19:50:39 +08:00
|
|
|
|
SessionPlayerComponent component = session.AddComponent<SessionPlayerComponent>();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|