[增加]1. 增加Session的获取接口
This commit is contained in:
parent
ca2df65204
commit
ef1e28b6ff
|
@ -77,10 +77,23 @@ namespace GameFrameX.Launcher.Common.Session
|
|||
/// <summary>
|
||||
/// 发送消息
|
||||
/// </summary>
|
||||
/// <param name="messageObject"></param>
|
||||
public void WriteAsync(MessageObject messageObject)
|
||||
/// <param name="messageObject">消息对象</param>
|
||||
public void Write(MessageObject messageObject)
|
||||
{
|
||||
WorkChannel?.Write(messageObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息
|
||||
/// </summary>
|
||||
/// <param name="messageObject">消息对象</param>
|
||||
/// <param name="errorCode">消息错误码</param>
|
||||
public async void WriteAsync(MessageObject messageObject, int errorCode = 0)
|
||||
{
|
||||
if (WorkChannel != null)
|
||||
{
|
||||
await WorkChannel.WriteAsync(messageObject, errorCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -38,7 +38,7 @@ namespace GameFrameX.Launcher.Common.Session
|
|||
/// <param name="roleId">链接ID</param>
|
||||
public static void KickOffLineByUserId(long roleId)
|
||||
{
|
||||
var roleSession = SessionMap.Values.FirstOrDefault(m => m.RoleId == roleId);
|
||||
var roleSession = Get(m => m.RoleId == roleId);
|
||||
if (roleSession != null)
|
||||
{
|
||||
if (SessionMap.TryRemove(roleSession.Id, out var value) && ActorManager.HasActor(roleSession.ActorId))
|
||||
|
@ -48,6 +48,38 @@ namespace GameFrameX.Launcher.Common.Session
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据角色ID获取会话对象,且会话对象必须已经存在才会返回
|
||||
/// </summary>
|
||||
/// <param name="roleId">角色ID</param>
|
||||
/// <returns>会话对象</returns>
|
||||
public static Session GetByRoleId(long roleId)
|
||||
{
|
||||
var roleSession = Get(m => m.RoleId == roleId);
|
||||
if (roleSession != null && ActorManager.HasActor(roleSession.ActorId))
|
||||
{
|
||||
return roleSession;
|
||||
}
|
||||
|
||||
return roleSession;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据角色ID获取会话对象.且会话对象必须已经存在才会返回
|
||||
/// </summary>
|
||||
/// <param name="actorId"></param>
|
||||
/// <returns>会话对象</returns>
|
||||
public static Session GetByActorId(long actorId)
|
||||
{
|
||||
var roleSession = Get(m => m.ActorId == actorId);
|
||||
if (roleSession != null && ActorManager.HasActor(roleSession.ActorId))
|
||||
{
|
||||
return roleSession;
|
||||
}
|
||||
|
||||
return roleSession;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取连接会话
|
||||
/// </summary>
|
||||
|
@ -58,6 +90,26 @@ namespace GameFrameX.Launcher.Common.Session
|
|||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据查询条件获取会话对象
|
||||
/// </summary>
|
||||
/// <param name="predicate">查询条件</param>
|
||||
/// <returns>会话对象</returns>
|
||||
public static Session Get(Func<Session, bool> predicate)
|
||||
{
|
||||
return SessionMap.Values.FirstOrDefault(predicate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据查询条件获取会话对象列表
|
||||
/// </summary>
|
||||
/// <param name="predicate">查询条件</param>
|
||||
/// <returns>会话对象列表</returns>
|
||||
public static List<Session> GetList(Func<Session, bool> predicate)
|
||||
{
|
||||
return SessionMap.Values.Where(predicate).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除玩家
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue