public void OnDisconnect(MobaClient client) { //每次下线的时候要通知好友显示离线状态 PlayerModel model = playerCache.GetModel(client); if (model != null) { string[] friends = model.FriendIdList.Split(','); foreach (string item in friends) { if (item.Equals("")) { continue; } int itemId = int.Parse(item); if (!playerCache.IsOnLine(itemId)) { continue; } MobaClient tempClient = playerCache.GetClient(itemId); Send(tempClient, OpCode.PlayerCode, OpPlayer.FriendOffLine, 0, "此玩家下线", model.Id); } matchCache.OffLine(client, playerCache.GetId(client)); playerCache.OffLine(client); } }
public void OnDisConnect(MOBAClient client) { //下线的时候,通知在线好友,显示离线状态 //***这里要通过客户端获取到玩家账号ID,再用账号ID获取到玩家ID,否则会报空 int accountID = accountCache.GetID(client); int playerID = playerCache.GetID(accountID); PlayerModel playerModel = playerCache.GetPlayerModel(playerID); if (playerModel != null) { foreach (int friendID in playerModel.FriendIdList) { if (!playerCache.IsOnLine(friendID)) //因为GetPlayerModel,GetClient是获取在线玩家的数据 { continue; } MOBAClient friendClient = playerCache.GetClient(friendID); Send(friendClient, OperationCode.PlayerCode, OpPlayer.FriendOnlineState, 1, "好友玩家下线", playerModel.Id); } } matchCache.OffLine(client, playerID); playerCache.OffLine(client); }