You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.1 KiB
60 lines
2.1 KiB
using System; |
|
|
|
namespace ET |
|
{ |
|
[FriendClass(typeof(RoleInfo))] |
|
public class C2A_GetRolesHandler : AMRpcHandler<C2A_GetRoles, A2C_GetRoles> |
|
{ |
|
protected override async ETTask Run(Session session, C2A_GetRoles request, A2C_GetRoles response, Action reply) |
|
{ |
|
if (session.DomainScene().SceneType != SceneType.Account) |
|
{ |
|
Log.Error($"请求的Scene错误,当前场景为:{session.DomainScene().SceneType}"); |
|
session.Dispose(); |
|
return; |
|
} |
|
|
|
if (session.GetComponent<SessionLockingComponent>() != null) |
|
{ |
|
response.Error = ErrorCode.ERR_RequestRepeadtedly; |
|
reply(); |
|
session.Disconnect().Coroutine(); |
|
return; |
|
} |
|
|
|
string token = session.DomainScene().GetComponent<TokenComponent>().Get(request.AccountId); |
|
|
|
if (token == null || token != request.Token) |
|
{ |
|
response.Error = ErrorCode.ERR_TokenError; |
|
reply(); |
|
session?.Disconnect().Coroutine(); |
|
return; |
|
} |
|
|
|
using (session.AddComponent<SessionLockingComponent>()) |
|
{ |
|
using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.CreateRole, request.AccountId)) |
|
{ |
|
var roleInfos = await DBManagerComponent.Instance.GetZoneDB(session.DomainZone()) |
|
.Query<RoleInfo>(d => d.AccountId == request.AccountId && d.ServerId == request.ServerId && d.State ==(int)RoleState.Normal); |
|
|
|
if (roleInfos == null || roleInfos.Count <= 0) |
|
{ |
|
reply(); |
|
return; |
|
} |
|
|
|
foreach (var roleInfo in roleInfos) |
|
{ |
|
response.RoleInfo.Add(roleInfo.ToMessage()); |
|
roleInfo?.Dispose(); |
|
} |
|
roleInfos.Clear(); |
|
|
|
reply(); |
|
} |
|
} |
|
} |
|
} |
|
} |