//玩家上线事件 public static async Task <User> UserOnLine(this GateUserComponent gateUserComponent, long userId, long sessionActorId) { User user = await UserHelp.QueryUserInfo(userId); if (user == null) { return(null); } user.IsOnLine = true;//改变在线状态 //给其他服务器广播玩家上线消息 gateUserComponent.BroadcastOnAndOffLineMessage(new G2S_UserOnline() { UserId = userId, SessionActorId = sessionActorId }); //记录玩家信息 gateUserComponent.mUserDic[userId] = user; return(user); }
//玩家下线事件 public static void UserOffline(this GateUserComponent gateUserComponent, long userId) { long gamerSeesionActorId = 0; if (gateUserComponent.mUserDic.ContainsKey(userId)) { gamerSeesionActorId = gateUserComponent.mUserDic[userId].GetUserClientSession().GetComponent <SessionUserComponent>().GamerSessionActorId; } if (gamerSeesionActorId != 0) { ActorHelp.SendeActor(gamerSeesionActorId, new Actor_UserOffLine());//告诉游戏服 用户下线 } if (gateUserComponent.mUserDic.ContainsKey(userId)) { gateUserComponent.mUserDic.Remove(userId); } //给其他服务器广播玩家下线消息 gateUserComponent.BroadcastOnAndOffLineMessage(new G2S_UserOffline() { UserId = userId }); }